1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using bbiwarg.Images;
- using bbiwarg.Utility;
- namespace bbiwarg.Detectors.Fingers
- {
- class Finger
- {
- private FingerSliceTrail sliceTrail;
- public Vector2D Tip { get { return sliceTrail.Start.Mid; } }
- public Vector2D Hand { get { return sliceTrail.End.Mid; } }
- public LineSegment2D LineSegment { get { return sliceTrail.LineSegment; } }
- public FingerSliceTrail SliceTrail { get { return sliceTrail; } private set { sliceTrail = value; } }
- public Finger(FingerSliceTrail sliceTrail)
- {
- SliceTrail = sliceTrail;
- }
- public float getSimilarity(Finger compareFinger)
- {
- LineSegment2D compareLineSegment = compareFinger.LineSegment;
- Line2D compareLine = compareLineSegment.Line;
- //thresholds
- float thresholdMaxAngle = (float)(30 * Math.PI / 180); // 30°
- float thresholdMaxParallelDistance = 40;
- float thresholdMaxVerticalDistance = 40;
- //check angle
- float angle = LineSegment.Line.getAngleBetween(compareLine);
- float angleSimilarity = Math.Max(1 - angle / thresholdMaxAngle, 0);
- //check parallel distance
- float parallelDistance = LineSegment.getParallelDistanceTo(compareLineSegment);
- float parallelDistanceSimilarity = Math.Max(1 - parallelDistance / thresholdMaxParallelDistance, 0);
- //check vertical distance
- float verticalDistance = LineSegment.getVerticalDistanceTo(compareLineSegment);
- float verticalDistanceSimilarity = Math.Max(1 - verticalDistance / thresholdMaxVerticalDistance, 0);
- return (angleSimilarity + parallelDistanceSimilarity + verticalDistanceSimilarity) / 3;
- }
- }
- }
|