none
How could I disable the skeleton stream? RRS feed

  • Question

  • Hi,

    How could I disable the skeleton stream?

    I've tried this: 

    sensor.SkeletonStream.Disable();

    but didn't work!

    When I call the Disable() method, the program freezes and stops responding.

            int i = 0;
            void myKinect_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
            {

                i++;
                Skeleton[] skeletons = null;          
                using (SkeletonFrame frame = e.OpenSkeletonFrame())
                {
                    if (frame != null)
                    {
                        skeletons = new Skeleton[frame.SkeletonArrayLength];
                        frame.CopySkeletonDataTo(skeletons);
                    }
                }
                if (skeletons == null) return;
                foreach (Skeleton skeleton in skeletons)
                {
                    if (skeleton.TrackingState == SkeletonTrackingState.Tracked)
                    {
                        textBox1.Text = i.ToString();
                        if (myKinect.SkeletonStream.IsEnabled)
                        {
                            myKinect.SkeletonStream.Disable();                                                                   
                        }
                    }
                }
            } 

    Thank you in advance


    • Edited by TheSkyFall Monday, June 10, 2013 9:24 PM
    Monday, June 10, 2013 9:22 PM

Answers

  • Do not call Disable() in the callback function since, the code for this will need to wait until the callback, from which you called disable, has completed. This creates the deadlock scneario. Keep in mind, calling Enabled() will take some time to complete cause the app to wait for some time to begin. Calling this from a UI thread may not be the best user experience.

    If your intent is just to ignore the skeletal data, in a fast way, then just ignore the frame as actorx suggested. Otherwise you will need to call this from another function in your application.

    You can create a local variable that tracks whether you want to process skeletal or not. If you want to ignore if, you just need to call .Dispose on the SkeletonFrame object and return.

                using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
                {
                    if (skeletonFrame != null && bProcessFrame)
                    {
                        skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength];
                        skeletonFrame.CopySkeletonDataTo(skeletons);
                    }
                    if (!bProcessFrame)
                        return;
                } // <- implicit call to .Dispose on skeletonFrame

     

    Monday, June 17, 2013 6:49 PM

All replies

  • Why do you disable the skeleton tracking, ?, If you do it, you should enable the skeleton tracking again before you call OpeSkeletonFrame. Maybe is SkeletonFrame Dispose() ,what you want.
    Tuesday, June 11, 2013 9:55 PM
  • I want to do something like this:

    SkeletonFrameReady()
    {     
     SkeletonStream.Disable();  
         // Do all the processing...   
      SkeletonStream.Enable(); 
    }

    I'm not sure if this is correct or not. I have to do a lot of processing, and this is why I thought I could disable the steam.

    Thank you.
    Tuesday, June 11, 2013 10:34 PM
  • Do not call Disable() in the callback function since, the code for this will need to wait until the callback, from which you called disable, has completed. This creates the deadlock scneario. Keep in mind, calling Enabled() will take some time to complete cause the app to wait for some time to begin. Calling this from a UI thread may not be the best user experience.

    If your intent is just to ignore the skeletal data, in a fast way, then just ignore the frame as actorx suggested. Otherwise you will need to call this from another function in your application.

    You can create a local variable that tracks whether you want to process skeletal or not. If you want to ignore if, you just need to call .Dispose on the SkeletonFrame object and return.

                using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
                {
                    if (skeletonFrame != null && bProcessFrame)
                    {
                        skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength];
                        skeletonFrame.CopySkeletonDataTo(skeletons);
                    }
                    if (!bProcessFrame)
                        return;
                } // <- implicit call to .Dispose on skeletonFrame

     

    Monday, June 17, 2013 6:49 PM
  • TSF,

    I get your intent.  You don't want to be Lucy on the conveyor belt eating all the chocolates.

    A better way to handle this is probably to just using polling instead of eventing to get your skeletons:  SkeletonStream.OpenNextFrame.

    You can then call for another frame whenever you finish processing the previous frame.

    James


    James Ashley - Presentation Layer Architect at Razorfish Emerging Experiences
    jamesashley@imaginativeuniversal.com
    www.imaginativeuniversal.com www.emergingexperiences.com

    Thursday, June 20, 2013 8:55 PM