using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using bbiwarg.Recognition.Tracking; using bbiwarg.Utility; using bbiwarg.Input.InputHandling; namespace bbiwarg.Recognition.FingerRecognition { /// /// Keeps track of fingers over a period of time. /// class FingerTracker : Tracker { /// /// Initializes a new instance of the FingerTracker class. /// /// Size of the input image. public FingerTracker(ImageSize imageSize) : base(imageSize) { } /// /// Updates the TrackedFingers with the detected fingers in the current frame and stores the tracked fingers. /// /// the current frame public void trackFingers(FrameData frameData) { trackObjects(frameData.DetectedFingers); frameData.TrackedFingers = getCurrentObjectsWithState(TrackingState.Tracked); } /// /// Calculates the similarity [0-1] of a tracked Finger and a detected finger /// /// the tracked finger /// the detected finger /// the similarity between both fingers public override float calculateSimilarity(TrackedFinger trackedFinger, Finger detectedFinger) { Vector2D tip, hand; if (trackedFinger.shouldFingerBeReversed(detectedFinger)) { tip = detectedFinger.HandPoint; hand = detectedFinger.TipPoint; } else { tip = detectedFinger.TipPoint; hand = detectedFinger.HandPoint; } float tipPointSimilarity = getPositionSimilarity(trackedFinger.TipPointPrediction, tip, Parameters.FingerTrackerMaxTipPointRelativeMove); float handPointSimilarity = getPositionSimilarity(trackedFinger.HandPointPrediction, hand, Parameters.FingerTrackerMaxHandPointRelativeMove); return tipPointSimilarity * handPointSimilarity; } /// /// Creates a TrackedFinger. /// /// The detected finger. /// a TrackedFinger protected override TrackedFinger createTrackedObject(Finger detectedObject) { return new TrackedFinger(idPool.getNextUnusedID(), detectedObject, Parameters.FingerTrackerNumFramesDetectedUntilTracked, Parameters.FingerTrackerNumFramesLostUntilDeleted); } } }