HandTracker.cs 2.1 KB

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