none
Switching tracked skeletons in a for-loop RRS feed

  • Question

  • Hi.

    I've created a class for managing tracking people on a scene captured by Kinect.

    I'm trying to access joints of all the skeletons in the skeleton frame with ChooseSkeletons() method by passing the TrackingID of each of them. However, the end result is that the program tracks only one skeleton. Am I doing something wrong? Does ChooseSkeletons method work only once for each DepthFrame?

    Below is the code of the method I've created to do this task: I've created  an array for skeletons and then inside for-loop I choose each of the skeletons that has TrackingState different from NotTracked.

    private void UpdatePersonas(ColorImageFrame colorFrame, DepthImageFrame depthFrame, SkeletonFrame skeletonFrame)
            {
                if (colorFrame != null && depthFrame != null && skeletonFrame != null && sensor != null)
                {
                    Skeleton[] closet = new Skeleton[skeletonFrame.SkeletonArrayLength];
                    skeletonFrame.CopySkeletonDataTo(closet);
                    for (int i = 0; i < MAX_SKELETON_COUNT; i++)
                    {
                        Skeleton currSkeleton = closet[i];
                        if (currSkeleton.TrackingState != SkeletonTrackingState.NotTracked)
                        {
                            if (personas[i] == null)
                            {
                                personas[i] = new Persona(personasWindows[i], sensor.ColorStream.Format);
                            }
                            sensor.SkeletonStream.ChooseSkeletons(currSkeleton.TrackingId);
                            Console.WriteLine("Tracked id: " + currSkeleton.TrackingId);
                            if (!personas[i].UpdatePersona(currSkeleton, colorFrame, depthFrame, skeletonFrame, pixels))
                                personasWindows[i].Source = dummyImage;
                        }
                        else
                        {
                            if (personas[i] != null)
                            {
                                personas[i] = null;
                                personasWindows[i].Source = dummyImage;
                            }
                        }
                    }
                }
    
            }

    Monday, April 30, 2012 3:49 PM

Answers

  • That's correct: ChooseSkeletons has its effect on subsequent frames. If you call it multiple times during processing of a frame, the last call wins.

    The purpose of ChooseSkeletons (and the AppChoosesSkeletons property) is to instruct the runtime which one or two of the six possible skeletons are to be tracked, overriding the runtime's automatic tracking logic.

    You can't use ChooseSkeletons as a way to get more than two fully-tracked skeletons per frame (if this is what you were attempting to do).

    John
    K4W Dev

    Tuesday, May 1, 2012 2:49 PM

All replies

  • ChooseSkeletons is not cumulative; each call overwrites the previous one. Try this instead:

                    int[] choices = new int[MAX_TRACKED_SKELETON_COUNT];
                    int chosenCount = 0;
                    for (int i = 0; i < MAX_SKELETON_COUNT; i++)
                    {
                        Skeleton currSkeleton = closet[i];
                        if (currSkeleton.TrackingState != SkeletonTrackingState.NotTracked)
                        {
                            ...
                            if (chosenCount < MAX_TRACKED_SKELETON_COUNT) // should always be true!
                            {
                                choices[chosenCount++] = currSkeleton.TrackingId;
                            }
                        }
                        else
                        {
                            ...
                        }
                    }
                    sensor.SkeletonStream.ChooseSkeletons(choices[0], choices[1]);

    MAX_TRACKED_SKELETON_COUNT should have a value of 2.

    John
    K4W Dev


    Monday, April 30, 2012 9:36 PM
  • I know that ChooseSkeletons isn't cumulative - that's why after invoking it, I'm running UpdatePersona method which should work on newly chosen tracked skeleton.

    Maybe I should rephrase my question - What I want to do is change tracked skeleton six times using one SkeletonFrame - is that possible? Or maybe ChooseSkeletons has its effect in the next frame?

    Tuesday, May 1, 2012 8:09 AM
  • That's correct: ChooseSkeletons has its effect on subsequent frames. If you call it multiple times during processing of a frame, the last call wins.

    The purpose of ChooseSkeletons (and the AppChoosesSkeletons property) is to instruct the runtime which one or two of the six possible skeletons are to be tracked, overriding the runtime's automatic tracking logic.

    You can't use ChooseSkeletons as a way to get more than two fully-tracked skeletons per frame (if this is what you were attempting to do).

    John
    K4W Dev

    Tuesday, May 1, 2012 2:49 PM
  • Well, that explains a lot - thanks for the answer.
    Thursday, May 3, 2012 7:32 AM