【问题标题】:Kinect V2 SDK 2.0 Basics, Drawing the bones of the skeleton?Kinect V2 SDK 2.0 基础,绘制骨骼骨骼?
【发布时间】:2015-04-15 16:33:49
【问题描述】:

好的,我对 Kinect 很陌生,我已经跟踪和绘制了关节,但是我一辈子都无法绘制每个关节之间的骨骼。

我有这段代码可以绘制骨骼的关节

 private void DrawBody(Body body) //takes body as argument
    {
        // Draw points
        foreach (JointType type in body.Joints.Keys)
        {
            // Draw all the body joints
            switch (type)
            {
                case JointType.Head:
                case JointType.FootLeft:
                case JointType.FootRight:
                    DrawJoint(body.Joints[type], 20, Brushes.Yellow, 2, Brushes.White);
                    break;
                case JointType.ShoulderLeft:
                case JointType.ShoulderRight:
                case JointType.HipLeft:
                case JointType.HipRight:
                     DrawJoint(body.Joints[type], 20, Brushes.YellowGreen, 2, Brushes.White);
                    break;
                case JointType.ElbowLeft:
                case JointType.ElbowRight:
                case JointType.KneeLeft:
                case JointType.KneeRight:
                    DrawJoint(body.Joints[type], 15, Brushes.LawnGreen, 2, Brushes.White);
                    break;
                case JointType.HandLeft:
                    DrawHandJoint(body.Joints[type], body.HandLeftState, 20, 2, Brushes.White);
                    break;
                case JointType.HandRight:
                    DrawHandJoint(body.Joints[type], body.HandRightState, 20, 2, Brushes.White);
                    break;
                default:
                    DrawJoint(body.Joints[type], 15, Brushes.RoyalBlue, 2, Brushes.White);
                    break;
            }                

        }         
    }

我的 DrawJoint 函数:

   private void DrawJoint(Joint joint, double radius, SolidColorBrush fill, double borderWidth, SolidColorBrush border)
    {
        //If Joint not tracked  then return Joint
        if (joint.TrackingState != TrackingState.Tracked) return;

        // Map the CameraPoint to ColorSpace so they match
        ColorSpacePoint colorPoint = kinectSensor.CoordinateMapper.MapCameraPointToColorSpace(joint.Position);

        // Create the UI element based on the parameters
        Ellipse El = new Ellipse();
        El.Fill = fill;
        El.Stroke = border;
        El.StrokeThickness = borderWidth;
        El.Width = 25;
        El.Height = 25;
        radius = 25;

        // Add the Ellipse to the canvas
        SkeletonCanvas.Children.Add(El);

        // Avoid exceptions based on bad tracking
        if (float.IsInfinity(colorPoint.X) || float.IsInfinity(colorPoint.X)) return;

        // Allign ellipse on canvas
        Canvas.SetLeft(El, colorPoint.X);
        Canvas.SetTop(El, colorPoint.Y);

    }

现在我被卡住了,从这一点开始,我将如何在画布上的每个关节之间绘制身体的“骨骼”,类似于我如何为关节添加 Eclipse?。

感谢任何帮助

【问题讨论】:

    标签: c# wpf xaml kinect


    【解决方案1】:

    在DrawBody(Body body) 函数中,您需要设置要绘制的“骨骼”。例如:

    private void DrawBody(Body body)
    {
        // left forearm
        DrawBone(body.Joints[JointType.HandLeft], body.Joints[JointType.ElbowLeft]);
        // right forearm
        DrawBone(body.Joints[JointType.HandRight], body.Joints[JointType.ElbowRight]);
        // ...etc...
    
    }
    

    DrawBone(Joint, Joint) 函数看起来像这样:

    private void DrawBone(Joint first, Joint second)
    {
        Line line = new Line();
        line.Stroke = Brushes.LightSteelBlue;
    
        line.X1 = first.Position.X;
        line.X2 = second.Position.X;
        line.Y1 = first.Position.Y;
        line.Y2 = second.Position.Y;
    
        line.StrokeThickness = 2;
        myCanvas.Children.Add(line);
    }
    

    我在这里根据记忆工作,所以语法可能有点不对。

    【讨论】:

    • 哦,对了,谢谢,但我决定放弃这种方法并使用 Kinect 附带的示例中的编码。我最后想通了,您是否设法弄清楚为什么映射的坐标在我的另一个问题上不起作用?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-05
    相关资源
    最近更新 更多