Click here to Skip to main content
Click here to Skip to main content

Kinect and WPF: Complete body tracking

By , 3 Dec 2013
Rate this:
Please Sign up or sign in to vote.

It's time for a really interesting and useful Kinect tutorial. We'll see how to achieve full body tracking using Kinect sensor, OpenNI library and Windows Presentation Foundation.

I found OpenNI C# samples a little messy, so I decided to develop a .NET 4 wrapper library which could be used into WPF applications whithout requiring .NET 2 staff like GDI+, System.Drawing, etc. I named it Nui.Vision and it's part of a larger framework I currently develop. Nui.Vision is a .NET 4 assembly which offers an easy-to-use body tracking API!

Update 20/04/2011

Nui.Vision is now compatible with the latest release of OpenNI framework (1.1.0.41). I have made some changes and bug-fixes to it, including the skeleton-display fix provided by roni26_wu (see comments below). An open-source version of Nui.Vision is coming soon!

Prerequisites

Using the Library

Using Nui.Vision is a piece of cake. All body tracking is done in the background, so you only need to update your user interface when the proper events fire. Firstly, add a reference to OpenNi.net.dll and Nui.Vision.dll. Also import a valid configuration file to your project, as described here. Do not forget to type the corresponding using statement:

using Nui.Vision;

Then declare a new NuiUserTracker object and initialize it in the constructor. Provide the path of the configuration file you previously imported (do not forget to paste the same file in the Debug/Release folders of your application):

_skeleton = new NuiUserTracker("SamplesConfig.xml");

Just below that, you need to define the UserUpdated event.

_skeleton.UsersUpdated += new NuiUserTracker.UsersUpdatedHandler(Skeleton_UserUpdated);

A proper event handler is created. The NuiUserEventArgs parameter provides you with a collection of all the recognized users! You can now get the coordinates (X, Y and Z) of every body part of every user (OpenNI currently supports 15 body parts)!

foreach (var user in e.Users) {
    float headX = user.Head.X;
    float headY = user.Head.Y;
    float headZ = user.Head.Z;
    float neckX = user.Neck.X;
    float neckY = user.Neck.Y;
    // etc... 
}

Quite easy, huh?

Here is a list of all the available body parts:

  • Head
  • Neck
  • LeftShoulder
  • LeftElbow
  • LeftHand
  • RightShoulder
  • RightElbow
  • RightHand
  • Torso
  • LeftKnee
  • LeftHip
  • LeftFoot
  • RightKnee
  • RightHip
  • RightFoot

You may now start developing cool WPF Kinect applications and games. Imagination's the limit.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)

About the Author

Vangos Pterneas
Product Manager LightBuzz
United Kingdom United Kingdom
I'm a Software Engineer and Entrepreneur, passionate about motion technology and the way it can affect people’s lives.
 
I have been a Kinect enthusiast since the release of the very first unofficial hacks and have already published some innovative commercial Kinect applications. These applications include complex home automation systems, 3D body scanning programs and motion-enabled product browsers for businesses.
 
I worked as a Windows developer and consultant for Microsoft Innovation Center and I'm now running my own company, LightBuzz Software. LightBuzz has been awarded the first place in Microsoft’s worldwide innovation competition, held in New York, for effectively combining Kinect and smartphone functionality.
 
When I am not coding, I love writing books, speaking and blogging about my favorite technological aspects.
Follow on   Twitter   Google+   LinkedIn

Comments and Discussions

 
Questionpoint cloud generating Pinmembermakoos22-May-11 23:09 
AnswerRe: point cloud generating PinmemberVangos Pterneas24-May-11 15:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140415.2 | Last Updated 3 Dec 2013
Article Copyright 2011 by Vangos Pterneas
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid