Kinect:我如何识别第一个跟踪的骨架并在之后用它做些什么

时间:2023-03-29
本文介绍了Kinect:我如何识别第一个跟踪的骨架并在之后用它做些什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我如何识别 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 等于检测到的第一个骨架,则对它执行操作,否则您不对稍后检测到的其他骨架执行操作.但是,我会看到 Kinect 用户检测,因为它具有其他单独检测骨架的方法ID/索引.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:我如何识别第一个跟踪的骨架并在之后用它做些什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:通过 OpenCV 的 camshift 算法控制鼠标指针(或鼠标的基本功能) 下一篇:将二进制字符串表示形式转换为字节数组

相关文章