Convert X Joint Value to Label/TextBox RRS feed

  • Question

  • Hey,

    I am using the SkeletalTracking quickstart example and I want to display the X Value of say the HandLeft Joint onto a label that I added to the MainWindow screen, how would I go about doing this easily? -- the example code is posted below

    I'm thinking that I have to add a statement after the "//set position" block, but not sure what to add.



    // This module contains code to do a basic green screen.
    // Copyright © Microsoft Corporation.  All rights reserved.  
    // This code is licensed under the terms of the 
    // Microsoft Kinect for Windows SDK (Beta) from Microsoft Research 
    // License Agreement:
    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.Research.Kinect.Nui;
    using Coding4Fun.Kinect.Wpf; 
    namespace SkeletalTracking
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
            public MainWindow()
            //Kinect Runtime
            Runtime nui = new Runtime();
            private void Window_Loaded(object sender, RoutedEventArgs e)
                //Initialize to do skeletal tracking
                #region TransformSmooth
                //Must set to true and set after call to Initialize
                nui.SkeletonEngine.TransformSmooth = true;
                //Use to transform and reduce jitter
                var parameters = new TransformSmoothParameters
                    Smoothing = .5f,
                    Correction = 0f,
                    Prediction = 0f,
                    JitterRadius = .05f,
                    MaxDeviationRadius =.04f
                nui.SkeletonEngine.SmoothParameters = parameters; 
                //add event to receive skeleton data
                nui.SkeletonFrameReady += new EventHandler<SkeletonFrameReadyEventArgs>(nui_SkeletonFrameReady);
            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();
                if(skeleton != null)
                    //set position
                    SetEllipsePosition(headEllipse, skeleton.Joints[JointID.Head]);
                    SetEllipsePosition(leftEllipse, skeleton.Joints[JointID.HandLeft]);
                    SetEllipsePosition(rightEllipse, skeleton.Joints[JointID.HandRight]);
            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);
            private void Window_Closed(object sender, EventArgs e)

    Saturday, November 12, 2011 7:30 AM

All replies

  • Yes that is the safest place to add your code.

    Your need to add somthing like..


    or you could do somthing like..

    Joint leftHand=skeleton.Joints[JointID.HandLeft];

    and then pass the joint you just referenced to that elipse funtion like

    SetEllipsePosition(leftEllipse, leftHand);
    Sunday, November 13, 2011 5:58 PM