0

How can i ID the first skeleton the kinect tracked and then do stuff with it. Im only interested in the first skeleton and whichever comes after i do not need them. Preferably the next skeleton that comes in is not tracked at all.

Can someone help me with this thanks. Currently the code below im using does not work. I have tried some quick linq query but im not very sure how to use it. Always having errors with it.

Can someone give me some examples i can work with thanks in advance!!

private void SensorSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
    {

            Skeleton[] skeletons = new Skeleton[0];


            using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
            {
                if (skeletonFrame != null)
                {
                    skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength];
                    skeletonFrame.CopySkeletonDataTo(skeletons);
                }
            }

            using (DrawingContext dc = this.drawingGroup.Open())
            {
                // Draw a transparent background to set the render size
                dc.DrawRectangle(Brushes.Black, null, new Rect(160, 0.0, RenderWidth, RenderHeight));

                if (skeletons.Length != 0)
                {


                   foreach (Skeleton skel in skeletons)
                    {
                        RenderClippedEdges(skel, dc);


                        if (skel.TrackingState == SkeletonTrackingState.Tracked)
                        {
                            this.TrackingId = Skel;
                            sensor.SkeletonStream.AppChoosesSkeletons = true;
                            sensor.SkeletonStream.ChooseSkeletons(skel.TrackingId);

                            this.DrawBonesAndJoints(skel, dc);

                            if (skel == null)
                            {

                                Process.Start("wmplayer.exe", "C:\\Users\\User\\Downloads\\Test.wma");
                            }
                        }
                        else if (skel.TrackingState == SkeletonTrackingState.NotTracked)
                        {
                            sensor.SkeletonStream.AppChoosesSkeletons = false;
                        }
                    }
                }

                // prevent drawing outside of our render area
                this.drawingGroup.ClipGeometry = new RectangleGeometry(new Rect(160, 0.0, RenderWidth, RenderHeight));
            }

    }
Hannes Ovrén
  • 21,229
  • 9
  • 65
  • 75
Azl
  • 5
  • 1
  • 5

2 Answers2

3

Kinect track player and set ID in diffrent index of Skeletons array (length == 6) every time when it detects the new one. That's why is necessary to save Player's ID when number of index with tracking id equal zero is 5.

    int skeletonId = 0;
    int trackId = 0;


    void myKinect_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
    {
        Skeleton[] skeletons = null;

        using (SkeletonFrame frame = e.OpenSkeletonFrame())
        {
            if (frame != null)
            {
                skeletons = new Skeleton[frame.SkeletonArrayLength];
                frame.CopySkeletonDataTo(skeletons);
            }
        }

        if (skeletons == null) return;

        //variable for count of null ID
        int skeletonsNull = 0;
        //counting...
        foreach (Skeleton skeletonText in skeletons)
        {
            if (skeletonText.TrackingId == 0)
            {
                skeletonsNull++;
            }
            else
            {
                skeletonId = skeletonText.TrackingId;
            }
        }


        if (skeletonsNull == 5)
        {
            trackId = skeletonId;
        }


        foreach (Skeleton skeleton in skeletons)
        {
            if (skeleton.TrackingId == trackId)
            {
             //do something   
            }
torcylius
  • 91
  • 1
  • 8
1

You can track only one skeleton with this piece of code:

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;
    }

    using (DrawingContext dc = this.drawingGroup.Open())
    {
            // Draw a transparent background to set the render size
        dc.DrawRectangle(Brushes.Black, null, new Rect(160, 0.0, RenderWidth, RenderHeight));

        RenderClippedEdges(skel, dc);            

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

            if (skeleton.TrackingID == trackingId)
            {
                ...
            }
        }

        ...
    }
}

This code finds the first skeleton detected, if it's tracking ID is equal to the first one detected, then you perform operations with it, otherwise you don't perform operations on other skeletons that are detected later. However, I would see Kinect user Detection as it has other methods of detecting skeletons with seperate ids/indexes. The method of IDs is great for distinguishing between multiple players, but they change largely for every skeleton. The indexes are saved for a short time so you could have some code for detecting that the skeleton left the frame.

Community
  • 1
  • 1
Liam McInroy
  • 4,339
  • 5
  • 32
  • 53
  • Thanks for your reply Lemur. I can understand your example but is there anyway i can draw the skeleton of the first tracked skeleton out? Like this.DrawBonesAndJoints(First, dc); – Azl Feb 26 '14 at 14:52
  • @user3032405 Yes this will do this, as it will only detect one skeleton at a time – Liam McInroy Feb 27 '14 at 00:33