Jelajahi Sumber

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

Daniel Kauth 11 tahun lalu
induk
melakukan
04aa791f1b

+ 2 - 2
bbiwarg/Constants.cs

@@ -67,8 +67,8 @@ namespace bbiwarg
 
 
         // colors
-        public static readonly Color ColorDetected = Color.White;
-        public static readonly Color ColorTracked = Color.Yellow;
+        public static readonly Color ColorDetected = Color.Green;
+        public static readonly Color ColorTracked = Color.LightGoldenrodYellow;
 
         //public static readonly Color EdgeColor = Color.Blue; // edgeImage draw direct to blue chanel from outputImage
 

+ 4 - 4
bbiwarg/Detectors/FingerDetection/FingerDetector.cs

@@ -280,8 +280,8 @@ namespace bbiwarg.Detectors.FingerDetection
 
         private FingerSliceTrail orderTrailTipToHand(FingerSliceTrail trail)
         {
-            int maxX = depthImage.Width - 1;
-            int maxY = depthImage.Height - 1;
+            int maxX = depthImage.Width - 2;
+            int maxY = depthImage.Height - 2;
 
             FingerSlice start = trail.Start;
             FingerSlice end = trail.End;
@@ -294,10 +294,10 @@ namespace bbiwarg.Detectors.FingerDetection
             float startOutLength = float.MaxValue;
             float endOutLength = float.MaxValue;
 
-            if (startOutSlice.Start.isWithin(0, 0, maxX, maxY) && startOutSlice.End.isWithin(0, 0, maxX, maxY))
+            if (startOutSlice.Start.isWithin(1, 1, maxX, maxY) && startOutSlice.End.isWithin(1, 1, maxX, maxY))
                 startOutLength = startOutSlice.Length;
 
-            if (endOutSlice.Start.isWithin(0, 0, maxX, maxY) && endOutSlice.End.isWithin(0, 0, maxX, maxY))
+            if (endOutSlice.Start.isWithin(1, 1, maxX, maxY) && endOutSlice.End.isWithin(1, 1, maxX, maxY))
                 endOutLength = endOutSlice.Length;
 
             if (startOutLength <= endOutLength)

+ 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 - 2
bbiwarg/Detectors/TouchDetection/TouchDetector.cs

@@ -31,7 +31,6 @@ namespace bbiwarg.Detectors.TouchDetection
             foreach (Finger finger in fingers)
             {
                 Vector2D tipPoint = finger.TipPoint;
-
                 outputImage.fillCircle(tipPoint.IntX, tipPoint.IntY, 3, Constants.TouchEventTipColor);
 
                 float floodValue = getFloodValue(tipPoint);
@@ -61,7 +60,7 @@ namespace bbiwarg.Detectors.TouchDetection
             Image<Gray, byte> touchArea = depthImage.Image.Copy(rect);
 
             MCvConnectedComp comp = new MCvConnectedComp();
-            CvInvoke.cvFloodFill(touchArea, relTouch, new MCvScalar(255), new MCvScalar(0), new MCvScalar(1), out comp, Emgu.CV.CvEnum.CONNECTIVITY.EIGHT_CONNECTED, Emgu.CV.CvEnum.FLOODFILL_FLAG.DEFAULT, IntPtr.Zero);
+            CvInvoke.cvFloodFill(touchArea, relTouch, new MCvScalar(255), new MCvScalar(0), new MCvScalar(2), out comp, Emgu.CV.CvEnum.CONNECTIVITY.EIGHT_CONNECTED, Emgu.CV.CvEnum.FLOODFILL_FLAG.DEFAULT, IntPtr.Zero);
 
             int matchedPixels = 0;
             int countedPixels = 0;

+ 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