Parcourir la source

moved ForeFingerDetection and PalmDetection to VideoHandle

Alexander Hendrich il y a 11 ans
Parent
commit
001d4c3908

+ 12 - 10
bbiwarg/DataSource/ForeFingerDetection.cs

@@ -22,7 +22,8 @@ namespace bbiwarg.DataSource
         public const int TOLERANCE_Z = 5;
         public const int TOLERANCE_2D = 7;
 
-        private IVideoHandle source;
+        private IInputProvider inputProvider;
+        private IVideoHandle videoHandle;
 
         private List<Vector> points;
         private HashSet<Vector> seenPoints;
@@ -33,18 +34,19 @@ namespace bbiwarg.DataSource
         private float highestZ;
 
 
-        public ForeFingerDetection(IVideoHandle source)
+        public ForeFingerDetection(IInputProvider inputProvider, IVideoHandle videoHandle)
         {
-            this.source = source;
+            this.inputProvider = inputProvider;
+            this.videoHandle = videoHandle;
         }
 
         public Vector getForeFingerPosition3D(uint handIndex)
         {
-            Vector palmPosition2D = source.getPalmPosition2D(handIndex);
+            Vector palmPosition2D = inputProvider.getPalmPosition2D(handIndex);
             palmPosition = new DenseVector(3);
             palmPosition[0] = palmPosition2D[0];
             palmPosition[1] = palmPosition2D[1];
-            palmPosition[2] = source.getDepth((int)palmPosition[0], (int)palmPosition[1]);
+            palmPosition[2] = videoHandle.getDepth((int)palmPosition[0], (int)palmPosition[1]);
 
             points = new List<Vector>();
             seenPoints = new HashSet<Vector>();
@@ -60,7 +62,7 @@ namespace bbiwarg.DataSource
                 checkPoint(points[i]);
             }
 
-            return foreFingerPosition;
+            return videoHandle.pixel2VertexPosition(foreFingerPosition);
         }
 
 
@@ -84,7 +86,7 @@ namespace bbiwarg.DataSource
                 }
 
                 Vector distanceVector = new DenseVector(3);
-                source.pixel2VertexPosition(palmPosition).Subtract(source.pixel2VertexPosition(point), distanceVector);
+                videoHandle.pixel2VertexPosition(palmPosition).Subtract(videoHandle.pixel2VertexPosition(point), distanceVector);
                 //palmPosition.Subtract(point, distanceVector);
 
                 float currentPointDistance = distanceVector.Norm(2);
@@ -100,14 +102,14 @@ namespace bbiwarg.DataSource
         private void addNeighbours(Vector point)
         {
             Vector currentPoint;
-            for (int y = -(int)Math.Min(TOLERANCE_2D, point[1]); y <= TOLERANCE_2D && point[1] + y < source.getHeight(); y++)
+            for (int y = -(int)Math.Min(TOLERANCE_2D, point[1]); y <= TOLERANCE_2D && point[1] + y < videoHandle.getHeight(); y++)
             {
-                for (int x = -(int)Math.Min(TOLERANCE_2D, point[0]); x <= TOLERANCE_2D && point[0] + x < source.getWidth(); x++)
+                for (int x = -(int)Math.Min(TOLERANCE_2D, point[0]); x <= TOLERANCE_2D && point[0] + x < videoHandle.getWidth(); x++)
                 {
                     currentPoint = new DenseVector(3);
                     currentPoint[0] = point[0] + x;
                     currentPoint[1] = point[1] + y;
-                    currentPoint[2] = source.getDepth((int)currentPoint[0], (int)currentPoint[1]);
+                    currentPoint[2] = videoHandle.getDepth((int)currentPoint[0], (int)currentPoint[1]);
                     if (Math.Abs(currentPoint[2] - point[2]) <= TOLERANCE_Z && !seenPoints.Contains(currentPoint))
                     {
                         points.Add(currentPoint);

+ 2 - 1
bbiwarg/DataSource/IVideoHandle.cs

@@ -32,9 +32,10 @@ namespace bbiwarg.DataSource
 
         DetectionStatus[] getFingerStatus(uint handIndex);
         Vector[] getFingerTipPositions3D(uint handIndex);
-        Vector getPalmPosition2D(uint handIndex);
         Vector getPalmPosition3D(uint handIndex);
         Vector getForearmPosition3D(uint handIndex);
+        Vector getForeFingerPosition3D(uint handIndex);
+        Palm getPalm(uint handIndex);
         int getWidth();
         int getHeight();
     }

+ 1 - 1
bbiwarg/DataSource/PalmDetection.cs

@@ -18,7 +18,7 @@ namespace bbiwarg.DataSource
         {
             this.input = input;
             this.videoHandle = videoHandle;
-            this.foreFingerDetection = new ForeFingerDetection(videoHandle);
+            this.foreFingerDetection = new ForeFingerDetection(input, videoHandle);
         }
 
         public Palm getPalm(uint handIndex)

+ 16 - 5
bbiwarg/DataSource/VideoHandle.cs

@@ -11,6 +11,9 @@ namespace bbiwarg.DataSource
 {
     class VideoHandle : IVideoHandle
     {
+        private ForeFingerDetection foreFingerDetection;
+        private PalmDetection palmDetection;
+
         private IInputProvider inputProvider;
         private DepthImage depthImage;
         private ConfidenceImage confidenceImage;
@@ -25,6 +28,9 @@ namespace bbiwarg.DataSource
             inputProvider.init();
             inputProvider.start();
             inputProvider.updateFrame();
+
+            foreFingerDetection = new ForeFingerDetection(inputProvider, this);
+            palmDetection = new PalmDetection(inputProvider, this);
             createImageData();
 
             maxU = (float)(Math.Tan(inputProvider.getHFOV() / 2f));
@@ -102,11 +108,6 @@ namespace bbiwarg.DataSource
             return inputProvider.getFingerTipPositions3D(handIndex);
         }
 
-        public Vector getPalmPosition2D(uint handIndex)
-        {
-            return inputProvider.getPalmPosition2D(handIndex);
-        }
-
         public Vector getPalmPosition3D(uint handIndex)
         {
             return inputProvider.getPalmPosition3D(handIndex);
@@ -117,6 +118,16 @@ namespace bbiwarg.DataSource
             return inputProvider.getForearmPosition3D(handIndex);
         }
 
+        public Vector getForeFingerPosition3D(uint handIndex)
+        {
+            return foreFingerDetection.getForeFingerPosition3D(handIndex);
+        }
+
+        public Palm getPalm(uint handIndex)
+        {
+            return palmDetection.getPalm(handIndex);
+        }
+
         // TODO
         public void createVertexArray(IntPtr vertexBuffer)
         {

+ 2 - 6
bbiwarg/Graphics/Output.cs

@@ -16,16 +16,12 @@ namespace bbiwarg.Graphics
     class Output : GameWindow
     {
         private IVideoHandle videoHandle;
-        private ForeFingerDetection foreFingerDetection;
-        private PalmDetection palmDetection;
 
         private uint imageBufferId, pointBufferId, quadBufferId;
 
         public Output(IVideoHandle videoHandle)
         {
             this.videoHandle = videoHandle;
-            this.foreFingerDetection = new ForeFingerDetection(videoHandle);
-            this.palmDetection = new PalmDetection(inputProvider, videoHandle);
         }
 
         protected override void OnLoad(EventArgs e)
@@ -77,7 +73,7 @@ namespace bbiwarg.Graphics
             pointData = new float[(4 + 3) * (3 + numFingersDetected)];
             Color y = Color.Yellow;
             Vector palmPosition = videoHandle.getPalmPosition3D(1);
-            Vector foreFingerPosition = videoHandle.pixel2VertexPosition(foreFingerDetection.getForeFingerPosition3D(1));
+            Vector foreFingerPosition = videoHandle.getForeFingerPosition3D(1);
             Vector foreArmPosition = videoHandle.getForearmPosition3D(1);
 
             pointData[0] = palmPosition[0];
@@ -137,7 +133,7 @@ namespace bbiwarg.Graphics
             // draw quads
             float[] quadData = new float[4 * (4 + 3) * 1];
 
-            Palm palm = palmDetection.getPalm(1);
+            Palm palm = videoHandle.getPalm(1);
             Vector ul = palm.getUpperLeft();
             Vector ur = palm.getUpperRight();
             Vector lr = palm.getLowerRight();