Question

I am trying to get my Kinect's SkeletonStream to feedback a data that tells me that nobody is detected. I can get feed if my skeleton is detected but I am unable to get any notification if there is nobody there. Is there a way to get the kinect to tell me if no skeletons are picked up?

private void kinect_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
    {
        using (SkeletonFrame frame = e.OpenSkeletonFrame())
        {
            if (frame == null)
            {
                return;
            }
            frame.GetSkeletons(ref allSkeletons);
            if (allSkeletons.All(s => s.TrackingState == SkeletonTrackingState.NotTracked))
                return;

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

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

                    if (joint.JointType == JointType.HipCenter)
                    {
                        hipCenter = joint.Position;
                        AdvanceFunction();
                    }

                }
                sdm.Draw(frame.GetSkeletons(), false);
            }

        }
    }
Was it helpful?

Solution

There is nothing that will simply tell you that no skeletons are currently being tracked. You will need to look through the skeleton frames to determine if there are any users.

Your foreach loop steps through all the skeletons...

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

    ....
}

In the first if statement -- if the current skeleton is not being actively tracked then the loop will move on to the next skeleton. You'll want to add a flag if any skeletons have been found. For example, you could do something like...

bool hasActivePlayer = false;

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

    hasActivePlayer = true;

    ....
}

if (hasActivePlayer == false)
{
    // you aren't tracking anyone, deal with it
}

You may also be interested in checking SkeletonTrackingState.PositionOnly. In this case the Kinect knows someone is there, but it is not actively tracking their skeleton. You can update the ckeck in the foreach loop if you want to look for it as well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top