TrackedHand.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. private void logStateChange()
  30. {
  31. String stateAsString = CurrentState.ToString().ToLower();
  32. Logger.log(String.Format("Hand #{0} {1}", this.ID, stateAsString), LogSubject.HandTracker);
  33. }
  34. }
  35. }