Saturday
Jan112014

Simplifying Kinect for Windows 1.x Skeleton Drawing

KinectTools is an abstraction over the code that handles the Kinect v1 sensors, Skeleton data, and drawing the skeleton. It exposes Brush and Pen properties for drawing so you have control over the look of your skeleton. It also can place a PNG file over the head as you move around, providing hours of jocularity.

If you've done any work with the Kinect for Windows 1.x SDK you've probably already created an abstraction such as this. But if you haven't here's a nice one for you.

What's cool about this is that it uses the term Body which is what SDK 2.0 calls a Skeleton. I've also written this abstraction for SDK 2.0 (only in pre-release) so using this will get you ready for the future. The next version of the GesturePak Recorder and sample code uses this abstraction as well.

Here's a very simple WPF app that uses the KinectTools SimpleBodyEngine class to draw the skeleton in real time, put an image of my head on top of it, and turn the background of the window red if you move your right hand out in front of your body 1/3 of a meter.

XAML:
<Window x:Class="SimpleBodyEngineTest.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="600" Width="800">
    <StackPanel>
        <StackPanel Orientation="Horizontal">
            <TextBlock Text="Sensor: "/>
            <TextBlock Text="{Binding SensorStatusName}" />
        </StackPanel>
        <Image x:Name="BodyImage" Source="{Binding ImageSource}" Stretch="None" />
    </StackPanel>
</Window>
Code:
using System;
using System.Windows;
using System.Windows.Media;
using Microsoft.Kinect;
using KinectTools;

namespace SimpleBodyEngineTest
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        // This object makes handling Kinect Skeleton objects easy!
        SimpleBodyEngine BodyEngine = new SimpleBodyEngine();

        public MainWindow()
        {
            InitializeComponent();
            // event handlers
            this.Closing += MainWindow_Closing;
            BodyEngine.BodyTracked += BodyEngine_BodyTracked;

            // put Carl's head on top of the Skeleton
            BodyEngine.HeadImageUri = new Uri("carl.png", UriKind.Relative);
            
            // bind the XAML to the SimpleBodyEngine
            this.DataContext = BodyEngine;
        }

        /// <summary>
        /// This event fires when a *tracked* skeleton frame is available
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void BodyEngine_BodyTracked(object sender, BodyTrackedEventArgs e)
        {
            // Get the Z position of the hand and spine
            var hand = e.Body.Joints[JointType.HandRight].Position.Z;
            var spine = e.Body.Joints[JointType.Spine].Position.Z;

            // if the hand is in front of the spine...
            if (Math.Abs(hand - spine) > .3)
                // turn the background red
                Background = Brushes.Red;
            else
                Background = Brushes.White;
        }

        void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            BodyEngine.Dispose();
        }
       
    }
}
Forget about the hundreds of lines of code to draw the Skeleton. If you just want to handle the data, read this blog post I wrote on the basics of Skeleton tracking. This code is so simple. Put up an image and bind it to a property. Create a new SimpleBodyEngine object and make it the DataContext. Done.

Download the code here and enjoy.

Carl

PrintView Printer Friendly Version

EmailEmail Article to Friend

References (107)

References allow you to track sources for this article, as well as articles that were written in response to this article.
  • Response
    Response: Chanel Maxi bags
    Waiting for the Fed SPDR Graham Replica Uk S 500 ETF Trust Phil: UNH, hedged stock Chanel Coco Bags position, doing great, up over 50 %,Graham Replica Uk, - RMM Phil - I just referred 10 people,Chanel Coco Bags. Last week was ...
  • Response
    Air Part 3 Review I Chanel Jumbo bag f Stargate Universe t replica watches hinks it can get by on endless wandering through barren planets and pseudomystical vision quests, it has another thing coming. The U-Boat Replica Uk follow-up to its big premiere consists of dreadful scene after ...
  • Response
    Response: code de la route
    That's a lot of code right there but thank you for sharing. Will test this bit and let you know if I get stuck.
  • Response
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: systèmes de paris
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: quality brand
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: systèmes de paris
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: product
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: product
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: roofing gold coast
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: 42nd Street Photo
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    comunicação visual em curitiba letras caixa toldos luminosos, banners
  • Response
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: Laura Glading
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: 42nd street photo
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: Link Schwartz
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: Laura Glading
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: laura glading
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: Link K Schwartz
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: laura glading
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: Laura Glading
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: Link Schwartz
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: link k schwartz
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: Link Schwartz
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: Edgard Romero Lazo
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: Judge Ray Harding
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: Judge Ray Harding
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: Judge Ray Harding
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: Eduardo Vela Ruiz
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: scott tucker
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: scott tucker
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: scott tucker
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: Scott Tucker
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: scott tucker
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: Curtis Debord
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: Post Brothers
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: zandile williams
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: zandile williams
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: Mark Dubowitz
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: Mark Dubowitz
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: zandile williams
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: zandile williams
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: zandile williams
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: zandile williams
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: zandile williams
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: zandile williams
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: zandile williams
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: zandile williams
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: zandile williams
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: zandile williams
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: zandile williams
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: zandile williams
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: zandile williams
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: zandile williams
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: heating systems
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    ... עבודה באוסטרליה חווה - עבודה בסינגפור בלוחות העבודה השונים עבודה באוסטרליה לבעלי דרכון ישראלי"ל מספקים מדי שבוע וחודש מגוון רחב מוצרים, יוקרתיים ואכותיים. אם יש לכם נסיון תעסוקתי או בלי עבודות בי... Simplifying Kinect for Windows 1.x Skeleton Drawing - Carl Franklin ...
  • Response
    Response: http://sco.lt
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: Belinda Broido
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: Ebon Talifarro
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Carl Franklin - Intellectual Hedonism - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: ministry jobs
    Carl Franklin - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: coffee green beans
    Carl Franklin - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Carl Franklin - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: more information
    Carl Franklin - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Carl Franklin - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: fat fast
    Carl Franklin - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
    Response: fat fast
    Carl Franklin - Blog - Simplifying Kinect for Windows 1.x Skeleton Drawing
  • Response
  • Response
    Response: new year 2016
    rtthh
  • Response
    Super Bowl d
  • Response
    Roland Garros 2016
  • Response
    Roland Garros
  • Response

Reader Comments (1)

Thank you Carl for sharing this useful information! :)

Comments for this entry have been disabled. Additional comments may not be added to this entry at this time.
« My findings after day 1 with Xamarin Forms | Main | Simplifying Speech Recognition with .NET »