Browse Source

removed background from outputImage

Alexander Hendrich 11 years ago
parent
commit
88b9fab410

+ 2 - 1
bbiwarg/Detectors/HandDetection/Hand.cs

@@ -23,10 +23,11 @@ namespace bbiwarg.Detectors.HandDetection
         public Image<Gray, byte> Mask { get; private set; }
         public List<Finger> Fingers { get; private set; }
 
-        public Hand(Image<Gray, byte> mask) {
+        public Hand(Image<Gray, byte> mask, Finger finger) {
             Mask = mask;
             Centroid = getCentroid();
             Fingers = new List<Finger>();
+            addFinger(finger);
         }
 
         public bool isInside(Vector2D point) {

+ 5 - 2
bbiwarg/Detectors/HandDetection/HandDetector.cs

@@ -19,6 +19,7 @@ namespace bbiwarg.Detectors.HandDetection
         private EdgeImage edgeImage;
         private List<Finger> fingers;
         public List<Hand> Hands { get; private set; }
+        public Image<Gray, byte> HandMask { get; private set; }
         public OutputImage outputImage;
 
         public HandDetector(DepthImage depthImage, EdgeImage edgeImage, List<Finger> fingers, OutputImage outputImage)
@@ -38,6 +39,7 @@ namespace bbiwarg.Detectors.HandDetection
             int height = depthImage.Height;
             int maxArea = width * height;
             Image<Gray, byte> image = edgeImage.Image.Copy().Dilate(2).Erode(2).Mul(255);
+            HandMask = image.CopyBlank();
 
             //draw top finger slice
             foreach (Finger finger in fingers)
@@ -79,9 +81,10 @@ namespace bbiwarg.Detectors.HandDetection
                     CvInvoke.cvFloodFill(image, finger.HandPoint, new MCvScalar(255), new MCvScalar(1), new MCvScalar(1), out comp, Emgu.CV.CvEnum.CONNECTIVITY.FOUR_CONNECTED, Emgu.CV.CvEnum.FLOODFILL_FLAG.DEFAULT, mask);
                     if (comp.area < maxArea * Constants.HandMaxSize)
                     {
-                        Hand hand = new Hand(mask.Copy(new Rectangle(1, 1, width, height)).Mul(255));
-                        hand.addFinger(finger);
+                        Image<Gray, byte> cropedMask = mask.Copy(new Rectangle(1, 1, width, height)).Mul(255);
+                        Hand hand = new Hand(cropedMask, finger);
                         Hands.Add(hand);
+                        HandMask = HandMask.Or(cropedMask);
                     }
                 }
             }

+ 1 - 1
bbiwarg/Detectors/TouchDetection/TouchDetector.cs

@@ -80,7 +80,7 @@ namespace bbiwarg.Detectors.TouchDetection
                     {
                         subtractColor = Constants.TouchEventAreaNonMatchedSubtractColor;
                     }
-                    Color newColor = subtractColor;//Color.FromArgb(Math.Max(color.R - subtractColor.R, 0), Math.Max(color.G - subtractColor.G, 0), Math.Max(color.B - subtractColor.B, 0));
+                    Color newColor = Color.FromArgb(Math.Max(color.R - subtractColor.R, 0), Math.Max(color.G - subtractColor.G, 0), Math.Max(color.B - subtractColor.B, 0));
                     outputImage.drawPixel(x, y, newColor);
                     countedPixels++;
                 }

+ 1 - 3
bbiwarg/VideoHandle.cs

@@ -172,9 +172,7 @@ namespace bbiwarg
 
             //remove background noise
             Timer.start("removeBackground");
-            //depthImage.removeBackground(handDetector.Hands);
-            //edgeImage = new EdgeImage(depthImage);
-            OutputImages[3].Image[0] = OutputImages[3].Image[1] = OutputImages[3].Image[2] = (depthImage.MaxDepth - depthImage.MinDepth) - depthImage.Image;
+            OutputImages[3].Image[0] = OutputImages[3].Image[1] = OutputImages[3].Image[2] = (depthImage.MaxDepth - depthImage.MinDepth) - depthImage.Image.Or(255-handDetector.HandMask);
             Timer.stop("removeBackground");
 
             //detect palm