kinect SDK 2.0关节角度和跟踪 [英] kinect sdk 2.0 joint angles and tracking

查看:116
本文介绍了kinect SDK 2.0关节角度和跟踪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查所访问的关节是否具有跟踪状态为已跟踪".我发现关节的8个角度,但似乎无法在屏幕上显示结果,

How to check whether the joints you are accessing have a tracking state of Tracked. I am finding the angles of 8 of the joints and I can't seem to get the result to be displayed on my screen,

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到程序有实时提要,但是当按下按钮时,由于某种原因会抛出空指针异常.我想这是因为我不确定关节是否被追踪.我该怎么做呢?

There is live feed coming from the kinect to the program, but when the button is pressed, there is a null pointer exception thrown for some reason. I am thinking it is because i am not sure if the joints are tracked. How do I go about doing that?

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

Also is my code to display the angles correct? I am using textbox for each result.

推荐答案

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

这会循环遍历Joints数组并检查每个关节是否JointTrackingStateTrackedInferredNotTracked,请参见

This loops through the Joints array and checks for every Joint if the JointTrackingState is Tracked, Inferred or NotTracked, see here. The program to calculate the angles is perfectly fine.

如果您对如何计算关节角度还有其他疑问,请参见

If you have more questions on how to calculate the angle of Joints see here.

如果您想要一个有效的程序,我将通过电子邮件将其发送给您.或参见

If you want a working programm, I'll send it to you per e-mail. Or see here. Hope this helps :)

这篇关于kinect SDK 2.0关节角度和跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆