Code covered by the BSD License  

Highlights from
Simulink Support for Kinect

image thumbnail

Simulink Support for Kinect



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

function corner_detection_viewer(block)
% Level-2 MATLAB file S-Function for displaying 3-D Corner Detection view for Simulink NID Depth XYZ data and Image data.
% Copyright 2011 The MathWorks, Inc.

% Register number of input and output ports
block.NumInputPorts   = 1;
block.NumOutputPorts  = 0;
% Setup functional port properties to dynamically inherited.
block.AllowSignalsWithMoreThan2D = 1;
block.InputPort(1).DimensionsMode    = 'Variable';
% Set block sample time to inherited
block.SampleTimes = [-1 0];
% Register methods
block.RegBlockMethod('SetInputPortDimensions', @SetInputPortDims);
block.RegBlockMethod('Start',   @Start);
block.RegBlockMethod('Outputs', @Output);  

% -----------------------------------------------------------------
% Callback functions
% -----------------------------------------------------------------

function SetInputDimsMode(block, port, dm)
% Set dimension mode
block.InputPort(port).DimensionsMode = dm;

function SetInputPortDims(block, idx, di)
block.InputPort(idx).Dimensions = di; % Set compiled dimensions

function DoPostPropSetup(block)
% Set the type of signal size to be dependent on input values, i.e.,
% dimensions have to be updated at output
block.SignalSizesComputeType = 'FromInputValueAndSize';

function Start(block)
set(gcf, 'Name', 'Corner Detection Viewer', 'NumberTitle', 'off');
whitebg('k'); % Backgroud color is black
view(37.5, 30); % Set default view

function Output(block)
cla; % Clear current axis and objects
for i = 1:size(block.InputPort(1).Data,1)
    if block.InputPort(1).Data(i,3) ~= 0 % Depth is valid
        line(block.InputPort(1).Data(i,1), block.InputPort(1).Data(i,3), block.InputPort(1).Data(i,2), ...
            'LineStyle', 'none', 'Marker', 'o', 'MarkerFaceColor', 'g', 'MarkerSize', 4);
set(gca, 'XLim', [-3.2 3.2], 'YLim', [0 10.0], 'ZLim', [-2.4 2.4]); % Set X/Y/Z limits in meters
set(gca, 'XGrid', 'on', 'YGrid', 'on', 'ZGrid', 'on'); % Draw X/Y/Z grid


Contact us