Kinect to Coordinate Mapping with help from Vitruvius
The one and only Vangos Pterneas is back (I'm telling you, he makes this job easy for me ;) with a new project, one that I see asked about all the time... Coordinate Mapping
A few months ago, I had published a detailed guide about converting between Kinect’s 3D and 2D coordinates. Today, I’m going to show you how to accomplish Coordinate Mapping with minimum effort and only one line of C# code!
Kinect understands the 3D space using an infrared sensor and a depth processor. The depth processor can measure the distance between the physical points and the device. Kinect SDK uses a structure named CameraSpacePoint to represent a point in the physical 3D space. A CameraSpacePoint is a set of three properties [X, Y, Z]. X is the distance in the horizontal axis, Y is the distance in the vertical axis, and Z is the distance (depth) between the point and the plane of the sensor.
The values are measured in meters. So, the CameraSpacePoint [1.5, 2.0, 4.7] is located 1.5 meters from the left, 2.0 meters from the top, and 4.7 meters from the sensor.
1 meter = 3.28 feet
1 meter = 39.37 inches
This concept is illustrated in the figure below:
However, when we develop a Kinect app, we use computer monitors. Somehow, we have to project the 3D points on the 2D screen space. There are 2 screen-spaces:
- Color Space: 1920×1080 pixels
- Depth/Infrared Space: 512×424 pixels
Obviously, points in the 2D space only have X and Y values, measured in pixels.
So, we have to convert meters to pixels! How’s that possible? I have thoroughly explained this process in my blog post Understanding Kinect Coordinate Mapping.
Coordinate Mapping is the native process of converting between the 3D and the 2D space.
Using Vitruvius, Coordinate Mapping is as simple as typing one line of C# code. Let’s have a look at an example:
var position = body.Joints[JointType.Head].Position;
This is how we find the position of the Head joint using the official Microsoft SDK. The point3D variable is a [X, Y, Z] combination. It indicates where the head of the person is located.
Projecting the 3D point to the 2D space is accomplished using Vitruvius’ ToPoint method. That method takes a Visualization enumeration as a parameter. To use the ToPoint method, you first need to import Vitruvius in your project:
2D Color Space (1920×1080)
This is how to convert the 3D point to a 2D point in the 1920×1080 Color Space:
2D Depth Space (512×424)
Similarly, you can convert the 3D point to a 2D point in the 512×424 Depth Space:
Using a different Coordinate Mapper
In case you are using multiple Kinect sensors, you can still work with Vitruvius! You simply have to specify which sensor the method should use:
You can access it by downloading Vitruvius.
‘Till the next time, keep Kinecting!
Project Information URL: http://pterneas.com/2016/06/23/kinect-coordinate-mapping-vitruvius/
Project Download URL: http://vitruviuskinect.com/
This conversation has been locked by the site admins. No new comments can be made.