0
如何檢查您正在訪問的關節是否有被跟蹤的跟蹤狀態。我發現關節的8角,我似乎無法得到的結果顯示我的屏幕上,kinect sdk 2.0關節角度和跟蹤
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的來到節目現場的飼料,但是當按鈕被按下,出於某種原因拋出空指針異常。我想這是因爲我不確定關節是否被跟蹤。我該如何去做呢?
也是我的代碼顯示角度正確嗎?我爲每個結果使用了文本框。
哪一行給出空指針。如果我們有堆棧跟蹤會很好.. –