Pārlūkot izejas kodu

Changed IVideoDataSource, IisuDataSource and TestDataSource to assume depth in millimeters from camera.

Daniel Kauth 11 gadi atpakaļ
vecāks
revīzija
bbe4c1f299

BIN
bbiwarg.v11.suo


+ 6 - 3
bbiwarg/DepthImage.cs

@@ -6,12 +6,15 @@ using System.Threading.Tasks;
 
 namespace bbiwarg
 {
+    /**
+     * Represents an depth image where the depth is given in distance to the camera in millimeters. 
+     */
     class DepthImage
     {
         private int width, height;
-        private ushort[] data;
+        private short[] data;
 
-        public DepthImage(int width, int height, ushort[] data)
+        public DepthImage(int width, int height, short[] data)
         {
             this.width = width;
             this.height = height;
@@ -28,7 +31,7 @@ namespace bbiwarg
             return height;
         }
 
-        public ushort getDepth(int x, int y)
+        public short getDepth(int x, int y)
         {
             return data[y * width + x];
         }

+ 3 - 0
bbiwarg/IVideoDataSource.cs

@@ -54,6 +54,9 @@ namespace bbiwarg
          */
         bool isActive();
         int getFrameRate();
+        /**
+         * The depth is given by the distance to the camera in millimeters. 
+         */
         DepthImage getDepthImage();
 
         /*

+ 3 - 6
bbiwarg/IisuDataSource.cs

@@ -128,13 +128,10 @@ namespace bbiwarg
 
             IntPtr imageData = depthImage.Value.Raw;
             
-            short[] tmp = new short[width * height];
-            Marshal.Copy(imageData, tmp, 0, width * height);
+            short[] depthData = new short[width * height];
+            Marshal.Copy(imageData, depthData, 0, width * height);
 
-            ushort[] data = new ushort[width * height];
-            Buffer.BlockCopy(tmp, 0, data, 0, numBytes);
-
-            return new DepthImage(width, height, data);
+            return new DepthImage(width, height, depthData);
         }
 
         private void checkHandIndex(uint handIndex) 

+ 2 - 2
bbiwarg/TestDataSource.cs

@@ -8,7 +8,7 @@ namespace bbiwarg
     {
         static void Main(string[] args)
         {
-            IVideoDataSource source = new IIsuDataSource("..\\..\\videos\\1.skv");
+            IVideoDataSource source = new IIsuDataSource("..\\..\\videos\\2.skv");
 
             source.init();
             source.start();
@@ -28,7 +28,7 @@ namespace bbiwarg
                     {
                         for (int y = 0; y < image.getHeight(); ++y) 
                         {
-                            int value = (image.getDepth(x, y) / 4) % 256; // / 4 because most values are small (< 1024)
+                            int value = (int) (image.getDepth(x, y) / 1000.0 * 255.0) % 256;
                             bm.SetPixel(x, y, Color.FromArgb(255, value, value, value));
                         }
                     }