Browse Source

Changed TouchEventVisualizer to draw a quadratic image. (otherwise event positions are not equally scaled on x and y)

Daniel Kauth 11 years ago
parent
commit
8d3f4df1a1

+ 12 - 12
bbiwarg/Detectors/Palm/PalmDetector.cs

@@ -142,10 +142,10 @@ namespace bbiwarg.Detectors.Palm
             return new Point(HelperFunctions.thresholdRange<int>(0, width - 1, pos.IntX), HelperFunctions.thresholdRange<int>(0, height - 1, pos.IntY));
         }
 
-        //public OutputImage i1, i2, i3, i4, i5, i6, i7, i8, i9;
+        public OutputImage i1, i2, i3, i4, i5, i6, i7, i8, i9;
         private void buildPointingHandMask()
         {
-            /*i1 = new OutputImage(width, height);
+            i1 = new OutputImage(width, height);
             i2 = new OutputImage(width, height);
             i3 = new OutputImage(width, height);
             i4 = new OutputImage(width, height);
@@ -153,22 +153,22 @@ namespace bbiwarg.Detectors.Palm
             i6 = new OutputImage(width, height);
             i7 = new OutputImage(width, height);
             i8 = new OutputImage(width, height);
-            i9 = new OutputImage(width, height);*/
+            i9 = new OutputImage(width, height);
 
             pointingHandMask = new Image<Gray, byte>(width, height, new Gray(0));
 
             // dst = (src > 0) ? 1 : 0;
             pointingHandMask = pointingHandMask.Or(edgeImage.Image.ThresholdBinary(new Gray(0), new Gray(1)));
-            //i1.Image[0] = i1.Image[1] = i1.Image[2] = 255 * pointingHandMask;
+            i1.Image[0] = i1.Image[1] = i1.Image[2] = 255 * pointingHandMask;
 
             pointingHandMask = pointingHandMask.Dilate(4);
-            //i2.Image[0] = i2.Image[1] = i2.Image[2] = 255 * pointingHandMask;
+            i2.Image[0] = i2.Image[1] = i2.Image[2] = 255 * pointingHandMask;
            
             fillFingerSlices(pointingHandMask, 1);
-            //i3.Image[0] = i3.Image[1] = i3.Image[2] = 255 * pointingHandMask;
+            i3.Image[0] = i3.Image[1] = i3.Image[2] = 255 * pointingHandMask;
 
             //pointingHandMask = pointingHandMask.Dilate(1);
-            //i4.Image[0] = i4.Image[1] = i4.Image[2] = 255 * pointingHandMask;
+            i4.Image[0] = i4.Image[1] = i4.Image[2] = 255 * pointingHandMask;
 
             MCvConnectedComp tmp = new MCvConnectedComp();
             // fill with value 2
@@ -176,19 +176,19 @@ namespace bbiwarg.Detectors.Palm
 
             // dst = (src > 1) ? 0 : 1    (src > 1 <-> src == 2 <-> src filled by flood fill)
             pointingHandMask = pointingHandMask.ThresholdBinaryInv(new Gray(1), new Gray(1));
-            //i5.Image[0] = i5.Image[1] = i5.Image[2] = 255 * pointingHandMask;
+            i5.Image[0] = i5.Image[1] = i5.Image[2] = 255 * pointingHandMask;
             
             pointingHandMask = pointingHandMask.Erode(8);
-            //i6.Image[0] = i6.Image[1] = i6.Image[2] = 255 * pointingHandMask;
+            i6.Image[0] = i6.Image[1] = i6.Image[2] = 255 * pointingHandMask;
 
             fillFingerSlices(pointingHandMask, 0);
-            //i7.Image[0] = i7.Image[1] = i7.Image[2] = 255 * pointingHandMask;
+            i7.Image[0] = i7.Image[1] = i7.Image[2] = 255 * pointingHandMask;
             
             pointingHandMask = pointingHandMask.Erode(2);
-            //i8.Image[0] = i8.Image[1] = i8.Image[2] = 255 * pointingHandMask;
+            i8.Image[0] = i8.Image[1] = i8.Image[2] = 255 * pointingHandMask;
             
             // only debug
-            //i9.Image[0] = i9.Image[1] = i9.Image[2] = 255 * handImage.And(pointingHandMask);
+            i9.Image[0] = i9.Image[1] = i9.Image[2] = 255 * handImage.And(pointingHandMask);
         }
 
         private void findLongestPalmContour()

+ 9 - 4
bbiwarg/Graphics/TouchEventVisualizer.cs

@@ -20,11 +20,12 @@ namespace bbiwarg.Graphics
 
         public TouchEventVisualizer(int width, int height)
         {
+            this.width = width;
+            this.height = height;
+
             OutputImage = new Graphics.OutputImage(width, height);
             touchPositions = new List<List<Vector2D>>();
             kalmanFilters = new List<Kalman2DPositionFilter>();
-            this.width = width;
-            this.height = height;
         }
 
         public void addPalmTouchEvent(PalmTouchEvent e, int currentFrame)
@@ -56,7 +57,8 @@ namespace bbiwarg.Graphics
                 pos = currentFilter.getCorrectedPosition(e.RelativePalmPosition);
             }
 
-            currentList.Add(new Vector2D((int)(pos.X * width), (int)(height - pos.Y * height)));
+            int size = Math.Min(width, height);
+            currentList.Add(new Vector2D((int)(pos.X * size), (int)(size - pos.Y * size)));
             if (addList)
             {
                 touchPositions.Add(currentList);
@@ -68,8 +70,11 @@ namespace bbiwarg.Graphics
 
         public void updateImage()
         {
-            OutputImage = new OutputImage(width, height);
+            OutputImage = new OutputImage(width, height);            
             
+            int size = Math.Min(width, height);
+            OutputImage.drawRectangle(0, 0, size - 1, size - 1, 255, 255, 255);
+
             foreach (List<Vector2D> positions in touchPositions)
             {
                 for (int i = 1; i < positions.Count; ++i)

+ 1 - 3
bbiwarg/VideoHandle.cs

@@ -187,9 +187,7 @@ namespace bbiwarg
             // 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}; /*, palmDetector.i1, palmDetector.i2, palmDetector.i3, palmDetector.i4, palmDetector.i5, palmDetector.i6,
-                                               palmDetector.i7, palmDetector.i8, palmDetector.i9};*/
+            OutputImages = new OutputImage[] { edgeFingerOutputImage, depthPalmTouchOutputImage, touchEventVisualizer.OutputImage};
             Timer.stop("processFrameUpdate");
         }
     }