0

I am creating a an application using Kinect, I want to track only 1 person at a time, right now Kinect starts detecting another person if he comes in within Kinect range. I have written the following code, and it detects any person who comes within Kinect range. Kindly tell me how can i restrict it to detect only 1 person at a time.

        /*------------------------------------------
         * 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];
                    leftShoulder = skl.Joints[JointType.ShoulderLeft];
                    Joint Head = skl.Joints[JointType.Head];
Taha Kirmani
  • 1,274
  • 6
  • 26
  • 55
  • Have you had a look at the [TrackingId](http://msdn.microsoft.com/en-us/library/microsoft.kinect.skeleton.trackingid.aspx) property on the Skeleton class? – DJH Apr 02 '14 at 12:15
  • I think you got the answer [here](http://social.msdn.microsoft.com/Forums/en-US/3798be27-aae5-4cf2-ae8c-dbb2737b1299/how-to-track-only-1-person-from-kinect?forum=kinectsdk) – Tomasz Kowalczyk Apr 03 '14 at 16:26

1 Answers1

1

I would see this answer I wrote on another question.

int trackingID;
skeletonTracked = new Skeleton();
bool first = true;
Skeleton skeleton;
Skeleton[] skeletons = new Skeleton[6];

...

public void AllFramesReady(object sender, AllFramesReadyEventArgs e)
{
    using (SkeletonFrame sFrame = e.OpenSkeletonFrame())
    {
        sFrame.CopySkeletonDataTo(skeletons);
        skeleton = (from s in skeletons where s.TrackingState == SkeletonTrackingState.Tracked select s).FirstOrDefault();
        if (skeleton == null)
            return;

        if (skeleton.TrackingState == SkeletonTrackingState.Tracked)
        {
            if (first)
            {
                skeletonTracked = skeleton;
                trackingId = skeleton.TrackingID;
                ...
                first = false;
            }

            if (skeleton.TrackingID == trackingId)
            {
                ...
            }
        }
    }
Community
  • 1
  • 1
Liam McInroy
  • 4,339
  • 5
  • 32
  • 53
  • Thank you so Much..I have implemented your code, but now when i run the program i got the following error message. `Object reference not set to an instance of an object.` on `SFrame.CopySkeletonDataTo(skeletons);` Line. Image-> http://postimg.org/image/l3yu35b7h/ – Taha Kirmani Apr 04 '14 at 08:03
  • @TahaKirmani The variables should be global and defined at the top of your file. The rest of the code should be in the `AllFramesReady` event. – Liam McInroy Apr 04 '14 at 12:41