Main Content

pcfromkinect

Point cloud from Kinect for Windows

Description

ptCloud = pcfromkinect(depthDevice,depthImage) returns a point cloud from a Kinect® depth image. The depthDevice input can be either a videoinput (Image Acquisition Toolbox) object or an imaq.VideoDevice (Image Acquisition Toolbox) object configured for Kinect (Versions 1 and 2) for Windows®.

This function requires the Image Acquisition Toolbox™ software, which supports Kinect for Windows.

example

ptCloud = pcfromkinect(depthDevice,depthImage,colorImage) adds color to the returned point cloud, specified by the colorImage input.

The Kinect for Windows system, designed for gaming, produces depthImage and colorImage as mirror images of the scene. The returned point cloud is corrected to match the actual scene.

ptCloud = pcfromkinect(depthDevice,depthImage,colorImage,alignment) additionally specifies the direction of the alignment of the image coordinate system, which can be color centric or depth centric.

Examples

collapse all

Plot a color point cloud from Kinect images. This example requires the Image Acquisition Toolbox software and the Kinect camera and a connection to the camera.

Create a System object™ for the color device.

colorDevice = imaq.VideoDevice('kinect',1)

Create a System object for the depth device.

depthDevice = imaq.VideoDevice('kinect',2)

Initialize the camera.

step(colorDevice);
step(depthDevice);

Load one frame from the device.

colorImage = step(colorDevice);
depthImage = step(depthDevice);

Extract the point cloud.

ptCloud = pcfromkinect(depthDevice,depthImage,colorImage);

Initialize a point cloud player to visualize 3-D point cloud data. The axis is set appropriately to visualize the point cloud from Kinect.

player = pcplayer(ptCloud.XLimits,ptCloud.YLimits,ptCloud.ZLimits,...
	'VerticalAxis','y','VerticalAxisDir','down');

xlabel(player.Axes,'X (m)');
ylabel(player.Axes,'Y (m)');
zlabel(player.Axes,'Z (m)');

Acquire and view 500 frames of live Kinect point cloud data.

for i = 1:500    
   colorImage = step(colorDevice);  
   depthImage = step(depthDevice);
 
   ptCloud = pcfromkinect(depthDevice,depthImage,colorImage);
 
   view(player,ptCloud);
end

Release the objects.

release(colorDevice);
release(depthDevice);

Input Arguments

collapse all

Input video object, specified as either a videoinput (Image Acquisition Toolbox) object or an imaq.VideoDevice (Image Acquisition Toolbox) object configured for Kinect for Windows.

Depth image, specified as an M-by-N pixel matrix. The original images, depthImage and colorImage, from Kinect are mirror images of the scene.

The Kinect depth camera has limited range. The limited range of the Kinect depth camera can cause pixel values in the depth image to not have corresponding 3-D coordinates. These missing pixel values are set to NaN in the Location property of the returned point cloud.

Data Types: uint16

Color image, specified as an M-by-N-by-3 RGB truecolor image that the Kinect returns. The original images, depthImage and colorImage, from Kinect are mirror images of the scene.

Data Types: uint8

Direction of the image coordinate system, specified as the character vector 'colorCentric' or 'depthCentric'. Set this value to 'colorCentric' to align depthImage with colorImage. Set alignment to 'depthCentric' to align colorImage with depthImage.

The origin of a right-handed world coordinate system is at the center of the depth camera. The x-axis of the coordinate system points to the right, the y-axis points downward, and the z-axis points away from the camera.

Note

For consistency across Computer Vision Toolbox™ use of coordinates systems, the coordinate system defined by this function is different from the one defined by Kinect Skeletal metadata.

Output Arguments

collapse all

Point cloud, returned as a pointCloud object. The origin of the coordinate system of the returned point cloud is at the center of the depth camera.

Version History

Introduced in R2015b