Browse Source

added fingertracking (using 3D)

Alexander Hendrich 11 years ago
parent
commit
a8621b36a9
2 changed files with 30 additions and 1 deletions
  1. 29 0
      bbiwarg/Graphics/Output.cs
  2. 1 1
      bbiwarg/Main/OutputTest.cs

+ 29 - 0
bbiwarg/Graphics/Output.cs

@@ -25,6 +25,7 @@ namespace bbiwarg.Graphics
         private uint[] triangles = new uint[0];
 
         private Point palmPoint;
+        private Point[] fingerPoints;
 
 
         public Output(IVideoDataSource source)
@@ -95,6 +96,12 @@ namespace bbiwarg.Graphics
             Vertex palmVertex = new Vertex(palmPosition[0], palmPosition[2], palmPosition[1]);
             palmPoint = new Point(palmVertex, Color.Yellow, 0.005f);
             graphicElements.Add(palmPoint);
+
+            fingerPoints = new Point[5];
+            for (int i = 0; i < 5; i++)
+            {
+                fingerPoints[i] = new Point(new Vertex(0f, 0f, 0f), Color.Yellow, 0.005f);
+            }
         }
 
         private void updateDepthPixels()
@@ -111,6 +118,28 @@ namespace bbiwarg.Graphics
             palmPoint.position.x = palmPosition[0];
             palmPoint.position.y = palmPosition[2];
             palmPoint.position.z = palmPosition[1];
+
+            
+            Vector[] fingerPositions = source.getFingerTipPositions3D(1);
+            DetectionStatus[] fingerStatus = source.getFingerStatus(1);
+            for(int i=0; i<5; i++) {
+                if(fingerStatus[i] == DetectionStatus.Tracked) {
+                   fingerPoints[i].position.x = fingerPositions[i][0];
+                   fingerPoints[i].position.y = fingerPositions[i][2];
+                   fingerPoints[i].position.z = fingerPositions[i][1];
+                } 
+                else if(fingerStatus[i] == DetectionStatus.Detected) {
+                    graphicElements.Add(fingerPoints[i]);
+                    fingerPoints[i].position.x = fingerPositions[i][0];
+                    fingerPoints[i].position.y = fingerPositions[i][2];
+                    fingerPoints[i].position.z = fingerPositions[i][1];
+                }
+                else if(fingerStatus[i] == DetectionStatus.Inactive && graphicElements.IndexOf(fingerPoints[i]) > -1) {
+                    graphicElements.Remove(fingerPoints[i]);
+                }
+            }
+
+            
         }
 
         private void initBuffers()

+ 1 - 1
bbiwarg/Main/OutputTest.cs

@@ -12,7 +12,7 @@ namespace bbiwarg.Main
     {
         static void Main(string[] args)
         {
-            IVideoDataSource source = new IIsuDataSource("..\\..\\videos\\2.skv");
+            IVideoDataSource source = new IIsuDataSource("..\\..\\videos\\6.skv");
             source.init();
             source.start();