Browse Source

Added KalmanFilter to filter the thumb convexity defact.

Daniel Kauth 11 years ago
parent
commit
727108d907
2 changed files with 21 additions and 1 deletions
  1. 19 1
      bbiwarg/Detectors/Palm/PalmDetector.cs
  2. 2 0
      bbiwarg/VideoHandle.cs

+ 19 - 1
bbiwarg/Detectors/Palm/PalmDetector.cs

@@ -30,6 +30,8 @@ namespace bbiwarg.Detectors.Palm
         private Contour<Point> palmContour;
         private List<MCvConvexityDefect> convexityDefects;
 
+        private static Kalman2DPositionFilter thumbDefactFilter;
+
         private bool valid = false;
         private Vector2D topLeft;
         private Vector2D topRight;
@@ -70,6 +72,11 @@ namespace bbiwarg.Detectors.Palm
             }
         }
 
+        public static void resetFilter()
+        {
+            thumbDefactFilter = null;
+        }
+
         private List<Finger> getFingersWithoutThumb(List<Finger> detectedFingers)
         {
             Finger leftMost = null;
@@ -204,7 +211,18 @@ namespace bbiwarg.Detectors.Palm
             if (convexityDefects.Count > 0)
             {
                 MCvConvexityDefect thumbDefect = convexityDefects[0];
-                Vector2D thumb = new Vector2D(thumbDefect.DepthPoint);
+
+                Vector2D thumb;
+                if (thumbDefactFilter == null)
+                {
+                    thumb = new Vector2D(thumbDefect.DepthPoint);
+                    thumbDefactFilter = new Kalman2DPositionFilter(thumb, 1.0e-2f, 1.0e-2f);
+                }
+                else
+                {
+                    thumb = thumbDefactFilter.getCorrectedPosition(new Vector2D(thumbDefect.DepthPoint));
+                }
+
                 Vector2D thumbDefectStart = new Vector2D(thumbDefect.StartPoint);
                 Vector2D thumbDefectEnd = new Vector2D(thumbDefect.EndPoint);
 

+ 2 - 0
bbiwarg/VideoHandle.cs

@@ -151,6 +151,8 @@ namespace bbiwarg
             //detect palm
             Timer.start("palmDetection");
             palmDetector = new PalmDetector(depthImage, edgeImage, fingerDetector.Fingers, depthPalmTouchOutputImage);
+            if (sourceIsMovie() && getCurrentMovieFrame() == 0)
+                PalmDetector.resetFilter();
             Timer.stop("palmDetection");
 
             //detect touchEvents