Quellcode durchsuchen

slightly improved performance for fingerDetection

Alexander Hendrich vor 11 Jahren
Ursprung
Commit
68447e73c3
2 geänderte Dateien mit 27 neuen und 19 gelöschten Zeilen
  1. 27 15
      bbiwarg/Detectors/Finger/Finger.cs
  2. 0 4
      bbiwarg/VideoHandle.cs

+ 27 - 15
bbiwarg/Detectors/Finger/Finger.cs

@@ -19,12 +19,14 @@ namespace bbiwarg.Detectors.Finger
         private PointF pointOnLine;
         private PointF start;
         private PointF end;
+        private bool startEndUpToDate;
 
         public Finger(FingerPoint fingerPoint)
         {
             fingerPoints = new List<FingerPoint>();
             nearest = fingerPoint;
             farthest = fingerPoint;
+            startEndUpToDate = false;
             addFingerPoint(fingerPoint);
         }
 
@@ -38,11 +40,15 @@ namespace bbiwarg.Detectors.Finger
             return farthest;
         }
 
-        public PointF getStart() {
+        public PointF getStart()
+        {
+            if (!startEndUpToDate) updateStartEnd();
             return start;
         }
 
-        public PointF getEnd() {
+        public PointF getEnd()
+        {
+            if (!startEndUpToDate) updateStartEnd();
             return end;
         }
 
@@ -56,19 +62,7 @@ namespace bbiwarg.Detectors.Finger
             //update farthest
             if (fingerPoint.getDepth() > farthest.getDepth()) farthest = fingerPoint;
 
-            //update direction+pointonline
-            PointF[] pointArray = new PointF[fingerPoints.Count];
-            int i = 0;
-            foreach (FingerPoint fp in fingerPoints)
-            {
-                pointArray[i] = new PointF(fp.getX(), fp.getY());
-                ++i;
-            }
-            PointCollection.Line2DFitting(pointArray, Emgu.CV.CvEnum.DIST_TYPE.CV_DIST_L2, out direction, out pointOnLine);
-
-            //update start+end
-            start = projectToLine(new PointF(farthest.getX(), farthest.getY()));
-            end = projectToLine(new PointF(nearest.getX(), nearest.getY()));
+            startEndUpToDate = false;
         }
 
         public float getMinDistance(FingerPoint fingerPoint)
@@ -106,5 +100,23 @@ namespace bbiwarg.Detectors.Finger
 
             return new PointF(ox + q * dx, oy + q * dy);
         }
+
+        private void updateStartEnd() {
+            //update direction+pointonline
+            PointF[] pointArray = new PointF[fingerPoints.Count];
+            int i = 0;
+            foreach (FingerPoint fp in fingerPoints)
+            {
+                pointArray[i] = new PointF(fp.getX(), fp.getY());
+                ++i;
+            }
+            PointCollection.Line2DFitting(pointArray, Emgu.CV.CvEnum.DIST_TYPE.CV_DIST_L2, out direction, out pointOnLine);
+
+            //update start+end
+            start = projectToLine(new PointF(farthest.getX(), farthest.getY()));
+            end = projectToLine(new PointF(nearest.getX(), nearest.getY()));
+
+            startEndUpToDate = true;
+        }
     }
 }

+ 0 - 4
bbiwarg/VideoHandle.cs

@@ -85,8 +85,6 @@ namespace bbiwarg
 
         private void processFrameUpdate()
         {
-            Stopwatch sw = new Stopwatch();
-            sw.Start();
             //read data from inputProvider
             inputFrame = inputProvider.getInputFrame();
             width = inputFrame.getWidth();
@@ -107,8 +105,6 @@ namespace bbiwarg
             //detect fingers
             fingerDetector = new FingerDetector(depthImage, edgeImage);
 
-            sw.Stop();
-            Console.WriteLine(sw.ElapsedMilliseconds);
         }
     }
 }