-->

Kinect

hobbydev kinect

I know they are about to release XBox One and they have already released Kinect for Windows but I still only have a Kinect for XBox for 360. I’m hoping to create a quick and sample application to test my Kinect and discover what’s in Kinect SDK so that I can remove it for a while from my gadgets-pending-to-be-tested-and-played-with list.

Until I buy a better and more recent hardware I just decided to utilise my existing sensor. I followed Channel9’s video tutorials and here is the code to display a video output of the sensor on the screen:

Xbox-360-Kinect-Standalone

Source code:

using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Microsoft.Kinect;

namespace KinectDemo
{
	public partial class MainWindow : Window
	{
		KinectSensor _sensor;

		public MainWindow()
		{
			InitializeComponent();
		}

		private void Button_Click(object sender, RoutedEventArgs e)
		{
			
		}

		private void Window_Loaded(object sender, RoutedEventArgs e)
		{
			if (KinectSensor.KinectSensors.Count > 0)
			{
				_sensor = KinectSensor.KinectSensors[0];

				if (_sensor.Status == KinectStatus.Connected)
				{
					_sensor.ColorStream.Enable();
					_sensor.DepthStream.Enable();
					_sensor.SkeletonStream.Enable();
					_sensor.AllFramesReady += _sensor_AllFramesReady;
					_sensor.Start();
				}
			}
		}

		void _sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e)
		{
			using (ColorImageFrame colorFrame = e.OpenColorImageFrame())
			{
				if (colorFrame == null)
				{
					return;
				}

				byte[] pixels = new byte[colorFrame.PixelDataLength];
				colorFrame.CopyPixelDataTo(pixels);

				int stride = colorFrame.Width * 4;
				image1.Source = BitmapSource.Create(colorFrame.Width, colorFrame.Height, 96, 96, PixelFormats.Bgr32, null, pixels, stride);
			}
		}

		void StopKinect(KinectSensor sensor)
		{
			if (sensor != null)
			{
				sensor.Stop();
				sensor.AudioSource.Stop();
			}
		}

		private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
		{
			StopKinect(_sensor);
		}
	}
}

I think for this amount of code and the simplicity it is a pretty good result.

Probably I will continue my conquest of Kinect after I get the latest one, but for now I’ll just call it.

Resources