12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Emgu.CV;
- using Emgu.CV.Structure;
- using bbiwarg.Images;
- using bbiwarg.Utility;
- namespace bbiwarg.Detectors.Fingers
- {
- class Finger
- {
- private Line2D line;
- public Line2D Line { get { return line; } }
- public Finger(Line2D line) {
- this.line = line;
- }
- public Vector2D getTipPoint() {
- if (line.P1.Y < line.P2.Y)
- return line.P1;
- else
- return line.P2;
- }
- public Vector2D getHandPoint() {
- if (line.P1.Y < line.P2.Y)
- return line.P2;
- else
- return line.P1;
- }
- public float getSimilarity(Finger compareFinger) {
- Line2D compareLine = compareFinger.Line;
- //thresholds
- float thresholdMaxAngle = (float)(30 * Math.PI / 180); // 30°
- float thresholdMaxParallelDistance = 40;
- float thresholdMaxVerticalDistance = 40;
- //check angle
- float angle = Line.getAngleBetween(compareLine);
- float angleSimilarity = Math.Max(1 - angle / thresholdMaxAngle, 0);
- //check parallel distance
- float parallelDistance = Line.getParallelDistanceTo(compareLine);
- float parallelDistanceSimilarity = Math.Max(1 - parallelDistance / thresholdMaxParallelDistance, 0);
- //check vertical distance
- float verticalDistance = Line.getVerticalDistanceTo(compareLine);
- float verticalDistanceSimilarity = Math.Max(1 - verticalDistance / thresholdMaxVerticalDistance, 0);
- return (angleSimilarity + parallelDistanceSimilarity + verticalDistanceSimilarity) / 3;
- }
- }
- }
|