Finger.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 Emgu.CV;
  8. using Emgu.CV.Structure;
  9. using bbiwarg.Images;
  10. using bbiwarg.Utility;
  11. namespace bbiwarg.Detectors.Fingers
  12. {
  13. class Finger
  14. {
  15. private Line2D line;
  16. public Line2D Line { get { return line; } }
  17. public Finger(Line2D line) {
  18. this.line = line;
  19. }
  20. public Vector2D getTipPoint() {
  21. if (line.P1.Y < line.P2.Y)
  22. return line.P1;
  23. else
  24. return line.P2;
  25. }
  26. public Vector2D getHandPoint() {
  27. if (line.P1.Y < line.P2.Y)
  28. return line.P2;
  29. else
  30. return line.P1;
  31. }
  32. public float getSimilarity(Finger compareFinger) {
  33. Line2D compareLine = compareFinger.Line;
  34. //thresholds
  35. float thresholdMaxAngle = (float)(30 * Math.PI / 180); // 30°
  36. float thresholdMaxParallelDistance = 40;
  37. float thresholdMaxVerticalDistance = 40;
  38. //check angle
  39. float angle = Line.getAngleBetween(compareLine);
  40. float angleSimilarity = Math.Max(1 - angle / thresholdMaxAngle, 0);
  41. //check parallel distance
  42. float parallelDistance = Line.getParallelDistanceTo(compareLine);
  43. float parallelDistanceSimilarity = Math.Max(1 - parallelDistance / thresholdMaxParallelDistance, 0);
  44. //check vertical distance
  45. float verticalDistance = Line.getVerticalDistanceTo(compareLine);
  46. float verticalDistanceSimilarity = Math.Max(1 - verticalDistance / thresholdMaxVerticalDistance, 0);
  47. return (angleSimilarity + parallelDistanceSimilarity + verticalDistanceSimilarity) / 3;
  48. }
  49. }
  50. }