kinect sdk 2.0关节角度和跟踪

如何检查您正在访问的关节是否具有Tracked跟踪状态。 我找到8个关节的角度,我似乎无法将结果显示在我的屏幕上,

public double AngleBetweenTwoVectors(Vector3D vectorA, Vector3D vectorB) { double dotProduct = 0.0; vectorA.Normalize(); vectorB.Normalize(); dotProduct = Vector3D.DotProduct(vectorA, vectorB); return (double)Math.Acos(dotProduct) / Math.PI * 180; } public double[] GetVector(Body skeleton) { Vector3D Shoulder = new Vector3D(skeleton.Joints[JointType.SpineShoulder].Position.X, skeleton.Joints[JointType.SpineShoulder].Position.Y, skeleton.Joints[JointType.SpineShoulder].Position.Z); Vector3D RShoulder = new Vector3D(skeleton.Joints[JointType.ShoulderRight].Position.X, skeleton.Joints[JointType.ShoulderRight].Position.Y, skeleton.Joints[JointType.ShoulderRight].Position.Z); Vector3D LShoulder = new Vector3D(skeleton.Joints[JointType.ShoulderLeft].Position.X, skeleton.Joints[JointType.ShoulderLeft].Position.Y, skeleton.Joints[JointType.ShoulderLeft].Position.Z); Vector3D RElbow = new Vector3D(skeleton.Joints[JointType.ElbowRight].Position.X, skeleton.Joints[JointType.ElbowRight].Position.Y, skeleton.Joints[JointType.ElbowRight].Position.Z); Vector3D LElbow = new Vector3D(skeleton.Joints[JointType.ElbowLeft].Position.X, skeleton.Joints[JointType.ElbowLeft].Position.Y, skeleton.Joints[JointType.ElbowLeft].Position.Z); Vector3D RWrist = new Vector3D(skeleton.Joints[JointType.WristRight].Position.X, skeleton.Joints[JointType.WristRight].Position.Y, skeleton.Joints[JointType.WristRight].Position.Z); Vector3D LWrist = new Vector3D(skeleton.Joints[JointType.WristLeft].Position.X, skeleton.Joints[JointType.WristLeft].Position.Y, skeleton.Joints[JointType.WristLeft].Position.Z); Vector3D RKnee = new Vector3D(skeleton.Joints[JointType.KneeRight].Position.X, skeleton.Joints[JointType.KneeRight].Position.Y, skeleton.Joints[JointType.KneeRight].Position.Z); Vector3D LKnee = new Vector3D(skeleton.Joints[JointType.KneeLeft].Position.X, skeleton.Joints[JointType.KneeLeft].Position.Y, skeleton.Joints[JointType.KneeLeft].Position.Z); Vector3D RAnkle = new Vector3D(skeleton.Joints[JointType.AnkleRight].Position.X, skeleton.Joints[JointType.AnkleRight].Position.Y, skeleton.Joints[JointType.AnkleRight].Position.Z); Vector3D LAnkle = new Vector3D(skeleton.Joints[JointType.AnkleLeft].Position.X, skeleton.Joints[JointType.AnkleLeft].Position.Y, skeleton.Joints[JointType.AnkleLeft].Position.Z); Vector3D Hip = new Vector3D(skeleton.Joints[JointType.SpineBase].Position.X, skeleton.Joints[JointType.SpineBase].Position.Y, skeleton.Joints[JointType.SpineBase].Position.Z); Vector3D RHip = new Vector3D(skeleton.Joints[JointType.HipRight].Position.X, skeleton.Joints[JointType.HipRight].Position.Y, skeleton.Joints[JointType.HipRight].Position.Z); Vector3D LHip = new Vector3D(skeleton.Joints[JointType.HipLeft].Position.X, skeleton.Joints[JointType.HipLeft].Position.Y, skeleton.Joints[JointType.HipLeft].Position.Z); double AngleRElbow = AngleBetweenTwoVectors(RElbow - RShoulder, RElbow - RWrist); double AngleRShoulder = AngleBetweenTwoVectors(RShoulder - Shoulder, RShoulder - RElbow); double AngleLElbow = AngleBetweenTwoVectors(LElbow - LShoulder, LElbow - LWrist); double AngleLShoulder = AngleBetweenTwoVectors(LShoulder - Shoulder, LShoulder - LElbow); double AngleRKnee = AngleBetweenTwoVectors(RKnee - RHip, RKnee - RAnkle); double AngleLKnee = AngleBetweenTwoVectors(LKnee - LHip, LKnee - LAnkle); double AngleRHip = AngleBetweenTwoVectors(RHip - Hip, RHip - RKnee); double AngleLHip = AngleBetweenTwoVectors(LHip - Hip, LHip - LKnee); Results.Add(AngleLShoulder); Results.Add(AngleLElbow); Results.Add(AngleLKnee); Results.Add(AngleLHip); Results.Add(AngleRShoulder); Results.Add(AngleRElbow); Results.Add(AngleRKnee); Results.Add(AngleRHip); double[] resultsArray = Results.ToArray(); return resultsArray; } private void Button_Click(object sender, RoutedEventArgs e) { result1.Text = Results[4].ToString(); result2.Text = Results[5].ToString(); result3.Text = Results[6].ToString(); result4.Text = Results[7].ToString(); result5.Text = Results[0].ToString(); result6.Text = Results[1].ToString(); result7.Text = Results[2].ToString(); result8.Text = Results[3].ToString(); } 

有从kinect到程序的实时馈送,但是当按下按钮时,由于某种原因抛出了空指针exception。 我在想这是因为我不确定是否跟踪了关节。 我该怎么做呢?

我的代码也显示正确的角度? 我为每个结果使用文本框。

 foreach (Joint joint in skeleton.Joints) { if (joint.TrackingState == JointTrackingState.Tracked) { //Do something } else if (joint.TrackingState == JointTrackingState.Inferred) { //Do something else } } 

如果JointTrackingStateTrackedInferredNotTracked ,则循环遍历Joints数组并检查每个Joint,请参见此处 。 计算角度的程序非常好。

如果您对如何计算关节角度有更多疑问,请参见此处

如果你想要一个有效的程序,我会通过电子邮件发送给你。 或者看这里 。 希望这可以帮助 :)