Code covered by the BSD License  

Highlights from
Simulink Support for Kinect

image thumbnail

Simulink Support for Kinect

by

 

25 Jul 2011 (Updated )

Simulink Support for Kinect is a set of Simulink blocks interfaced with OpenNI and Kinect SDK.

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

setup_kinectsdk(varargin)
function setup_kinectsdk(varargin)
% SETUP_KINECTSDK
%   This function is used to check necessity settings to use the Simulink Support for Kinect which wraps Microsoft Kinect SDK for Windows.
%   User can execute this function either with GUI or programmatically.
%
%   <What you need to install to use Simulink Support for Kinect>
%   Install the following 3rd party software on your PC:
%   - Microsoft Visual Studio 2010 (VC++) Express Edition
%   - Microsoft Kinect SDK for Windows (version 1.6)
%
%   For more detailed information, please read Simulink_Support_for_Kinect_En/Ja.doc.
%   After completion of all the above steps, it needs to run this function again.
%
%   <How to use>
%   - GUI based set up (a dialog pops up to specify necessity information)
%   >>setup_kinectsdk
%
%   - MATLAB prompt based set up (specify necessity information as arguments)
%   setup_kinectsdk(Path to the SDK)
%   >>sdk_dir = 'C:\Program Files\Microsoft SDKs\Kinect\v1.6';
%   >>setup_kinectsdk(sdk_dir);

%
%   Copyright 2011-2012 The MathWorks, Inc.
%


% run desired set up 
switch nargin
    case 0 % execute GUI based set up
        if ~GuiCheck3rdParty()
            return;
        end
        kinectSDK_dir = GuiBasedSetUp();

    case 2 % execute prompt based set up
        kinectSDK_dir = PromptBasedSetUp(varargin{2});

    otherwise
            error('### ERROR: Invalid argument.')
end

disp('### Confirming Simulink Support for Kinect installations with Kinect SDK...');

% Specify the folder name of doc in Japanese or English depending on locale
if strcmp(get(0, 'lang'), 'ja_jp')
    nid_doc = 'doc_ja';
else
    nid_doc = 'doc_en';
end 

% set MATLAB path to Lib directory and doc directory 
disp(['### Setting MATLAB path to .\Lib and .\Lib\' nid_doc ' directories.']);
addpath([pwd '\Lib']);
addpath([pwd '\Lib\' nid_doc]);
savepath;

% generate simlinkforknidinfo.m in Lib directory
setupinfo = [pwd  '\Lib\simulinkfornidinfo.m'];
disp(['### Generating ' setupinfo]);
try
    fid = fopen(setupinfo, 'w');
    fprintf(fid, '%% This file is automatically generated by setup_kinectsdk.m\n');
    fprintf(fid, sprintf('SIMULINKFORNIDDRIVER = ''KINECT_SDK'';\n')); 
    fprintf(fid, sprintf('SIMULINKFORNIDKINECTSDKPATH = ''%s'';\n', regexprep(kinectSDK_dir, '\\', '\\\')));
    fclose(fid);
catch
    fclose(fid);
    error(['### ERROR: Failed to generate ' setupinfo]);
end

% Shipping files should not include mex file (binary) due to the FX license policy. 
% Kinect SDK should be installed by user and cmex file should be compiled by user. 
disp('### Generating C MEX file for Simulink Support for Kinect...');
cd('.\Lib');
makecmexfile4nid;
cd('..');

disp('### Successful completion of Simulink Support for Kinect installations with Kinect SDK.');

end


% =========================================================================
% Sub function: GuiCheck3rdParty
function ret = GuiCheck3rdParty()

ret = false;
if strcmp(computer, 'PCWIN') || strcmp(computer, 'PCWIN64')
    yes_no = questdlg(sprintf([ ...
        '1. Microsoft Visual Studio 2010 (VC++) Express Edition\n\n' ...
        '2. Microsoft Kinect SDK for Windows\n']), ...
        'Did you install all necessity 3rd party software?', ...
        'Yes', 'No', 'No');
else
    error('ERROR: Simulink Support for Kinect unsupported platform.');
end

switch yes_no
    case 'Yes'
        ret = true;
        
    case 'No'
        eval('help setup_kinectsdk');
end
end


% =========================================================================
% Sub function: GuiBasedSetUp
function kinectSDK_dir = GuiBasedSetUp()

% check Kinect SDK path
if strcmp(computer, 'PCWIN') || strcmp(computer, 'PCWIN64')
    % Configure path to Kinect SDK
    kinectSDK_dir = uigetdir('C:\','Specify Kinect SDK v1.6 installation path (e.g. C:\Program Files\Microsoft SDKs\Kinect\v1.6).');
else
    error('ERROR: Simulink Support for Kinect unsupported platform.');
end
end % End of sub function


% =========================================================================
% Sub function: PromptBasedSetUp
function kinectSDK_dir = PromptBasedSetUp(dir1)

% check Kinect SDK path
if dir1 == 0
    error('### ERROR: Kinect SDK path is not specified.');
else
    if strcmp(computer, 'PCWIN') || strcmp(computer, 'PCWIN64')
        kinectSDK_dir = dir1;
    else
        error('ERROR: Simulink Support for Kinect unsupported platform.');
    end
end

end % End of sub function


% [EOF]

Contact us