[# KINECT] HowTo: Display the contents of the depth sensor in our applications

image

Hi,

today is a little modify code application that displays the contents of the web cam of Kinect to show in this case, the processed image from the Sensor Kinect Depth in a WPF application. The image that gives us Depth Sensor is the result of the process of information returns the sensor infrared possessing Kinect along with the image of the House of Kinect. With these 2 elements (and a few more things) Kinect manages to assemble a model with some depth which is which gives us Depth Sensor.

The big difference with the previous post is that in this case we will work with the event DepthFrameReady() (line 42) which is that will deliver us the processed image of the DepthSensor. From this moment, we work with an external class DepthImageHelper() to process the image from the sensor in a format compatible with an IMAGE.

   1: namespace ElBruno.KinectViewer
   2: {
   3:     using System.Windows;
   4:     using Microsoft.Research.Kinect.Nui;
   5:  
   6:     /// <summary>
   7:     /// Interaction logic for MainWindow.xaml
   8:     /// </summary>
   9:     public partial class MainWindow
  10:     {
  11:         private Runtime kinect;
  12:         private InteropBitmapHelper imageHelper;
  13:         private RuntimeOptions RuntimeOptions { get; set; }
  14:         
  15:         public MainWindow()
  16:         {
  17:             InitializeComponent();
  18:             Loaded += MainWindowLoaded;
  19:         }
  20:  
  21:         void MainWindowLoaded(object sender, RoutedEventArgs e)
  22:         {
  23:             InitKinect();
  24:         }
  25:  
  26:         void InitKinect()
  27:         {
  28:             if (Runtime.Kinects.Count == 0)
  29:                 return;
  30:             kinect = Runtime.Kinects[0];
  31:             RuntimeOptions = RuntimeOptions.UseDepthAndPlayerIndex | 
  32:                 RuntimeOptions.UseSkeletalTracking | 
  33:                 RuntimeOptions.UseColor;
  34:             kinect.Initialize(RuntimeOptions);
  35:             kinect.DepthStream.Open(ImageStreamType.Depth, 2, ImageResolution.Resolution320x240,
  36:                 RuntimeOptions.HasFlag(RuntimeOptions.UseDepthAndPlayerIndex) || 
  37:                 RuntimeOptions.HasFlag(RuntimeOptions.UseSkeletalTracking) ? 
  38:                 ImageType.DepthAndPlayerIndex : ImageType.Depth);
  39:             kinect.DepthFrameReady += this.KinectDepthFrameReady;
  40:         }
  41:  
  42:         void KinectDepthFrameReady(object sender, ImageFrameReadyEventArgs e)
  43:         {
  44:             var planarImage = e.ImageFrame.Image;
  45:             var depthImageHelper = new DepthImageHelper();
  46:             byte[] convertedDepthBits = depthImageHelper.ConvertDepthFrame(planarImage.Bits, RuntimeOptions);
  47:  
  48:             if (this.imageHelper == null)
  49:             {
  50:                 this.imageHelper = new InteropBitmapHelper(planarImage.Width, planarImage.Height, convertedDepthBits);
  51:                 this.DepthSensorViewer.Source = this.imageHelper.InteropBitmap;
  52:             }
  53:             else
  54:             {
  55:                 this.imageHelper.UpdateBits(convertedDepthBits);
  56:             }
  57:         }
  58:     }
  59: }

If we run the application we can see the result of the DepthSensor similar to the following image.

image

The example code can be downloaded from

https://SkyDrive.live.com/embedicon.aspx/code%20Samples/2011%2011%2017%20ElBruno.KinectViewer%20DepthSensor.zip?CID=bef06dffdb192125 & sc = documents

Greetings @ Here

The Bruno

Source: http://en.wikipedia.org/wiki/Kinect

About these ads

Un pensamiento en “[# KINECT] HowTo: Display the contents of the depth sensor in our applications

  1. Pingback: [#KINECT] My posts for #KinectSdk | El Bruno

Deja un comentario

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s