Palm.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using bbiwarg.Utility;
  7. using bbiwarg.Recognition.HandRecognition;
  8. using bbiwarg.Recognition.Tracking;
  9. namespace bbiwarg.Recognition.PalmRecognition
  10. {
  11. public enum HandSide
  12. {
  13. Undefined = 0,
  14. Right = 1,
  15. Left = 2
  16. }
  17. public class Palm : TrackableObject
  18. {
  19. public Hand Hand { get; private set; }
  20. public ConvexityDefect ThumbDefect { get; private set; }
  21. public HandSide HandSide { get; private set; }
  22. public Vector2D WristUpper { get; private set; }
  23. public Vector2D FingersUpper { get; private set; }
  24. public Vector2D FingersLower { get; private set; }
  25. public Vector2D WristLower { get; private set; }
  26. public Quadrangle Quad { get; private set; }
  27. public Palm(Hand hand, ConvexityDefect thumbDefect, HandSide handSide, Vector2D wristUpper, Vector2D fingersUpper, Vector2D fingersLower, Vector2D wristLower)
  28. {
  29. Hand = hand;
  30. ThumbDefect = thumbDefect;
  31. HandSide = handSide;
  32. WristUpper = wristUpper;
  33. FingersUpper = fingersUpper;
  34. FingersLower = fingersLower;
  35. WristLower = wristLower;
  36. hand.Palm = this;
  37. createQuad();
  38. }
  39. public Vector2D getRelativePosition(Vector2D absolutePosition)
  40. {
  41. Vector2D relativePosition = Quad.getRelativePosition(absolutePosition);
  42. float x = Math.Max(0, Math.Min(1, relativePosition.X));
  43. float y = Math.Max(0, Math.Min(1, relativePosition.Y));
  44. return new Vector2D(x, y);
  45. }
  46. public bool isInside(Vector2D position)
  47. {
  48. return Quad.isInside(position, Parameters.PalmInsideTolerance);
  49. }
  50. private void createQuad()
  51. {
  52. if (HandSide == HandSide.Left)
  53. Quad = new Quadrangle(WristUpper, FingersUpper, FingersLower, WristLower);
  54. else
  55. Quad = new Quadrangle(FingersUpper, WristUpper, WristLower, FingersLower);
  56. }
  57. }
  58. }