Main Content

Preview Color and Depth Streams Simultaneously from Kinect for Windows V2

This example shows how to preview color and depth streams using the Kinect® for Windows® V2.

Requirements

  • MATLAB® and Image Acquisition Toolbox™

  • Kinect for Windows V2 sensor

  • Minimum PC configuration: Windows 10 64-bit

Identify Kinect for Windows V2

The imaqhwinfo("kinect") command provides information on the Kinect's color and depth devices. Since the Kinect has two sensors, a color and a depth sensor, it is enumerated as two devices.

kinectDeviceInfo = imaqhwinfo("kinect");
kinectDeviceInfo.DeviceIDs
ans=1×2 cell array
    {[1]}    {[2]}

Only one Kinect for Windows V2 can be used per computer. However, you can use the Kinect V1 and Kinect V2 together in the same MATLAB session. The devices will be enumerated as devices IDs [1],[2] (Kinect V1) and [3],[4] (Kinect V2).

Obtain Kinect V2 Device Information

Information on a specific device can be obtained by simply indexing into the device information structure array.

Get Kinect color device information.

colorDevice = kinectDeviceInfo.DeviceInfo(1)
colorDevice = struct with fields:
             DefaultFormat: 'BGR_1920x1080'
       DeviceFileSupported: 0
                DeviceName: 'Kinect V2 Color Sensor'
                  DeviceID: 1
     VideoInputConstructor: 'videoinput('kinect', 1)'
    VideoDeviceConstructor: 'imaq.VideoDevice('kinect', 1)'
          SupportedFormats: {'BGR_1920x1080'}

Get Kinect depth device information.

depthDevice = kinectDeviceInfo.DeviceInfo(2)
depthDevice = struct with fields:
             DefaultFormat: 'Depth_512x424'
       DeviceFileSupported: 0
                DeviceName: 'Kinect V2 Depth Sensor'
                  DeviceID: 2
     VideoInputConstructor: 'videoinput('kinect', 2)'
    VideoDeviceConstructor: 'imaq.VideoDevice('kinect', 2)'
          SupportedFormats: {'Depth_512x424'}

Create Color and Depth videoinput Objects

A videoinput object represents the connection between MATLAB and an image acquisition device.

Create a color videoinput object.

colorVid = videoinput("kinect",1)

Create a depth videoinput object.

depthVid = videoinput("kinect",2)

Preview Both Color and Depth Objects

Preview both videoinput objects.

preview([colorVid depthVid]);

PreviewColorAndDepthStreamsFromKinectExample_01.png

kinect-depthVid-preview.png

Clear videoinput Objects

delete(colorVid);
delete(depthVid);

Related Topics