none
Kinect skeletal tracking problems RRS feed

  • Question

  • Hi all , I'm using c# and vs2010 , tried a million different examples and books but just cannot get the skeleton to draw and i'd really appreciate some help , here is a bit of my code

    public partial class MainWindow : Window
        {
            
            Skeleton[] skeletons;
            KinectSensor sensor;

            public MainWindow()
            {
                InitializeComponent();
    }

            private void Initialize()
            {
                if (sensor == null)
                   return;


                this.sensor.SkeletonStream.TrackingMode = SkeletonTrackingMode.Default;

                this.sensor.SkeletonFrameReady += kinectSensor_SkeletonFrameReady;

                this.sensor.SkeletonStream.Enable();
                this.sensor.Start();

                var kinectsensor = KinectSensor.KinectSensors[0];

                var skeletondData = this.sensor.SkeletonStream.OpenNextFrame(500);
                
                this.sensor.SkeletonStream.AppChoosesSkeletons = true;
                this.sensor.SkeletonStream.ChooseSkeletons(1, 5);
            }

            private void kinectSensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
            {
                using (SkeletonFrame frame = e.OpenSkeletonFrame())
                {
                    if (frame == null)
                        return;

                    frame.GetSkeletons(ref skeletons);

                    if (skeletons.All(s => s.TrackingState == SkeletonTrackingState.NotTracked))
                        return;

                    foreach (var skeleton in skeletons)
                    {
                        if (skeleton.TrackingState != SkeletonTrackingState.Tracked)
                            continue;

                        foreach (Joint joint in skeleton.Joints)
                        {
                            if (joint.TrackingState != JointTrackingState.Tracked)
                                continue;
                        }
                    }
                }
            }


            private void WindowLoaded(object sender, RoutedEventArgs e)
            {
                foreach (var potentialSensor in KinectSensor.KinectSensors)
                {
                    if (potentialSensor.Status == KinectStatus.Connected)
                    {
                        this.sensor = potentialSensor;
                        break;
                    }
                }

            
                
                if (null != this.sensor)
                {
                    this.sensor.DepthStream.Enable(DepthFormat);

                    this.depthWidth = this.sensor.DepthStream.FrameWidth;

                    this.depthHeight = this.sensor.DepthStream.FrameHeight;

                    this.sensor.ColorStream.Enable(ColorFormat);

                    int colorWidth = this.sensor.ColorStream.FrameWidth;
                    int colorHeight = this.sensor.ColorStream.FrameHeight;

                    this.colorToDepthDivisor = colorWidth / this.depthWidth;

                    sensor.SkeletonStream.Enable(); // Enable skeletal tracking
                    sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);
                    SkeletonDisplayManager skeletonManager = new SkeletonDisplayManager(this.sensor, skeletonCanvas);

     
                    this.sensor.AllFramesReady += this.SensorAllFramesReady;

                    
                    this.sensor.SkeletonFrameReady += this.kinectSensor_SkeletonFrameReady;

                    try
                    {
                        this.sensor.Start();
                    }
                    catch (IOException)
                    {
                        this.sensor = null;
                    }
                }

                if (null == this.sensor)
                {
                    this.statusBarText.Text = Properties.Resources.NoKinectReady;
                }

            }

    }

    Friday, March 8, 2013 5:18 PM

Answers

  • What is your intent with the following lines in your code?

    this.sensor.SkeletonStream.AppChoosesSkeletons = true;
    this.sensor.SkeletonStream.ChooseSkeletons(1, 5);

    This will tell the SkeletonStream to ignore any skeletons other than those whose tracking ID has the value 1 or 5.

    You can't make any assumptions about which specific tracking ID value will be assigned to any given skeleton... This API is intended to be used after examining at least one skeleton frame: Your code can observe which skeletons are in the Tracked or PositionOnly state, and then decide if you want to force one or more of them into the Tracked state by calling ChooseSkeletons.

    If the automatic skeleton selection logic would be sufficient for your needs, you should remove those two lines of code. Otherwise, you'll need to add more logic to determine the identities of the skeletons you want tracked, and pass those to the ChooseSkeletons, rather than hardcoded constants.


    John | Kinect for Windows development team

    Tuesday, March 12, 2013 6:41 PM