Plot colored point cloud from Kinect for Windows
This example shows how to plot color point cloud using the Kinect for Windows v2.
1. MATLAB, Image Acquisition Toolbox and Computer Vision System Toolbox.
2. A Kinect for Windows v2 sensor.
3. Minimum PC configuration: Windows 8 64-bit.
colorDevice = imaq.VideoDevice('kinect',1) depthDevice = imaq.VideoDevice('kinect',2)
colorDevice = imaq.VideoDevice with properties: Device: 'Kinect Color Sensor (kinect-1)' VideoFormat: 'RGB_640x480' ROI: [1 1 640 480] ReturnedColorSpace: 'rgb' ReturnedDataType: 'uint8' DeviceProperties: [1x1 imaq.internal.DeviceProperties] depthDevice = imaq.VideoDevice with properties: Device: 'Kinect Depth Sensor (kinect-2)' VideoFormat: 'Depth_640x480' ROI: [1 1 640 480] ReturnedColorSpace: 'grayscale' ReturnedDataType: 'uint16' DeviceProperties: [1x1 imaq.internal.DeviceProperties]
colorImage = colorDevice(); depthImage = depthDevice();
depthDevice must be a Kinect depth videoinput object or a Kinect depth imaq.VideoDevice object.
depthImage must be uint16. colorImage must be uint8.
ptCloud = pcfromkinect(depthDevice, depthImage, colorImage); % Initialize a 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 Kinect point cloud data. while isOpen(player) colorImage = colorDevice(); depthImage = depthDevice(); ptCloud = pcfromkinect(depthDevice, depthImage, colorImage); view(player, ptCloud); end
- 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.