none
Taking joint data from the closest player only RRS feed

  • Question

  • Hello!I would like to know how i can take the data from the closest player to kinect only.i want to recognize only the first person that appears to kinect and noone else above him.How can i convert this?

     SkeletonData skeleton = (from s in allSkeletons.Skeletons
                                         where s.TrackingState == SkeletonTrackingState.Tracked
                                         select s).FirstOrDefault();

    Wednesday, April 25, 2012 10:08 AM

Answers

  • Try to send all tracked skeletons to the following method and it will get you the closest player only

    private static Skeleton GetPrimarySkeleton(IEnumerable<Skeleton> skeletons)
            {
                Skeleton primarySkeleton = null;
                foreach (Skeleton skeleton in skeletons)
                {
                    if (skeleton.TrackingState != SkeletonTrackingState.Tracked)
                    {
                        continue;
                    }
    
                    if (primarySkeleton == null)
                        primarySkeleton = skeleton;
                    else if (primarySkeleton.Position.Z > skeleton.Position.Z)
                        primarySkeleton = skeleton;
                }
                return primarySkeleton;
            }


    Thanks,
    MOHAMED A. SAKR | Software Development Lead Engineer | EgyptNetwork
    Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members. Also try to Vote as Helpful


    Wednesday, April 25, 2012 2:33 PM

All replies

  • You can get it using Z or depth value

    Please check the below code

      Skeleton[] trackedskeletons = (from skl in _skeletonData
                  where skl.TrackingState == SkeletonTrackingState.Tracked                              select skl).ToArray<Skeleton>();
      Skeleton[] _skeleton;
      float depth = 0;
      foreach (Skeleton skl in trackedskeletons)
                    {
                        if (depth ==0 || skl.Position.Z<depth)
                        {
                            depth = skl.Position.Z;
                            _skeleton = skl;
                            
                        }
                    }

    Wednesday, April 25, 2012 11:38 AM
  • Try to send all tracked skeletons to the following method and it will get you the closest player only

    private static Skeleton GetPrimarySkeleton(IEnumerable<Skeleton> skeletons)
            {
                Skeleton primarySkeleton = null;
                foreach (Skeleton skeleton in skeletons)
                {
                    if (skeleton.TrackingState != SkeletonTrackingState.Tracked)
                    {
                        continue;
                    }
    
                    if (primarySkeleton == null)
                        primarySkeleton = skeleton;
                    else if (primarySkeleton.Position.Z > skeleton.Position.Z)
                        primarySkeleton = skeleton;
                }
                return primarySkeleton;
            }


    Thanks,
    MOHAMED A. SAKR | Software Development Lead Engineer | EgyptNetwork
    Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members. Also try to Vote as Helpful


    Wednesday, April 25, 2012 2:33 PM
  • Any updates

    Please feedback


    Thanks,
    MOHAMED A. SAKR | Software Development Lead Engineer | EgyptNetwork
    Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members. Also try to Vote as Helpful

    Saturday, April 28, 2012 7:04 PM
  • it worked!thank you very much!
    Thursday, May 10, 2012 8:08 PM
  • , code works great. Thanks!

    I spent a night trying to do the same (get nearest player) using MS's KinectManager class, but there's no sample for using it with WinForms, only WPF sample. It would be great if someone could post an easy sample for using KinectManager class, which have option to get skeletons for most active player, sticky player etc. Would be handy in some more complex project.

    For now, your code for getting the nearest player is working good for me :)

    // chall3ng3r //


    www.orison.biz/blogs/chall3ng3r/

    Saturday, March 16, 2013 7:45 PM