using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace bbiwarg.Recognition.FingerRecognition { public enum TrackingState { None, Detected, Tracked, Lost, } class FingerHistory { public List Fingers { get; private set; } public List States { get; private set; } public Finger LastFinger { get; private set; } public Finger CurrentFinger { get { return Fingers[Fingers.Count - 1]; } } public TrackingState CurrentState { get { return States[States.Count - 1]; } } public FingerHistory(Finger finger) { Fingers = new List(); States = new List(); Fingers.Add(finger); States.Add(TrackingState.Detected); LastFinger = finger; } public void addFinger(Finger finger) { TrackingState previousState = CurrentState; TrackingState newState = TrackingState.None; int numFramesInCurrentState = getNumFramesInCurrentState(); if (finger == null) newState = TrackingState.Lost; else if (previousState == TrackingState.Tracked) newState = TrackingState.Tracked; else if (previousState == TrackingState.Detected) { if (numFramesInCurrentState == Constants.FingerNumFramesUntilTracked) newState = TrackingState.Tracked; else newState = TrackingState.Detected; } Fingers.Add(finger); States.Add(newState); if (finger != null) LastFinger = finger; } public int getNumFramesInCurrentState() { TrackingState currentState = CurrentState; int count = 0; for (int i = States.Count - 1; i >= 0; i++) { if (States[i] == currentState) count++; else break; } return count; } } }