12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- 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;
- using bbiwarg.Graphics;
- using bbiwarg.Recognition.HandRecognition;
- using bbiwarg.Recognition.TouchRecognition;
- using bbiwarg.Recognition.Tracking;
- using Emgu.CV;
- namespace bbiwarg.Recognition.FingerRecognition
- {
- class Finger : TrackableObject
- {
- public Vector2D TipPoint { get { return SliceTrail.StartSlice.Mid; } }
- public Vector2D HandPoint { get { return SliceTrail.EndSlice.Mid; } }
- public Vector2D MidPoint { get { return SliceTrail.MidSlice.Mid; } }
- public Vector2D Direction { get { return LineSegment.Direction; } }
- public Vector2D TipDirection { get { return SliceTrail.getStartDirection(); } }
- public Vector2D HandDirection { get { return SliceTrail.getEndDirection(); } }
- public LineSegment2D LineSegment { get { return SliceTrail.LineSegment; } }
- public FingerSliceTrail SliceTrail { get; private set; }
- public Contour<Point> Contour { get { return SliceTrail.getContour(); } }
- public Hand Hand { get; private set; }
- public TouchEvent TouchEvent { get; private set; }
- public Finger(FingerSliceTrail sliceTrail)
- : base()
- {
- SliceTrail = sliceTrail;
- }
- public override float getSimilarity(TrackableObject compareObject)
- {
- Finger compareFinger = (Finger)compareObject;
- LineSegment2D compareLineSegment = compareFinger.LineSegment;
- Line2D compareLine = compareLineSegment.Line;
-
- //tip position
- float tipPointDistance = TipPoint.getDistanceTo(compareFinger.TipPoint);
- float tipPointSimilarity = Math.Max(0, 1 - tipPointDistance / Constants.ImageDiagonalLength);
- //hand position
- float handPointDistance = HandPoint.getDistanceTo(compareFinger.HandPoint);
- float handPointSimilarity = Math.Max(0, 1 - handPointDistance / Constants.ImageDiagonalLength);
- /*
- //check angle
- float angle = LineSegment.Line.getAngleBetween(compareLine);
- float angleSimilarity = Math.Max(1 - angle / Constants.FingerSimilarityMaxAngle, 0);
- //check parallel distance
- float parallelDistance = LineSegment.getParallelDistanceTo(compareLineSegment);
- float parallelDistanceSimilarity = Math.Max(1 - parallelDistance / Constants.FingerSimilarityMaxParallelDistance, 0);
- //check vertical distance
- float verticalDistance = LineSegment.getVerticalDistanceTo(compareLineSegment);
- float verticalDistanceSimilarity = Math.Max(1 - verticalDistance / Constants.FingerSimilarityMaxVerticalDistance, 0);
- */
- float similarity = tipPointSimilarity * handPointSimilarity;
- //float similarity = tipPointSimilarity * handPointSimilarity * angleSimilarity * parallelDistanceSimilarity * verticalDistanceSimilarity;
- //float similarity = (tipPointSimilarity + handPointSimilarity + angleSimilarity + parallelDistanceSimilarity + verticalDistanceSimilarity)/5;
- //float similarity = (angleSimilarity + parallelDistanceSimilarity + verticalDistanceSimilarity) / 3;
- return similarity;
- }
- public void setHand(Hand hand) {
- Hand = hand;
- }
- public void setTouchEvent(TouchEvent touchEvent) {
- TouchEvent = touchEvent;
- }
- }
- }
|