HandTracker.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using BBIWARG.Input.InputHandling;
  2. using BBIWARG.Recognition.Tracking;
  3. using BBIWARG.Utility;
  4. namespace BBIWARG.Recognition.HandRecognition
  5. {
  6. /// <summary>
  7. /// Keeps track of hands over a period of time.
  8. /// </summary>
  9. internal class HandTracker : Tracker<Hand, TrackedHand>
  10. {
  11. /// <summary>
  12. /// Initializes a new instance of the HandTracker class.
  13. /// </summary>
  14. /// <param name="imageSize">Size of the input image.</param>
  15. public HandTracker(ImageSize imageSize)
  16. : base(imageSize)
  17. {
  18. }
  19. /// <summary>
  20. /// Calculates the similarity [0-1] of a tracked Hand and a detected Hand.
  21. /// </summary>
  22. /// <param name="trackedHand">the tracked hand</param>
  23. /// <param name="detectedHand">the detected hand</param>
  24. /// <returns>the similarity</returns>
  25. public override float calculateSimilarity(TrackedHand trackedHand, Hand detectedHand)
  26. {
  27. return getPositionSimilarity(trackedHand.CentroidPrediction, detectedHand.Centroid, Parameters.HandTrackerMaxCentroidRelativeMove);
  28. }
  29. /// <summary>
  30. /// Updates the TrackedHands with the detected hands in the current frame and stores the results in frameData.trackedFingers.
  31. /// </summary>
  32. /// <param name="frameData">the current frame</param>
  33. public void trackHands(FrameData frameData)
  34. {
  35. trackObjects(frameData.DetectedHands);
  36. frameData.TrackedHands = getCurrentObjectsWithState(TrackingState.Tracked);
  37. }
  38. /// <summary>
  39. /// Creates a TrackedHand.
  40. /// </summary>
  41. /// <param name="detectedObject">the detected hand</param>
  42. /// <returns>a tracked hand</returns>
  43. protected override TrackedHand createTrackedObject(Hand detectedObject)
  44. {
  45. return new TrackedHand(idPool.getNextUnusedID(), detectedObject, Parameters.HandTrackerNumFramesDetectedUntilTracked, Parameters.HandTrackerNumFramesLostUntilDeleted);
  46. }
  47. }
  48. }