A lot of Kinect developers need to create apps that calculate a lot of complex human body measurements. Today I’ll show you how to use Vitruvius to measure angles in the 3D and 2D space.
This is what you’ll be able to do after reading the following tutorial:
What is an angle?
An angle is a combination of two lines. To measure an angle, all you need is 3 points in the 3D or 2D space: a starting point, a middle point, and an end point.
The official Kinect SDK includes the following built-in types of points, so, first, let me give you some background information:
A CameraSpacePoint is a set of coordinates in the 3D space. It has X, Y, and Z values, all measured in meters. The X value represents the horizontal distance of the point, measured from the left side of the field-of-view. The Y value represents the vertical distance of the point, measured from the top of the field-of-view. The Z value represents the distance between the point and the sensor plane. The CameraSpacePoint is the only Kinect point that gives us information about the 3D world.
A ColorSpacePoint is a set of coordinates in the 2D Color space. The Color space is a 1920×1080 frame. A ColorSpacePoint only has two coordinates: the X coordinate defines the distance from the left edge of the frame, and the Y coordinate defines the distance from the top of the frame.
A DepthSpacePoint is, again, a set of coordinates in the 2D Depth space. The Depth space is a 512×424 frame. A depth point has X and Y values, just like the color points. The Depth space is equivalent to the Infrared space, so you can use the same type of points for both.
What about the joints?
You already know that Kinect’s power is the ability to calculate the positions of 25 human body joints. A Joint is a structure that includes:
- The position in the 3D space
- The type/name of the joint
- The tracking accuracy
The position of a joint in the 3D space is expressed as a CameraSpacePoint. To properly map the 3D-position into the 2D-position, you need to use Coordinate Mapping.
Measuring an angle with Vitruvius
Vitruvius contains some handy extension methods that will help you measure an angle using CameraSpacePoints, ColorSpacePoints, or DepthSpacePoints. First, you need to include the proper namespace in your C# file:
We assume that you already know how to get a Body object from a BodyFrame. Let’s say that you want to measure the angle on your elbow. This angle is formed by 3 joints — the shoulder, the elbow, and the wrist:
Joint shoulder = body.Joints[JointType.ShoulderLeft]; Joint elbow = body.Joints[JointType.ElbowLeft]; Joint wrist = body.Joints[JointType.WristLeft];
The middle point of the angle is, of course, the elbow. The starting point of the angle is the shoulder. The end point of the angle is the wrist. So, here you are:
double angle = elbow.Angle(shoulder, wrist);
The Angle method is an extension method, included in Vitruvius. This way, you can calculate any angle for any human body joint!
The above code is equivalent to the following:
double angle = elbow.Position.Angle(shoulder.Position, wrist.Position);
Need to measure the same angle in the Color or Depth space? No problem! Vitruvius includes another handy extension method, called ToPoint. Here’s how you can use it:
var shoulderColor = shoulder.ToPoint(Viualization.Color); var elbowColor = elbow.ToPoint(Viualization.Color); var wristColor = wrist.ToPoint(Viualization.Color); double angle = elbowColor.Angle(shoulderColor, wristColor);
Similarly, you can calculate the angle in the Depth/Infrared space:
var shoulderDepth = shoulder.ToPoint(Viualization.Depth); var elbowDepth = elbow.ToPoint(Viualization.Depth); var wristDepth = wrist.ToPoint(Viualization.Depth); double angle = elbowColor.Angle(shoulderColor, wristColor);
Same principles apply to HD Face points, too!
CameraSpacePoint nose = face.Nose; CameraSpacePoint cheekLeft = face.CheekLeft; CameraSpacePoint cheekRight = face.CheekRight; double angle = nose.Angle(cheekLeft, cheekRight);
Note: the sample projects included with Vitruvius also contain a handy Arc control. Using the Arc control, you can visualize the angle on top of a body very easily.
Why do you need this?
Except the obvious reason (measuring an angle), such Mathematical calculations are extremely helpful when you need to compare the relative positions between a few points. Gesture detection, sign language identification, or even facial expressions!
The above code (including angle measurements and Arc controls) is supported in the following platforms, frameworks, and engines:
- Windows Presentation Foundation (.NET 4.5+)
- Windows Store (WinRT)
As you see, Vitruvius is helping innovative companies create Kinect apps fast. Vitruvius simplifies Kinect development, so you can now focus on what’s really important: your app, your research, and your customers.