To recognize the skeleton is to obtain the joint positions of a human. The joint type is "Joint", which is defined in Kinect for Windows SDK 2.0 as follows.
Data concerning joint is represented by "Joint" type. "Joint" type is a struct containing 3 member variables.
Quoted from Kinect.h of Kinect for Windows SDK 2.0 |
---|
enum _JointType { JointType_SpineBase= 0, JointType_SpineMid= 1, JointType_Neck= 2, JointType_Head= 3, JointType_ShoulderLeft= 4, JointType_ElbowLeft= 5, JointType_WristLeft= 6, JointType_HandLeft= 7, JointType_ShoulderRight= 8, JointType_ElbowRight= 9, JointType_WristRight= 10, JointType_HandRight= 11, JointType_HipLeft= 12, JointType_KneeLeft= 13, JointType_AnkleLeft= 14, JointType_FootLeft= 15, JointType_HipRight= 16, JointType_KneeRight= 17, JointType_AnkleRight= 18, JointType_FootRight= 19, JointType_SpineShoulder= 20, JointType_HandTipLeft= 21, JointType_ThumbLeft= 22, JointType_HandTipRight= 23, JointType_ThumbRight= 24, JointType_Count= ( JointType_ThumbRight + 1 ) }; enum _TrackingState { TrackingState_NotTracked= 0, TrackingState_Inferred= 1, TrackingState_Tracked= 2 }; typedef struct _Joint { JointType JointType; CameraSpacePoint Position; TrackingState TrackingState; } Joint; |
type of return value | function name | descriptions | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
void | setSkeleton() | Recognize skeleton and set the data to the following member variables.
|
type | variable name | descriptions |
---|---|---|
vector<vector<Joint>> | skeleton | Vector of skeleton information. The set of a human joints is vector<Joint> , and this is the skeleton information. In order to handle multiple people, it is a vector of skeleton information, that is, vector<vector<Joint>> . The coordinates of the joint are positions in the CameraSpace coordinate system.
skelton[index ][jointType ].JointType == jointType holds, you can directly access the information of a specified joint of a specified skeleton. |
vector<int> | skeletonId | A vector of bodyIndex corresponding to the skeletons. The bodyIndex of skeleton[index ] is held at skeletonId[index ]. |
vector<UINT64> | skeletonTrackingId | A vector of trackingId corresponding to the skeletons. The trackingId fo skeleton[index ] is held at skeletonTrackingId[index ]. |
Since the position and resolution of each sensor is different, the data is obtained as a value expressed in the coordinate system of each sensor. When using data obtained from different sensors at the same time, it is necessary to convert the coordinates to match.
Kinect V2 has 3 coordinate systems, ColorSpace, DepthSpace, and CameraSpace. There are 3 data types ColorSpacePoint, DepthSpacePoint, and CameraSpacePoint representing coordinates in each coordinate system.
Quoted from Kinect.h of Kinect for Windows SDK 2.0 |
---|
typedef struct _ColorSpacePoint { float X; float Y; } ColorSpacePoint; typedef struct _DepthSpacePoint { float X; float Y; } DepthSpacePoint; typedef struct _CameraSpacePoint { float X; float Y; float Z; } CameraSpacePoint; |
For the RGB image, Depth image, and skeleton information, the coordinate system is different. The coordinate system of the RGB image is ColorSpace, that of the Depth image is DepthSpace, and that of the skeleton information is CameraSpace.
Coordinate system | type of coordinates | Captured Data |
---|---|---|
ColorSpace | ColorSpacePoint | RGB image |
DepthSpace | DepthSpacePoint | depth image, bodyIndex image, infrared image |
CameraSpace | CameraSpacePoint | skeleton information |
CameraSpace coordinate system representing skeleton position |
---|
The CameraSpace is a 3-dimensional coordinate system with the following features.
(2016/11/12 figure changed, and description added). |
"Coordinate system conversion function" held by ICoordinateMapper class of Kinect V2 is as follows.
type of return value | function name | descriptions |
---|---|---|
HRESULT | MapCameraPointToColorSpace( CameraSpacePoint sp , ColorSpacePoint *cp ) |
Convert the coordinates sp in the CameraSpace to the coordinates cp in the ColorSpace. Return value is S_OK or error code. |
HRESULT | MapCameraPointToDepthSpace( CameraSpacePoint sp , DelpthSpacePoint *dp ) |
Convert the coordinates sp in the CameraSpace to the coordinates dp in DepthSpace. Return value is S_OK or error code. |
HRESULT | MapDepthPointToColorSpace( DepthSpacePoint dp , UINT16 depth , ColorSpacePoint *cp ) |
Convert the coordinates dp in DepthSpace and distance depth to the coordinates cp in ColorSpace. Return value is S_OK or error code. |
HRESULT | MapDepthPointToCameraSpace( DepthSpacePoint dp , UINT16 depth , CameraSpacePoint *sp ) |
Convert the coordinates dp in DepthSpace and distance depth to the coordinates sp in CameraSpace. Return value is S_OK or error code. |
An instance of ICoordinateMapper class used for mapping coordinate systems in Kinect V2 is held in NtKinect's member variable "coordinateMapper".
type | variable name | descriptions |
---|---|---|
CComPtr<ICoordinateMapper> | coordinateMapper | An instance of ICoordinateMapper used for mapping coordinate systems. |
Call kinect.setSkeleton() function to get skeleton information to kinect.skeleton. Since the joint positions are expressed in the CameraSpace coordinate system, we convert them to the coordinates of ColorSpace and draw rectangles on the RGB image. (in the green letter part)。
Since Joint type data has meaning only when the value of its "TrackingState" member variable is "TrackingState_Tracked" or "TrackingState_Inferred", if it is "TrackingState_NotTracked" , drawing rectangle for that joint is skipped.
main.cpp |
|
On the RGB image, the recognized joints are indicated by small red rectangles. Note that it is usual to express colors in BGR order in OpenCV, so cv::Scalar(0,0,255) means (blue, green, red) = (0, 0, 255), that is, red.
Since the above zip file may not include the latest "NtKinect.h", Download the latest version from here and replace old one with it.