Plot Color Point Cloud from Kinect for Windows V2
This example shows how to plot a color point cloud using the Kinect® for Windows® V2.
MATLAB®, Image Acquisition Toolbox™, and Computer Vision Toolbox™
Kinect for Windows V2 sensor
Minimum PC configuration: Windows 10 64-bit
Create System Objects for Kinect V2 Device
The Kinect camera has separate sensors for color and depth. Create separate system objects for the color sensor and depth sensor.
colorDevice = imaq.VideoDevice("kinect",1)
colorDevice = imaq.VideoDevice with properties: Device: 'Kinect V2 Color Sensor (kinect-1)' VideoFormat: 'BGR_1920x1080' ROI: [1 1 1920 1080] ReturnedColorSpace: 'rgb' ReturnedDataType: 'uint8' ReadAllFrames: 'off' DeviceProperties: [1×1 imaq.internal.DeviceProperties]
depthDevice = imaq.VideoDevice("kinect",2)
depthDevice = imaq.VideoDevice with properties: Device: 'Kinect V2 Depth Sensor (kinect-2)' VideoFormat: 'Depth_512x424' ROI: [1 1 512 424] ReturnedColorSpace: 'grayscale' ReturnedDataType: 'uint16' ReadAllFrames: 'off' DeviceProperties: [1×1 imaq.internal.DeviceProperties]
Initialize the sensors.
Grab one frame from each of the sensors.
colorImage = colorDevice(); depthImage = depthDevice();
Extract Point Cloud
depthDevice must be a Kinect depth
videoinput object or a Kinect depth
depthimage must be
colorImage must be
ptCloud = pcfromkinect(depthDevice,depthImage,colorImage);
Initialize a player to visualize the 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 Kinect point cloud data.
while isOpen(player) colorImage = colorDevice(); depthImage = depthDevice(); ptCloud = pcfromkinect(depthDevice,depthImage,colorImage); view(player,ptCloud); end
Close the player when you are done.
Release the Devices
More About Kinect Point Clouds
The origin of a right-handed world coordinate system is at the center of the camera. The X axis of the coordinate system is pointing to the right, the Y axis is pointing downward, and the Z axis is pointing away from the camera.
Since the Kinect depth camera has limited range, some pixels in the depth image do not have corresponding 3-D coordinates. The values for those pixels are set to NaN in the Location property of ptCloud.
Since Kinect was designed for gaming, the original images, colorImage and depthImage, from Kinect are mirror images of the scene. The returned point cloud is corrected to match the actual scene.