Coder Perfect

Kinect v2.0 Motion can be saved as a BVH file.


I’d like to save the Kinect 2 motion capture data as a BVH file. I found code for Kinect 1 that performs this, which you can find here. I went over the code and discovered a few things that I couldn’t figure out. For example, in the above-mentioned code, I tried to figure out what the Skeleton skel object, which appears in multiple places throughout the code, is. If not, is there any known application that may achieve the desired result?

EDIT: I tried changing Skeleton skeleton to Body skeleton, which I believe is the correct object for the Kinect SDK 2.0. When I try to get the location of the body, however, I receive the following error:

tempMotionVektor[0] = -Math.Round( skel.Position.X * 100,2);
tempMotionVektor[1] = Math.Round( skel.Position.Y * 100,2) + 120;
tempMotionVektor[2] = 300 - Math.Round( skel.Position.Z * 100,2);

When invoking the function Position for the Body skel, I get problems. In SDK 2.0, how do I get the skeleton’s X, Y, and Z? I attempted to alter the three lines above to:

tempMotionVektor[0] = -Math.Round(skel.Joints[0].Position.X * 100, 2);
tempMotionVektor[1] = Math.Round(skel.Joints[0].Position.Y * 100, 2) + 120;
tempMotionVektor[2] = 300 - Math.Round(skel.Joints[0].Position.Z * 100, 2);

EDIT: After merging bodyBasicsWPF and kinect2bvh, I was able to save a bvh file. However, the skeleton I’m storing appears to be inefficient. The elbows are moving in weird ways. I’m attempting to figure out if I need to make any changes to the kinectSkeletonBVH.cp file. More specifically, what are the changes in the joint axis orientation for the kinect 2 version. How can I change the following line: skel.BoneOrientations[JointType.ShoulderCenter]. AbsoluteRotation. Quaternion; I tried to change that line with skel. JointOrientations[JointType.ShoulderCenter].Orientation. Am I right? I am using the following code to add the joint to BVHBone objects:

BVHBone hipCenter = new BVHBone(null, JointType.SpineBase.ToString(), 6, TransAxis.None, true);
BVHBone hipCenter2 = new BVHBone(hipCenter, "HipCenter2", 3, TransAxis.Y, false);
BVHBone spine = new BVHBone(hipCenter2, JointType.SpineMid.ToString(), 3, TransAxis.Y, true);
BVHBone shoulderCenter = new BVHBone(spine, JointType.SpineShoulder.ToString(), 3, TransAxis.Y, true);

BVHBone collarLeft = new BVHBone(shoulderCenter, "CollarLeft", 3, TransAxis.X, false);
BVHBone shoulderLeft = new BVHBone(collarLeft, JointType.ShoulderLeft.ToString(), 3, TransAxis.X, true);
BVHBone elbowLeft = new BVHBone(shoulderLeft, JointType.ElbowLeft.ToString(), 3, TransAxis.X, true);
BVHBone wristLeft = new BVHBone(elbowLeft, JointType.WristLeft.ToString(), 3, TransAxis.X, true);
BVHBone handLeft = new BVHBone(wristLeft, JointType.HandLeft.ToString(), 0, TransAxis.X, true);

BVHBone neck = new BVHBone(shoulderCenter, "Neck", 3, TransAxis.Y, false);
BVHBone head = new BVHBone(neck, JointType.Head.ToString(), 3, TransAxis.Y, true);
BVHBone headtop = new BVHBone(head, "Headtop", 0, TransAxis.None, false);

I’m not sure where the axis for each Joint is calculated in the code.

Asked by Jose Ramon

Solution #1

By reading the Skeleton, the method you used to get a BVH file for Kinect 1.0 uses the joints information to construct bone vectors.

public static double[] getBoneVectorOutofJointPosition(BVHBone bvhBone, Skeleton skel)
    double[] boneVector = new double[3] { 0, 0, 0 };
    double[] boneVectorParent = new double[3] { 0, 0, 0 };
    string boneName = bvhBone.Name;

    JointType Joint;
    if (bvhBone.Root == true)
        boneVector = new double[3] { 0, 0, 0 };
        if (bvhBone.IsKinectJoint == true)
            Joint = KinectSkeletonBVH.String2JointType(boneName);

            boneVector[0] = skel.Joints[Joint].Position.X;
            boneVector[1] = skel.Joints[Joint].Position.Y;
            boneVector[2] = skel.Joints[Joint].Position.Z;

Nguyên Lê ng – Kinect2BVH.V2 source

Except in Kinect 2.0, the Skeleton class has been replaced by the Body class, therefore you’ll need to update it to deal with a Body and get the joints by following the steps below.


Answered by Khaled.K

Post is based on