2015-04-15 116 views
1

好吧,我對Kinect來說很新,我有關節跟蹤和繪製,但是我不能爲我的生活畫出每個關節之間的骨骼。Kinect V2 SDK 2.0基礎知識,繪製骨骼的骨骼?

我有這樣的代碼,將以此爲骨架的關節

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

任何幫助表示讚賞感謝

回答

0

在你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); 
} 

我從記憶這裏,所以語法可能會關閉一點點工作。

+0

噢,對了,謝謝你,但我決定放棄這種方法,並使用Kinect附帶的示例中的代碼。我最終弄明白了,你是否設法弄清楚爲什麼座標圖不能用於我的另一個問題? – ShatteredPheonix