فهرست منبع

-fixed memory leak in tracker (no more list of detected object)
-added block numbers to touchevent visualizer

Alexander Hendrich 10 سال پیش
والد
کامیت
dad7bc23fe

+ 6 - 5
bbiwarg/Constants.cs

@@ -66,9 +66,9 @@ namespace bbiwarg
         public static readonly int FingerNumFramesDetectedUntilTracked = 5;
         public static readonly int FingerNumFramesLostUntilDeleted = 10;
         public static readonly float FingerMinSimilarityForTracking = 0.7f;
-        public static readonly float FingermXX = 0.0005f;
-        public static readonly float FingermXY = 0.0005f;
-        public static readonly float FingermYY = 0.0005f;
+        public static readonly float FingermXX = 0.00005f;
+        public static readonly float FingermXY = 0.0000f;
+        public static readonly float FingermYY = 0.00005f;
 
         // hand detection
         public static readonly float HandMaxSize = 0.7f;
@@ -91,8 +91,8 @@ namespace bbiwarg
         public static readonly float PalmMaxPrecentageQuadForegroundReset = 0.5f;
 
         //palm Grid
-        public static readonly int PalmGridNumRows = 4;
-        public static readonly int PalmGridNumColumns = 3;
+        public static readonly int PalmGridNumRows = 3;
+        public static readonly int PalmGridNumColumns = 4;
 
         // touch detection
         public static readonly float TouchEventMinTouchValue = 0.3f;
@@ -139,6 +139,7 @@ namespace bbiwarg
         public static readonly Color TouchEventVisualizerLineColor = Color.Yellow;
         public static readonly Color TouchEventVisualizerPointColor = Color.Red;
         public static readonly Color TouchEventVisualizerGridColor = Color.White;
+        public static readonly Color TouchEventVisualizerTextColor = Color.White;
 
         public static readonly Color PalmQuadColor = Color.Blue;
         public static readonly Color PalmGridColor = Color.CornflowerBlue;

+ 6 - 6
bbiwarg/Graphics/OutputImage.cs

@@ -100,17 +100,17 @@ namespace bbiwarg.Graphics
             Vector2D c = quad.TopRight;
             Vector2D d = quad.BottomRight;
 
-            Vector2D relAB = (b - a) / numRows;
-            Vector2D relDC = (c - d) / numRows;
-            Vector2D relBC = (c - b) / numCols;
-            Vector2D relAD = (d - a) / numCols;
+            Vector2D relAB = (b - a) / numCols;
+            Vector2D relDC = (c - d) / numCols;
+            Vector2D relBC = (c - b) / numRows;
+            Vector2D relAD = (d - a) / numRows;
 
-            for (int i = 1; i < numRows; i++)
+            for (int i = 1; i < numCols; i++)
             {
                 drawLineSegment(new bbiwarg.Utility.LineSegment2D(a + i * relAB, d + i * relDC), gridColor);
             }
 
-            for (int i = 1; i < numCols; i++)
+            for (int i = 1; i < numRows; i++)
             {
                 drawLineSegment(new bbiwarg.Utility.LineSegment2D(a + i * relAD, b + i * relBC), gridColor);
             }

+ 9 - 0
bbiwarg/Graphics/TouchEventVisualizer.cs

@@ -95,6 +95,15 @@ namespace bbiwarg.Graphics
             {
                 OutputImage.drawLineSegment(new LineSegment2D(new Vector2D(0, i * heightPerRow), new Vector2D(width - 1, i * heightPerRow)), Constants.TouchEventVisualizerGridColor);
             }
+                        
+            for (int row = 0; row < numRows; row++) {
+                for (int col = 0; col < numColumns; col++) {
+                    int x = (int)((col+0.5f)*widthPerColumn)-5;
+                    int y = (int)((row+0.5f)*heightPerRow)+5;
+                    OutputImage.drawText(x,y,(1+row*numColumns+col).ToString(),Constants.TouchEventVisualizerTextColor);
+                }
+            }
+
 
             foreach (int id in currentPositions.Keys)
                 drawTouchGesture(currentPositions[id], 1);

+ 2 - 2
bbiwarg/MainBBWIWARG.cs

@@ -17,8 +17,8 @@ namespace bbiwarg
             Console.SetWindowSize(Constants.ConsoleWidth, Constants.ConsoleHeight);
 
             InputProvider inputProvider;
-            //inputProvider = new InputProvider(); // camera
-            inputProvider = new VideoInputProvider("..\\..\\videos\\touch\\4.skv"); // video
+            inputProvider = new InputProvider(); // camera
+            //inputProvider = new VideoInputProvider("..\\..\\videos\\touch\\4.skv"); // video
             inputProvider.initialize();
             inputProvider.start();
 

+ 17 - 15
bbiwarg/Recognition/Tracking/TrackedObject.cs

@@ -22,10 +22,10 @@ namespace bbiwarg.Recognition.Tracking
         private bool wasTrackedBefore;
 
         public int ID { get; private set; }
-        public List<T> DetectedObjects;
-        public T CurrentObject { get { return DetectedObjects[DetectedObjects.Count - 1]; } }
-        public List<TrackingState> States;
-        public TrackingState CurrentState { get { return States[States.Count - 1]; } }
+        public T CurrentObject { get; private set; }
+        public T LastObject { get; private set; }
+        public TrackingState CurrentState { get; private set; }
+        public TrackingState PreviousState { get; private set; }
         public int NumFramesInCurrentState { get; private set; }
 
         public TrackedObject(int id, T detectedObject, int numFramesDetectedUntilTracked, int numFramesLostUntilDeleted)
@@ -34,11 +34,11 @@ namespace bbiwarg.Recognition.Tracking
             this.numFramesDetectedUntilTracked = numFramesDetectedUntilTracked;
             this.numFramesLostUntilDeleted = numFramesLostUntilDeleted;
             wasTrackedBefore = false;
-            DetectedObjects = new List<T>();
-            States = new List<TrackingState>();
 
-            DetectedObjects.Add(detectedObject);
-            States.Add(TrackingState.Detected);
+            CurrentObject = detectedObject;
+            LastObject = detectedObject;
+            CurrentState = TrackingState.Detected;
+            PreviousState = TrackingState.Undefined;
             NumFramesInCurrentState = 1;
         }
 
@@ -47,18 +47,21 @@ namespace bbiwarg.Recognition.Tracking
         public virtual void updateFrame(T detectedObject)
         {
             if (detectedObject != null)
+            {
                 detectedObject.setTracked(ID);
+                LastObject = detectedObject;
+            }
 
-            TrackingState previousState = CurrentState;
             TrackingState newState = getNewState(detectedObject);
 
             if (!wasTrackedBefore && newState == TrackingState.Tracked)
                 wasTrackedBefore = true;
 
-            DetectedObjects.Add(detectedObject);
-            States.Add(newState);
+            PreviousState = CurrentState;
+            CurrentState = newState;
+            CurrentObject = detectedObject;
 
-            if (previousState == newState)
+            if (PreviousState == newState)
                 NumFramesInCurrentState++;
             else
                 NumFramesInCurrentState = 1;
@@ -66,12 +69,11 @@ namespace bbiwarg.Recognition.Tracking
 
         private TrackingState getNewState(T detectedObject)
         {
-            TrackingState previousState = CurrentState;
             TrackingState newState = TrackingState.Undefined;
 
             if (detectedObject != null)
             {
-                switch (previousState)
+                switch (CurrentState)
                 {
                     case TrackingState.Lost:
                         if (wasTrackedBefore)
@@ -90,7 +92,7 @@ namespace bbiwarg.Recognition.Tracking
                         break;
                 }
             }
-            else if (previousState == TrackingState.Lost && NumFramesInCurrentState >= numFramesLostUntilDeleted)
+            else if (CurrentState == TrackingState.Lost && NumFramesInCurrentState >= numFramesLostUntilDeleted)
                 newState = TrackingState.Deleted;
             else
                 newState = TrackingState.Lost;