|
@@ -7,31 +7,47 @@ using bbiwarg.Utility;
|
|
|
|
|
|
namespace bbiwarg.Recognition.Tracking
|
|
namespace bbiwarg.Recognition.Tracking
|
|
{
|
|
{
|
|
|
|
+ public class TrackingStateChangeEventArgs : EventArgs
|
|
|
|
+ {
|
|
|
|
+ public TrackingState NextState { get; private set; }
|
|
|
|
+ public TrackingState PreviousState { get; private set; }
|
|
|
|
+
|
|
|
|
+ public TrackingStateChangeEventArgs(TrackingState nextState, TrackingState previousState)
|
|
|
|
+ {
|
|
|
|
+ NextState = nextState;
|
|
|
|
+ PreviousState = previousState;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public delegate void TrackingStateChangedEventHandler(object sender, TrackingStateChangeEventArgs e);
|
|
|
|
+
|
|
class TrackableObjectHistory<T> where T : TrackableObject
|
|
class TrackableObjectHistory<T> where T : TrackableObject
|
|
{
|
|
{
|
|
private static List<int> usedIDs = new List<int>();
|
|
private static List<int> usedIDs = new List<int>();
|
|
public int ID { get; private set; }
|
|
public int ID { get; private set; }
|
|
public List<T> TrackedObjects { get; private set; }
|
|
public List<T> TrackedObjects { get; private set; }
|
|
public List<TrackingState> States { get; private set; }
|
|
public List<TrackingState> States { get; private set; }
|
|
- public TrackableObject LastObject { get; private set; }
|
|
|
|
- public TrackableObject CurrentObject { get { return TrackedObjects[TrackedObjects.Count - 1]; } }
|
|
|
|
|
|
+ public T LastObject { get; private set; }
|
|
|
|
+ public T CurrentObject { get { return TrackedObjects[TrackedObjects.Count - 1]; } }
|
|
public TrackingState CurrentState { get { return States[States.Count - 1]; } }
|
|
public TrackingState CurrentState { get { return States[States.Count - 1]; } }
|
|
public int NumFramesInCurrentState { get; private set; }
|
|
public int NumFramesInCurrentState { get; private set; }
|
|
- private String className;
|
|
|
|
- private LogSubject logSubject;
|
|
|
|
- private int numFramesUntilTracked;
|
|
|
|
|
|
+ private int numFramesDetectedUntilTracked;
|
|
|
|
+ private int numFramesLostUntilDeleted;
|
|
|
|
+
|
|
|
|
+ public event TrackingStateChangedEventHandler StateChanged;
|
|
|
|
+
|
|
|
|
+ protected virtual void OnStateChanged(TrackingStateChangeEventArgs e) { if (StateChanged != null) StateChanged(this, e); }
|
|
|
|
|
|
- public TrackableObjectHistory(LogSubject logSubject, int numFramesUntilTracked)
|
|
|
|
|
|
+ public TrackableObjectHistory(int numFramesDetectedUntilTracked, int numFramesLostUntilDeleted)
|
|
{
|
|
{
|
|
ID = getNextUnusedID();
|
|
ID = getNextUnusedID();
|
|
TrackedObjects = new List<T>();
|
|
TrackedObjects = new List<T>();
|
|
- States = new List<TrackingState>();
|
|
|
|
TrackedObjects.Add(null);
|
|
TrackedObjects.Add(null);
|
|
|
|
+ States = new List<TrackingState>();
|
|
States.Add(TrackingState.None);
|
|
States.Add(TrackingState.None);
|
|
NumFramesInCurrentState = 1;
|
|
NumFramesInCurrentState = 1;
|
|
- this.className = typeof(T).Name;
|
|
|
|
- this.logSubject = logSubject;
|
|
|
|
- this.numFramesUntilTracked = numFramesUntilTracked;
|
|
|
|
|
|
+ this.numFramesDetectedUntilTracked = numFramesDetectedUntilTracked;
|
|
|
|
+ this.numFramesLostUntilDeleted = numFramesLostUntilDeleted;
|
|
}
|
|
}
|
|
|
|
|
|
~TrackableObjectHistory()
|
|
~TrackableObjectHistory()
|
|
@@ -44,43 +60,44 @@ namespace bbiwarg.Recognition.Tracking
|
|
TrackingState previousState = CurrentState;
|
|
TrackingState previousState = CurrentState;
|
|
TrackingState newState = TrackingState.None;
|
|
TrackingState newState = TrackingState.None;
|
|
|
|
|
|
|
|
+ //get newState
|
|
if (detectedObject != null)
|
|
if (detectedObject != null)
|
|
{
|
|
{
|
|
if (previousState == TrackingState.None)
|
|
if (previousState == TrackingState.None)
|
|
- {
|
|
|
|
newState = TrackingState.Detected;
|
|
newState = TrackingState.Detected;
|
|
- Logger.log(className + " #" + ID + " detected", logSubject);
|
|
|
|
- }
|
|
|
|
else if (previousState == TrackingState.Lost)
|
|
else if (previousState == TrackingState.Lost)
|
|
- {
|
|
|
|
newState = TrackingState.Tracked;
|
|
newState = TrackingState.Tracked;
|
|
- Logger.log(className + " #" + ID.ToString() + " re-tracked", logSubject);
|
|
|
|
- }
|
|
|
|
else if (previousState == TrackingState.Tracked)
|
|
else if (previousState == TrackingState.Tracked)
|
|
newState = TrackingState.Tracked;
|
|
newState = TrackingState.Tracked;
|
|
else if (previousState == TrackingState.Detected)
|
|
else if (previousState == TrackingState.Detected)
|
|
{
|
|
{
|
|
- if (NumFramesInCurrentState == numFramesUntilTracked)
|
|
|
|
- {
|
|
|
|
|
|
+ if (NumFramesInCurrentState == numFramesDetectedUntilTracked)
|
|
newState = TrackingState.Tracked;
|
|
newState = TrackingState.Tracked;
|
|
- Logger.log(className + " #" + ID.ToString() + " tracked", logSubject);
|
|
|
|
- }
|
|
|
|
else
|
|
else
|
|
newState = TrackingState.Detected;
|
|
newState = TrackingState.Detected;
|
|
}
|
|
}
|
|
-
|
|
|
|
- LastObject = detectedObject;
|
|
|
|
- detectedObject.setTracked(ID);
|
|
|
|
}
|
|
}
|
|
|
|
+ else if (previousState == TrackingState.Lost && NumFramesInCurrentState == numFramesLostUntilDeleted)
|
|
|
|
+ newState = TrackingState.Delete;
|
|
else
|
|
else
|
|
newState = TrackingState.Lost;
|
|
newState = TrackingState.Lost;
|
|
|
|
|
|
|
|
+ //update numFramesInCurrentState
|
|
if (newState == previousState)
|
|
if (newState == previousState)
|
|
NumFramesInCurrentState++;
|
|
NumFramesInCurrentState++;
|
|
|
|
+ else
|
|
|
|
+ NumFramesInCurrentState = 1;
|
|
|
|
+
|
|
|
|
+ //update lastObject
|
|
|
|
+ if (detectedObject != null)
|
|
|
|
+ {
|
|
|
|
+ LastObject = detectedObject;
|
|
|
|
+ detectedObject.setTrackID(ID);
|
|
|
|
+ }
|
|
|
|
|
|
TrackedObjects.Add(detectedObject);
|
|
TrackedObjects.Add(detectedObject);
|
|
States.Add(newState);
|
|
States.Add(newState);
|
|
-
|
|
|
|
|
|
+ OnStateChanged(new TrackingStateChangeEventArgs(newState, previousState));
|
|
}
|
|
}
|
|
|
|
|
|
public static int getNextUnusedID()
|
|
public static int getNextUnusedID()
|