Bladeren bron

Merge branch 'master' of https://git.tk.informatik.tu-darmstadt.de/etri-smartspaces

Alexander Hendrich 11 jaren geleden
bovenliggende
commit
977923cebd

+ 16 - 34
bbiwarg/DataSource/ForeFingerDetection.cs

@@ -19,8 +19,8 @@ namespace bbiwarg.DataSource
          *  handIndex: which hand's forefinger's position
          */
 
-        public const int TOLERANCE_Z = 5;
-        public const int TOLERANCE_2D = 7;
+        public const int TOLERANCE_Z = 3;
+        public const int TOLERANCE_2D = 3;
 
         private IInputProvider inputProvider;
         private IVideoHandle videoHandle;
@@ -30,8 +30,6 @@ namespace bbiwarg.DataSource
         private Vector palmPosition;
         private Vector foreFingerPosition;
         private float foreFingerDistance;
-        private float lowestY;
-        private float highestZ;
 
 
         public ForeFingerDetection(IInputProvider inputProvider, IVideoHandle videoHandle)
@@ -52,8 +50,6 @@ namespace bbiwarg.DataSource
             seenPoints = new HashSet<Vector>();
             foreFingerPosition = palmPosition;
             foreFingerDistance = 0;
-            lowestY = palmPosition[1];
-            highestZ = palmPosition[2];
 
             points.Add(palmPosition);
             seenPoints.Add(palmPosition);
@@ -68,35 +64,16 @@ namespace bbiwarg.DataSource
 
         private void checkPoint(Vector point)
         {
-            bool isLowestY = point[1] <= lowestY;
-            bool isHighestZ = point[2] >= highestZ;
-            if (isLowestY || isHighestZ)
-            {
-                if (isLowestY)
-                {
-                    if (lowestY == foreFingerPosition[1])
-                        foreFingerDistance = 0;
-                    lowestY = point[1];
-                }
-                if (isHighestZ)
-                {
-                    if (highestZ == foreFingerPosition[2])
-                        foreFingerDistance = 0;
-                    highestZ = point[2];
-                }
-
-                Vector distanceVector = new DenseVector(3);
-                videoHandle.pixel2VertexPosition(palmPosition).Subtract(videoHandle.pixel2VertexPosition(point), distanceVector);
-                //palmPosition.Subtract(point, distanceVector);
+            Vector distanceVector = new DenseVector(3);
+            videoHandle.pixel2VertexPosition(palmPosition).Subtract(videoHandle.pixel2VertexPosition(point), distanceVector);
 
-                float currentPointDistance = distanceVector.Norm(2);
-                if (currentPointDistance >= foreFingerDistance)
-                {
-                    foreFingerPosition = point;
-                    foreFingerDistance = currentPointDistance;
-                    addNeighbours(point);
-                }
+            float currentPointDistance = distanceVector.Norm(2);
+            if (currentPointDistance >= foreFingerDistance)
+            {
+                foreFingerPosition = point;
+                foreFingerDistance = currentPointDistance;
             }
+            addNeighbours(point);
         }
 
         private void addNeighbours(Vector point)
@@ -110,7 +87,7 @@ namespace bbiwarg.DataSource
                     currentPoint[0] = point[0] + x;
                     currentPoint[1] = point[1] + y;
                     currentPoint[2] = videoHandle.getDepth((int)currentPoint[0], (int)currentPoint[1]);
-                    if (Math.Abs(currentPoint[2] - point[2]) <= TOLERANCE_Z && !seenPoints.Contains(currentPoint))
+                    if (Math.Abs(currentPoint[2] - point[2]) <= TOLERANCE_Z && point[1] <= palmPosition[1] && !seenPoints.Contains(currentPoint))
                     {
                         points.Add(currentPoint);
                         seenPoints.Add(currentPoint);
@@ -118,5 +95,10 @@ namespace bbiwarg.DataSource
                 }
             }
         }
+
+        public List<Vector> getHandPoints()
+        {
+            return points;
+        }
     }
 }

+ 2 - 0
bbiwarg/DataSource/IVideoHandle.cs

@@ -1,4 +1,5 @@
 using System;
+using System.Collections.Generic;
 using System.Drawing;
 using MathNet.Numerics.LinearAlgebra.Single;
 
@@ -35,6 +36,7 @@ namespace bbiwarg.DataSource
         Vector getPalmPosition3D(uint handIndex);
         Vector getForearmPosition3D(uint handIndex);
         Vector getForeFingerPosition3D(uint handIndex);
+        List<Vector> getHandPoints();
         Palm getPalm(uint handIndex);
         int getWidth();
         int getHeight();

+ 5 - 0
bbiwarg/DataSource/VideoHandle.cs

@@ -123,6 +123,11 @@ namespace bbiwarg.DataSource
             return foreFingerDetection.getForeFingerPosition3D(handIndex);
         }
 
+        public List<Vector> getHandPoints()
+        {
+            return foreFingerDetection.getHandPoints();
+        }
+
         public Palm getPalm(uint handIndex)
         {
             return palmDetection.getPalm(handIndex);

+ 8 - 1
bbiwarg/Graphics/Output.cs

@@ -62,9 +62,16 @@ namespace bbiwarg.Graphics
 
             // foreFinger
             Vector foreFingerPosition = videoHandle.getForeFingerPosition3D(1);
-            Point foreFingerPoint = new Point(foreFingerPosition, Color.Red, 0.005f);
+            Point foreFingerPoint = new Point(foreFingerPosition, Color.Red, 0.05f);
             foreFingerPoint.draw();
 
+            //handPoints
+            List<Vector> handPoints = videoHandle.getHandPoints();
+            for (int i = 0; i < handPoints.Count(); i++)
+            {
+                new Point(videoHandle.pixel2VertexPosition(handPoints[i]), Color.Yellow, 0.001f).draw();
+            }
+
             // foreArm (iisu)
             Vector foreArmPosition = videoHandle.getForearmPosition3D(1);
             Point foreArmPoint = new Point(foreArmPosition, Color.Yellow, 0.005f);