Browse Source

Merge branch 'master' of https://git.tk.informatik.tu-darmstadt.de/etri-smartspaces

Alexander Hendrich 11 năm trước cách đây
mục cha
commit
1ad9f2c64f

+ 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);
 

+ 5 - 0
bbiwarg/Graphics/OutputImage.cs

@@ -54,5 +54,10 @@ namespace bbiwarg.Graphics
         {
             Image.Draw(new CircleF(new PointF(x, y), radius), new Rgb(color), 0);
         }
+
+        public void drawRectangle(int x, int y, int width, int height, byte r, byte g, byte b, int thichness = 0)
+        {
+            Image.Draw(new Rectangle(x, y, width, height), new Rgb(r, g, b), thichness);
+        }
     }
 }

+ 3 - 2
bbiwarg/Graphics/TouchEventVisualizer.cs

@@ -20,6 +20,7 @@ namespace bbiwarg.Graphics
 
         public TouchEventVisualizer(int width, int height)
         {
+            OutputImage = new Graphics.OutputImage(width, height);
             touchPositions = new List<List<Vector2D>>();
             kalmanFilters = new List<Kalman2DPositionFilter>();
             this.width = width;
@@ -55,7 +56,7 @@ namespace bbiwarg.Graphics
                 pos = currentFilter.getCorrectedPosition(e.RelativePalmPosition);
             }
 
-            currentList.Add(new Vector2D((int)(pos.X * width), (int)(pos.Y * height)));
+            currentList.Add(new Vector2D((int)(pos.X * width), (int)(height - pos.Y * height)));
             if (addList)
             {
                 touchPositions.Add(currentList);
@@ -68,7 +69,7 @@ namespace bbiwarg.Graphics
         public void updateImage()
         {
             OutputImage = new OutputImage(width, height);
-
+            
             foreach (List<Vector2D> positions in touchPositions)
             {
                 for (int i = 1; i < positions.Count; ++i)

+ 15 - 7
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
@@ -170,16 +172,22 @@ namespace bbiwarg
                 touchEventVisualizer = new TouchEventVisualizer(Width, Height);
             if (getCurrentMovieFrame() == 0)
                 touchEventVisualizer.Reset();
-            foreach (PalmTouchEvent e in palmTouchDetector.PalmTouchEvents)
+            if (palmTouchDetector != null)
             {
-                if (sourceIsMovie())
-                    touchEventVisualizer.addPalmTouchEvent(e, getCurrentMovieFrame());
-                else
-                    touchEventVisualizer.addPalmTouchEvent(e, videoFrame);
+                foreach (PalmTouchEvent e in palmTouchDetector.PalmTouchEvents)
+                {
+                    if (sourceIsMovie())
+                        touchEventVisualizer.addPalmTouchEvent(e, getCurrentMovieFrame());
+                    else
+                        touchEventVisualizer.addPalmTouchEvent(e, videoFrame);
+                }
+                touchEventVisualizer.updateImage();
             }
-            touchEventVisualizer.updateImage();
 
-            // output images
+            // add borders
+            edgeFingerOutputImage.drawRectangle(0, 0, Width - 1, Height - 1, 255, 255, 255);
+            depthPalmTouchOutputImage.drawRectangle(0, 0, Width - 1, Height - 1, 255, 255, 255);
+            touchEventVisualizer.OutputImage.drawRectangle(0, 0, Width - 1, Height - 1, 255, 255, 255);
             OutputImages = new OutputImage[] { edgeFingerOutputImage, depthPalmTouchOutputImage, touchEventVisualizer.OutputImage};
 
             Timer.stop("processFrameUpdate");