Bladeren bron

Changed constants for thumb defect detection.

Daniel Kauth 11 jaren geleden
bovenliggende
commit
0269232d9a
2 gewijzigde bestanden met toevoegingen van 26 en 9 verwijderingen
  1. 2 2
      bbiwarg/Constants.cs
  2. 24 7
      bbiwarg/Detectors/PalmDetection/PalmDetector.cs

+ 2 - 2
bbiwarg/Constants.cs

@@ -50,8 +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;
+        public static readonly float PalmMaxThumbDefectLengthQuotient = 2.05f;
+        public static readonly float PalmMinThumbDefectLengthQuotient = 1.35f;
         
         //palm Grid
         public static readonly int PalmGridRows = 4;

+ 24 - 7
bbiwarg/Detectors/PalmDetection/PalmDetector.cs

@@ -152,7 +152,7 @@ namespace bbiwarg.Detectors.PalmDetection
             pointingHandMask = pointingHandMask.Or(edgeImage.Image);
             i1.Image[0] = i1.Image[1] = i1.Image[2] = 255 * pointingHandMask;
 
-            pointingHandMask = pointingHandMask.Dilate(2);
+            pointingHandMask = pointingHandMask.Dilate(1);
             i2.Image[0] = i2.Image[1] = i2.Image[2] = 255 * pointingHandMask;
            
             fillFirstFingerSlices(pointingHandMask, 1);
@@ -217,7 +217,7 @@ namespace bbiwarg.Detectors.PalmDetection
             List<MCvConvexityDefect> newDefects = new List<MCvConvexityDefect>();
             foreach (MCvConvexityDefect d in convexityDefects)
             {
-                bool remove = false;
+                bool fingerIntersectsStartEnd = false;
                 float minFingerLineDist = float.MaxValue;
                 foreach (Finger f in fingers)
                 {
@@ -225,7 +225,7 @@ namespace bbiwarg.Detectors.PalmDetection
                     Vector2D intersection = defectLine.Line.getIntersection(f.LineSegment.Line);
                     if (intersection.isInBox(defectLine.P1, defectLine.P2) && intersection.isInBox(f.LineSegment.P1, f.LineSegment.P2))
                     {
-                        remove = true;
+                        fingerIntersectsStartEnd = true;
                         break;
                     }
                     
@@ -235,12 +235,13 @@ namespace bbiwarg.Detectors.PalmDetection
                         minFingerLineDist = dist;
                 }
                 
-                if (minFingerLineDist >= Constants.PalmMinDefectMidFingerLineDistance && !remove)
+                if (minFingerLineDist >= Constants.PalmMinDefectMidFingerLineDistance && !fingerIntersectsStartEnd)
                     newDefects.Add(d);
             }
             convexityDefects = newDefects;
         }
 
+        private int i = 0;
         private MCvConvexityDefect? findThumbDefect()
         {
             foreach (MCvConvexityDefect d in convexityDefects)
@@ -261,7 +262,25 @@ namespace bbiwarg.Detectors.PalmDetection
                     return d;
                 }
             }
-            Console.WriteLine("no palm defect found");
+
+
+            /*Console.WriteLine("no palm defect found (" + i + ")");
+            foreach (MCvConvexityDefect d in convexityDefects)
+            {
+                Vector2D depth = new Vector2D(d.DepthPoint);
+                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);
+
+                Console.WriteLine("angle: " + angle + " quotient: " + lengthQuotient);
+            }*/
+
+            ++i;
             return null;
         }
 
@@ -321,8 +340,6 @@ namespace bbiwarg.Detectors.PalmDetection
 
         private void draw()
         {
-
-
             if (palmContour != null && palmContour.Count<Point>() > 0) {
                 outputImage.drawContour(palmContour, Constants.PalmConturColor);
                 outputImage.drawPoints(palmContour.GetConvexHull(Emgu.CV.CvEnum.ORIENTATION.CV_CLOCKWISE), Constants.PalmConvexHullColor);