Entries:
Comments:
Posts:

Loading User Information from Channel 9

Something went wrong getting user information from Channel 9

Latest Achievement:

Loading User Information from MSDN

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements

Content Obsolete

This content is no longer current. We recommend you try the following url for more up to date content: http://channel9.msdn.com/Series/KinectQuickstart/Skeletal-Tracking-Fundamentals

Skeletal Tracking Fundamentals (Beta 2 SDK)

Download

Right click “Save as…”

Update: Kinect for Window SDK v1 Quickstart Series now Available (Feb 1st)

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).

  • [00:31] Skeleton Tracking API
  • [01:24] Understanding Skeleton Quality and Joint data
  • [03:27] Setup skeleton tracking
  • [03:44] Adding a basic hand tracked cursor
  • [09:12] Using TransformSmoothing to remove “skeletal jitter”

 

Updates for Kinect for Windows SDK Beta 2 (Nov, 2011)

The video has not been updated for Beta 2, but the following changes have been made:

  • Previously, the SkeletonFrameReady event would only fire when there was a tracked skeleton. The SkeletonFrameReady has been updated to fire continuously even when there are no skeletons being tracked. To get tracked skeletons, you can filter the list of skeletons to see if the TrackingState property is set to SkeletonTrackingState.Tracked.
  • Beta 2 includes a sample (Microsoft.Samples.Kinect.WpfViewers) set of user controls for visualizing data from the Color/RGB and Depth cameras that you can reuse in your application. The samples can be found at: "\Program Files\Microsoft SDKs\Kinect\v1.0 Beta2\Samples\KinectSDKSamples.zip"

 

Setup

The steps below assume you have setup your development environment as explained in the Setting Up Your Development Environment video.

Task: Setup skeleton tracking

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

image

 

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

Running the application

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.

image

 

When the breakpoint fires, you can inspect the SkeletonFrameReadyEventArgs to see that the SkeletonFrame returns a collection of six skeletons as shown below.

 

image

 

 

Task: Add a basic hand tracked cursor

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.

Designing your UI

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>

Get the Tracked Skeleton

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

Getting a Joint position

A Joint position returns X,Y,Z values as explained below

  • X = Horizontal position measured as the distance, in meters from the Kinect along the X Axis
  • Y = Vertical position measured as the distance, in meters from the Kinect along the Y Axis
  • Z = Distance from Kinect measured in meters

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.

Setting an Ellipse Position

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

 

Putting it all together

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))

image

 

 

Task: Using TransformSmoothing to for less skeletal jitter

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

Follow the Discussion

  • AlexAlex

    Superb. Microsoft is back.

  • Bruno AlvesBruno Alves

    Muito bom isto!
    Abre novas e incríveis possibilidades!!!

    Testarei assim que puder!

  • adamadam

    cant wait to play with all this! thank you

  • Michael ScherotterMichael Scherotter

    Well done, Dan! You make it look very easy - I can't wait to try it out!

  • JoshyJoshy

    that's too cool, i cant wait to try it myself.

  • ChrisChris

    Can you use Kinect directly from a Silverlight app?

  • nadianadia

    Great! I tried the kinect and it is fantastic!

  • GREAT!

  • Henry ramirezHenry ramirez

    AWESOME!!!!!!!!!!!!!!!!!!!!!!

  • Ray ChambersRay Chambers

    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!

  • SquirrelSquirrel

    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 Wink

  • Dan FernandezDan

    @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

  • BasBas It finds lightbulbs.

    If two of the six skeletons are tracked... why are the other four returned?

  • Carlos BittencourtCarlos Bittencourt

    Thank you!!!!!

  • alexalex

    is it possible to post the complete code. I have some problems to have all this coded together... thanks!

  • Dan FernandezDan

    @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

  • PatrickPatrick

    This is really great, but do you have any examples of how to do gesture tracking?

  • Deacon FrostDeacon Frost

    Nice.

  • Dan FernandezDan

    @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.   

  • AlexAlex

    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)

  • AlexAlex

    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

  • LoganLogan

    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

  • RockRock

    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!

  • PaulPaul

    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.

  • PradeepPradeep

    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'

  • SanthoshSanthosh

    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

  • omaromar

    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

  • Firdosh TangriFirdosh Tangri

    @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

  • omaromar

    THANK YOU Firdosh.
    I solved my problem. Although it seems strange that this detail was not mentioned in this tutorial.

  • ThomasThomas

    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?

  • OMARFUZZERomarfuzzer KINECTEANDO

    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

  • AlexeyAlexey

    Can I see only part of skeletan for example in a sitting pose?

  • DavidDavid

    Say if i dont want to use the Ellipse but i want to use the mouse Cursor, how do i do this?

  • HieuHieu

    Yah. Got it!!
    Tks alot.

  • IrfanIrfan

    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

  • outforceoutforce

    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!!

  • irfanirfan

    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

  • Fernando CardenasFernando Cardenas

    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

  • ManuelManuel

    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 Smiley

    A.

     

    Can you tell me witch plugin was giving you this problem?

    Thanks

  • Hi, I am working on project detection of suicide boombers and I need to carry out experiment in order to detect concealed device on their body, for that I am using kinect technology ,Please can any help me with their ideas in this project and how to download kinect software.
  • NashtasticNashtastic

    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?

  • alexMalexM

    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...

  • bijanbijan

    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

  • bijanbijan

    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...  

  • ignacioignacio

    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!!

  • GeorgeGeorge

    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.

  • GeorgeGeorge

    Just noticed my infrared light turns off at the moment the circles stop moving. I don't know what could be going on.

  • kminantkminant

    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!!

  • RuiRui

    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

  • JerryJerry

    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!!

  • RogerRoger

    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.

  • DaveDave

    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-/

  • VahidVahid

    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

  • VahidVahid

    I found out what the problem was. I actually needed to put the ellipses in a canvas

  • DiegoDiego

    for those guys whose have problems with the SCALETO method... just need to write the USING for the Having4Fun dll!!! its works!!!

  • JoshJosh

    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!

  • ChristianChristian

    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

  • HoareHoare

    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!!

  • HoareHoare

    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!!

  • HoareHoare

    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!!

  • VlatkoVlatko

    Is it possible to add custom Joints on the tracked skeleton?
    Please contact me at toretorev@yahoo.com

  • terryterry

    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)
    {

    }





    }

    }

Remove this comment

Remove this thread

close

Comments Closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.