none
How to track only 1 person from Kinect? RRS feed

  • General discussion

  • Hi,

    I am creating a virtual dressing room using Kinect, I want to track only 1 person at a time, right now the cloth switches to another person if he comes within Kinect range..I have written the following code to restrict the number of skeleton to 1, but its not giving me the reuslt..Kindly check it and guide me how to how to restrict Kinect to register the first person only.

                SkeletonFrame usingSkeletonFrame = e.OpenSkeletonFrame();
    
                    if (usingSkeletonFrame != null)
                    {
    
    
                       _skeletons = new Skeleton[usingSkeletonFrame.SkeletonArrayLength];
                       usingSkeletonFrame.CopySkeletonDataTo(_skeletons);
    
                       firstSkeleton = _skeletons[0].TrackingId;
                       firstSkeletonTrackingState = _skeletons[0].TrackingState;
      
    
    
                  if (SkeletonTrackingState.Tracked == firstSkeletonTrackingState)
                    //{
    
                if(_skeletons.Length >0)            
                //  if (_skeletons.Length == SkeletonTrackingState.Tracked)
                {
                    isSkeleton = true;
                    foreach (Skeleton skl in _skeletons)
                    {
                        if (skl.TrackingState == SkeletonTrackingState.Tracked)
                        {
    
    

    Thanks,

    Taha

    Monday, March 31, 2014 6:31 AM

All replies

  • The SDK will always track 2 people. In your code you have a bug. You are always making an assumption index 0 is the first person, that is not correct. You must ALWAYS iterate over the collection of skeletons to find the tracking state for a skeleton state that is Tracked. Once you know a skeleton is tracked, then you can record that as your firstSkeleton. Remember you will always get 2, so if there are 2 people in view, then you need to make a decision on which id you want.

    http://msdn.microsoft.com/en-us/library/jj131025.aspx


    Carmine Sirignano - MSFT

    Monday, March 31, 2014 7:08 PM
  • You may want to "select" the right skeleton based on the position (in front of the sensor) or the closest skeleton (comparing their Skeleton.Position.Z).

    This thread may help you :
    http://social.msdn.microsoft.com/Forums/en-US/06d9116e-8b52-4c20-9f6a-2fa143d9ef49/kinect-skeleton-tracking-question-only-track-one-the-nearest-skeleton?forum=kinectsdknuiapi

    Vincent Guigui Innovative Technologies Expert at OCTO Technology Kinect For Windows MVP award

    Tuesday, April 1, 2014 9:29 PM
  • Thank you so Much for the Help. I have edit my code..Right now its simply detecting any skeleton that he finds and place the cloth on that skeleton. This is really disturbing when there are multiple people in front of Kinect Device. Kindly tell me what i can add in this code?

                /*------------------------------------------
                 * SKELETON JOINTS
                --------------------------------------------
                 */
                Skeleton[] _skeletons = new Skeleton[0];
    
    
                using (SkeletonFrame usingSkeletonFrame = e.OpenSkeletonFrame())
                {
                    if (usingSkeletonFrame != null)
                    {
                       _skeletons = new Skeleton[usingSkeletonFrame.SkeletonArrayLength];
                       usingSkeletonFrame.CopySkeletonDataTo(_skeletons);
    
                      
                    }                
                }
    
    
    
                if(_skeletons.Length >0)            
                //  if (_skeletons.Length == SkeletonTrackingState.Tracked)
                {
    
    
                    isSkeleton = true;
                    foreach (Skeleton skl in _skeletons)
                    {
                        if (skl.TrackingState == SkeletonTrackingState.Tracked)
                        {
    
                            // string str = "";
    
                            Joint shoulderCenter = skl.Joints[JointType.ShoulderCenter];
                            Joint rightShoulder = skl.Joints[JointType.ShoulderRight];
    


    Wednesday, April 2, 2014 5:17 AM
  • T.,

    You can use the TrackingId for the skeleton to make it more sticky, something like this:

            int _trackedSkeletonId = 0;
            Skeleton _currentSkeleton;

            void sensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
            {
                _currentSkeleton = null;

                using (SkeletonFrame frame = e.OpenSkeletonFrame())
                {
                    if (frame == null)
                        return;

                    if (_skeletons == null) _skeletons = new Skeleton[frame.SkeletonArrayLength];
                    frame.CopySkeletonDataTo(_skeletons);

                    bool bSklFound = false;
                    foreach (Skeleton skl in _skeletons)
                    {
                        if (skl.TrackingState == SkeletonTrackingState.Tracked)
                        {
                            if (_currentSkeleton == null)
                            {
                                _currentSkeleton = skl;
                                bSklFound = true;
                                break;
                            }
                            else if (skl.TrackingId == _trackedSkeletonId)
                            {
                                _currentSkeleton = skl;
                                bSklFound = true;
                                break;
                            }
                        }
                    }
                    if (bSklFound == true)
                    {
                        _trackedSkeletonId = _currentSkeleton.TrackingId;
                        //do what you want with one found skeleton
                    }
                    else
                    {
                        _currentSkeleton = null;
                    }
                }
            }


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

    Wednesday, April 2, 2014 2:46 PM
  • Thank you so Much for the Help James :) I have implemented your code,and its working perfectly Fine NOW.. but few times when a new person enters in the frame/Range it switches the cloth on him. Any idea why it does this sometimes?


                Skeleton[] _skeletons = new Skeleton[6];

                _currentSkeleton = null;

              //  bool bSklFound = false;

    using (SkeletonFrame usingSkeletonFrame = e.OpenSkeletonFrame()) { if (usingSkeletonFrame != null) { if (_skeletons == null) _skeletons = new Skeleton[usingSkeletonFrame.SkeletonArrayLength]; usingSkeletonFrame.CopySkeletonDataTo(_skeletons); bool bSklFound = false; foreach (Skeleton skl in _skeletons) { if (skl.TrackingState == SkeletonTrackingState.Tracked) { if (_currentSkeleton == null) { _currentSkeleton = skl; bSklFound = true; break; } else if (skl.TrackingId == _trackedSkeletonId) { _currentSkeleton = skl; bSklFound = true; break; } } } if (bSklFound == true) { _trackedSkeletonId = _currentSkeleton.TrackingId; //do what you want with one found skeleton Joint shoulderCenter = _currentSkeleton.Joints[JointType.ShoulderCenter]; Joint rightShoulder = _currentSkeleton.Joints[JointType.ShoulderRight]; leftShoulder = _currentSkeleton.Joints[JointType.ShoulderLeft]; Joint Head = _currentSkeleton.Joints[JointType.Head]; wristLeft = _currentSkeleton.Joints[JointType.WristLeft]; wristRight = _currentSkeleton.Joints[JointType.WristRight]; Joint hipsCenter = _currentSkeleton.Joints[JointType.HipCenter]; Joint elbowLeft = _currentSkeleton.Joints[JointType.ElbowLeft]; Joint wrist = _currentSkeleton.Joints[JointType.WristRight]; } else { _currentSkeleton = null; } } } //DRAW Method if (mouseX >= currentXposition[i] && mouseX <= currentXposition[i] + displayItemsWidth && mouseY >= displayItemsY && mouseY <= displayItemsY + displayItemsHeight ) { shirtXposition = shoulderCenterPos.X;// -180; shirtYposition = shoulderCenterPos.Y;// +20; currentShirt = _image1Display[i];





    • Edited by tahakirmani Thursday, April 3, 2014 7:05 AM
    Thursday, April 3, 2014 6:10 AM
  • Joints position are evaluated in meter

    So 18cm should be 0.18f


    Vincent Guigui Innovative Technologies Expert at OCTO Technology Kinect For Windows MVP award

    Thursday, April 3, 2014 6:47 AM
  • It might not be breaking the loop.  You can fix it by adding another break statement like this:

                        foreach (Skeleton skl in _skeletons)
                        {
                            if (skl.TrackingState == SkeletonTrackingState.Tracked)
                            {
                                if (_currentSkeleton == null)
                                {
                                    ...
                                    bSklFound = true;
                                    break;
                                }
                                else if (skl.TrackingId == _trackedSkeletonId)
                                {
                                    ..
                                    bSklFound = true;
                                    break;
                                }
                            }
       if(bSklFound == true) // <----
        break;----
                        }


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

    Friday, April 4, 2014 5:31 PM
  • I am getting the following Error message, when adding  break statement.

                                if (shoulderCenter.TrackingState == JointTrackingState.Tracked)
                                {
                                    break;
                                    //SHOULDER Center
                                    shoulderCenterPos = sensor.CoordinateMapper.MapSkeletonPointToDepthPoint(shoulderCenter.Position, DepthImageFormat.Resolution640x480Fps30);
    
                                    shirtXposition = shoulderCenterPos.X;// -180;
                                    shirtYposition = shoulderCenterPos.Y;// +20;
    
    No enclosing loop out of which to break or continue



    • Edited by tahakirmani Saturday, April 5, 2014 5:01 AM
    Saturday, April 5, 2014 5:00 AM
  • Sorry Tahakirmani.  The second break was dumb advice on my part.

    I'm not sure why tracking is switching on you.  If you are using the jointtrackingstate rather than the skeletontrackingstate, though, it may be because there are more states for joints than there are for skeletons.

    You might want to try:

     if (shoulderCenter.TrackingState == JointTrackingState.Tracked || shoulderCenter.TrackingState == JointTrackingState.Inferred)

    {

     ....

    }


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

    Tuesday, April 8, 2014 5:57 PM