using BBIWARG.Recognition.Tracking;
using BBIWARG.Utility;
using System;
namespace BBIWARG.Recognition.HandRecognition
{
///
/// Represents a hand that is tracked for several frames
///
internal class TrackedHand : TrackedObject
{
///
/// the kalman filter for the centroid prediction
///
private Kalman2DPositionFilter centroidKalman;
///
/// predicted position of the centroid
///
public Vector2D CentroidPrediction { get { return centroidKalman.getPrediction(); } }
///
/// Initializes a new instance of the TrackedHand class.
///
/// The track ID.
/// The detected hand.
/// The number of consecutive frames detected until the hand is considered to be tracked.
/// The number of consecutive frames lost until the hand should be deleted.
public TrackedHand(int id, Hand detectedHand, int numFramesDetectedUntilTracked, int numFramesLostUntilDeleted)
: base(id, detectedHand, numFramesDetectedUntilTracked, numFramesLostUntilDeleted)
{
centroidKalman = new Kalman2DPositionFilter(Parameters.HandmXX, Parameters.HandmXY, Parameters.HandmYY);
centroidKalman.setInitialPosition(detectedHand.Centroid);
logStateChange();
}
///
/// Updates the tracked hand with the given hand, logs the state change and updates the centroid prediction (kalman filter)
///
/// the detected hand
public override void updateFrame(Hand detectedHand)
{
base.updateFrame(detectedHand);
if (NumFramesInCurrentState == 1)
logStateChange();
if (detectedHand != null)
centroidKalman.getCorrectedPosition(detectedHand.Centroid);
}
///
/// logs the state change
///
private void logStateChange()
{
String stateAsString = CurrentState.ToString().ToLower();
Logger.log(String.Format("Hand #{0} {1}", this.ID, stateAsString), LogSubject.HandTracker);
}
}
}