PalmImage.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 numRows = 4;
  46. int numColumns = 3;
  47. Vector2D relAB = (b - a) / numRows;
  48. Vector2D relDC = (c - d) / numRows;
  49. Vector2D relBC = (c - b) / numColumns;
  50. Vector2D relAD = (d - a) / numColumns;
  51. for (int i = 1; i < numRows; i++)
  52. {
  53. drawLine(new Emgu.CV.Structure.LineSegment2DF(a + i * relAB, d + i * relDC), PalmImageState.palmGrid);
  54. }
  55. for (int i = 1; i < numColumns; i++)
  56. {
  57. drawLine(new Emgu.CV.Structure.LineSegment2DF(a + i * relAD, b + i * relBC), PalmImageState.palmGrid);
  58. }
  59. }
  60. }
  61. }