Browse Source

Merge branch 'master' of https://git.tk.informatik.tu-darmstadt.de/etri-smartspaces

Conflicts:
	bbiwarg/Detectors/Fingers/Finger.cs
	bbiwarg/Images/PalmImage.cs
	bbiwarg/VideoHandle.cs
Alexander Hendrich 11 years ago
parent
commit
9370bef4f2
2 changed files with 46 additions and 16 deletions
  1. 44 15
      bbiwarg/Images/PalmImage.cs
  2. 2 1
      bbiwarg/VideoHandle.cs

+ 44 - 15
bbiwarg/Images/PalmImage.cs

@@ -8,38 +8,66 @@ using Emgu.CV;
 using Emgu.CV.Structure;
 using System.Drawing;
 
+using bbiwarg.Detectors.Fingers;
+using bbiwarg.Utility;
+
 namespace bbiwarg.Images
 {
     class PalmImage
     {
         private Image<Gray, Byte> image;
         private int width, height;
-        private Contour<Point> contour;
         bool[,] inContour;
-
-        public PalmImage(EdgeImage edgeImage)
+        
+        public PalmImage(EdgeImage edgeImage, FingerTracker fingerTracker)
         {
-            image = edgeImage.getImage().Clone();
+            image = edgeImage.getImage(); //.Clone();
             width = image.Width;
             height = image.Height;
+            
+            foreach (Finger f in fingerTracker.getFingers())
+            {
+                Vector<float> tip = new Vector<float>(new float[] { f.getTipPoint().x, f.getTipPoint().y });
+                Vector<float> hand = new Vector<float>(new float[] { f.getHandPoint().x, f.getHandPoint().y });
 
-            findContours();
 
+                for (int x = 0; x < width; ++x)
+                {
+                    for (int y = 0; y < height; ++y)
+                    {
+                        if (image.Data[y, x, 0] != 0)
+                        {
+                           Vector<float> p = new Vector<float>(new float[] { x, y });
 
-            
+                            float l2 = (tip - hand) * (tip - hand);
+                            float t = (p - tip) * (hand - tip) / l2;
+                            if (t >= 0.0 && t <= 1.0)
+                            {
+                                Vector<float> tmp = hand - tip;
+                                tmp.multiply(t);
+                                Vector<float> projection = tip + tmp;
+
+                                if (p.distance(projection) <= 15)
+                                    image.Data[y, x, 0] = 0;
+                            }
+                        }
+                    }
+                }
+            }
+
+            findContour();
         }
 
-        private void findContours()
+        private void findContour()
         {
-            image = image.Dilate(3);
-            contour = image.FindContours(Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_NONE, Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_EXTERNAL);
+            //image = image.Dilate(1);
+            Contour<Point> contour = image.FindContours(Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_NONE,
+                                                        Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_LIST);
 
             Contour<Point> maxContour = contour;
             double maxPerimeter = 0;
-            int count = 0;
             while (contour != null)
             {
-                ++count;
                 if (contour.Perimeter > maxPerimeter)
                 {
                     maxPerimeter = contour.Perimeter;
@@ -48,11 +76,12 @@ namespace bbiwarg.Images
                 contour = contour.HNext;
             }
 
-            //Console.WriteLine("numContours: " + count + "\nmaxPerimeter = " + maxPerimeter);
-
             inContour = new bool[width, height];
-            foreach (Point p in maxContour)
-                inContour[p.X, p.Y] = true;
+            if (maxContour != null)
+            {
+                foreach (Point p in maxContour)
+                    inContour[p.X, p.Y] = true;
+            }
         }
 
         public bool belongsToPalm(int x, int y)

+ 2 - 1
bbiwarg/VideoHandle.cs

@@ -117,7 +117,6 @@ namespace bbiwarg
 
             //create images
             edgeImage = new EdgeImage(depthImage);
-            palmImage = new PalmImage(edgeImage);
             touchImage = new TouchImage(width, height);
             fingerImage = new FingerImage(width, height);
 
@@ -128,6 +127,8 @@ namespace bbiwarg
             //detect+track touchEvents
             touchDetector = new TouchDetector(fingerTracker.getFingers(), depthImage, touchImage);
             touchTracker.setDetectedTouchEventsThisFrame(touchDetector.getTouchEvents(), touchImage);
+
+            palmImage = new PalmImage(edgeImage, fingerTracker);
         }
     }
 }