Finger.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. namespace bbiwarg.Detectors.Fingers
  10. {
  11. class Finger
  12. {
  13. private FingerSliceTrail sliceTrail;
  14. public Vector2D Tip { get { return sliceTrail.Start.Mid; } }
  15. public Vector2D Hand { get { return sliceTrail.End.Mid; } }
  16. public LineSegment2D LineSegment { get { return sliceTrail.LineSegment; } }
  17. public FingerSliceTrail SliceTrail { get { return sliceTrail; } private set { sliceTrail = value; } }
  18. public Finger(FingerSliceTrail sliceTrail)
  19. {
  20. SliceTrail = sliceTrail;
  21. }
  22. public float getSimilarity(Finger compareFinger)
  23. {
  24. LineSegment2D compareLineSegment = compareFinger.LineSegment;
  25. Line2D compareLine = compareLineSegment.Line;
  26. //thresholds
  27. float thresholdMaxAngle = (float)(30 * Math.PI / 180); // 30°
  28. float thresholdMaxParallelDistance = 40;
  29. float thresholdMaxVerticalDistance = 40;
  30. //check angle
  31. float angle = LineSegment.Line.getAngleBetween(compareLine);
  32. float angleSimilarity = Math.Max(1 - angle / thresholdMaxAngle, 0);
  33. //check parallel distance
  34. float parallelDistance = LineSegment.getParallelDistanceTo(compareLineSegment);
  35. float parallelDistanceSimilarity = Math.Max(1 - parallelDistance / thresholdMaxParallelDistance, 0);
  36. //check vertical distance
  37. float verticalDistance = LineSegment.getVerticalDistanceTo(compareLineSegment);
  38. float verticalDistanceSimilarity = Math.Max(1 - verticalDistance / thresholdMaxVerticalDistance, 0);
  39. return (angleSimilarity + parallelDistanceSimilarity + verticalDistanceSimilarity) / 3;
  40. }
  41. }
  42. }