TrackedPalm.cs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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.Recognition.HandRecognition;
  8. using bbiwarg.Utility;
  9. namespace bbiwarg.Recognition.PalmRecognition
  10. {
  11. class TrackedPalm : TrackedObject<Palm>
  12. {
  13. private Kalman2DPositionFilter wristUpperKalman;
  14. private Kalman2DPositionFilter wristLowerKalman;
  15. private Kalman2DPositionFilter fingersUpperKalman;
  16. private Kalman2DPositionFilter fingersLowerKalman;
  17. public Vector2D WristUpperPrediction { get { return wristUpperKalman.getPrediction(); } }
  18. public Vector2D WristLowerPrediction { get { return wristLowerKalman.getPrediction(); } }
  19. public Vector2D FingersUpperPrediction { get { return fingersUpperKalman.getPrediction(); } }
  20. public Vector2D FingersLowerPrediction { get { return fingersLowerKalman.getPrediction(); } }
  21. public Palm OptimizedPalm { get; private set; }
  22. public TrackedPalm(int id, Palm detectedPalm, int numFramesDetectedUntilTracked, int numFramesLostUntilDeleted)
  23. : base(id, detectedPalm, numFramesDetectedUntilTracked, numFramesLostUntilDeleted)
  24. {
  25. wristUpperKalman = new Kalman2DPositionFilter(Parameters.PalmmXX, Parameters.PalmmXY, Parameters.PalmmYY);
  26. wristLowerKalman = new Kalman2DPositionFilter(Parameters.PalmmXX, Parameters.PalmmXY, Parameters.PalmmYY);
  27. fingersUpperKalman = new Kalman2DPositionFilter(Parameters.PalmmXX, Parameters.PalmmXY, Parameters.PalmmYY);
  28. fingersLowerKalman = new Kalman2DPositionFilter(Parameters.PalmmXX, Parameters.PalmmXY, Parameters.PalmmYY);
  29. wristUpperKalman.setInitialPosition(detectedPalm.WristUpper);
  30. wristLowerKalman.setInitialPosition(detectedPalm.WristLower);
  31. fingersUpperKalman.setInitialPosition(detectedPalm.FingersUpper);
  32. fingersLowerKalman.setInitialPosition(detectedPalm.FingersLower);
  33. updateOptimizedPalm(detectedPalm);
  34. logStateChange();
  35. }
  36. public override void updateFrame(Palm detectedPalm)
  37. {
  38. base.updateFrame(detectedPalm);
  39. if (NumFramesInCurrentState == 1)
  40. logStateChange();
  41. if (detectedPalm != null)
  42. {
  43. wristUpperKalman.getCorrectedPosition(detectedPalm.WristUpper);
  44. wristLowerKalman.getCorrectedPosition(detectedPalm.WristLower);
  45. fingersUpperKalman.getCorrectedPosition(detectedPalm.FingersUpper);
  46. fingersLowerKalman.getCorrectedPosition(detectedPalm.FingersLower);
  47. updateOptimizedPalm(detectedPalm);
  48. }
  49. }
  50. private void updateOptimizedPalm(Palm detectedPalm)
  51. {
  52. OptimizedPalm = new Palm(detectedPalm.Hand, detectedPalm.ThumbDefect, detectedPalm.HandSide, WristUpperPrediction, FingersUpperPrediction, FingersLowerPrediction, WristLowerPrediction);
  53. }
  54. private void logStateChange()
  55. {
  56. String stateAsString = CurrentState.ToString().ToLower();
  57. Logger.log(String.Format("Palm #{0} {1}", this.ID, stateAsString), LogSubject.PalmTracker);
  58. }
  59. }
  60. }