TrackedHand.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. namespace bbiwarg.Recognition.HandRecognition
  9. {
  10. class TrackedHand : TrackedObject<Hand>
  11. {
  12. private Kalman2DPositionFilter centroidKalman;
  13. public Vector2D CentroidPrediction { get { return centroidKalman.getPrediction(); } }
  14. public TrackedHand(int id, Hand detectedHand, int numFramesDetectedUntilTracked, int numFramesLostUntilDeleted)
  15. : base(id, detectedHand, numFramesDetectedUntilTracked, numFramesLostUntilDeleted)
  16. {
  17. centroidKalman = new Kalman2DPositionFilter(Parameters.HandmXX, Parameters.HandmXY, Parameters.HandmYY);
  18. centroidKalman.setInitialPosition(detectedHand.Centroid);
  19. logStateChange();
  20. }
  21. public override void updateFrame(Hand detectedHand)
  22. {
  23. base.updateFrame(detectedHand);
  24. if (NumFramesInCurrentState == 1)
  25. logStateChange();
  26. if (detectedHand != null)
  27. centroidKalman.getCorrectedPosition(detectedHand.Centroid);
  28. }
  29. public override float calculateSimilarity(Hand detectedHand)
  30. {
  31. float centroidSimilarity = getPositionSimilarity(CentroidPrediction, detectedHand.Centroid, Parameters.HandTrackerMaxCentroidMove);
  32. return centroidSimilarity;
  33. }
  34. private void logStateChange()
  35. {
  36. String stateAsString = CurrentState.ToString().ToLower();
  37. Logger.log(String.Format("Hand #{0} {1}", this.ID, stateAsString), LogSubject.HandTracker);
  38. }
  39. }
  40. }