Jelajahi Sumber

improved touchDetector (floodfill)

Alexander Hendrich 11 tahun lalu
induk
melakukan
706182e34c
2 mengubah file dengan 15 tambahan dan 11 penghapusan
  1. 2 4
      bbiwarg/Constants.cs
  2. 13 7
      bbiwarg/Detectors/TouchDetection/TouchDetector.cs

+ 2 - 4
bbiwarg/Constants.cs

@@ -51,11 +51,9 @@ namespace bbiwarg
         public static readonly int PalmGridColumns = 3;
 
         // touch detection
-        public static readonly float TouchEventMinFloodValue = 0.33f;
-        public static readonly int TouchEventTipCorrectionFactor = 5;
+        public static readonly float TouchEventMinFloodValue = 0.2f;
+        public static readonly int TouchEventTipCorrectionFactor = 7;
         public static readonly int TouchEventAreaSize = 30;
-        public static readonly int TouchEventMaxDepthDifference = 20;
-        public static readonly int TouchEventFingerDiameter = 5;
         public static readonly int TouchEventNumFramesUntilTracked = 2;
 
         // output window

+ 13 - 7
bbiwarg/Detectors/TouchDetection/TouchDetector.cs

@@ -50,12 +50,18 @@ namespace bbiwarg.Detectors.TouchDetection
 
         private float getFloodValue(Point touchPoint)
         {
-            Int16 depthAtTouch = (Int16)(depthImage.getDepthAt(touchPoint) + Constants.TouchEventFingerDiameter);
+            int minX = Math.Max(touchPoint.X - 2*Constants.TouchEventAreaSize / 3, 0);
+            int maxX = Math.Min(touchPoint.X + Constants.TouchEventAreaSize / 3, depthImage.Width-1);
+            int minY = Math.Max(touchPoint.Y - 2*Constants.TouchEventAreaSize / 3, 0);
+            int maxY = Math.Min(touchPoint.Y + Constants.TouchEventAreaSize / 3, depthImage.Height-1);
 
-            int minX = Math.Max(touchPoint.X - Constants.TouchEventAreaSize / 2, 0);
-            int maxX = Math.Min(touchPoint.X + Constants.TouchEventAreaSize / 2, depthImage.Width-1);
-            int minY = Math.Max(touchPoint.Y - Constants.TouchEventAreaSize / 2, 0);
-            int maxY = Math.Min(touchPoint.Y + Constants.TouchEventAreaSize / 2, depthImage.Height-1);
+
+            Vector2D relTouch = new Vector2D(touchPoint.X - minX, touchPoint.Y - minY);
+            Rectangle rect = new Rectangle(minX, minY, maxX - minX + 1, maxY - minY + 1);
+            Image<Gray, byte> touchArea = depthImage.Image.Copy(rect);
+
+            MCvConnectedComp comp = new MCvConnectedComp();
+            CvInvoke.cvFloodFill(touchArea, relTouch, new MCvScalar(255), new MCvScalar(0), new MCvScalar(1), out comp, Emgu.CV.CvEnum.CONNECTIVITY.EIGHT_CONNECTED, Emgu.CV.CvEnum.FLOODFILL_FLAG.DEFAULT, IntPtr.Zero);
 
             int matchedPixels = 0;
             int countedPixels = 0;
@@ -63,10 +69,10 @@ namespace bbiwarg.Detectors.TouchDetection
             {
                 for (int y = minY; y <= maxY; y++)
                 {
-                    Int16 depth = depthImage.getDepthAt(x, y);
                     Color color = outputImage.getColotAt(x, y);
+                    byte depth = touchArea.Data[y - minY, x - minX, 0];
                     Color subtractColor;
-                    if (depthAtTouch < depth && Math.Abs(depthAtTouch - depth) < Constants.TouchEventMaxDepthDifference)
+                    if(depth == 255)
                     {
                         matchedPixels++;
                         subtractColor = Constants.TouchEventAreaMatchedSubtractColor;