none
How to extract the skeleton's coordinates for the whole skeleton? RRS feed

All replies

  • Please find the code .

                

    <Window x:Class="Play_v_6.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="923" Loaded="Window_Loaded" Closing="Window_Closing" xmlns:my="clr-namespace:Microsoft.Samples.Kinect.WpfViewers;assembly=Microsoft.Samples.Kinect.WpfViewers">
        <Grid>
            <Canvas>
                <my:KinectDepthViewer HorizontalAlignment="Left" Margin="12,12,0,0" Name="kinectDepthViewer1" VerticalAlignment="Top" Height="218" Width="384" Kinect="{Binding ElementName=kinectSensorChooser1, Path=Kinect}" />
            <my:KinectSensorChooser HorizontalAlignment="Left" Margin="326,179,0,0" Name="kinectSensorChooser1" VerticalAlignment="Top" Width="328" />
            <my:KinectSkeletonViewer HorizontalAlignment="Left" Margin="499,12,0,0" Name="kinectSkeletonViewer1" VerticalAlignment="Top" Height="229" Width="373" Kinect="{Binding ElementName=kinectSensorChooser1, Path=Kinect}" />

                <Ellipse Height="10" Width="10" Fill="Blue" Name="HipCenter"/>

                <Ellipse Height="10" Width="10" Fill="Blue" Name="Spine"/>
                <Ellipse Height="10" Width="10" Fill="Blue" Name="ShoulderCenter"/>
                <Ellipse Height="25" Width="15" Fill="yellow" Name="Head" Canvas.Left="113" Canvas.Top="12" />
                <Ellipse Height="10" Width="10" Fill="Blue" Name="ShoulderLeft"/>
                <Ellipse Height="10" Width="10" Fill="Magenta" Name="ElbowLeft"/>
                <Ellipse Height="10" Width="10" Fill="Blue" Name="WristLeft"/>
                <Ellipse Height="10" Width="10" Fill="Blue" Name="HandLeft"/>
                <Ellipse Height="10" Width="10" Fill="Blue" Name="ShoulderRight"/>
                <Ellipse Height="10" Width="10" Fill="Magenta" Name="ElbowRight"/>
                <Ellipse Height="10" Width="10" Fill="Blue" Name="WristRight"/>
                <Ellipse Height="10" Width="10" Fill="Blue" Name="HandRight"/>
                <Ellipse Height="10" Width="10" Fill="Blue" Name="HipLeft"/>
                <Ellipse Height="15" Width="10" Fill="Red" Name="KneeLeft" Canvas.Left="28" Canvas.Top="86" />
                <Ellipse Height="10" Width="10" Fill="Blue" Name="AnkleLeft" Canvas.Left="70" Canvas.Top="42" />
                <Ellipse Height="10" Width="10" Fill="Blue" Name="FootLeft" Canvas.Left="12" Canvas.Top="99" />
                <Ellipse Height="10" Width="10" Fill="Blue" Name="HipRight" Canvas.Left="118" Canvas.Top="74" />
                <Ellipse Height="15" Width="10" Fill="Red" Name="KneeRight" Canvas.Left="246" Canvas.Top="20" />
                <Ellipse Height="10" Width="10" Fill="Blue" Name="AnkleRight" Canvas.Left="416" Canvas.Top="12" />
                <Ellipse Height="10" Width="10" Fill="Blue" Name="FootRight" Canvas.Left="454" Canvas.Top="12" />
            </Canvas>


        </Grid>
    </Window>

    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;
    using Coding4Fun.Kinect.Wpf;
    using System.Diagnostics;


    namespace Play_v_6
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
            }

            private void Window_Loaded(object sender, RoutedEventArgs e)
            {
                kinectSensorChooser1.KinectSensorChanged += new DependencyPropertyChangedEventHandler(kinectSensorChooser1_KinectSensorChanged);
            }

            void kinectSensorChooser1_KinectSensorChanged(object sender, DependencyPropertyChangedEventArgs e)
            {
                KinectSensor oldsensor = (KinectSensor)e.OldValue;

                StopKinect(oldsensor);

                KinectSensor newsensor = (KinectSensor)e.NewValue;

                newsensor.DepthStream.Enable();
                newsensor.SkeletonStream.Enable();

                
                newsensor.SkeletonFrameReady += new EventHandler<SkeletonFrameReadyEventArgs>(newsensor_SkeletonFrameReady);
                //newsensor.AllFramesReady += new EventHandler<AllFramesReadyEventArgs>(newsensor_AllFramesReady);
                newsensor.Start();
                //throw new NotImplementedException();
            }

           



            public void SetEllipsePosition(Ellipse ellipse, Joint joint)
            {
                Canvas.SetLeft(ellipse, (320 * joint.Position.X) + 320);
                Canvas.SetTop(ellipse, (240 * -joint.Position.Y) + 240);
            }



            Skeleton[] skeletons = null;

            void newsensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
            {

                 using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
                 {              
                     if (skeletonFrame != null)
                    {
                        if (this.skeletons == null)
                        {
                            this.skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength];
                        }   
                        skeletonFrame.CopySkeletonDataTo(this.skeletons);
                        Skeleton skeleton = this.skeletons.Where(s => s.TrackingState == SkeletonTrackingState.Tracked).FirstOrDefault();




                       /*if (skeleton != null)
                        {
                            // Calculate height.
                          //  double height = Math.Round(skeleton.Height(), 2);

                        }*/



                        if (skeleton != null)
                        {
                            
                            SetEllipsePosition(HipCenter, skeleton.Joints[JointType.HipCenter]);
                            SetEllipsePosition(Spine, skeleton.Joints[JointType.Spine]);
                            SetEllipsePosition(ShoulderCenter, skeleton.Joints[JointType.ShoulderCenter]);
                            SetEllipsePosition(Head, skeleton.Joints[JointType.Head]);
                            SetEllipsePosition(ShoulderLeft, skeleton.Joints[JointType.ShoulderLeft]);
                            SetEllipsePosition(ElbowLeft, skeleton.Joints[JointType.ElbowLeft]);
                            SetEllipsePosition(WristLeft, skeleton.Joints[JointType.WristLeft]);
                            SetEllipsePosition(HandLeft, skeleton.Joints[JointType.HandLeft]);
                            SetEllipsePosition(ShoulderRight, skeleton.Joints[JointType.ShoulderRight]);
                            SetEllipsePosition(ElbowRight, skeleton.Joints[JointType.ElbowRight]);
                            SetEllipsePosition(WristRight, skeleton.Joints[JointType.WristRight]);
                            SetEllipsePosition(HandRight, skeleton.Joints[JointType.HandRight]);
                            SetEllipsePosition(HipLeft, skeleton.Joints[JointType.HipLeft]);
                            SetEllipsePosition(KneeLeft, skeleton.Joints[JointType.KneeLeft]);
                            SetEllipsePosition(AnkleLeft, skeleton.Joints[JointType.AnkleLeft]);
                            SetEllipsePosition(FootLeft, skeleton.Joints[JointType.FootLeft]);
                            SetEllipsePosition(HipRight, skeleton.Joints[JointType.HipRight]);
                            SetEllipsePosition(KneeRight, skeleton.Joints[JointType.KneeRight]);
                            SetEllipsePosition(AnkleRight, skeleton.Joints[JointType.AnkleRight]);
                            SetEllipsePosition(FootRight, skeleton.Joints[JointType.FootRight]);

                  
                        }

                        
                        
                          
                        if(skeleton !=null)

                        {
                            Joint j = skeleton.Joints[JointType.Head];

                        
                        if (j.TrackingState == JointTrackingState.Tracked)
                            {
                                Console.WriteLine("The output of X Y Z coordinates");
                             Debug.WriteLine("Head: X AXIS" + j.Position.X + ",Y AXIS \t " + j.Position.Y + ",Z AXIS\t " + j.Position.Z);
                            }
                        }
                        if (skeleton != null)
                        {
                            Joint j = skeleton.Joints[JointType.KneeLeft];

                            if (j.TrackingState == JointTrackingState.Tracked)
                            {
                                Console.WriteLine("The output of X Y Z coordinates");

                                Console.WriteLine("Head: X AXIS" + j.Position.X + ",Y AXIS \t " + j.Position.Y + ",Z AXIS\t " + j.Position.Z);
                            }
                        }


                         }

                }
            }

            

            private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
            {
                StopKinect(kinectSensorChooser1.Kinect);
            }

            void StopKinect(KinectSensor sensor)
            {
                if (sensor != null)
                {
                    sensor.Stop();
                }

            }

        }
    }

    Thursday, September 26, 2013 9:36 PM