FingerTracker.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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.Utility;
  8. using bbiwarg.Input.InputHandling;
  9. namespace bbiwarg.Recognition.FingerRecognition
  10. {
  11. class FingerTracker : Tracker<Finger, TrackedFinger>
  12. {
  13. public FingerTracker(ImageSize imageSize)
  14. : base(imageSize)
  15. {
  16. }
  17. public void trackFingers(FrameData frameData) {
  18. trackObjects(frameData.DetectedFingers);
  19. frameData.TrackedFingers = getCurrentObjectsWithState(TrackingState.Tracked);
  20. }
  21. public override float calculateSimilarity(TrackedFinger trackedFinger, Finger detectedFinger)
  22. {
  23. Vector2D tip, hand;
  24. if (trackedFinger.shouldFingerBeReversed(detectedFinger))
  25. {
  26. tip = detectedFinger.HandPoint;
  27. hand = detectedFinger.TipPoint;
  28. }
  29. else
  30. {
  31. tip = detectedFinger.TipPoint;
  32. hand = detectedFinger.HandPoint;
  33. }
  34. float tipPointSimilarity = getPositionSimilarity(trackedFinger.TipPointPrediction, tip, Parameters.FingerTrackerMaxTipPointRelativeMove);
  35. float handPointSimilarity = getPositionSimilarity(trackedFinger.HandPointPrediction, hand, Parameters.FingerTrackerMaxHandPointRelativeMove);
  36. return tipPointSimilarity * handPointSimilarity;
  37. }
  38. protected override TrackedFinger createTrackedObject(Finger detectedObject)
  39. {
  40. return new TrackedFinger(idPool.getNextUnusedID(), detectedObject, Parameters.FingerTrackerNumFramesDetectedUntilTracked, Parameters.FingerTrackerNumFramesLostUntilDeleted);
  41. }
  42. }
  43. }