PalmDetector.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using bbiwarg.Recognition.HandRecognition;
  7. using bbiwarg.Utility;
  8. using Emgu.CV.Structure;
  9. using Emgu.CV;
  10. namespace bbiwarg.Recognition.PalmRecognition
  11. {
  12. class PalmDetector
  13. {
  14. private List<Hand> hands;
  15. private List<Hand> palmHands;
  16. public List<Palm> Palms { get; private set; }
  17. public PalmDetector(List<Hand> hands)
  18. {
  19. this.hands = hands;
  20. findPalmHands();
  21. createPalms();
  22. }
  23. private void findPalmHands()
  24. {
  25. palmHands = new List<Hand>();
  26. foreach (Hand hand in hands)
  27. {
  28. if (hand.ThumbDefect != null)
  29. palmHands.Add(hand);
  30. }
  31. }
  32. private void createPalms()
  33. {
  34. Palms = new List<Palm>();
  35. foreach (Hand palmHand in palmHands)
  36. {
  37. ConvexityDefect thumbDefect = palmHand.ThumbDefect;
  38. Vector2D handLength = 1.5f*thumbDefect.VectorLong;
  39. Vector2D handWidth = 0.45f*handLength.getOrthogonal(palmHand.Side == HandSide.Right);
  40. Vector2D fingersUpper = thumbDefect.Inner + 0.75f*handLength;
  41. Vector2D wristUpper = thumbDefect.Inner - 0.25f*handLength;
  42. Vector2D wristLower = wristUpper + handWidth;
  43. Vector2D fingersLower = wristLower + 0.75f * handLength - 0.2f * handWidth;
  44. Palm palm = new Palm(palmHand, wristUpper, wristLower, fingersLower, fingersUpper);
  45. Palms.Add(palm);
  46. palmHand.setPalm(palm);
  47. }
  48. }
  49. }
  50. }