Sfoglia il codice sorgente

improved fingerDetection performance by 4

Alexander Hendrich 11 anni fa
parent
commit
b282826850

+ 8 - 23
bbiwarg/Detectors/Fingers/FingerDetector.cs

@@ -31,7 +31,7 @@ namespace bbiwarg.Detectors.Fingers
 
         private void findFingers()
         {
-            int minNumSlices = 20;
+            int minNumSlices = 8;
             int width = depthImage.Width;
             int height = depthImage.Height;
             int maxX = width - 1;
@@ -39,7 +39,7 @@ namespace bbiwarg.Detectors.Fingers
 
             Fingers = new List<Finger>();
 
-            for (int y = 1; y < maxY; y++)
+            for (int y = 1; y < maxY; y+=5) //y++ for 100% coverage, but y++ for 99% coverage and 3 times better perfomance
             {
                 for (int x = 1; x < maxX; x++)
                 {
@@ -80,8 +80,8 @@ namespace bbiwarg.Detectors.Fingers
 
         private FingerSliceTrail findFingerSliceTrail(FingerSlice startSlice, Vector2D startDirection)
         {
-            int minNumSlicesForCorrection = 15;
-            int numRemoveForCorrection = 5;
+            int minNumSlicesForCorrection = 8;
+            int numRemoveForCorrection = 3;
 
             int maxX = depthImage.Width - 1;
             int maxY = depthImage.Height - 1;
@@ -119,17 +119,8 @@ namespace bbiwarg.Detectors.Fingers
             int maxX = depthImage.Width - 1;
             int maxY = depthImage.Height - 1;
 
-            int numDirectionsForAverage = 10;
-
-            List<Vector2D> directions = new List<Vector2D>();
-            int numDirections = Math.Min(trail.NumSlices - 1, numDirectionsForAverage);
-            for (int i = 0; i < numDirections; i++)
-            {
-                directions.Add(trail.Slices[i + 1].Mid - trail.Slices[i].Mid);
-            }
-
-            Vector2D currentDirection = Vector2D.mean(directions).normalize();
-            Vector2D currentPosition = trail.End.Mid + currentDirection;
+            Vector2D currentDirection = trail.getEndDirection();
+            Vector2D currentPosition = trail.End.Mid + 2*currentDirection;
 
             int gapCounter = 0;
             int numSlices = trail.NumSlices;
@@ -145,13 +136,8 @@ namespace bbiwarg.Detectors.Fingers
                     gapCounter = 0;
                     numSlices++;
                     trail.addSlice(nextSlice);
-                    directions.Add((nextSlice.Mid - lastSlice.Mid));
-
-                    if (directions.Count == numDirectionsForAverage)
-                        directions.RemoveAt(0);
-
-                    currentDirection = Vector2D.mean(directions).normalize();
-                    currentPosition = nextSlice.Mid + currentDirection;
+                    currentDirection = trail.getEndDirection();
+                    currentPosition = nextSlice.Mid + 2*currentDirection;
 
                     lastSlice = nextSlice;
                 }
@@ -226,7 +212,6 @@ namespace bbiwarg.Detectors.Fingers
                     return end;
                 }
             }
-
             return null;
         }
 

+ 7 - 0
bbiwarg/Detectors/Fingers/FingerSliceTrail.cs

@@ -25,5 +25,12 @@ namespace bbiwarg.Detectors.Fingers
         {
             Slices.Add(slice);
         }
+
+        public Vector2D getEndDirection() {
+            int numSlicesToInnerEnd = 5;
+            int innerEndIndex = Math.Max(0, NumSlices - numSlicesToInnerEnd);
+
+            return (End.Mid - Slices[innerEndIndex].Mid).normalize();
+        }
     }
 }