Pārlūkot izejas kodu

Removed palm grid when no hands are detected for a certain number of frames.

Daniel Kauth 11 gadi atpakaļ
vecāks
revīzija
c3cbb53998

+ 2 - 1
bbiwarg/Constants.cs

@@ -58,7 +58,8 @@ namespace bbiwarg
         public static readonly float PalmThumbDefectmXX = 50.0f;
         public static readonly float PalmThumbDefectmXY = -25.0f;
         public static readonly float PalmThumbDefectmYY = 50.0f;
-        public static readonly float PalmThumbDefectProcessNoise = 5.0e+1f;    
+        public static readonly float PalmThumbDefectProcessNoise = 5.0e+1f;
+        public static readonly int PalmNumFramesNoHandReset = 5;
 
         //palm Grid
         public static readonly int PalmGridRows = 3;

+ 16 - 9
bbiwarg/Recognition/PalmRecognition/PalmDetector.cs

@@ -25,10 +25,12 @@ namespace bbiwarg.Recognition.PalmRecognition
         private List<MCvConvexityDefect> convexityDefects;
         private Vector2D thumbDefectStart;
         private Vector2D thumbDefectEnd;
-        public Vector2D thumbDefectDepth, lastThumbDefectDepth;
+        public Vector2D thumbDefectDepth;
         
         private Kalman2DPositionFilter thumbDefectDepthFilter, thumbDefectStartFilter, thumbDefectEndFilter;
 
+        private int numFramesNoHandFound;
+
         public Quadrangle PalmQuad { get; private set; }
 
         public PalmDetector()
@@ -80,9 +82,16 @@ namespace bbiwarg.Recognition.PalmRecognition
                 findConvexityDefectsSortedByDepth();
                 if (pointingHand != null)
                     removeConvexityDefectsCausedByFingers();
-                findHandPoints();
+                findHandPoints(hands.Count);
             }
-            
+
+            if (hands.Count == 0)
+            {
+                ++numFramesNoHandFound;
+                if (numFramesNoHandFound == Constants.PalmNumFramesNoHandReset)
+                    reset();
+            }
+
             draw();
         }
 
@@ -91,9 +100,9 @@ namespace bbiwarg.Recognition.PalmRecognition
             thumbDefectDepthFilter.reset();
             thumbDefectStartFilter.reset();
             thumbDefectEndFilter.reset();
-            lastThumbDefectDepth = null;
             palmContour = null;
             PalmQuad = null;
+            numFramesNoHandFound = 0;
         }
 
         private void findLongestPalmContour()
@@ -186,7 +195,7 @@ namespace bbiwarg.Recognition.PalmRecognition
             return null;
         }
 
-        private void findHandPoints()
+        private void findHandPoints(int numHands)
         {
             MCvConvexityDefect? thumbDefect = findThumbDefect();
 
@@ -195,7 +204,7 @@ namespace bbiwarg.Recognition.PalmRecognition
                 thumbDefectDepth = new Vector2D(thumbDefect.Value.DepthPoint);
                 thumbDefectStart = new Vector2D(thumbDefect.Value.StartPoint);
                 thumbDefectEnd = new Vector2D(thumbDefect.Value.EndPoint);
-                
+
                 if (!thumbDefectDepthFilter.Initialized)
                 {
                     thumbDefectDepthFilter.setInitialPosition(thumbDefectDepth);
@@ -209,8 +218,6 @@ namespace bbiwarg.Recognition.PalmRecognition
                     thumbDefectEnd = thumbDefectEndFilter.getCorrectedPosition(thumbDefectEnd);
                 }
 
-                lastThumbDefectDepth = thumbDefectDepth;
-
                 Vector2D handLength, handWidth, longestLineEndpoint, topLeft, bottomLeft, bottomRight, topRight;
 
                 Vector2D startDepth = thumbDefectStart - thumbDefectDepth;
@@ -231,7 +238,7 @@ namespace bbiwarg.Recognition.PalmRecognition
                     handWidth = 0.85f * new Vector2D(-handLength.Y, handLength.X);
                 else
                     handWidth = 0.85f * new Vector2D(handLength.Y, -handLength.X);
-                
+
                 topLeft = longestLineEndpoint + 0.15f * handLength;
                 bottomLeft = thumbDefectDepth - 0.4f * handLength;
                 bottomRight = bottomLeft + handWidth;