Archivos para 17/11/11

[# 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

1 comentario

[#KINECT] HowTo: Mostrar el contenido del depth sensor en nuestras aplicaciones

 

image

Buenas,

hoy toca modificar un poco el código de la aplicación que muestra el contenido de la cámara web de Kinect para mostrar en este caso, la imagen procesada del Depth Sensor de Kinect en una aplicación WPF. La imagen que nos entrega el Depth Sensor es el resultado del proceso de la información que retorna el sensor infrarojo que posee Kinect junto con la imagen de la cámara de Kinect. Con estos 2 elementos (y un par de cosillas más) Kinect consigue armar un modelo con cierta profundidad que es el que nos entrega el Depth Sensor.

La gran diferencia con el post anterior es que en este caso trabajaremos con el evento DepthFrameReady() (línea 42) que es el que nos entregará la imagen procesada del DepthSensor. A partir de este momento, trabajamos con una clase externa DepthImageHelper() para procesar la imagen del sensor en un formato compatible con un 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: }

 

Si ejecutamos la aplicación podremos ver el resultado del DepthSensor similar a la siguiente imagen.

image

El código del ejemplo lo pueden descargar desde

https://skydrive.live.com/embedicon.aspx/Code%20Samples/2011%2011%2017%20ElBruno.KinectViewer%20DepthSensor.zip?cid=bef06dffdb192125&sc=documents

 

Saludos @ Here

El Bruno

   

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

4 comentarios

Seguir

Get every new post delivered to your Inbox.

Únete a otros 898 seguidores