Browse Source

added getFingetTipPositions2D

Alexander Hendrich 11 years ago
parent
commit
bbf9c9ed2f

+ 3 - 0
bbiwarg/DataSource/IVideoDataSource.cs

@@ -54,6 +54,8 @@ namespace bbiwarg.DataSource
          */
         bool isActive();
         int getFrameRate();
+        float getHFOV();
+        float getVFOV();
         /**
          * The depth is given by the distance to the camera in millimeters. 
          */
@@ -73,6 +75,7 @@ namespace bbiwarg.DataSource
         Vector getPalmNormal3D(uint handIndex);
         FingerStatus[] getFingerStatus(uint handIndex);
         Vector[] getFingerTipPositions3D(uint handIndex);
+        Vector[] getFingerTipPositions2D(uint handIndex);
         HandSide getHandSide(uint handIndex);
     }
 }

+ 27 - 1
bbiwarg/DataSource/IisuDataSource.cs

@@ -25,11 +25,14 @@ namespace bbiwarg.DataSource
         private IDataHandle<Iisu.Data.Vector3>[] palmNormals3D = new IDataHandle<Iisu.Data.Vector3>[2];
         private IDataHandle<int[]>[] fingerStatus = new IDataHandle<int[]>[2];
         private IDataHandle<Iisu.Data.Vector3[]>[] fingerTipPositions3D = new IDataHandle<Iisu.Data.Vector3[]>[2];
+        private IDataHandle<Iisu.Data.Vector2[]>[] fingerTipPositions2D = new IDataHandle<Iisu.Data.Vector2[]>[2];
         private IDataHandle<int>[] handSides = new IDataHandle<int>[2];
         private IDataHandle<Iisu.Data.IImageData> depthImage;
         private IDataHandle<Iisu.Data.IImageData> colorImage;
         private IDataHandle<Iisu.Data.IImageData> confidenceImage;
         private IDataHandle<Iisu.Data.IImageData> uvImage;
+        private IParameterHandle<float> hfov;
+        private IParameterHandle<float> vfov;
 
         /*
          * Creates an Iisu data source.
@@ -58,8 +61,10 @@ namespace bbiwarg.DataSource
                 device.RegisterParameterHandle<int>("SOURCE.MOVIE.PlayMode").Value = 0; // playMode = once
             else
                 device.RegisterParameterHandle<int>("SOURCE.DEPTHSENSE.AmplitudeThreshold").Value = 100; // confidence-threshhold
-            
+
             frameRate = device.RegisterParameterHandle<float>("SOURCE.FrameRate");
+            hfov = device.RegisterParameterHandle<float>("SOURCE.CAMERA.DEPTH.HFOV");
+            vfov = device.RegisterParameterHandle<float>("SOURCE.CAMERA.DEPTH.VFOV");
 
             // events
             device.EventManager.RegisterEventListener("DEVICE.Status", new Iisu.EventDelegates.Device.Status(onDeviceStatusChanged));
@@ -93,6 +98,9 @@ namespace bbiwarg.DataSource
 
             fingerTipPositions3D[0] = device.RegisterDataHandle<Iisu.Data.Vector3[]>("CI.HAND1.FingerTipPositions3D");
             fingerTipPositions3D[1] = device.RegisterDataHandle<Iisu.Data.Vector3[]>("CI.HAND2.FingerTipPositions3D");
+            
+            fingerTipPositions2D[0] = device.RegisterDataHandle<Iisu.Data.Vector2[]>("CI.HAND1.FingerTipPositions2D");
+            fingerTipPositions2D[1] = device.RegisterDataHandle<Iisu.Data.Vector2[]>("CI.HAND2.FingerTipPositions2D");
 
             handSides[0] = device.RegisterDataHandle<int>("CI.HAND1.Side");
             handSides[1] = device.RegisterDataHandle<int>("CI.HAND1.Side");
@@ -133,6 +141,14 @@ namespace bbiwarg.DataSource
             return (int) frameRate.Value;
         }
 
+        public float getHFOV() {
+            return hfov.Value;
+        }
+
+        public float getVFOV() {
+            return vfov.Value;
+        }
+
         public DepthImage getDepthImage()
         {
             Iisu.Data.IImageInfos imageInfos = depthImage.Value.ImageInfos;
@@ -273,6 +289,16 @@ namespace bbiwarg.DataSource
             return results;
         }
 
+        public Vector[] getFingerTipPositions2D(uint handIndex)
+        {
+            checkHandIndex(handIndex);
+            Iisu.Data.Vector2[] positions = fingerTipPositions2D[handIndex - 1].Value;
+            Vector[] results = new DenseVector[positions.Length];
+            for (int i = 0; i < positions.Length; ++i)
+                results[i] = new DenseVector(positions[i].ToArray());
+            return results;
+        }
+
         public HandSide getHandSide(uint handIndex)
         {
             checkHandIndex(handIndex);

+ 37 - 8
bbiwarg/Test/OutputTest.cs

@@ -78,22 +78,51 @@ namespace bbiwarg.Test
 
             for (int i = 0; i < pixel.Count; i++)
             {
-                pixel[i].depth = imageData.getDepth(pixel[i].x, pixel[i].y);
+                pixel[i].depth = 300;// imageData.getDepth(pixel[i].x, pixel[i].y);
                 pixel[i].color = imageData.getColor(pixel[i].x, pixel[i].y);
                 pixel[i].draw();
             }
 
-            Vector palmVertex = source.getPalmPosition3D(1);
+
+            /*
             Vector palmPixel = source.getPalmPosition2D(1);
-            Pixel3D palmPosition = new Pixel3D((int)palmPixel[0], (int)palmPixel[1], width, height);
-            palmPosition.depth = (short)(palmVertex[1] * 1000);
+            Vector palmVertex = source.getPalmPosition3D(1);
+             
+            float palmXn = palmVertex[0];
+            float palmYn = palmVertex[2];
+            float palmZn = palmVertex[1];
+
+            float alphaX = source.getHFOV();
+            float alphaY = source.getVFOV();
+
+            double maxXn = Math.Tan(alphaX/2) / palmZn;
+            double maxYn = Math.Tan(alphaY/2) / palmZn;
+
+            double u = 0.5f + palmXn / maxXn;
+            double v = 0.5f + palmYn / maxYn;
+
+            Console.WriteLine("u:" + u + " v:" + v);
+             
+            int palmX = (int)(u * depthImage.getWidth());
+            int palmY = (int)(1 - v) * depthImage.getHeight());
+             */
+
+            Vector palm = source.getPalmPosition2D(1);
+            Vector[] fingers = source.getFingerTipPositions2D(1);
+
+            Console.WriteLine(fingers[0][0]);
+
+            Pixel3D palmPosition = new Pixel3D((int)palm[0], (int)palm[1], width, height);
+            Pixel3D finger1Position = new Pixel3D((int)fingers[0][0], (int)fingers[0][1], width, height);
+            palmPosition.depth = 300;// depthImage.getDepth((int)palmPixel[0], (int)palmPixel[1]);// (short)(palmVertex[1] * 1000);
+            finger1Position.depth = 300;// depthImage.getDepth((int)palmPixel[0], (int)palmPixel[1]);// (short)(palmVertex[1] * 1000);
             palmPosition.color = Color.Red;
+            finger1Position.color = Color.Red;
             palmPosition.size = 3;
+            finger1Position.size = 3;
             palmPosition.draw();
-            //Console.WriteLine(palmPosition.toString());
-
-            //Console.WriteLine("Palm Position: x: " + (int)palmPixel[0] + " y: " + (int)palmPixel[1] + " 3DDepth: " + palmPosition.depth + " ImageDepth: " + imageData.getDepth((int)palmPixel[0], (int)palmPixel[1]));
-
+            finger1Position.draw();
+            
             for (int i = 0; i < triangles.Count; i++)
             {
                 triangles[i].draw();