简体   繁体   English

Kinect V2 SDK 2.0基础知识,绘制骨骼的骨骼?

[英]Kinect V2 SDK 2.0 Basics, Drawing the bones of the skeleton?

Okay, I am pretty new to Kinect, I have the joints tracked and drawn however I cannot for the life of me draw the bones between each joint. 好的,我对Kinect还是很陌生,我已经跟踪并绘制了关节,但是我一生都无法在每个关节之间绘制骨骼。

I have this code which will draw the joints of the skeleton 我有这段代码将绘制骨骼的关节

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

        }         
    }

My DrawJoint Function: 我的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);

    }

Now I am stuck, from this point onwards how would I draw the 'Bones' of the body between each joint on a canvas similiar to how I added the Eclipse for the Joints?. 现在我被困住了,从现在开始,我将如何在画布上绘制每个关节之间的“骨骼”,就像如何为关节添加Eclipse?

Any help is appreciated thanks 任何帮助表示赞赏,谢谢

In your DrawBody(Body body) function, you'll need to set up the "bones" that you want to draw. DrawBody(Body body)函数中,您需要设置要绘制的“骨骼”。 Eg: 例如:

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...

}

The DrawBone(Joint, Joint) function would look something like this: 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);
}

I'm working from memory here so syntax might be off a little. 我在这里从内存中工作,因此语法可能会有点偏离。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM