using BBIWARG.Input.InputHandling;
using BBIWARG.Recognition.Tracking;
using BBIWARG.Utility;
namespace BBIWARG.Recognition.FingerRecognition
{
///
/// Keeps track of fingers over a period of time.
///
internal class FingerTracker : Tracker
{
///
/// Initializes a new instance of the FingerTracker class.
///
/// Size of the input image.
public FingerTracker(ImageSize imageSize)
: base(imageSize)
{
}
///
/// 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;
}
///
/// 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);
}
///
/// Creates a TrackedFinger.
///
/// The detected finger.
/// a TrackedFinger
protected override TrackedFinger createTrackedObject(Finger detectedObject)
{
return new TrackedFinger(idPool.getNextUnusedID(), detectedObject, Parameters.FingerTrackerNumFramesDetectedUntilTracked, Parameters.FingerTrackerNumFramesLostUntilDeleted);
}
}
}