Browse Source

added finger cripple check

Alexander Hendrich 11 years ago
parent
commit
27278677a9
2 changed files with 37 additions and 9 deletions
  1. 4 1
      bbiwarg/Constants.cs
  2. 33 8
      bbiwarg/Detectors/FingerDetection/FingerDetector.cs

+ 4 - 1
bbiwarg/Constants.cs

@@ -33,7 +33,7 @@ namespace bbiwarg
         public static readonly int FingerStepSize = 2;
         public static readonly int FingerMinNumSlices = 30 / FingerStepSize;
         public static readonly int FingerRemoveNumSlicesForCorrection = 5;
-        public static readonly int FingerMaxGapCounter = 10;
+        public static readonly int FingerMaxGapCounter = 5;
         public static readonly int FingerMaxSliceDifferencePerStep = 5;
         public static readonly int FingerMaxSize = 30;
         public static readonly int FingerMinSize = 5;
@@ -42,6 +42,8 @@ namespace bbiwarg
         public static readonly int FingerOutSliceFactor = 10;
         public static readonly int FingerContourMargin = 2;
         public static readonly int FingerSliceOverlapFactor = 2;
+        public static readonly int FingerCrippleOutFactor = 8;
+        public static readonly int FingerCrippleOutMinDifference = 15;
         public static readonly float FingerMinSimilarityForTracking = 0.75f;
 
         // hand detection
@@ -80,6 +82,7 @@ namespace bbiwarg
         public static readonly Color FingerTrackedColor = ColorTracked;
         public static readonly Color FingerTipOutSliceColor = Color.Gray;
         public static readonly Color FingerHandOutSliceColor = Color.DarkSlateGray;
+        public static readonly Color FingerContourColor = Color.Red;
 
         public static readonly Color TouchEventDetectedColor = ColorDetected;
         public static readonly Color TouchEventTrackedColor = ColorTracked;

+ 33 - 8
bbiwarg/Detectors/FingerDetection/FingerDetector.cs

@@ -28,10 +28,11 @@ namespace bbiwarg.Detectors.FingerDetection
             this.edgeImageAdapted = edgeImage.copy();
             this.outputImage = outputImage;
 
-            findFingers();
+            detectFingers();
+            drawFingers();
         }
 
-        private void findFingers()
+        private void detectFingers()
         {
             int maxX = depthImage.Width - 1;
             int maxY = depthImage.Height - 1;
@@ -252,15 +253,31 @@ namespace bbiwarg.Detectors.FingerDetection
             Finger finger = new Finger(trail);
 
             //add finger
-            Fingers.Add(finger);
-
-            //draw finger
-            drawDetectedFinger(finger);
+            if (!isCrippleFinger(finger))
+                Fingers.Add(finger);
 
             //remove edges around detected finger to improve performance
             edgeImageAdapted.removeEdgesInsidePolygon(finger.getContour().ToArray());
         }
 
+        private bool isCrippleFinger(Finger finger)
+        {
+            int maxX = depthImage.Width - 1;
+            int maxY = depthImage.Height - 1;
+
+            FingerSlice midSlice = finger.SliceTrail.Slices[finger.SliceTrail.NumSlices / 2];
+            Vector2D direction = midSlice.LineSegment.Line.Direction;
+            Vector2D out1 = (midSlice.Start - Constants.FingerCrippleOutFactor * direction).moveInBound(0, 0, maxX, maxY);
+            Vector2D out2 = (midSlice.End + Constants.FingerCrippleOutFactor * direction).moveInBound(0, 0, maxX, maxY);
+
+            Int16 depthAtFinger = depthImage.getDepthAt(midSlice.Mid);
+            Int16 depthAtOut1 = depthImage.getDepthAt(out1);
+            Int16 depthAtOut2 = depthImage.getDepthAt(out2);
+            int minDepthDifference = Math.Min(Math.Abs(depthAtFinger - depthAtOut1), Math.Abs(depthAtFinger - depthAtOut2));
+
+            return (minDepthDifference < Constants.FingerCrippleOutMinDifference);
+        }
+
         private FingerSlice findOutSlice(Vector2D start, Vector2D direction)
         {
             int maxX = depthImage.Width - 1;
@@ -315,7 +332,15 @@ namespace bbiwarg.Detectors.FingerDetection
             return trail;
         }
 
-        private void drawDetectedFinger(Finger finger)
+        private void drawFingers()
+        {
+            foreach (Finger finger in Fingers)
+            {
+                drawFinger(finger);
+            }
+        }
+
+        private void drawFinger(Finger finger)
         {
             FingerSliceTrail trail = finger.SliceTrail;
             for (int i = 0; i < trail.NumSlices; i++)
@@ -323,7 +348,7 @@ namespace bbiwarg.Detectors.FingerDetection
                 outputImage.drawLineSegment(trail.Slices[i].LineSegment, Constants.FingerSliceColor);
             }
             outputImage.drawLineSegment(finger.LineSegment, Constants.FingerDetectedColor);
-            outputImage.drawContour(finger.getContour(), Color.Red, 1);
+            outputImage.drawContour(finger.getContour(), Constants.FingerContourColor, 1);
         }
     }
 }