1

We have been having trouble with finding up to date tutorials for the Kinect SDK 1.8. All of the tutorials that we have found online are for an older version of the SDK. If anyone could help, would someone please tell us what version of the Kinect SDK this code is written in and how to update the code to the latest SDK code(version 1.8).


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;

namespace KinectSkeletonApplication3
{
    public partial class MainWindow : Window
    {
        //Instantiate the Kinect runtime. Required to initialize the device.
        //IMPORTANT NOTE: You can pass the device ID here, in case more than one Kinect device is connected.


        Runtime runtime = Runtime.Kinects[0];

        public MainWindow()
        {
            InitializeComponent();

            //Runtime initialization is handled when the window is opened. When the window
            //is closed, the runtime MUST be unitialized.
            this.Loaded += new RoutedEventHandler(MainWindow_Loaded);
            this.Unloaded += new RoutedEventHandler(MainWindow_Unloaded);

            runtime.SkeletonFrameReady += new EventHandler<SkeletonFrameReadyEventArgs>(runtime_SkeletonFrameReady);
        }

        void runtime_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
        {
            SkeletonFrame skeletonSet = e.SkeletonFrame;

            SkeletonData data = (from s in skeletonSet.Skeletons
                                 where s.TrackingState == SkeletonTrackingState.Tracked
                                 select s).FirstOrDefault();
            if (data != null)
            {
                SetEllipsePosition(Head, data.Joints[JointID.Head]);
                SetEllipsePosition(leftHand, data.Joints[JointID.HandLeft]);
                SetEllipsePosition(rightHand, data.Joints[JointID.HandRight]);
                ProcessGesture(data.Joints[JointID.Head], data.Joints[JointID.HandLeft], data.Joints[JointID.HandRight]);
            }     

        }

        private void ProcessGesture(Joint head, Joint handLeft, Joint handRight)
        {
            if ((handRight.position.Y > head.position.Y) || (handLeft.position.Y > head.position.Y))
            {
                MessageBox.Show("Your hand is above your head, bitch.");
            }
            else if ((handRight.position.Y < 0) || (handLeft.position.Y < 0))
            {
                MessageBox.Show("Your hand is below your waist, bitch.");
            }
            else if (handRight.position.X < handLeft.position.X)
            {
                MessageBox.Show("Your hands are crossed, bitch.");
            }
        }


        private void SetEllipsePosition(Ellipse ellipse, Joint joint)
        {
            Microsoft.Research.Kinect.Nui.Vector vector = new Microsoft.Research.Kinect.Nui.Vector();
            vector.X = ScaleVector(640, joint.Position.X);
            vector.Y = ScaleVector(480, -joint.Position.Y);
            vector.Z = joint.Position.Z;

            Joint updatedJoint = new Joint();
            updatedJoint.ID = joint.ID;
            updatedJoint.TrackingState = JointTrackingState.Tracked;
            updatedJoint.Position = vector;

            Canvas.SetLeft(ellipse, updatedJoint.Position.X);
            Canvas.SetTop(ellipse, updatedJoint.Position.Y);


        }

        private float ScaleVector(int length, float position)
        {
            float value = (((((float)length) / 1f) / 2f) * position) + (length / 2);
            if (value > length)
            {
                return (float)length;
            }
            if (value < 0f)
            {
                return 0f;
            }
            return value;
        }

        void MainWindow_Unloaded(object sender, RoutedEventArgs e)
        {
            runtime.Uninitialize();
        }

        void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            //Since only a color video stream is needed, RuntimeOptions.UseColor is used.
            runtime.Initialize(Microsoft.Research.Kinect.Nui.RuntimeOptions.UseColor | RuntimeOptions.UseSkeletalTracking);
        }


    }
}

  • If you have any information about the Kinect dlls, that would be helpful to include in your question. – Adam Zuckerman Mar 13 '14 at 02:52
  • What have you tried? For which class for function you can´t find an equivalent in the 1.8 SDK? – Thomas Hetzer Mar 13 '14 at 08:44
  • At present, the only function that is returning a compile error is runtime_SkeletonFrameReady. We have tried to look at current library classes and methods and comparing them to what we have, but no luck. Additionally, there might be some confusion as to what version of the SDK we are using. I see people talking about the Beta SDK and then other people saying to upgrade from v1.8 to 1.0, which is leaving me very confused. Is 1.8 a beta version? We are using code from a version prior to 1.8, but are using 1.8 currently. – Barret5Ocal Mar 19 '14 at 02:24
  • As an unrelated question, why does it seem like the Kinect SDK is so poorly documented? You'd think Microsoft would have some sort of official thing for circumstances like this. – Barret5Ocal Mar 19 '14 at 02:30

1 Answers1

0

I would see this blog post and this one. They both describe the main changes from the beta to v1.0. v1.0 Has the same structure as 1.8, and for an example of a converted piece of code, see Converting Kinect Methods from Beta 2, to Version 1. While converting to v1.8 may seem daunting and not worth the work, stay with it, it is much more efficient and effective.

Community
  • 1
  • 1
Liam McInroy
  • 4,339
  • 5
  • 32
  • 53