Kinect V2 can acquire RGB camera image with resolution of 1920 x 1080. Since OpenCV uses BGR format or BGRA format as the basis, NtKinect adopts the BGRA format.
type of return value | function name | description |
---|---|---|
void | setRGB() | Get the RGB image and set it to the public member variable rgbImage. |
type | variable name | description |
---|---|---|
cv::Mat | rgbImage | Image of RGB camera. The resolution is 1920 x 1080 and GBRA format. The coordinates of the image are the positions in the ColorSpace coordinate system.
cv::Vec4b pixel = rgbImage.at<cv::Vec4b>(y,x); pixel[0] // Blue pixel[1] // Green pixel[2] // Red pixel[3] // Alpha |
Depth (distance) images can be acquired with a resolution of 512 x 424. The measurable distance range is from 500 mm to 8000 mm, but the range to recognize human beings is from 500 mm to 4500 mm.
In the Kinect20.lib IDepthFrameSource has the "get_DepthMaxReliableDistance()" and "get_DepthMaxReliableDistance()" functions, each returns 500 and 4500 respectively.
In NtKinect, the obtained Depth image is represented by UINT16 (16 bit unsigned integer) for each pixel.
type of return value | function name | descriptions |
---|---|---|
void | setDepth(bool raw = true) |
Set the Depth image to the member variable "depthImage". When this function is called with no argument or "true" as first argument, the distance is set in mm for each pixel. When this function is called with "false", a value obtained by multiplying the distance by 65535/4500 is set for each pixel. That is, the image is mapped to the luminance of the black and white image of 0 (black) to 65535 (white) with the distance of 0 mm to 4500 mm. |
type | variable name | descriptions |
---|---|---|
cv::Mat | depthImage | Depth image.
The resolution is of 512 x 424 and each pixel is represented by UINT16. The coordinates of the image are the position in the DepthSpace coordinate system.
UINT16 depth = rgbImage.at<UINT16>(y , x ); |
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.setDepth() function to set depth (distance) data to kinect.depthImage. Since no argument is specified, the value of pixel is raw, that is, the distance to the object in millimeters.
By painting pixels farther than 2000 mm with blue, only images of nearby objects are displayed. Since we can not measure a value smaller than 500 mm, we treat that pixel as being more than 8000 mm.
Since RGB image and Depth image are different in resolution, one pixel of Depth image corresponds to 4 pixels of the RGB image and the 4 x 4 rectangle area is painted.
main.cpp |
|
Since the above zip file may not include the latest "NtKinect.h", Download the latest version from here and replace old one with it.