Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kinect: Convert Joint.Position.Z in millimeters

I know how to convert in pixels the value obtained from Joint.Position.X and Joint.Position.Y. There is an example in which I do it:

void kinectSensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
    {
        using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
        {
            if (skeletonFrame != null)
            {
                Skeleton[] skeletonData = new Skeleton[skeletonFrame.SkeletonArrayLength]; //conterrà tutti gli skeleton

                skeletonFrame.CopySkeletonDataTo(skeletonData);

                Skeleton playerSkeleton = (from s in skeletonData where s.TrackingState == SkeletonTrackingState.Tracked select s).FirstOrDefault();

                if (playerSkeleton != null)
                {
                    Joint rightHand = playerSkeleton.Joints[JointType.HandRight];
                    Joint leftHand = playerSkeleton.Joints[JointType.HandLeft];

                    //EDIT: The following formulas used to convert X and Y coordinates in pixels are wrong.
                    //Please, see the answer for details
                    rightHandPosition = new float[] { (((0.5f * rightHand.Position.X) + 0.5f) * (640)), (((-0.5f * rightHand.Position.Y) + 0.5f) * (480)) };
                    leftHandPosition = new float[] { (((0.5f * leftHand.Position.X) + 0.5f) * (640)), (((-0.5f * leftHand.Position.Y) + 0.5f) * (480)), leftHand.Position.Z };
                }
             }
         }
    }

Now, what I want to do is obtain the real depth (in millimeters) using Joint.Depth.Z. Referring to the previous example, I want to obtain two 3D arrays for rightHandPosition and leftHandPosition, with the the last coordinate that represents the depth. What is the right formula in order to transform the value returned from rightHand.Position.Z and leftHand.Position.Z in the corresponding value in millimeters?

EDIT: The formulas used to transform X and Y coordinates in pixels in the code above are wrong. Please, read the following answer by me.

like image 456
Vito Gentile Avatar asked Feb 18 '23 04:02

Vito Gentile


1 Answers

I have realized that Joint.Position.X and Joint.Position.Y are not limited between -1 and 1. This wrong information is quite diffused on internet, and this is the reason why I'm replying to myself.

As Evil Closet Monkey has mentioned, in the comments above, the official documentation says that "skeleton space coordinates are expressed in meters". It's also confirmed by a member of the Kinect for Windows Team in this post.

It means that in order to convert X, Y and Z coordinates, obtained with Joint.Position.X, Joint.Position.Y and Joint.Position.Z, in millimeters, you simply have to divide these values by 1000 (or you can also work in meters, with no conversions needed).

like image 130
Vito Gentile Avatar answered Feb 27 '23 15:02

Vito Gentile