PalmTracker.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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.PalmRecognition
  10. {
  11. class PalmTracker : Tracker<Palm, TrackedPalm>
  12. {
  13. public PalmTracker(ImageSize imageSize)
  14. : base(imageSize)
  15. {
  16. }
  17. public void trackPalms(FrameData frameData)
  18. {
  19. trackObjects(frameData.DetectedPalms);
  20. frameData.TrackedPalms = getOptimizedPalms();
  21. }
  22. public override float calculateSimilarity(TrackedPalm trackedPalm, Palm detectedPalm)
  23. {
  24. float handSimilarity = (detectedPalm.Hand.TrackID == trackedPalm.LastObject.Hand.TrackID) ? 1 : 0;
  25. float wristUpperSimilarity = getPositionSimilarity(trackedPalm.WristUpperPrediction, detectedPalm.WristUpper, Parameters.PalmTrackerMaxWristUpperRelativeMove);
  26. float wristLowerSimilarity = getPositionSimilarity(trackedPalm.WristLowerPrediction, detectedPalm.WristLower, Parameters.PalmTrackerMaxWristLowerRelativeMove);
  27. float fingersUpperSimilarity = getPositionSimilarity(trackedPalm.FingersUpperPrediction, detectedPalm.FingersUpper, Parameters.PalmTrackerMaxFingersUpperRelativeMove);
  28. float fingersLowerSimilarity = getPositionSimilarity(trackedPalm.FingersLowerPrediction, detectedPalm.FingersLower, Parameters.PalmTrackerMaxFingersLowerRelativeMove);
  29. return handSimilarity * wristUpperSimilarity * wristLowerSimilarity * fingersUpperSimilarity * fingersLowerSimilarity;
  30. }
  31. protected override TrackedPalm createTrackedObject(Palm detectedPalm)
  32. {
  33. return new TrackedPalm(idPool.getNextUnusedID(), detectedPalm, Parameters.PalmTrackerNumFramesDetectedUntilTracked, Parameters.PalmTrackerNumFramesLostUntilDeleted);
  34. }
  35. private List<Palm> getOptimizedPalms()
  36. {
  37. List<Palm> optimizedPalms = new List<Palm>();
  38. foreach (TrackedPalm tp in TrackedObjects)
  39. {
  40. if (tp.CurrentState == TrackingState.Tracked)
  41. optimizedPalms.Add(tp.OptimizedPalm);
  42. }
  43. return optimizedPalms;
  44. }
  45. }
  46. }