Esempio n. 1
0
 void xtion_DepthFrameReady( object sender, DepthFrameReadyEventArgs e )
 {
     this.Dispatcher.BeginInvoke( DispatcherPriority.Background, new Action( () =>
     {
         imageDepth.Source = e.DepthGenerator.ToBitmapSource();
     } ) );
 }
Esempio n. 2
0
		void DepthClient_FrameReady(object sender, FrameReadyEventArgs e)
		{
			DepthFrameReadyEventArgs args = new DepthFrameReadyEventArgs();
			DepthFrameData dfd = new DepthFrameData();

			MemoryStream ms = new MemoryStream(e.Data);
			BinaryReader br = new BinaryReader(ms);

			dfd.PlayerIndexBitmask = br.ReadInt32();
			dfd.PlayerIndexBitmaskWidth = br.ReadInt32();

			DepthImageFrame frame = br.ReadDepthImageFrame();
			dfd.ImageFrame = frame;

			int dataLength = (int)(ms.Length - ms.Position);

			if(_depthShort == null || _depthShort.Length != dataLength / 2)
				_depthShort = new short[dataLength / 2];

			Buffer.BlockCopy(e.Data, (int)br.BaseStream.Position, _depthShort, 0, dataLength);

			dfd.DepthData = _depthShort;

			DepthFrame = dfd;
			args.DepthFrame = dfd;

			if(DepthFrameReady != null)
				DepthFrameReady(this, args);
		}
Esempio n. 3
0
		private void client_DepthFrameReady(object sender, DepthFrameReadyEventArgs e)
		{
			if(_outputBitmap == null || 
				_outputBitmap.PixelWidth != e.DepthFrame.ImageFrame.Width || 
				_outputBitmap.PixelHeight != e.DepthFrame.ImageFrame.Height)
			{
				this._outputBitmap = new WriteableBitmap(
					e.DepthFrame.ImageFrame.Width, 
					e.DepthFrame.ImageFrame.Height, 
					96,  // DpiX
					96,  // DpiY
					PixelFormats.Bgr32,
					null);

				this.Depth.Source = this._outputBitmap;
			}

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

			this._outputBitmap.WritePixels(
				new Int32Rect(0, 0, e.DepthFrame.ImageFrame.Width, e.DepthFrame.ImageFrame.Height), 
				convertedDepthBits,
				e.DepthFrame.ImageFrame.Width * 4,
				0);
		}
Esempio n. 4
0
        private void _HandleDepthFrameReady(object sender, DepthFrameReadyEventArgs frame)
        {
            // Log frame
            this.Logger.LogFrame((DepthFrame)frame.Frame);

            foreach (Delegate d in this.DepthFrameReady.GetInvocationList())
            {
                d.DynamicInvoke(new object[] { sender, frame });
            }
        }
Esempio n. 5
0
        private async void DepthThread()
        {
            try {
                short[] depthShort = null;

                var reader = new DataReader( Client.InputStream );
                reader.InputStreamOptions = InputStreamOptions.Partial;

                while ( IsConnected ) {
                    await reader.LoadAsync( 4 );
                    var size = reader.ReadUInt32();

                    await reader.LoadAsync( size );
                    byte[] bytes = new byte[size];
                    reader.ReadBytes( bytes );

                    MemoryStream ms = new MemoryStream( bytes );
                    BinaryReader br = new BinaryReader( ms );

                    DepthFrameData dfd = new DepthFrameData();
                    dfd.PlayerIndexBitmask = br.ReadInt32();
                    dfd.PlayerIndexBitmaskWidth = br.ReadInt32();

                    DepthImageFrame frame = br.ReadDepthImageFrame();
                    dfd.ImageFrame = frame;

                    int dataLength = (int)(ms.Length - ms.Position);

                    if ( depthShort == null || depthShort.Length != dataLength / 2 )
                        depthShort = new short[dataLength / 2];

                    Buffer.BlockCopy( bytes, (int)br.BaseStream.Position, depthShort, 0, dataLength );

                    dfd.DepthData = depthShort;

                    DepthFrame = dfd;

                    DepthFrameReadyEventArgs args = new DepthFrameReadyEventArgs();
                    args.DepthFrame = dfd;

                    Context.Send( delegate
                    {
                        if ( DepthFrameReady != null )
                            DepthFrameReady( this, args );
                    }, null );
                }
            }
            catch ( IOException ) {
                Disconnect();
            }
        }
Esempio n. 6
0
		private void DepthThread()
		{
			try
			{
				NetworkStream ns = Client.GetStream();
				BinaryReader networkReader = new BinaryReader(ns);
				short[] depthShort = null;

				while(Client.Connected)
				{
					DepthFrameReadyEventArgs args = new DepthFrameReadyEventArgs();
					DepthFrameData dfd = new DepthFrameData();

					int size = networkReader.ReadInt32();
					byte[] data = networkReader.ReadBytes(size);

					MemoryStream ms = new MemoryStream(data);
					BinaryReader br = new BinaryReader(ms);

					dfd.PlayerIndexBitmask = br.ReadInt32();
					dfd.PlayerIndexBitmaskWidth = br.ReadInt32();

					DepthImageFrame frame = br.ReadDepthImageFrame();
					dfd.ImageFrame = frame;

					int dataLength = (int)(ms.Length - ms.Position);

					if(depthShort == null || depthShort.Length != dataLength / 2)
						depthShort = new short[dataLength / 2];

					Buffer.BlockCopy(data, (int)br.BaseStream.Position, depthShort, 0, dataLength);

					dfd.DepthData = depthShort;

					DepthFrame = dfd;
					args.DepthFrame = dfd;

					Context.Send(delegate
					{
						if(DepthFrameReady != null)
							DepthFrameReady(this, args);
					}, null);
				}
			}
			catch(IOException)
			{
				Client.Close();
			}
		}
Esempio n. 7
0
		void client_DepthFrameReady(object sender, DepthFrameReadyEventArgs e)
		{
			if(_outputBitmap == null)
			{
				this._outputBitmap = new WriteableBitmap(
					e.DepthFrame.ImageFrame.Width, 
					e.DepthFrame.ImageFrame.Height);

				this.Depth.Source = this._outputBitmap;
			}

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

			Buffer.BlockCopy(convertedDepthBits, 0, _outputBitmap.Pixels, 0, convertedDepthBits.Length);
			_outputBitmap.Invalidate();
		}
Esempio n. 8
0
		private byte[] ConvertDepthFrame(short[] depthFrame, DepthFrameReadyEventArgs 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 = 1;
			const int GreenIndex = 2;
			const int BlueIndex = 3;

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

			for (int i16 = 0, i32 = 0; i16 < depthFrame.Length && i32 < depthFrame.Length * 4; i16++, i32 += 4)
			{
				int player = depthFrame[i16] & args.DepthFrame.PlayerIndexBitmask;
				int realDepth = depthFrame[i16] >> args.DepthFrame.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;
		}
Esempio n. 9
0
 private void _DepthFrameReady(object sender, DepthFrameReadyEventArgs frame)
 {
     //DepthDrawingHelper.Draw((DepthFrame) frame.Frame, this.depthBitmap);
 }