Jelajahi Sumber

Added palm contour.

Daniel Kauth 11 tahun lalu
induk
melakukan
06fcc1c850
3 mengubah file dengan 33 tambahan dan 3 penghapusan
  1. 4 0
      bbiwarg/Graphics/OutputWindow.cs
  2. 28 2
      bbiwarg/Images/PalmImage.cs
  3. 1 1
      bbiwarg/MainBBWIWARG.cs

+ 4 - 0
bbiwarg/Graphics/OutputWindow.cs

@@ -119,6 +119,10 @@ namespace bbiwarg.Graphics
                         green = blue = 0;
                     }
 
+                    // show palm contour
+                    if (videoHandle.isPalmPointAt(x, y))
+                        red = Int16.MaxValue;
+
                     depthTextureData[index] = red;
                     depthTextureData[index + 1] = green;
                     depthTextureData[index + 2] = blue;

+ 28 - 2
bbiwarg/Images/PalmImage.cs

@@ -14,6 +14,8 @@ namespace bbiwarg.Images
     {
         private Image<Gray, Byte> image;
         private int width, height;
+        private Contour<Point> contour;
+        bool[,] inContour;
 
         public PalmImage(EdgeImage edgeImage)
         {
@@ -22,16 +24,40 @@ namespace bbiwarg.Images
             height = image.Height;
 
             findContours();
+
+
+            
         }
 
         private void findContours()
         {
-        
+            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);
+
+            Contour<Point> maxContour = contour;
+            double maxPerimeter = 0;
+            int count = 0;
+            while (contour != null)
+            {
+                ++count;
+                if (contour.Perimeter > maxPerimeter)
+                {
+                    maxPerimeter = contour.Perimeter;
+                    maxContour = contour;
+                }
+                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;
         }
 
         public bool belongsToPalm(int x, int y)
         {
-            return false;
+            return inContour[x, y];
         }
     }
 }

+ 1 - 1
bbiwarg/MainBBWIWARG.cs

@@ -12,7 +12,7 @@ namespace bbiwarg
     {
         static void Main(string[] args)
         {
-            IInputProvider inputProvider = new IisuInputProvider("..\\..\\videos\\touch\\4.skv");
+            IInputProvider inputProvider = new IisuInputProvider("..\\..\\videos\\touch\\1.skv");
             VideoHandle videoHandle = new VideoHandle(inputProvider);
             videoHandle.start();