Practical Windows Kinect in C#Chapter List

While there is a very good example of how to draw a complete skeleton in the SDK it isn't explained in detail and, in common with most examples, it does things in clever and correct ways.

This makes it a piece of code to admire but only if you can work out what it is doing and how. In this article the objective is not only to create a full skeleton graphic but to make it perfectly clear how it is done.

Getting started with the full Skeleton

As explained in the previous chapter, the Kinect doesn't return a skeleton, just a set of joints that it has detected. It is entirely up to us what to do with this set of joints.

One of the problems with the example skeleton viewer is that at first look you might think that something clever was going on that relied on the way that the Kinect returns the data.

Let's try and draw a skeleton in a step-by-step way that shows how it all works. The instructions that follow just get you to the point where we can access the skeleton data as described in chapter 6. So while there is nothing new it at first it is included for completeness.

Start a new C# Windows Forms project.

Make sure you have loaded a reference to the Kinect DLL and add:

using Microsoft.Kinect;

and

using System.Runtime.InteropServices;using System.Drawing.Imaging;

so that we can use the GDI and Bitmaps.

To the start of the program. In the Form's constructor we create a Runtime object so that we can use the Kinect:

The new AllFramesReady event can be used to trigger code when all of the frame types you hve requested are ready to be processed. So we can simply use a single event handler:

sensor.AllFramesReady += FramesReady;

Finally we can set the sensor running:

sensor.Start();}

The Kinect will now return video images from the video camera, depth data and skeleton data.

Getting the Video

Now to display the image we simply need to write the code for the FramesReady event handler.

However we are going to want to modify the video returned from the camera by drawing a skeleton on it in the same position as the user. For this reason we need to convert the video to a Bitmap and use the GDI graphics object to draw on it.