Bladeren bron

added ConfidenceImage

Alexander Hendrich 11 jaren geleden
bovenliggende
commit
85974c18e5

+ 39 - 0
bbiwarg/DataSource/ConfidenceImage.cs

@@ -0,0 +1,39 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace bbiwarg.DataSource
+{
+    /**
+     * Represents an confidence image where the depth is given in distance to the camera in millimeters. 
+     */
+    class ConfidenceImage
+    {
+        private int width, height;
+        private short[] data;
+
+        public ConfidenceImage(int width, int height, short[] data)
+        {
+            this.width = width;
+            this.height = height;
+            this.data = data;
+        }
+
+        public int getWidth()
+        {
+            return width;
+        }
+
+        public int getHeight()
+        {
+            return height;
+        }
+
+        public short getConfidence(int x, int y)
+        {
+            return data[y * width + x];
+        }
+    }
+}

+ 1 - 0
bbiwarg/DataSource/IVideoDataSource.cs

@@ -59,6 +59,7 @@ namespace bbiwarg.DataSource
          */
         DepthImage getDepthImage();
         ColorImage getColorImage();
+        ConfidenceImage getConfidenceImage();
         /*
          * all handIndices have to be 1 or 2
          */

+ 21 - 3
bbiwarg/DataSource/IisuDataSource.cs

@@ -27,6 +27,7 @@ namespace bbiwarg.DataSource
         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;
 
         /*
          * Creates an Iisu data source.
@@ -47,9 +48,9 @@ namespace bbiwarg.DataSource
             IDeviceConfiguration conf = handle.CreateDeviceConfiguration();
             if (moviePath.Length != 0)
                 conf.MoviePath = moviePath;
-            
+
             device = handle.InitializeDevice(conf);
-            
+
             // parameters
             if (moviePath.Length != 0)
                 device.RegisterParameterHandle<int>("SOURCE.MOVIE.PlayMode").Value = 0; // playMode = once
@@ -60,8 +61,8 @@ namespace bbiwarg.DataSource
             
             // data
             depthImage = device.RegisterDataHandle<Iisu.Data.IImageData>("SOURCE.CAMERA.DEPTH.Image");
-
             colorImage = device.RegisterDataHandle<Iisu.Data.IImageData>("SOURCE.CAMERA.COLOR.Image");
+            confidenceImage = device.RegisterDataHandle<Iisu.Data.IImageData>("SOURCE.CAMERA.CONFIDENCE.Image");
             
             handOpen[0] = device.RegisterDataHandle<bool>("CI.HAND1.IsOpen");
             handOpen[1] = device.RegisterDataHandle<bool>("CI.HAND2.IsOpen");
@@ -125,6 +126,8 @@ namespace bbiwarg.DataSource
 
         public DepthImage getDepthImage()
         {
+            
+
             Iisu.Data.IImageInfos imageInfos = depthImage.Value.ImageInfos;
             int width = (int) imageInfos.Width;
             int height = (int) imageInfos.Height;
@@ -153,6 +156,21 @@ namespace bbiwarg.DataSource
             return new ColorImage(width, height, colorData);
         }
 
+        public ConfidenceImage getConfidenceImage()
+        {
+            Iisu.Data.IImageInfos imageInfos = confidenceImage.Value.ImageInfos;
+            int width = (int)imageInfos.Width;
+            int height = (int)imageInfos.Height;
+            int numBytes = (int)imageInfos.BytesRaw;
+
+            IntPtr imageData = confidenceImage.Value.Raw;
+
+            short[] confidenceData = new short[width * height];
+            Marshal.Copy(imageData, confidenceData, 0, width * height);
+
+            return new ConfidenceImage(width, height, confidenceData);
+        }
+
         private void checkHandIndex(uint handIndex) 
         {
             if (handIndex < 1 || handIndex > 2)

+ 15 - 9
bbiwarg/Test/OutputTest.cs

@@ -56,23 +56,29 @@ namespace bbiwarg.Test
             
             
             DepthImage depthImage = source.getDepthImage();
+            ConfidenceImage confidenceImage = source.getConfidenceImage();
             int width = depthImage.getWidth();
             int height = depthImage.getHeight();
 
             for (int x = 0; x < width-1; x++) {
                 for (int y = 0; y < height-1; y++)
                 {
-                    short depth = depthImage.getDepth(x, y);
+                    short confidence = confidenceImage.getConfidence(x,y);
 
-                    int relX = x - width / 2;
-                    int relY = height/2 - y;
+                    if(confidence > 100) {
+                        short depth = depthImage.getDepth(x, y);
 
-                    GL.Begin(BeginMode.Polygon);
-                    GL.Vertex3(relX-0.5f, relY+0.5f, -depth);
-                    GL.Vertex3(relX+0.5f, relY+0.5f, -depth);
-                    GL.Vertex3(relX+0.5f, relY-0.5f, -depth);
-                    GL.Vertex3(relX-0.5f, relY-0.5f, -depth);
-                    GL.End();
+
+                        int relX = x - width / 2;
+                        int relY = height/2 - y;
+
+                        GL.Begin(BeginMode.Polygon);
+                        GL.Vertex3(relX-0.5f, relY+0.5f, -depth);
+                        GL.Vertex3(relX+0.5f, relY+0.5f, -depth);
+                        GL.Vertex3(relX+0.5f, relY-0.5f, -depth);
+                        GL.Vertex3(relX-0.5f, relY-0.5f, -depth);
+                        GL.End();
+                    }
                 }
             }
 

+ 1 - 0
bbiwarg/bbiwarg.csproj

@@ -57,6 +57,7 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="DataSource\ColorImage.cs" />
+    <Compile Include="DataSource\ConfidenceImage.cs" />
     <Compile Include="DataSource\DepthImage.cs" />
     <Compile Include="DataSource\IisuDataSource.cs" />
     <Compile Include="DataSource\IVideoDataSource.cs" />