Hand.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 bbiwarg.Recognition.FingerRecognition;
  9. using bbiwarg.Utility;
  10. namespace bbiwarg.Recognition.HandRecognition
  11. {
  12. class Hand
  13. {
  14. public enum HandSide
  15. {
  16. Left,
  17. Right
  18. }
  19. public Vector2D Centroid { private set; get; }
  20. public HandSide Side { get; set; }
  21. public Image<Gray, byte> Mask { get; private set; }
  22. public List<Finger> Fingers { get; private set; }
  23. public Hand(Image<Gray, byte> mask)
  24. {
  25. Mask = mask;
  26. Centroid = getCentroid();
  27. Fingers = new List<Finger>();
  28. }
  29. public bool isInside(Vector2D point)
  30. {
  31. return (Mask.Data[point.IntY, point.IntX, 0] != 0);
  32. }
  33. public void addFinger(Finger finger)
  34. {
  35. Fingers.Add(finger);
  36. }
  37. private Vector2D getCentroid()
  38. {
  39. MCvPoint2D64f gravityCenter = Mask.GetMoments(true).GravityCenter;
  40. return new Vector2D((float)gravityCenter.x, (float)gravityCenter.y);
  41. }
  42. }
  43. }