Finger.cs 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using bbiwarg.Images;
  8. using bbiwarg.Utility;
  9. using bbiwarg.Graphics;
  10. using bbiwarg.Recognition.HandRecognition;
  11. using bbiwarg.Recognition.TouchRecognition;
  12. using bbiwarg.Recognition.Tracking;
  13. using Emgu.CV;
  14. namespace bbiwarg.Recognition.FingerRecognition
  15. {
  16. class Finger : TrackableObject
  17. {
  18. public Vector2D TipPoint { get { return SliceTrail.StartSlice.Mid; } }
  19. public Vector2D HandPoint { get { return SliceTrail.EndSlice.Mid; } }
  20. public Vector2D MidPoint { get { return SliceTrail.MidSlice.Mid; } }
  21. public Vector2D Direction { get { return LineSegment.Direction; } }
  22. public Vector2D TipDirection { get { return SliceTrail.getStartDirection(); } }
  23. public Vector2D HandDirection { get { return SliceTrail.getEndDirection(); } }
  24. public LineSegment2D LineSegment { get { return SliceTrail.LineSegment; } }
  25. public FingerSliceTrail SliceTrail { get; private set; }
  26. public Contour<Point> Contour { get { return SliceTrail.getContour(); } }
  27. public Hand Hand { get; private set; }
  28. public TouchEvent TouchEvent { get; private set; }
  29. public Finger(FingerSliceTrail sliceTrail)
  30. : base()
  31. {
  32. SliceTrail = sliceTrail;
  33. }
  34. public override float getSimilarity(TrackableObject compareObject)
  35. {
  36. Finger compareFinger = (Finger)compareObject;
  37. LineSegment2D compareLineSegment = compareFinger.LineSegment;
  38. Line2D compareLine = compareLineSegment.Line;
  39. //tip position
  40. float tipPointDistance = TipPoint.getDistanceTo(compareFinger.TipPoint);
  41. float tipPointSimilarity = Math.Max(0, 1 - tipPointDistance / Constants.ImageDiagonalLength);
  42. //hand position
  43. float handPointDistance = HandPoint.getDistanceTo(compareFinger.HandPoint);
  44. float handPointSimilarity = Math.Max(0, 1 - handPointDistance / Constants.ImageDiagonalLength);
  45. /*
  46. //check angle
  47. float angle = LineSegment.Line.getAngleBetween(compareLine);
  48. float angleSimilarity = Math.Max(1 - angle / Constants.FingerSimilarityMaxAngle, 0);
  49. //check parallel distance
  50. float parallelDistance = LineSegment.getParallelDistanceTo(compareLineSegment);
  51. float parallelDistanceSimilarity = Math.Max(1 - parallelDistance / Constants.FingerSimilarityMaxParallelDistance, 0);
  52. //check vertical distance
  53. float verticalDistance = LineSegment.getVerticalDistanceTo(compareLineSegment);
  54. float verticalDistanceSimilarity = Math.Max(1 - verticalDistance / Constants.FingerSimilarityMaxVerticalDistance, 0);
  55. */
  56. float similarity = tipPointSimilarity * handPointSimilarity;
  57. //float similarity = tipPointSimilarity * handPointSimilarity * angleSimilarity * parallelDistanceSimilarity * verticalDistanceSimilarity;
  58. //float similarity = (tipPointSimilarity + handPointSimilarity + angleSimilarity + parallelDistanceSimilarity + verticalDistanceSimilarity)/5;
  59. //float similarity = (angleSimilarity + parallelDistanceSimilarity + verticalDistanceSimilarity) / 3;
  60. return similarity;
  61. }
  62. public void setHand(Hand hand) {
  63. Hand = hand;
  64. }
  65. public void setTouchEvent(TouchEvent touchEvent) {
  66. TouchEvent = touchEvent;
  67. }
  68. }
  69. }