Connect Microsoft Kinect 2.0 with Matlab

Matlab can connect with Kinect 2.0 without any external library. For this we need a PC connected with Microsoft Kinect 2.0. Installation of kinect studio is not necessary.

Install kinect plugin available in matlab. To check whether this plugin is available or not, just Click on Addons in Home tab and then select Get Addons. From the addon explorer, select Image acquisition toolbox support package for kinect for windows sensor and install it. While installing, it will prompt for your mathworks account. Just login with your account and allow all third party plugin tools installed in the meanwhile.

After installing the kinect plugin, type

info = imaqhwinfo('kinect');

This will help us to know whether kinect is supported in matlab installed in your computer or not. If it is installed, it will display:

info = 
       AdaptorDllName: '<matlabroot>\toolbox\imaq\imaqadaptors\win64\mwkinectimaq.dll'
    AdaptorDllVersion: '4.6 (R2013b)'
          AdaptorName: 'kinect'
            DeviceIDs: {[1]  [2]}
           DeviceInfo: [1x2 struct]
Device ID 1 and 2 corresponds to RGB and depth sensor outputs respectively.

For calling RGB camera, the following command must be called
vid = videoinput('kinect', 1);

For depth sensor,
vid = videoinput('kinect', 2, 'Depth_512x424');

Following statements are used to set parameters.
src = getselectedsource(vid);
vid.FramesPerTrigger = 1;

To start viewing the video, preview(vid); is used. This could be ended by closepreview(vid);

Meanwhile, if we need to start and stop acquisition just to capture an image, the following statements would help.

Inorder to store the acquired images to a variable a getdata statement will help as follows.
depth = getdata(vid);

A sample code to acquire an image from the depth sensor is given below:
close all
clear all
warning off
vid = videoinput('kinect', 2, 'Depth_512x424');
% vid = videoinput('kinect', 1);
src = getselectedsource(vid);
vid.FramesPerTrigger = 1;
depth = getdata(vid);

Be the first to comment

Leave a Reply

Your email address will not be published.