Browse Source

-removed z-index for hands
-increased finger contour for hand separation

Alexander Hendrich 11 years ago
parent
commit
c94a8016d3

+ 0 - 2
bbiwarg/Images/DepthImage.cs

@@ -23,7 +23,6 @@ namespace bbiwarg.Images
 
         public DepthImage(Image<Gray, Int16> image)
         {
-            //image = image.SmoothBlur(3,3,true);
             image = image.SmoothMedian(Parameters.DepthImageMedianSize);
             
             //threshold min&maxDepth
@@ -33,7 +32,6 @@ namespace bbiwarg.Images
             //smooth+threshold (dst = (src > (MaxDepth - MinDepth)) ? MaxDepth - MinDepth : src)
             Image = (image - MinDepth).ThresholdTrunc(new Gray(MaxDepth - MinDepth)).Convert<Gray, byte>();
             
-            //Image = Image.SmoothBlur(3,3, true);
             Image = Image.SmoothMedian(Parameters.DepthImageMedianSize);
         }
 

+ 1 - 1
bbiwarg/InputHandler.cs

@@ -272,7 +272,7 @@ namespace bbiwarg
             //image2
             foreach (Hand h in handTracker.Hands)
             {
-                OutputImages[2].drawImage(h.Mask.ThresholdBinary(new Gray(0), new Gray(255)), Parameters.HandColor[h.ZIndex % Parameters.HandNumColors]);
+                OutputImages[2].drawImage(h.Mask.ThresholdBinary(new Gray(0), new Gray(255)), Parameters.HandColor[h.TrackID % Parameters.HandNumColors]);
                 OutputImages[2].fillCircle(h.Centroid.IntX, h.Centroid.IntY, 5, Parameters.HandCentroidColor);
                 OutputImages[2].drawText(h.Centroid.IntX, h.Centroid.IntY, h.TrackID.ToString(), Parameters.HandIDColor);
 

+ 2 - 2
bbiwarg/Parameters.cs

@@ -23,7 +23,7 @@ namespace bbiwarg
         public static readonly String InputMoviePath = "..\\..\\videos\\touch\\4.skv";
 
         // Logger
-        public static readonly LogSubject LogLevel = LogSubject.None;
+        public static readonly LogSubject LogLevel = LogSubject.Timer;
         public static readonly int ConsoleWidth = 90;
         public static readonly int ConsoleHeight = 30;
 
@@ -109,7 +109,7 @@ namespace bbiwarg
         // palm detection
 
         // palm tracker
-        public static readonly int PalmTrackerNumFramesDetectedUntilTracked = 2;
+        public static readonly int PalmTrackerNumFramesDetectedUntilTracked = 5;
         public static readonly int PalmTrackerNumFramesLostUntilDeleted = 5;
         public static readonly float PalmTrackerMaxWristUpperMove = 0.25f * ImageDiagonalLength;
         public static readonly float PalmTrackerMaxWristLowerMove = 0.25f * ImageDiagonalLength;

+ 0 - 1
bbiwarg/Recognition/FingerRecognition/Finger.cs

@@ -23,7 +23,6 @@ namespace bbiwarg.Recognition.FingerRecognition
         public LineSegment2D LineSegment { get { return SliceTrail.LineSegment; } }
         public FingerSliceTrail SliceTrail { get; private set; }
         public Contour<Point> Contour { get { return SliceTrail.Contour; } }
-        public Contour<Point> InnerContour { get { return SliceTrail.InnerContour; } }
         public Hand Hand { get; private set; }
         public TouchEvent TouchEvent { get; private set; }
 

+ 1 - 24
bbiwarg/Recognition/HandRecognition/Hand.cs

@@ -23,9 +23,7 @@ namespace bbiwarg.Recognition.HandRecognition
     class Hand : TrackableObject
     {
         public List<ConvexityDefect> ConvexityDefects { get; private set; }
-        public int ZIndex { get; private set; }
         public Vector2D Centroid { get; private set; }
-        public Vector2D CentroidInHand { get; private set; }
         public Image<Gray, byte> Mask { get; private set; }
         public List<Finger> Fingers { get; private set; }
         public ConvexityDefect ThumbDefect { get; private set; }
@@ -51,11 +49,6 @@ namespace bbiwarg.Recognition.HandRecognition
             Fingers.Add(finger);
         }
 
-        public void setZIndex(int zIndex)
-        {
-            ZIndex = zIndex;
-        }
-
         public void mergeWith(Hand mergeHand)
         {
             extendMask(mergeHand.Mask);
@@ -94,9 +87,8 @@ namespace bbiwarg.Recognition.HandRecognition
 
                 if (trail != null)
                     Mask.FillConvexPoly(trail.OuterContour.ToArray(), new Gray(1));
-
-                Mask = Mask.Dilate(1);
             }
+            Mask = Mask.Dilate(1);
         }
 
         public void findThumbDefect()
@@ -166,21 +158,6 @@ namespace bbiwarg.Recognition.HandRecognition
             //find centroid
             MCvPoint2D64f gravityCenter = Mask.GetMoments(true).GravityCenter;
             Centroid = new Vector2D((float)gravityCenter.x, (float)gravityCenter.y);
-
-            //find centroid in hand
-            if (isInside(Centroid))
-                CentroidInHand = Centroid;
-            else
-            {
-                Finger finger = Fingers[0];
-                Vector2D direction = (finger.HandPoint - Centroid).normalize();
-                CentroidInHand = Centroid;
-                while (!isInside(CentroidInHand) && CentroidInHand.isInBound())
-                    CentroidInHand += direction;
-
-                if (!isInside(CentroidInHand))
-                    CentroidInHand = Fingers[0].HandPoint;
-            }
         }
 
     }

+ 4 - 14
bbiwarg/Recognition/HandRecognition/HandDetector.cs

@@ -34,9 +34,8 @@ namespace bbiwarg.Recognition.HandRecognition
             createModifiedHandEdgeImage();
             findHands();
             fixOverlappingFingers();
-            setZIndexes();
-            createHandMask();
             findThumbDefects();
+            createHandMask();
         }
 
         private void createModifiedHandEdgeImage()
@@ -46,8 +45,8 @@ namespace bbiwarg.Recognition.HandRecognition
             foreach (Finger finger in fingers)
             {
                 Int16 depthAtHand = depthImage.getDepthAt(finger.HandPoint);
-                Point[] contour = finger.InnerContour.ToArray();
-                modifiedHandDepthImage.DrawPolyline(contour, false, new Gray(depthAtHand), 2);
+                Point[] contour = finger.Contour.ToArray();
+                modifiedHandDepthImage.DrawPolyline(contour, false, new Gray(depthAtHand), 1);
             }
         }
 
@@ -87,19 +86,10 @@ namespace bbiwarg.Recognition.HandRecognition
         {
             Image<Gray, byte> mask = new Image<Gray, byte>(Parameters.ImageWidth + 2, Parameters.ImageHeight + 2);
             MCvConnectedComp comp = new MCvConnectedComp();
-            CvInvoke.cvFloodFill(modifiedHandDepthImage, p, new MCvScalar(255), new MCvScalar(Parameters.HandFloodFillDownDiff), new MCvScalar(Parameters.HandFloodFillUpDiff), out comp, Emgu.CV.CvEnum.CONNECTIVITY.EIGHT_CONNECTED, Emgu.CV.CvEnum.FLOODFILL_FLAG.DEFAULT, mask);
+            CvInvoke.cvFloodFill(modifiedHandDepthImage, p, new MCvScalar(255), new MCvScalar(Parameters.HandFloodFillDownDiff), new MCvScalar(Parameters.HandFloodFillUpDiff), out comp, Emgu.CV.CvEnum.CONNECTIVITY.FOUR_CONNECTED, Emgu.CV.CvEnum.FLOODFILL_FLAG.DEFAULT, mask);
             return mask.Copy(new Rectangle(1, 1, Parameters.ImageWidth, Parameters.ImageHeight));
         }
 
-        private void setZIndexes()
-        {
-            //sort depending on depth of centroid (far->near)
-            Hands.Sort((h1, h2) => depthImage.getDepthAt(h2.CentroidInHand).CompareTo(depthImage.getDepthAt(h1.CentroidInHand)));
-
-            for (int i = 0; i < Hands.Count; i++)
-                Hands[i].setZIndex(i);
-        }
-
         private void fixOverlappingFingers()
         {
             extendOrMergeThroughOverlappingFingers();