瀏覽代碼

ForeFingerDetection hinzugefügt und IVideoHandle/VideoHandle erweitert.

jost_vincent.schultz 11 年之前
父節點
當前提交
d202f8bea6

+ 84 - 0
bbiwarg/DataSource/ForeFingerDetection.cs

@@ -0,0 +1,84 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using MathNet.Numerics.LinearAlgebra.Single;
+
+using System.Drawing;
+
+
+namespace bbiwarg.DataSource
+{
+    class ForeFingerDetection
+    {
+        /*
+         * Returns the forefinger's position
+         * all fingers (except der forefinger) have to be inactive
+         * params:
+         *  handIndex: which hand's forefinger's position
+         */
+
+        public const int TOLERANCE_Z = 5;
+        public const int TOLERANCE_2D = 5;
+
+        private IVideoHandle source;
+        private HashSet<Vector> seenPoints;
+        private Vector palmPosition;
+        private Vector foreFingerPosition;
+        private float foreFingerDistance;
+
+
+
+        public ForeFingerDetection(IVideoHandle source)
+        {
+            this.source = source;
+        }
+
+        public Vector getForeFingerPosition3D(uint handIndex)
+        {
+            seenPoints = new HashSet<Vector>();
+            Vector palmPosition2D = source.getPalmPosition2D(handIndex);
+            palmPosition = new DenseVector(3);
+            palmPosition[0] = palmPosition2D[0];
+            palmPosition[1] = palmPosition2D[1];
+            palmPosition[2] = source.getDepth((int)palmPosition[0], (int)palmPosition[1]);
+
+            foreFingerPosition = palmPosition;
+            checkPoint(palmPosition);
+            return foreFingerPosition;
+        }
+
+        private void checkNeighbours(Vector point)
+        {
+            for (int y = -(int)Math.Min(TOLERANCE_2D, point[1]); y <= TOLERANCE_2D && point[1] + y < source.getHeight(); y++)
+            {
+                for (int x = -(int)Math.Min(TOLERANCE_2D, point[0]); x <= TOLERANCE_2D && point[0] + x < source.getWidth(); x++)
+                {
+                    Vector currentPoint = new DenseVector(3);
+                    currentPoint[0] = point[0] + x;
+                    currentPoint[1] = point[1] + y;
+                    currentPoint[2] = source.getDepth((int) currentPoint[0], (int) currentPoint[1]);
+                    if(Math.Abs(currentPoint[2]-point[2]) <= TOLERANCE_Z)
+                      checkPoint(currentPoint);
+                }
+            }
+        }
+        private void checkPoint(Vector point)
+        {
+            if (!seenPoints.Contains<Vector>(point))
+            {
+                seenPoints.Add(point);
+                Vector distanceVector = new DenseVector(3);
+                palmPosition.Subtract(point, distanceVector);
+                float currentPointDistance = distanceVector.Norm(2);
+                if (currentPointDistance >= foreFingerDistance)
+                {
+                    foreFingerPosition = point;
+                    foreFingerDistance = currentPointDistance;
+                    checkNeighbours(point);
+                }
+            }
+        }
+    }
+}

+ 3 - 0
bbiwarg/DataSource/IVideoHandle.cs

@@ -31,6 +31,9 @@ namespace bbiwarg.DataSource
         VertexArray getVertexArray();
         //convert2Dto3D(float x, float y, int depth)
 
+        Vector getPalmPosition2D(uint handIndex);
         Vector getPalmPosition3D(uint handIndex);
+        int getWidth();
+        int getHeight();
     }
 }

+ 15 - 2
bbiwarg/DataSource/VideoHandle.cs

@@ -77,6 +77,12 @@ namespace bbiwarg.DataSource
             return colorImage.getColor(xInColorImage, yInColorImage);
         }
 
+        public Vector getPalmPosition2D(uint handIndex)
+        {
+            //improved palm recognition or just return the value provided by inputprovider
+            return inputProvider.getPalmPosition2D(handIndex);
+        }
+
         public Vector getPalmPosition3D(uint handIndex)
         {
             //improved palm recognition or just return the value provided by inputprovider
@@ -128,7 +134,14 @@ namespace bbiwarg.DataSource
             vertexData[index + 1] = y;
             vertexData[index + 2] = z;
         }
-        
-        
+
+        public int getWidth()
+        {
+            return depthImage.getWidth();
+        }
+        public int getHeight()
+        {
+            return depthImage.getHeight();
+        }
     }
 }

+ 1 - 0
bbiwarg/bbiwarg.csproj

@@ -56,6 +56,7 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="DataSource\ForeFingerDetection.cs" />
     <Compile Include="DataSource\IInputProvider.cs" />
     <Compile Include="DataSource\UVImage.cs" />
     <Compile Include="DataSource\ColorImage.cs" />