PalmImage.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Emgu.CV;
  7. using Emgu.CV.Structure;
  8. using System.Drawing;
  9. using bbiwarg.Detectors.Fingers;
  10. using bbiwarg.Utility;
  11. using bbiwarg.Detectors.Touch;
  12. namespace bbiwarg.Images
  13. {
  14. public enum PalmImageState
  15. {
  16. none = 0,
  17. palmContour = 1,
  18. wristLine = 2,
  19. thumbLine = 3,
  20. palmRect = 4,
  21. palmGrid = 5
  22. }
  23. class PalmImage
  24. {
  25. private Image<Gray, Byte> image;
  26. public PalmImage(int width, int height)
  27. {
  28. image = new Image<Gray, byte>(width, height);
  29. }
  30. public PalmImageState getStateAt(int x, int y)
  31. {
  32. return (PalmImageState)image.Data[y, x, 0];
  33. }
  34. public void drawContour(Contour<Point> contour)
  35. {
  36. image.Draw(contour.GetConvexHull(Emgu.CV.CvEnum.ORIENTATION.CV_CLOCKWISE), new Gray((byte)PalmImageState.palmContour), 1);
  37. //image.Draw(contour, new Gray((byte)PalmImageState.palmContour), 1);
  38. }
  39. public void drawLine(LineSegment2DF line, PalmImageState state)
  40. {
  41. image.Draw(line, new Gray((byte)state), 1);
  42. }
  43. public void drawGrid(Vector2D a, Vector2D b, Vector2D c, Vector2D d)
  44. {
  45. int columnCount = 4;
  46. int rowCount = 3;
  47. Vector2D bc = c - b;
  48. for (int i = 1; i < columnCount; i++)
  49. {
  50. Vector2D bci = b + (bc * ((float)i/columnCount));
  51. Vector2D adi = a + (bc * ((float)i/columnCount));
  52. drawLine(new LineSegment2DF(bci, adi), PalmImageState.palmGrid);
  53. }
  54. Vector2D ab = b - a;
  55. for (int i = 1; i < rowCount; i++)
  56. {
  57. Vector2D abi = a + (ab * ((float)i / rowCount));
  58. Vector2D dci = d + (ab * ((float)i / rowCount));
  59. drawLine(new LineSegment2DF(abi, dci), PalmImageState.palmGrid);
  60. }
  61. }
  62. }
  63. }