Browse Source

small performance improvement for fingerDetection

Alexander Hendrich 11 years ago
parent
commit
2a8ab128bb
2 changed files with 31 additions and 9 deletions
  1. 29 7
      bbiwarg/Detectors/Fingers/FingerDetector.cs
  2. 2 2
      bbiwarg/VideoHandle.cs

+ 29 - 7
bbiwarg/Detectors/Fingers/FingerDetector.cs

@@ -25,8 +25,19 @@ namespace bbiwarg.Detectors.Fingers
             this.edgeImage = edgeImage;
             this.fingerImage = fingerImage;
 
+            Stopwatch sw = new Stopwatch();
+            sw.Start();
+
             findFingerPoints();
+
+            sw.Stop();
+            Console.WriteLine("findFingerPoints:" + sw.ElapsedMilliseconds);
+            sw.Restart();
+
             findFingers();
+
+            Console.WriteLine("findFingers:" + sw.ElapsedMilliseconds);
+            sw.Stop();
         }
 
         public List<Finger> getFingers() {
@@ -68,13 +79,24 @@ namespace bbiwarg.Detectors.Fingers
             float maxYIndex = (direction.y == 0) ? float.MaxValue : ((direction.y > 0) ? ((height - start.y) / direction.y) : (-start.y / direction.y));
 
             float maxIndex = Math.Min(maxFingerSize, Math.Min(maxXIndex, maxYIndex));
-            
-            while (!edgeFound && index < maxIndex) {
-                if (edgeImage.isEdgeAt((int)edge.x, (int)edge.y))
-                    edgeFound = true;
-                else {
-                    index += stepSize;
-                    edge += direction;
+
+            if (index < maxIndex)
+            {
+                Int16 depthStart = depthImage.getDepthAt((int)start.x, (int)start.y);
+                Int16 depthEdge = depthImage.getDepthAt((int)edge.x, (int)edge.y);
+
+                if (depthStart > depthEdge)
+                {
+                    while (!edgeFound && index < maxIndex)
+                    {
+                        if (edgeImage.isEdgeAt((int)edge.x, (int)edge.y))
+                            edgeFound = true;
+                        else
+                        {
+                            index += stepSize;
+                            edge += direction;
+                        }
+                    }
                 }
             }
             

+ 2 - 2
bbiwarg/VideoHandle.cs

@@ -92,7 +92,7 @@ namespace bbiwarg
         }
 
         public bool isPalmPointAt(int x, int y) {
-            return palmImage.belongsToPalm(x, y);
+            return false;// palmImage.belongsToPalm(x, y);
         }
 
         public TouchImageState getTouchImageStateAt(int x, int y) {
@@ -128,7 +128,7 @@ namespace bbiwarg
             touchDetector = new TouchDetector(fingerTracker.getFingers(), depthImage, touchImage);
             touchTracker.setDetectedTouchEventsThisFrame(touchDetector.getTouchEvents(), touchImage);
 
-            palmImage = new PalmImage(edgeImage, fingerTracker);
+            //palmImage = new PalmImage(edgeImage, fingerTracker);
         }
     }
 }