Просмотр исходного кода

Added constraint for thumb defect.

Daniel Kauth 11 лет назад
Родитель
Сommit
de9c2d1a7a
2 измененных файлов с 25 добавлено и 11 удалено
  1. 6 5
      bbiwarg/Constants.cs
  2. 19 6
      bbiwarg/Detectors/PalmDetection/PalmDetector.cs

+ 6 - 5
bbiwarg/Constants.cs

@@ -10,7 +10,7 @@ namespace bbiwarg
     class Constants
     {
         // BBIWARG
-        public static readonly bool TimerOutputAll = true;
+        public static readonly bool TimerOutputAll = false;
 
         // depth image
         public static readonly int DepthImageMedianSize = 3;
@@ -43,9 +43,10 @@ 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.2f;
-        public static readonly float PalmMinThumbDefectLengthQuotient = 1.2f;
-        public static readonly float PalmMinTumbDefectDepth = 30.0f;
+        public static readonly float PalmMaxThumbDefectStartEndLengthQuotient = 2.2f;
+        public static readonly float PalmMinThumbDefectStartEndLengthQuotient = 1.2f;
+        public static readonly float PalmMinTumbDefectDepthThumbLengthQuotient = 0.8f;
+        public static readonly float PalmMaxTumbDefectDepthThumbLengthQuotient = 1.2f;
         
         //palm Grid
         public static readonly int PalmGridRows = 4;
@@ -54,7 +55,7 @@ namespace bbiwarg
         // touch detection
         public static readonly float TouchEventMinFloodValue = 0.2f;
         public static readonly int TouchEventTipCorrectionFactor = 7;
-        public static readonly int TouchEventAreaSize = 30;
+        public static readonly int TouchEventAreaSize = 25;
         public static readonly int TouchEventNumFramesUntilTracked = 2;
 
         // output window

+ 19 - 6
bbiwarg/Detectors/PalmDetection/PalmDetector.cs

@@ -42,7 +42,12 @@ namespace bbiwarg.Detectors.PalmDetection
         {
             this.outputImage = outputImage;
 
-            if (hands.Count == 2)
+            if (hands.Count == 1 && hands[0].Fingers.Count == 1)
+            {
+                palmHand = hands[0];
+                pointingHand = null;
+            }
+            else if (hands.Count == 2)
             {
                 if (hands[0].Fingers.Count > 1)
                 {
@@ -64,10 +69,14 @@ namespace bbiwarg.Detectors.PalmDetection
                     pointingHand = hands[1];
                     palmHand = hands[0];
                 }
+            }
 
+            if ((hands.Count == 1 && hands[0].Fingers.Count == 1) || hands.Count == 2)
+            {
                 findLongestPalmContour();
                 findConvexityDefectsSortedByDepth();
-                removeConvexityDefectsCausedByFingers();
+                if (pointingHand != null)
+                    removeConvexityDefectsCausedByFingers();
                 findHandPoints();
             }
             
@@ -153,15 +162,19 @@ namespace bbiwarg.Detectors.PalmDetection
                 Vector2D start = new Vector2D(d.StartPoint);
                 Vector2D end = new Vector2D(d.EndPoint);
 
+                float angle = (float)((depth - start).getAngleBetween(depth - end) * 180 / Math.PI);
+
                 float l1 = (depth - start).Length;
                 float l2 = (depth - end).Length;
-                float lengthQuotient = Math.Max(l1, l2) / Math.Min(l1, l2);
+                float startEndLengthQuotient = Math.Max(l1, l2) / Math.Min(l1, l2);
 
-                float angle = (float) ((depth - start).getAngleBetween(depth - end) * 180 / Math.PI);
+                float depthThumbLengthQuotient = d.Depth / palmHand.Fingers[0].LineSegment.Length;
 
                 if (angle <= Constants.PalmMaxThumbDefectAngle && 
-                    lengthQuotient >= Constants.PalmMinThumbDefectLengthQuotient && lengthQuotient <= Constants.PalmMaxThumbDefectLengthQuotient &&
-                    d.Depth >= Constants.PalmMinTumbDefectDepth)
+                    startEndLengthQuotient >= Constants.PalmMinThumbDefectStartEndLengthQuotient && 
+                    startEndLengthQuotient <= Constants.PalmMaxThumbDefectStartEndLengthQuotient &&
+                    depthThumbLengthQuotient >= Constants.PalmMinTumbDefectDepthThumbLengthQuotient &&
+                    depthThumbLengthQuotient <= Constants.PalmMaxTumbDefectDepthThumbLengthQuotient)
                 {
                     return d;
                 }