我无法显示我跟踪的骨架 [英] I cant display my tracked skeleton

查看:70
本文介绍了我无法显示我跟踪的骨架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是代码。基本上,当我运行应用程序时,它会跟踪kinect前面的骨架并且代码可以工作,但是当我添加"this.DrawBonesAndJoints(skeleton,dc);"时,程序中断和错误显示在:

 联合joint0 = skeleton.Joints [jointType0];

 联合joint1 = skeleton.Joints [jointType1];

Below is the code. Basically when i run the application it does track the skeleton that is infront of the kinect and the code works, but when i add in "this.DrawBonesAndJoints(skeleton, dc);" the program breaks and error indicated at:
 Joint joint0 = skeleton.Joints[jointType0];
 Joint joint1 = skeleton.Joints[jointType1];

private int CurrentTrackingId = 0;
private Skeleton[] skeletons = new Skeleton[0];

Skeleton FindSkeleton(SkeletonFrameReadyEventArgs e)
{
    Skeleton skeleton = null;

    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 (CurrentTrackingId != 0)
            {
                // Tracked someone
                skeleton =
                    (from s in skeletons
                     where s.TrackingState == SkeletonTrackingState.Tracked &&
                           s.Joints[JointType.Head].TrackingState == JointTrackingState.Tracked &&
                           s.TrackingId == CurrentTrackingId
                     select s).FirstOrDefault();
                
                    this.DrawBonesAndJoints(skeleton, dc);

                    PatientTextblock.Text = "Patient on Bed";
                    StatusTextblock.Background = new SolidColorBrush(Colors.White);
                    StatusTextblock.Foreground = new SolidColorBrush(Colors.Black);
//
                    if (skeleton == null)
                {
                    // Patient is gone!
                    PatientTextblock.Text = "PATIENT LEAVING BED!";
                    StatusTextblock.Background = new SolidColorBrush(Colors.White);
                    StatusTextblock.Foreground = new SolidColorBrush(Colors.Black);
                    Process.Start("wmplayer.exe", "C:\\Users\\User\\Downloads\\PatientLeavingBed.wma");
                    CurrentTrackingId = 0;
                    sensor.SkeletonStream.AppChoosesSkeletons = false;
                }
            }
            else
            {
                // Try to find someone new

                skeleton =
                    (from s in skeletons
                     where s.TrackingState == SkeletonTrackingState.Tracked &&
                           s.Joints[JointType.Head].TrackingState == JointTrackingState.Tracked
                     select s).FirstOrDefault();

                if (skeleton != null)
                {
                    // Found one; start tracking them

                    CurrentTrackingId = skeleton.TrackingId;
                    sensor.SkeletonStream.AppChoosesSkeletons = true;
                    sensor.SkeletonStream.ChooseSkeletons(CurrentTrackingId);
                }
            }
            // prevent drawing outside of our render area
            this.drawingGroup.ClipGeometry = new RectangleGeometry(new Rect(160, 0.0, RenderWidth, RenderHeight));
        }
    }

    return skeleton;
}

我的代码有问题吗?我只需要显示kinect跟踪的第一个跟踪骨架。我不想跟踪第一个跟踪骨架后的骨架的其余部分。

Is there any problem with my code? I just need to display the first tracked skeleton the kinect tracked. I do not want to track the rest of the skeleton that comes after the first tracked skeleton.

谢谢!

Zong Li

推荐答案

李,

错误信息是什么?

James


这篇关于我无法显示我跟踪的骨架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆