Setting Up Your Development Environment (Beta 2 SDK)
Content Archived
This content is no longer current. Our recommendation for up to date content: http://channel9.msdn.com/Series/KinectQuickstart/Skeletal-Tracking-Fundamentals
Please use the newly updated Kinect for Windows SDK Quickstart series. The content below will only work with the Beta 2 version of the Kinect for Windows SDK.
This video covers the basics of skeletal tracking using the Kinect sensor. You may find it easier to follow along by downloading the Kinect for Windows SDK Quickstarts samples and slides that have been updated for Beta 2 (Nov, 2011).
The video has not been updated for Beta 2, but the following changes have been made:
The steps below assume you have setup your development environment as explained in the Setting Up Your Development Environment video.
Create the Window_Loaded event
Go to the properties window (F4), select the MainWindow, select the Events tab, and double click on the Loaded event to create the Window_Loaded event

Initializing the runtime
Create a new variable outside of the Window_Loaded event to reference the Kinect runtime.
C#
Runtime nui = new Runtime();
Visual Basic
Dim nui As New Runtime()
In the Window_Loaded event, initialize the runtime with the options you want to use. For this example, set RuntimeOptions.UseSkeletalTracking to receive skeletal data and register for the SkeletonFrameReady event.
C#
nui.Initialize(RuntimeOptions.UseSkeletalTracking);
nui.SkeletonFrameReady += new EventHandler<SkeletonFrameReadyEventArgs>(nui_SkeletonFrameReady);
void nui_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
{
}
Visual Basic
nui.Initialize(RuntimeOptions.UseSkeletalTracking) AddHandler nui.SkeletonFrameReady, AddressOf nui_SkeletonFrameReady Private Sub nui_SkeletonFrameReady(ByVal sender As Object, ByVal e As SkeletonFrameReadyEventArgs) End Sub
Add a breakpoint inside the SkeletonFrameReady event and run the application.
Note – You will need to stand far enough away that the Kinect can see all or most of your skeleton for the SkeletonFrameReady event to fire.
![]()
When the breakpoint fires, you can inspect the SkeletonFrameReadyEventArgs to see that the SkeletonFrame returns a collection of six skeletons as shown below.

In this example, we're going to use the position of the tracked skeleton's, head, left hand, and right hand to move ellipse controls.
Starting from the project above, switch to MainWindow.xaml and make sure you can see the XAML code. We will add three three ellipses of varying color onto a Canvas control named MainCanvas as shown in the XAML below.
XAML
<Canvas Name="MainCanvas">
<Ellipse Canvas.Left="0" Canvas.Top="0" Height="50" Name="headEllipse" Stroke="Black" Width="50" Fill="Orange" />
<Ellipse Canvas.Left="50" Canvas.Top="0" Height="50" Name="rightEllipse" Stroke="Black" Width="50" Fill="SlateGray" />
<Ellipse Canvas.Left="100" Canvas.Top="0" Fill="SpringGreen" Height="50" Name="leftEllipse" Stroke="Black" Width="50" />
</Canvas>
In the SkeletonFrameReady event, we'll use a LINQ query to get the first tracked skeleton.
C#
void nui_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
{
SkeletonFrame allSkeletons = e.SkeletonFrame;
//get the first tracked skeleton
SkeletonData skeleton = (from s in allSkeletons.Skeletons
where s.TrackingState == SkeletonTrackingState.Tracked
select s).FirstOrDefault();
}
Visual Basic
Private Sub nui_SkeletonFrameReady(ByVal sender As Object, ByVal e As SkeletonFrameReadyEventArgs)
Dim allSkeletons As SkeletonFrame = e.SkeletonFrame
'get the first tracked skeleton
Dim skeleton As SkeletonData = ( _
From s In allSkeletons.Skeletons _
Where s.TrackingState = SkeletonTrackingState.Tracked _
Select s).FirstOrDefault()
End Sub
A Joint position returns X,Y,Z values as explained below
Scaling a Joint value
Given that the X and Y positions are distance measurements, we can use the Coding4Fun Kinect Toolkit ScaleTo method to scale the value to a maximum X and Y position as shown below.
C#
Joint HandRight = skeleton.Joints[JointID.HandRight].ScaleTo(640, 480);
Visual Basic
Dim HandRight = skeleton.Joints(JointID.HandRight).ScaleTo(640, 480)
You can also constrain the maximum values for the skeletal joints to a smaller range. For example, if you were designing an application where the user can reach around the screen to touch things, you may not want them to have to walk two feet left or right to reach the edges. By using the second version of the ScaleTo method, you can specify the range of the specified joint to something smaller as shown:
C#
Joint HandRight = skeleton.Joints[JointID.HandRight].ScaleTo(640, 480, .5f, .5f);
Visual Basic
Dim HandRight = skeleton.Joints(JointID.HandRight).ScaleTo(640, 480, .5f, .5f)
This code will make it so that your right hand only has to travel one meter (joint range of -0.5 to +0.5) to traverse the pixels at 0 to 640. If you set this value to –1 to +1, for example, then the right hand would have to travel two meters total, one meter to the left, one meter to the right to traverse the 640 pixels.
Also, as you can see above, you can get a particular Joint, like the HandRight Joint, by using the skeleton indexer for the Joints collection.
To move the ellipses in our MainWindow to the location of a Joint, we will use the method below that sets the Canvas.Left and Canvas.Top position to the X (Left) and Y (Top) value from the Joint parameter.
C#
private void SetEllipsePosition(FrameworkElement ellipse, Joint joint)
{
var scaledJoint = joint.ScaleTo(640, 480, .5f, .5f);
Canvas.SetLeft(ellipse, scaledJoint.Position.X);
Canvas.SetTop(ellipse, scaledJoint.Position.Y);
}
Visual Basic
Private Sub SetEllipsePosition(ByVal ellipse As FrameworkElement, ByVal joint As Joint)
Dim scaledJoint = joint.ScaleTo(640, 480,.5f,.5f)
Canvas.SetLeft(ellipse, scaledJoint.Position.X)
Canvas.SetTop(ellipse, scaledJoint.Position.Y)
End Sub
Finally, in the nui_SkeletonFrameReady event, call the SetEllipsePosition methods for the three joints as shown below:
C#
SetEllipsePosition(headEllipse, skeleton.Joints[JointID.Head]); SetEllipsePosition(leftEllipse, skeleton.Joints[JointID.HandLeft]); SetEllipsePosition(rightEllipse, skeleton.Joints[JointID.HandRight]);
Visual Basic
SetEllipsePosition(headEllipse, skeleton.Joints(JointID.Head)) SetEllipsePosition(leftEllipse, skeleton.Joints(JointID.HandLeft)) SetEllipsePosition(rightEllipse, skeleton.Joints(JointID.HandRight))

Using the same application as above, you may notice jitteriness in the hand positions as small changes between updates to the SkeletalFrameReady event change the location of the ellipses.
Using TransformSmoothParameters
To see the difference between using and not using TransformSmoothing, toggle the true/false TransformSmooth property. There are two ways to use TransformSmoothing, you can set it to true and it will use a default set of parameters, or you can customize and experiment with each of the parameters to find the parameters that work best for your application. To do that, you’ll need create the TransformSmoothParameters struct yourself and define the parameters.
You must set the TransformSmoothParameters after calling the nui.Initialize method.
Note: Since every application is different, you will need to experiment with the parameters to understand what's right for your application.
C#
private void SetupKinect()
{
if (Runtime.Kinects.Count == 0)
{
this.Title = "No Kinect connected";
}
else
{
//use first Kinect
nui = Runtime.Kinects[0];
//Initialize to do skeletal tracking
nui.Initialize(RuntimeOptions.UseSkeletalTracking);
//add event to receive skeleton data
nui.SkeletonFrameReady += new EventHandler<SkeletonFrameReadyEventArgs>(nui_SkeletonFrameReady);
//to experiment, toggle TransformSmooth between true & false
// parameters used to smooth the skeleton data
nui.SkeletonEngine.TransformSmooth = true;
TransformSmoothParameters parameters = new TransformSmoothParameters();
parameters.Smoothing = 0.7f;
parameters.Correction = 0.3f;
parameters.Prediction = 0.4f;
parameters.JitterRadius = 1.0f;
parameters.MaxDeviationRadius = 0.5f;
nui.SkeletonEngine.SmoothParameters = parameters;
}
}
Visual Basic
Private Sub SetupKinect()
If Runtime.Kinects.Count = 0 Then
Me.Title = "No Kinect connected"
Else
'use first Kinect
nui = Runtime.Kinects(0)
'Initialize to do skeletal tracking
nui.Initialize(RuntimeOptions.UseSkeletalTracking)
'add event to receive skeleton data
AddHandler nui.SkeletonFrameReady, AddressOf nui_SkeletonFrameReady
'to experiment, toggle TransformSmooth between true & false
' parameters used to smooth the skeleton data
nui.SkeletonEngine.TransformSmooth = True
Dim parameters As New TransformSmoothParameters()
parameters.Smoothing = 0.7f
parameters.Correction = 0.3f
parameters.Prediction = 0.4f
parameters.JitterRadius = 1.0f
parameters.MaxDeviationRadius = 0.5f
nui.SkeletonEngine.SmoothParameters = parameters
End If
End Sub
Superb. Microsoft is back.
Muito bom isto!
Abre novas e incríveis possibilidades!!!
Testarei assim que puder!
cant wait to play with all this! thank you
Well done, Dan! You make it look very easy - I can't wait to try it out!
that's too cool, i cant wait to try it myself.
Can you use Kinect directly from a Silverlight app?
Great! I tried the kinect and it is fantastic!
GREAT!
AWESOME!!!!!!!!!!!!!!!!!!!!!!
This is amazeaballs! - Have already got my feet and elbow tracked etc.. awesome :) Will now and try some simple if statements to detect if balls are touching... all progress haha - well done and thankyou!
Just curious, is finger tracking going to become available at some point? I see loads more of potential for this if it is
Great tutorial and had fun with Kinect. If it could only talk back to me ![]()
@El Pibe: While it technically wouldn't be through your Kinect, you can use Text-To-Speech (TTS) to have a computerized-style voice talk back to you. The TTS engine is built into Microsoft.Speech APIs
If two of the six skeletons are tracked... why are the other four returned?
Thank you!!!!!
is it possible to post the complete code. I have some problems to have all this coded together... thanks!
@alex: Yes, the full source code is the first link in the article, posted here for your convenience - http://files.ch9.ms/coding4fun/KinectForWindowsSDKQuickstarts.zip
This is really great, but do you have any examples of how to do gesture tracking?
Nice.
@Patrick: For some best practices watch Ali Vassigh and Arturo Toledo's talk during the Kinect SDK Beta Launch - Designing for the Body: UX Considerations for Kinect Applications as that discusses gestures and gesture interpretation.
Hi,
I can't get the Examples running. When I try to start any of the Quick Start Projects VS2010 shows an "Unspecified Error". Here's the stack trace. Can anyone help me please!?
System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
at Ankh.VS.SolutionExplorer.SolutionExplorerWindow.get_SolutionExplorerFrame()
at Ankh.VS.SolutionExplorer.SolutionExplorerWindow.Initialize()
at Ankh.VS.VsActivatorCommand.OnExecute(CommandEventArgs e)
at Ankh.Commands.CommandMapItem.OnExecute(CommandEventArgs e)
at Ankh.Commands.CommandMapper.Execute(AnkhCommand command, CommandEventArgs e)
Hi,
I've fixed the problem. It was due to a plugin which I didn't even need and deactivated. All samples work just fine. Looking forward to play arround with the SDK :)
A.
Anyone want to be a guinea pig for me? I have Pong working on my computer and am looking for someone to try my .exe.
Thanks,
Barzimeron
when I add in the SetEllipsePosition(...) it gives me the error:
'Microsoft.Research.Kinect.Nui.Joint' does not contain a definition for 'ScaleTo' and no extension method 'ScaleTo' accepting a first argument of type 'Microsoft.Research.Kinect.Nui.Joint' could be found (are you missing a using directive or an assembly reference?)
I added a reference to Microsoft.Research.Kinect, and Coding4Fun.Kinect.Wpf as well as the two using statements for the Microsoft Research references
Thanks, Logan
Exelente para realizar muchisimas aplicaciones realmente muy muy bueno
Very good for make good aplications in some way .
Im very glad to see these new hardward by Microsoft
Great tutorial, thanks a lot.
Is there a way to get the xyz position data of the tracked joints? Maybe output in a matrix in some way?
If anyone knows how this can be done, please let me know!
What's the trick to getting:
1) The player index to activate and
2) The joints to establish tracking?
I have to gesticulate wildly to accomplish either of these, and it doesn't happen reliably. Somehow, it doesn't seem deterministic.
The Joint object does not seem to have the scaleTo method any more. I get compile error when n I try to use the method.
ScaleTo is not a member of 'Microsoft.Research.Kinect.Nui.Joint'
Awesome Dan,
Thank you for the samples and I have been able to create an application using this and control through hand gestures :). Works great and everyone liked it.
Now cant wait for the release version of the SDK. Sure you guys must have lots of advancements.
I failed to find more information on TransformSmoothParameters and ScaleTo on how to control the distance from the sensor and still be able to render a standard size skeleton everytime.
Appreciate if you can share something on this.
Regards
Santhosh
Hi, I have a problem, I try running this code sample using c # and KinectForWindowsSDKQuickstarts I have the following error:
WAS NullReferenceException unhandled by user code.
In the line:
SetEllipsePosition (headEllipse, skeleton.Joints [JointID.Head]);
I have no problem with the other examples just this.
thanks for your help
@Omar - Thats because when you start the app none of the Skeletons are being tracked so the skeleton variable is null. This should fix it
//set position
if (skeleton != null)
{
SetEllipsePosition(headEllipse, skeleton.Joints[JointID.Head]);
SetEllipsePosition(leftEllipse, skeleton.Joints[JointID.HandLeft]);
SetEllipsePosition(rightEllipse, skeleton.Joints[JointID.HandRight]);
}
Cheers,
Firdosh
THANK YOU Firdosh.
I solved my problem. Although it seems strange that this detail was not mentioned in this tutorial.
The article says "A Joint position returns X,Y,Z values as explained below..."
But how does one get the z position of a joint?
How do I downloadCoding4Fun.Kinect.WinForm.dll?
Thanks, these tutorials are great.
How would I go about changing the color of an ellipse with hand movement? Here's what I have so far:
private void SetEllipseProperties(FrameworkElement ellipse, Joint joint)
{
var scaledJoint = joint.ScaleTo(640, 480, .5f, .5f);
// change position
Canvas.SetLeft(ellipse, scaledJoint.Position.X);
Canvas.SetTop(ellipse, scaledJoint.Position.Y);
//change color
ellipse.Fill = someColorFunction(scaledJoint.Position.Y);
}but it doesn't like ellipse.Fill. It tells me "System.Windows.FrameworkElement' does not contain a definition for 'Fill' and no extension method 'Fill' accepting a first argument of type 'System.Windows.FrameworkElement' could be found (are you missing a using directive or an assembly reference?)", yet here, myEllipse.Fill is directly changed.
I'm very new at this -- any help is appreciated!
Michael
Can I see only part of skeletan for example in a sitting pose?
Say if i dont want to use the Ellipse but i want to use the mouse Cursor, how do i do this?
Yah. Got it!!
Tks alot.
hi..
how do i add to track other parts..
not switch but to add..
currently the program track head,left hand & right hand,
how do i make it track maybe, left feet & right feet too?
i actually try to add the SetEllipsePosition but it come out that it is defined more than once
hey guys,
this is some exciting stuff. i was trying the code out and everything works really gr8.
the only problem i am facing is my application freezes after 8sec. like i can see the Ellipses moving with my movements but it just freezes after 8 secs.
please help!!!
thank you!!
Hi thanks for this videos but i have a question,
how do i get the x & y coordinates? as i want to use it to control the x & y coordinates of the mouse cursor
Irfan
I have the same problem:
Thanks, these tutorials are great.
How would I go about changing the color of an ellipse with hand movement? Here's what I have so far:
1
2
3
4
5
6
7
8
9
10
11
12
private void SetEllipseProperties(FrameworkElement ellipse, Joint joint)
{
var scaledJoint = joint.ScaleTo(640, 480, .5f, .5f);
// change position
Canvas.SetLeft(ellipse, scaledJoint.Position.X);
Canvas.SetTop(ellipse, scaledJoint.Position.Y);
//change color
ellipse.Fill = someColorFunction(scaledJoint.Position.Y);
}
but it doesn't like ellipse.Fill. It tells me "System.Windows.FrameworkElement' does not contain a definition for 'Fill' and no extension method 'Fill' accepting a first argument of type 'System.Windows.FrameworkElement' could be found (are you missing a using directive or an assembly reference?)", yet here, myEllipse.Fill is directly changed.
I'm very new at this -- any help is appreciated!
Michael
No me funciona el scaleto.
Pone que no se encontró el método ScaleTo en el joint.
@Alex:Can you tell me how do you solved that problem? I have the same issue and can't seem to solve it.
Thanks
Hi,
I've fixed the problem. It was due to a plugin which I didn't even need and deactivated. All samples work just fine. Looking forward to play arround with the SDK
A.
Can you tell me witch plugin was giving you this problem?
Thanks
Is it just me or is this example busted with Beta 2? I get a FileNotFound Exception on Microsoft.Research.Kinect when the skeleton tracking starts.
Here is what I get:
Error 1 'mySkeletalTracking.MainWindow' does not contain a definition for 'Window_Unloaded' and no extension method 'Window_Unloaded' accepting a first argument of type 'mySkeletalTracking.MainWindow' could be found (are you missing a using directive or an assembly reference?) C:\Users\Nelson\Documents\Visual Studio 2010\Projects\mySkeletalTracking\mySkeletalTracking\MainWindow.xaml 4 110 mySkeletalTracking
Can anybody help me? What am I missing?
I am always getting a NullReferenceException for this:
Dim HandRight = skeleton.Joints(JointID.HandRight).ScaleTo(320, 240, 0.5F, 0.5F)
declaration and setting HandRight to null won't help, nor did resetting the project file...
hi
my programing is poor
can you send a project(exe and source for windows 7 64bit) that return skeleton.Joints to text file?
i need it hard
thanks
my email is:
bijanasb@gmail.com
hey guys,
this is some exciting stuff. i was trying the code out and everything works really gr8.
the only problem i am facing is my application freezes after 8sec. like i can see the Ellipses moving with my movements but it just freezes after 8 secs.
please help!!!
thank you!!
Have the same problem. And it doesn't matter if it debugging session or just using .exe
hm...
hey guys!! great tutorial!! i've done everything exaclty as it shows here but when i try to run it it says that the " reference of the object its not define as the instance of the object"
what can be the problem?? thanks!!
I have a quick question guys if its no bother. I got the project set up and it works except that after a few seconds the ellipses freeze. I would go to debug but it's kind of hard debugging movement alone. It seems as if the event handler stops firing or something.
Just noticed my infrared light turns off at the moment the circles stop moving. I don't know what could be going on.
Hello everybody,
i'm just following the quicktutorials and they are fantastic, i had only the NullReferenceException fail but thanks to @Firdosh Tangri answer now it is solved.
Thanks!!
I have your problem.
I receive the "System.NullReferenceException: Object reference not set to an instance of an object." error and i dont know what to do more.
Do you know the solution?
best regards
Got everything working. I'm still learning C#, but I did figure out how to add different joints, change the ellipses to rectangles and change colors, etc.
Now on to bigger and better things. I'd like to add a button to the window and the right hand ellipse hovers over it, that would then activate the click event (like it does on the XBox).
I'll be working on that, but right now, I have no idea how to do it, but any suggestions would be appreciated!!
For everybody having issues with the ScaledTo function, it's included in the "Coding4Fun Kinect Toolkit" located here: http://c4fkinect.codeplex.com/
The actual code is this:
public static Joint ScaleTo(this Joint joint, int width, int height, float skeletonMaxX, float skeletonMaxY)
{
Vector pos = new Vector()
{
X = Scale(width, skeletonMaxX, joint.Position.X),
Y = Scale(height, skeletonMaxY, -joint.Position.Y),
Z = joint.Position.Z,
W = joint.Position.W
};
Joint j = new Joint()
{
ID = joint.ID,
TrackingState = joint.TrackingState,
Position = pos
};
return j;
}
public static Joint ScaleTo(this Joint joint, int width, int height)
{
return ScaleTo(joint, width, height, 1.0f, 1.0f);
}
private static float Scale(int maxPixel, float maxSkeleton, float position)
{
float value = ((((maxPixel / maxSkeleton) / 2) * position) + (maxPixel/2));
if(value > maxPixel)
return maxPixel;
if(value < 0)
return 0;
return value;
}
Hope the formatting turns out OK.
Hi Dan, I came across this webpage by for hacker who calls himself TechBitar. He got Kinect to control servos wired to an Arduino microcontroller. He used your tutorial as basis for his VB code that does the trick.
http://www.instructables.com/id/Kinect-controls-Arduino-wired-Servos-using-Visual-/
Hi
when I tried to run the sample code the skeleton detection is fired even if there is no skeleton to detect. Can you tell me what the problem could be?
tnx
I found out what the problem was. I actually needed to put the ellipses in a canvas
for those guys whose have problems with the SCALETO method... just need to write the USING for the Having4Fun dll!!! its works!!!
I got your tutorial to work great. However we are attempting to track the position and joints of a manikin with the kinect and have seen it work on occasions. Are there any tips or tricks that you could provide to make this more reliable? How does the kinect determine what is a skeleton and what is not?
Thanks!
Hi, I also had the problem with the freezing video stream. In my case I had to remove the depricated "Runtime nui = new Runtime()" with "Runtime nui;" The nui is initialized later on by the "nui = Runtime.Kinects[0];" command.
Greez
hello every i have a question , how can i gain the postion of one person from the video.the size of my video is 640*480. I know there is a method Joint.Position.X or Joint.Position.Y, but the data of i got if not exact? This problem bothering me!I need help!!
hello guies, i have a question , how can i gain the postion of one person from the video.the size of my video is 640*480. I know there is a method Joint.Position.X or Joint.Position.Y, but the data of i got if not exact? This problem bothering me!I need help!!
hello every i have a question , how can i gain the postion of one person from the video.the size of my video is 640*480. I know there is a method Joint.Position.X or Joint.Position.Y, but the data of i got if not exact? This problem bothering me!I need help!!
Please contact me, 986461745@qq.com
hello everyone, i have a question , how can i get the postion of one person from the video.the size of my video is 640*480. I know there is a method Joint.Position.X or Joint.Position.Y, but the data of i got is not exact? This problem bothering me!I need help!!
Please contact me, 986461745@qq.com
who can help!!
Is it possible to add custom Joints on the tracked skeleton?
Please contact me at toretorev@yahoo.com
Hi,
I am new to Kinect SDK and C# too i am trying the bellow mentioned code i am not able to atrt the kinect itself can any one please help me on this.
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 Microsoft.Kinect;
namespace WpfApplication2
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
Microsoft.Kinect.KinectSensor kinectSensor;
public SkeletonFrame skeletonframe;
bool closing = false;
const int skeletonCount = 6; //API always returns 6 skeleton
Skeleton[] allSkeletons = new Skeleton[skeletonCount];
public MainWindow()
{
InitializeComponent();
}
private KinectSensor InitializeKinectServices(KinectSensor sensor)
{
sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);
sensor.DepthStream.Enable(DepthImageFormat.Resolution320x240Fps30);
/* var parameters = new TransformSmoothParameters
{
Smoothing = 0.7f,
Correction = 0.3f,
Prediction = 0.4f,
JitterRadius = 1.0f,
MaxDeviationRadius = 0.5f
};
sensor.SkeletonStream.Enable(parameters);*/
sensor.Start();
sensor.AudioSource.Start();
return sensor;
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
//return sensor;
InitializeKinectServices(kinectSensor);
// kinectSensor.SkeletonStream.Enable();
// kinectSensor.SkeletonFrameReady += new EventHandler<SkeletonFrameReadyEventArgs>(KinectAllFramesReady);
}
private void KinectAllFramesReady(object sender, SkeletonFrameReadyEventArgs e)
{
SkeletonFrame skeletonFrameData = e.OpenSkeletonFrame();
skeletonFrameData.CopySkeletonDataTo(allSkeletons);
//get the first tracked skeleton
Skeleton skeleton = (from s in allSkeletons where s.TrackingState == SkeletonTrackingState.Tracked select s).FirstOrDefault();
SetEllipsePosition(headEllipse, skeleton.Joints[JointType.Head] );
SetEllipsePosition(leftEllipse, skeleton.Joints[JointType.HandLeft]);
SetEllipsePosition(rightEllipse, skeleton.Joints[JointType.HandRight]);
}
private void SetEllipsePosition(FrameworkElement ellipse, Joint joint)
{
Canvas.SetLeft(ellipse, joint.Position.X);
Canvas.SetTop(ellipse, joint.Position.Y);
}
private void Grid_Unloaded(object sender, RoutedEventArgs e)
{
//inectSensor.Stop();
}
private void Grid_Loaded(object sender, RoutedEventArgs e)
{
}
}
}