123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- using BBIWARG.Recognition.Tracking;
- using BBIWARG.Utility;
- using System;
- using System.Collections.Generic;
- namespace BBIWARG.Recognition.FingerRecognition
- {
-
-
-
- internal class TrackedFinger : TrackedObject<Finger>
- {
-
-
-
- private Kalman2DPositionFilter handPointKalman;
-
-
-
- private List<Vector2D> lastRawDirections;
-
-
-
- private Kalman2DPositionFilter tipPointKalman;
-
-
-
- public Vector2D HandPointPrediction { get { return handPointKalman.getPrediction(); } }
-
-
-
- public Vector2D MeanDirection { get { return Vector2D.mean(lastRawDirections); } }
-
-
-
- public Vector2D TipPointPrediction { get { return tipPointKalman.getPrediction(); } }
-
-
-
-
-
-
-
- public TrackedFinger(int id, Finger detectedFinger, int numFramesDetectedUntilTracked, int numFramesLostUntilDeleted)
- : base(id, detectedFinger, numFramesDetectedUntilTracked, numFramesLostUntilDeleted)
- {
- tipPointKalman = new Kalman2DPositionFilter(Parameters.FingermXX, Parameters.FingermXY, Parameters.FingermYY);
- tipPointKalman.setInitialPosition(detectedFinger.TipPoint);
- handPointKalman = new Kalman2DPositionFilter(Parameters.FingermXX, Parameters.FingermXY, Parameters.FingermYY);
- handPointKalman.setInitialPosition(detectedFinger.HandPoint);
- lastRawDirections = new List<Vector2D>();
- logStateChange();
- }
-
-
-
-
-
- public bool shouldFingerBeReversed(Finger detectedFinger)
- {
- Vector2D meanDirection = Vector2D.mean(lastRawDirections);
- return meanDirection.isInOppositeDirection(detectedFinger.Direction);
- }
-
-
-
-
- public override void updateFrame(Finger detectedFinger)
- {
- base.updateFrame(detectedFinger);
- if (NumFramesInCurrentState == 1)
- logStateChange();
- if (detectedFinger != null)
- {
- Vector2D rawDirection = detectedFinger.Direction;
- if (shouldFingerBeReversed(detectedFinger))
- detectedFinger.reverse();
- tipPointKalman.getCorrectedPosition(detectedFinger.TipPoint);
- handPointKalman.getCorrectedPosition(detectedFinger.HandPoint);
- lastRawDirections.Add(rawDirection);
- if (lastRawDirections.Count == Parameters.FingerTrackerNumDirectionsForMeanDirection)
- lastRawDirections.RemoveAt(0);
- }
- }
-
-
-
- private void logStateChange()
- {
- String stateAsString = CurrentState.ToString().ToLower();
- Logger.log(String.Format("Finger #{0} {1}", this.ID, stateAsString), LogSubject.FingerTracker);
- }
- }
- }
|