如何从Kinect一次检测1个骨架?

时间:2014-04-02 05:36:25

标签: c# visual-studio-2010 visual-studio kinect kinect-sdk

我正在使用Kinect创建一个应用程序,我想一次只跟踪一个人,现在Kinect开始检测另一个人,如果他进入Kinect范围内。我编写了以下代码,它可以检测到Kinect范围内的任何人。请告诉我如何限制它一次只检测一个人。

        /*------------------------------------------
         * 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];

1 个答案:

答案 0 :(得分:1)

我会在另一个问题上看到this answer

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