Esempio n. 1
0
        public void TestDispose()
        {
            DepthFrameData data = new DepthFrameData();

            data.Dispose();
            Assert.AreEqual(data.DataPointer, IntPtr.Zero);
        }
Esempio n. 2
0
        public void TestDisposedSize()
        {
            DepthFrameData data = new DepthFrameData();

            data.Dispose();
            Assert.AreEqual(data.SizeInBytes, 0);
        }
Esempio n. 3
0
        public void TextCompressBodyFrame()
        {
            DepthFrameData frame = FakeImageData.RandomDepthFrame();

            SnappyFrameCompressor compressor = new SnappyFrameCompressor(KinectFrameInformation.DepthFrame);

            compressor.Compress(frame.DataPointer);

            SnappyFrameDecompressor decompressor = new SnappyFrameDecompressor(KinectFrameInformation.DepthFrame);

            var barray = compressor.CompressedFrameData;

            fixed(byte *bptr = &barray[0])
            {
                decompressor.UnCompress(new IntPtr(bptr), compressor.CompressedSize);
            }

            var decomparray = decompressor.UnCompressedFrameData;

            fixed(byte *bptr = &barray[0])
            {
                FakeImageData.ByteCheck(frame.DataPointer, new IntPtr(bptr), decompressor.UnCompressedSize);
            }

            frame.Dispose();
        }
Esempio n. 4
0
        public void TestConstrutor()
        {
            DepthFrameData data = new DepthFrameData();
            bool           pass = data.DataPointer != IntPtr.Zero;

            data.Dispose();
            Assert.AreEqual(true, pass);
        }
 public void DepthTestConstructor()
 {
     using (DepthFrameData depthFrame = new DepthFrameData())
     {
         DepthFrameDataEventArgs args = new DepthFrameDataEventArgs(depthFrame);
         Assert.AreEqual(depthFrame, args.DepthData);
     }
 }
Esempio n. 6
0
        public void TestSize()
        {
            DepthFrameData data     = new DepthFrameData();
            int            expected = 512 * 424 * 2;
            bool           pass     = data.SizeInBytes == expected;

            data.Dispose();
            Assert.AreEqual(pass, true);
        }
Esempio n. 7
0
        public void TestDisposeAccess()
        {
            DepthFrameData data = new DepthFrameData();

            data.Dispose();

            //Should throw exception
            var pointer = data.DataPointer;
        }
 public void TestNullDevice()
 {
     using (DepthFrameData frame = new DepthFrameData())
     {
         using (ImmutableDepthTexture texture = new ImmutableDepthTexture(null, frame))
         {
         }
     }
 }
Esempio n. 9
0
        /// <summary>
        /// Contructor
        /// </summary>
        /// <param name="depthData">Depth Frame data</param>
        public DepthFrameDataEventArgs(DepthFrameData depthData)
        {
            if (depthData == null)
            {
                throw new ArgumentNullException("depthData");
            }

            this.depthData = depthData;
        }
Esempio n. 10
0
        public void TestMultipleDispose()
        {
            DepthFrameData data = new DepthFrameData();

            data.Dispose();
            //Second call to dispose should do nothing
            data.Dispose();

            Assert.AreEqual(data.DataPointer, IntPtr.Zero);
        }
Esempio n. 11
0
 public void TestCopy()
 {
     using (DepthFrameData frame = new DepthFrameData())
     {
         using (DynamicDepthTexture texture = new DynamicDepthTexture(device))
         {
             texture.Copy(device.ImmediateContext, frame);
         }
     }
 }
 public void TestCreate()
 {
     using (DepthFrameData frame = new DepthFrameData())
     {
         using (ImmutableDepthTexture texture = new ImmutableDepthTexture(device, frame))
         {
             Assert.AreNotEqual(texture.NormalizedView.NativePointer, IntPtr.Zero);
             Assert.AreNotEqual(texture.RawView.NativePointer, IntPtr.Zero);
         }
     }
 }
Esempio n. 13
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="sensor">Kinect sensor</param>
        public KinectSensorDepthFrameProvider(KinectSensor sensor)
        {
            if (sensor == null)
            {
                throw new ArgumentNullException("sensor");
            }

            this.sensor      = sensor;
            this.depthReader = this.sensor.DepthFrameSource.OpenReader();
            this.depthReader.FrameArrived += depthReader_FrameArrived;
            this.frameData = new DepthFrameData();
        }
Esempio n. 14
0
        /// <summary>
        /// Creates an immutable depth texture, allocates GPU resources
        /// </summary>
        /// <param name="device">Direct3D Device</param>
        /// <param name="data">Depth frame data</param>
        public ImmutableDepthTexture(Device device, DepthFrameData data)
        {
            if (device == null)
            {
                throw new ArgumentNullException("device");
            }
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            DataRectangle dr = new DataRectangle(data.DataPointer, Consts.DepthWidth * sizeof(ushort));

            this.texture        = new Texture2D(device, DepthTextureDescriptors.ImmutableResource, dr);
            this.rawView        = new ShaderResourceView(device, this.texture, DepthTextureDescriptors.RawView);
            this.normalizedView = new ShaderResourceView(device, this.texture, DepthTextureDescriptors.NormalizedView);
        }
Esempio n. 15
0
        public static DepthFrameData RandomDepthFrame()
        {
            DepthFrameData data = new DepthFrameData();
            Random         r    = new Random();

            ushort[] d = new ushort[512 * 424];
            for (int i = 0; i < d.Length; i++)
            {
                d[i] = (ushort)r.Next(0, ushort.MaxValue);
            }

            fixed(ushort *ptr = &d[0])
            {
                memcpy(data.DataPointer, new IntPtr(ptr), 512 * 424 * 2);
            }

            return(data);
        }
Esempio n. 16
0
		private void client_DepthFrameReady(object sender, DepthFrameData e)
		{
			if(_depthBitmap == null || _depthBitmap.PixelWidth != e.ImageFrame.Width || _depthBitmap.PixelHeight != e.ImageFrame.Height)
			{
				_depthBitmap = new WriteableBitmap(e.ImageFrame.Width, e.ImageFrame.Height);
				this.Depth.Source = this._depthBitmap;
			}

			byte[] convertedDepthBits = ConvertDepthFrame(e.DepthData.ToArray(), e);

			InMemoryRandomAccessStream depthStream = new InMemoryRandomAccessStream();
			DataWriter depthWriter = new DataWriter(depthStream.GetOutputStreamAt(0));
			depthWriter.WriteBytes(convertedDepthBits);

			Stream s = _depthBitmap.PixelBuffer.AsStream();
			s.Write(convertedDepthBits, 0, convertedDepthBits.Length);
			_depthBitmap.Invalidate();
		}
Esempio n. 17
0
		private byte[] ConvertDepthFrame(byte[] depthFrame, DepthFrameData args)
		{
			int[] intensityShiftByPlayerR = { 1, 2, 0, 2, 0, 0, 2, 0 };
			int[] intensityShiftByPlayerG = { 1, 2, 2, 0, 2, 0, 0, 1 };
			int[] intensityShiftByPlayerB = { 1, 0, 2, 2, 0, 2, 0, 2 };

			const int RedIndex = 2;
			const int GreenIndex = 1;
			const int BlueIndex = 0;

			byte[] depthFrame32 = new byte[args.ImageFrame.Width * args.ImageFrame.Height * 4];

			for (int i16 = 0, i32 = 0; i16 < depthFrame.Length && i32 < depthFrame.Length * 4; i16+=2, i32 += 4)
			{
				short val = (short)(depthFrame[i16] | (depthFrame[i16+1] << 8));
				int player = val & args.PlayerIndexBitmask;
				int realDepth = val >> args.PlayerIndexBitmaskWidth;
				
				// transform 13-bit depth information into an 8-bit intensity appropriate
				// for display (we disregard information in most significant bit)
				byte intensity = (byte)(~(realDepth >> 4));

				if (player == 0 && realDepth == 0)
				{
					// white 
					depthFrame32[i32 + RedIndex] = 255;
					depthFrame32[i32 + GreenIndex] = 255;
					depthFrame32[i32 + BlueIndex] = 255;
				}
				else
				{
					// tint the intensity by dividing by per-player values
					depthFrame32[i32 + RedIndex] = (byte)(intensity >> intensityShiftByPlayerR[player]);
					depthFrame32[i32 + GreenIndex] = (byte)(intensity >> intensityShiftByPlayerG[player]);
					depthFrame32[i32 + BlueIndex] = (byte)(intensity >> intensityShiftByPlayerB[player]);
				}
			}

			return depthFrame32;
		}
 private void FrameReceived(object sender, DepthFrameDataEventArgs e)
 {
     this.currentFrameData = e.DepthData;
     this.upload           = true;
 }
Esempio n. 19
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            RenderForm form = new RenderForm("Kinect depth sample");

            RenderDevice  device    = new RenderDevice(SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport);
            RenderContext context   = new RenderContext(device);
            DX11SwapChain swapChain = DX11SwapChain.FromHandle(device, form.Handle);

            KinectSensor sensor = KinectSensor.GetDefault();

            sensor.Open();



            bool                           doQuit      = false;
            bool                           doUpload    = false;
            DepthFrameData                 currentData = null;
            DynamicDepthTexture            depth       = new DynamicDepthTexture(device);
            KinectSensorDepthFrameProvider provider    = new KinectSensorDepthFrameProvider(sensor);

            provider.FrameReceived += (sender, args) => { currentData = args.DepthData; doUpload = true; };

            form.KeyDown += (sender, args) => { if (args.KeyCode == Keys.Escape)
                                                {
                                                    doQuit = true;
                                                }
            };

            RenderLoop.Run(form, () =>
            {
                if (doQuit)
                {
                    form.Dispose();
                    return;
                }

                if (doUpload)
                {
                    depth.Copy(context, currentData);
                    doUpload = false;
                }

                context.RenderTargetStack.Push(swapChain);

                device.Primitives.ApplyFullTri(context, depth.NormalizedView);

                device.Primitives.FullScreenTriangle.Draw(context);
                context.RenderTargetStack.Pop();
                swapChain.Present(0, SharpDX.DXGI.PresentFlags.None);
            });

            swapChain.Dispose();
            context.Dispose();
            device.Dispose();

            depth.Dispose();
            provider.Dispose();

            sensor.Close();
        }
Esempio n. 20
0
 /// <summary>
 /// Copy depth frame to graphics card
 /// </summary>
 /// <param name="context">Device context</param>
 /// <param name="data">Depth frame data</param>
 public void Copy(DeviceContext context, DepthFrameData data)
 {
     this.texture.Upload(context, data.DataPointer, data.SizeInBytes);
 }
Esempio n. 21
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            RenderForm form = new RenderForm("Kinect depth local stream sample");

            RenderDevice  device    = new RenderDevice(SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport);
            RenderContext context   = new RenderContext(device);
            DX11SwapChain swapChain = DX11SwapChain.FromHandle(device, form.Handle);

            PixelShader pixelShaderRaw = ShaderCompiler.CompileFromFile <PixelShader>(device, "DepthToWorld.fx", "PS_Raw");

            KinectSensor sensor = KinectSensor.GetDefault();

            sensor.Open();

            KinectFrameServer frameServer = new KinectFrameServer(32000, sensor);

            KinectFrameClient frameClient = new KinectFrameClient(IPAddress.Parse("127.0.0.1"), 32000);

            RayTableTexture     rayTable     = RayTableTexture.FromCoordinateMapper(device, sensor.CoordinateMapper);
            RenderCameraTexture renderCamera = new RenderCameraTexture(device);

            frameClient.Connect();


            bool doQuit = false;


            bool uploadDepth = false;
            bool uploadBody  = false;

            int mode = 0; //0 = body index, 1 = depth, 2 = world

            DepthFrameData      depthData = null;
            DynamicDepthTexture depth     = new DynamicDepthTexture(device);

            IDepthFrameProvider networkDepth = (IDepthFrameProvider)frameClient;

            networkDepth.FrameReceived += (sender, args) => { depthData = args.DepthData; uploadDepth = true; };

            BodyIndexFrameData      bodyIndexData    = null;
            DynamicBodyIndexTexture bodyIndexTexture = new DynamicBodyIndexTexture(device);

            IBodyIndexFrameProvider networkBody = (IBodyIndexFrameProvider)frameClient;

            networkBody.FrameReceived += (sender, args) => { bodyIndexData = args.FrameData; uploadBody = true; };


            form.KeyDown += (sender, args) => { if (args.KeyCode == Keys.Escape)
                                                {
                                                    doQuit = true;
                                                }
                                                if (args.KeyCode == Keys.Space)
                                                {
                                                    mode++; if (mode > 2)
                                                    {
                                                        mode = 0;
                                                    }
                                                }
            };

            RenderLoop.Run(form, () =>
            {
                if (doQuit)
                {
                    form.Dispose();
                    return;
                }

                if (uploadDepth)
                {
                    depth.Copy(context, depthData);
                    uploadDepth = false;

                    if (mode == 2)
                    {
                        //Convert depth to world
                        context.Context.OutputMerger.SetRenderTargets(renderCamera.RenderView);
                        device.Primitives.ApplyFullTriVS(context);
                        context.Context.PixelShader.Set(pixelShaderRaw);
                        context.Context.PixelShader.SetShaderResource(0, depth.RawView);

                        context.Context.PixelShader.SetShaderResource(1, rayTable.ShaderView);

                        device.Primitives.FullScreenTriangle.Draw(context);
                        context.RenderTargetStack.Apply();
                    }
                }

                if (uploadBody)
                {
                    bodyIndexTexture.Copy(context, bodyIndexData);
                    uploadBody = false;
                }

                context.RenderTargetStack.Push(swapChain);

                if (mode == 0)
                {
                    device.Primitives.ApplyFullTri(context, bodyIndexTexture.NormalizedView);
                }
                else if (mode == 1)
                {
                    device.Primitives.ApplyFullTri(context, depth.NormalizedView);
                }
                else
                {
                    device.Primitives.ApplyFullTri(context, renderCamera.ShaderView);
                }

                device.Primitives.FullScreenTriangle.Draw(context);
                context.RenderTargetStack.Pop();
                swapChain.Present(0, SharpDX.DXGI.PresentFlags.None);
            });

            swapChain.Dispose();
            context.Dispose();
            device.Dispose();

            depth.Dispose();
            bodyIndexTexture.Dispose();
            frameClient.Stop();
            frameServer.Dispose();

            rayTable.Dispose();
            renderCamera.Dispose();

            pixelShaderRaw.Dispose();

            sensor.Close();
        }
 public DummyDepthProvider()
 {
     this.frameData = new DepthFrameData();
 }
Esempio n. 23
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            RenderForm form = new RenderForm(header);

            RenderDevice  device    = new RenderDevice(SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport);
            RenderContext context   = new RenderContext(device);
            DX11SwapChain swapChain = DX11SwapChain.FromHandle(device, form.Handle);

            PixelShader pixelShaderRaw  = ShaderCompiler.CompileFromFile <PixelShader>(device, "DepthToWorld.fx", "PS_Raw");
            PixelShader pixelShaderNorm = ShaderCompiler.CompileFromFile <PixelShader>(device, "DepthToWorld.fx", "PS_Normalized");

            RayTableTexture rayTable = null;
            KinectSensor    sensor   = KinectSensor.GetDefault();

            sensor.CoordinateMapper.CoordinateMappingChanged += (s, e) =>
            {
                if (rayTable == null)
                {
                    rayTable = RayTableTexture.FromCoordinateMapper(device, sensor.CoordinateMapper);
                }
            };
            sensor.Open();


            RenderCameraTexture renderCamera = new RenderCameraTexture(device);

            bool doQuit   = false;
            bool doUpload = false;
            bool useRaw   = true;

            DepthFrameData                 currentData = null;
            DynamicDepthTexture            depth       = new DynamicDepthTexture(device);
            KinectSensorDepthFrameProvider provider    = new KinectSensorDepthFrameProvider(sensor);

            provider.FrameReceived += (sender, args) => { currentData = args.DepthData; doUpload = true; };

            form.KeyDown += (sender, args) => { if (args.KeyCode == Keys.Escape)
                                                {
                                                    doQuit = true;
                                                }
                                                if (args.KeyCode == Keys.Space)
                                                {
                                                    useRaw = !useRaw;
                                                }
            };

            RenderLoop.Run(form, () =>
            {
                form.Text = header + (useRaw ? " - Raw Mode": " - Normalized Mode");

                if (doQuit)
                {
                    form.Dispose();
                    return;
                }

                if (doUpload && rayTable != null)
                {
                    depth.Copy(context, currentData);

                    //Convert depth to world
                    context.Context.OutputMerger.SetRenderTargets(renderCamera.RenderView);
                    device.Primitives.ApplyFullTriVS(context);

                    if (useRaw)
                    {
                        context.Context.PixelShader.Set(pixelShaderRaw);
                        context.Context.PixelShader.SetShaderResource(0, depth.RawView);
                    }
                    else
                    {
                        context.Context.PixelShader.Set(pixelShaderNorm);
                        context.Context.PixelShader.SetShaderResource(0, depth.NormalizedView);
                    }

                    context.Context.PixelShader.SetShaderResource(1, rayTable.ShaderView);

                    device.Primitives.FullScreenTriangle.Draw(context);
                    context.RenderTargetStack.Apply();
                }

                context.RenderTargetStack.Push(swapChain);

                device.Primitives.ApplyFullTri(context, renderCamera.ShaderView);

                device.Primitives.FullScreenTriangle.Draw(context);
                context.RenderTargetStack.Pop();
                swapChain.Present(0, SharpDX.DXGI.PresentFlags.None);
            });

            swapChain.Dispose();
            context.Dispose();
            device.Dispose();

            depth.Dispose();
            renderCamera.Dispose();
            if (rayTable != null)
            {
                rayTable.Dispose();
            }
            provider.Dispose();

            pixelShaderNorm.Dispose();
            pixelShaderRaw.Dispose();

            sensor.Close();
        }