1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using bbiwarg.Recognition.Tracking;
- using bbiwarg.Recognition.HandRecognition;
- using bbiwarg.Utility;
- namespace bbiwarg.Recognition.PalmRecognition
- {
- class TrackedPalm : TrackedObject<Palm>
- {
- private Kalman2DPositionFilter wristUpperKalman;
- private Kalman2DPositionFilter wristLowerKalman;
- private Kalman2DPositionFilter fingersUpperKalman;
- private Kalman2DPositionFilter fingersLowerKalman;
- public Vector2D WristUpperPrediction { get { return wristUpperKalman.getPrediction(); } }
- public Vector2D WristLowerPrediction { get { return wristLowerKalman.getPrediction(); } }
- public Vector2D FingersUpperPrediction { get { return fingersUpperKalman.getPrediction(); } }
- public Vector2D FingersLowerPrediction { get { return fingersLowerKalman.getPrediction(); } }
- public Palm OptimizedPalm { get; private set; }
- public TrackedPalm(int id, Palm detectedPalm, int numFramesDetectedUntilTracked, int numFramesLostUntilDeleted)
- : base(id, detectedPalm, numFramesDetectedUntilTracked, numFramesLostUntilDeleted)
- {
- wristUpperKalman = new Kalman2DPositionFilter(Parameters.PalmmXX, Parameters.PalmmXY, Parameters.PalmmYY);
- wristLowerKalman = new Kalman2DPositionFilter(Parameters.PalmmXX, Parameters.PalmmXY, Parameters.PalmmYY);
- fingersUpperKalman = new Kalman2DPositionFilter(Parameters.PalmmXX, Parameters.PalmmXY, Parameters.PalmmYY);
- fingersLowerKalman = new Kalman2DPositionFilter(Parameters.PalmmXX, Parameters.PalmmXY, Parameters.PalmmYY);
- wristUpperKalman.setInitialPosition(detectedPalm.WristUpper);
- wristLowerKalman.setInitialPosition(detectedPalm.WristLower);
- fingersUpperKalman.setInitialPosition(detectedPalm.FingersUpper);
- fingersLowerKalman.setInitialPosition(detectedPalm.FingersLower);
- updateOptimizedPalm(detectedPalm);
- logStateChange();
- }
- public override void updateFrame(Palm detectedPalm)
- {
- base.updateFrame(detectedPalm);
- if (NumFramesInCurrentState == 1)
- logStateChange();
- if (detectedPalm != null)
- {
- wristUpperKalman.getCorrectedPosition(detectedPalm.WristUpper);
- wristLowerKalman.getCorrectedPosition(detectedPalm.WristLower);
- fingersUpperKalman.getCorrectedPosition(detectedPalm.FingersUpper);
- fingersLowerKalman.getCorrectedPosition(detectedPalm.FingersLower);
- updateOptimizedPalm(detectedPalm);
- }
- }
- private void updateOptimizedPalm(Palm detectedPalm)
- {
- OptimizedPalm = new Palm(detectedPalm.Hand, detectedPalm.ThumbDefect, detectedPalm.HandSide, WristUpperPrediction, FingersUpperPrediction, FingersLowerPrediction, WristLowerPrediction);
- }
- private void logStateChange()
- {
- String stateAsString = CurrentState.ToString().ToLower();
- Logger.log(String.Format("Palm #{0} {1}", this.ID, stateAsString), LogSubject.PalmTracker);
- }
- }
- }
|