我如何知道第一个跟踪的骨架

我如何知道第一个跟踪的骨架

本文介绍了Kinect:我如何知道第一个跟踪的骨架,做后面的东西的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何可以i ID第一骨架kinect跟踪,然后做它的东西。我只对第一个骨骼感兴趣,后来我不需要他们。优选地,进入的下一个骨架根本不被跟踪。

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.

有人可以帮我这个谢谢。目前下面的代码使用不工作。我试过一些快速linq查询,但我不是很确定如何使用它。总是有错误。

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

    }


推荐答案

您可以使用这段程式码只追踪一个骨架:

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)
            {
                ...
            }
        }

        ...
    }
}

检测到,如果它的跟踪ID等于检测到的第一个,则您使用它执行操作,否则您不对稍后检测的其他骨架执行操作。但是,我会看到,因为它有其他方法检测骨骼与独立ids / indexes。 ID的方法是伟大的区分多个玩家,但他们变化很大的每个骨架。索引保存的时间很短,所以你可以有一些代码来检测骨架是否离开框架。

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.

这篇关于Kinect:我如何知道第一个跟踪的骨架,做后面的东西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-27 20:52