Browse Source

Added additional criterion for thumb defect.

Daniel Kauth 10 years ago
parent
commit
a9a3cc72fd
3 changed files with 15 additions and 26 deletions
  1. 3 1
      bbiwarg/Constants.cs
  2. 11 24
      bbiwarg/Detectors/Palm/PalmDetector.cs
  3. 1 1
      bbiwarg/Images/DepthImage.cs

+ 3 - 1
bbiwarg/Constants.cs

@@ -40,7 +40,7 @@ namespace bbiwarg
         public static readonly int FingerMinNumSlices = 7;
         public static readonly int FingerRemoveNumSlicesForCorrection = 3;
         public static readonly int FingerMaxGapCounter = 10;
-        public static readonly int FingerMaxSliceDifferencePerStep = 8;
+        public static readonly int FingerMaxSliceDifferencePerStep = 5;
         public static readonly int FingerMaxSize = 35;
         public static readonly int FingerMinSize = 5;
         public static readonly int FingerNumSlicesForRelativeDirection = 5;
@@ -50,6 +50,8 @@ namespace bbiwarg
         // palm detection
         public static readonly float PalmMinDefectMidFingerLineDistance = 20; // defects with mid point ((start + end) / 2) closer than this to a finger line are removed 
         public static readonly float PalmMaxThumbDefectAngle = 110; // degree
+        public static readonly float PalmMaxThumbDefectLengthQuotient = 2.0f;
+        public static readonly float PalmMinThumbDefectLengthQuotient = 1.4f;
         
         //palm Grid
         public static readonly int PalmGridRows = 4;

+ 11 - 24
bbiwarg/Detectors/Palm/PalmDetector.cs

@@ -119,36 +119,17 @@ namespace bbiwarg.Detectors.Palm
             return result;
         }
 
-        private void fillFingerSlices(Image<Gray, Byte> image, byte val)
+        private void fillFirstFingerSlices(Image<Gray, Byte> image, byte val)
         {
             foreach (Finger f in fingers)
             {
-                //foreach (FingerSlice s in f.SliceTrail.Slices)
-                {
                     image.Draw(new LineSegment2DF(f.SliceTrail.Slices[0].Start, f.SliceTrail.Slices[0].End), new Gray(val), 1);
-                }
-            }
-        }
-
-        private Finger getLongestFinger()
-        {
-            float maxLength = 0;
-            Finger longest = null;
-            foreach (Finger f in fingers)
-            {
-
-                if (f.LineSegment.Length > maxLength)
-                {
-                    maxLength = f.LineSegment.Length;
-                    longest = f;
-                }
             }
-            return longest;
         }
 
         private Point getPointInPointingHand()
         {
-            Finger finger = getLongestFinger();
+            Finger finger = fingers[0];
             if (finger == null)
                 return new Point(0, 0);
             Vector2D direction = (finger.Hand - finger.Tip).normalize();
@@ -174,7 +155,7 @@ namespace bbiwarg.Detectors.Palm
             pointingHandMask = pointingHandMask.Dilate(2);
             i2.Image[0] = i2.Image[1] = i2.Image[2] = 255 * pointingHandMask;
            
-            fillFingerSlices(pointingHandMask, 1);
+            fillFirstFingerSlices(pointingHandMask, 1);
             i3.Image[0] = i3.Image[1] = i3.Image[2] = 255 * pointingHandMask;
 
             //pointingHandMask = pointingHandMask.Dilate(1);
@@ -191,7 +172,7 @@ namespace bbiwarg.Detectors.Palm
             pointingHandMask = pointingHandMask.Erode(6);
             i6.Image[0] = i6.Image[1] = i6.Image[2] = 255 * pointingHandMask;
 
-            fillFingerSlices(pointingHandMask, 0);
+            fillFirstFingerSlices(pointingHandMask, 0);
             i7.Image[0] = i7.Image[1] = i7.Image[2] = 255 * pointingHandMask;
             
             pointingHandMask = pointingHandMask.Erode(2);
@@ -268,13 +249,19 @@ namespace bbiwarg.Detectors.Palm
                 Vector2D start = new Vector2D(d.StartPoint);
                 Vector2D end = new Vector2D(d.EndPoint);
 
+                float l1 = (depth - start).Length;
+                float l2 = (depth - end).Length;
+                float lengthQuotient = Math.Max(l1, l2) / Math.Min(l1, l2);
+
                 float angle = (float) ((depth - start).getAngleBetween(depth - end) * 180 / Math.PI);
 
-                if (angle <= Constants.PalmMaxThumbDefectAngle)
+                if (angle <= Constants.PalmMaxThumbDefectAngle && 
+                    lengthQuotient >= Constants.PalmMinThumbDefectLengthQuotient && lengthQuotient <= Constants.PalmMaxThumbDefectLengthQuotient)
                 {
                     return d;
                 }
             }
+            Console.WriteLine("no palm defect found");
             return null;
         }
 

+ 1 - 1
bbiwarg/Images/DepthImage.cs

@@ -82,7 +82,7 @@ namespace bbiwarg.Images
 
                 outputImage.fillCircle(mid.IntX, mid.IntY, 3, Color.Blue);
 
-                if (true) //(BackgroundMask.Data[mid.IntY, mid.IntX,0] != 0)
+                if (BackgroundMask.Data[mid.IntY, mid.IntX,0] != 0)
                     CvInvoke.cvFloodFill(BackgroundMask, mid, new MCvScalar(0), new MCvScalar(3), new MCvScalar(3), out comp, Emgu.CV.CvEnum.CONNECTIVITY.FOUR_CONNECTED, Emgu.CV.CvEnum.FLOODFILL_FLAG.DEFAULT, IntPtr.Zero);
             }