Getting started with the Microsoft Kinect SDK is pretty straightforward. Download it from Microsoft Research, install and you can test it by running the Sample Skeletal Viewer that is located in the Microsoft Kinect for Windows SDK BETA in the Start menu. You might also need the DirectX SDK to be installed. Finally, you want to download the Coding4Fun Kinect helper library for easy converting of images (http://c4fkinect.codeplex.com/ and click Download on the right side of the page). There’s a helpful video guide for a more in-depth installation walkthrough.

Start a new WPF C# application. Right click “References” in the Solution Explorer and add “Coding4Fun.Kinect.Wpf” and “Microsoft.Research.Kinect” via the Browse tab. If you have done this step at least once, you can use the Recent tab as well.

Now it comes to the application itself. Drag an image into the display space and call it image. Revise the MainWindow.xaml.cs code to look like this. You’ll get a window that shows the depth image in real time!

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Tom_Anderson;
using Microsoft.Research.Kinect.Nui;
using Coding4Fun.Kinect.Wpf;
using System.Threading;

namespace WPF
{
///

/// Interaction logic for MainWindow.xaml
///

public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Loaded += new RoutedEventHandler(Window_Loaded);
}

void Window_Loaded(object sender, RoutedEventArgs e)
{
Runtime nui = new Runtime();
try
{
nui.Initialize(RuntimeOptions.UseDepth);
OpenDepth(nui);
}
catch (InvalidOperationException)
{
MessageBox.Show(“Not plugged in?”);
this.Close();
}
}

private void OpenDepth(Runtime nui)
{
nui.DepthFrameReady += new EventHandler(nui_DepthFrameReady);
try
{
nui.DepthStream.Open(ImageStreamType.Depth, 2, ImageResolution.Resolution640x480, ImageType.Depth);
}
catch (Exception)
{
MessageBox.Show(“Initialization error. Image size incorrect?”);
this.Close();
}
}

void nui_DepthFrameReady(object sender, ImageFrameReadyEventArgs e)
{
image.Source = ImageFrameExtensions.ToBitmapSource(e.ImageFrame);
}
}
}