image thumbnail

Simulink for PCV (Point Cloud Viewer)

by

 

12 Jun 2012 (Updated )

Simulink for PCV is a block for 3D Point Cloud View and wrapped native OpenCV library.

setup_opencv(varargin)
function setup_opencv(varargin)
% SETUP_OPENCV
%   This function is used to check necessity settings to use the Point Cloud Viewer
%   block which wraps OpenCV.
%   User can execute this function either with GUI or programmatically.
%
%  <What version of MATLAB you need to install
%   - MATLAB R2011b or later
%
%   <What you need to install to use OpenCV>
%   Install the following 3rd party software on your PC:
%   - Microsoft Visual Studio 2010 (VC++) Express Edition
%   - OpenCV 2.3.1 for Windows 32bit/64bit (OpenCV-2.3.1-win-superpack.exe)
%
%   <How to use>
%   - GUI based set up (a dialog pops up to specify necessity information)
%   >>setup_opencv
%
%   - MATLAB prompt based set up (specify necessity information as arguments)
%   setup_opencv(path to OpenCV)
%   >>dir1 = 'C:\opencv';
%   >>setup_opencv(dir1);
%
%   - Manually, set Windows environment path to OpenCV dll depending on MATLAB 32bit/64bit
%   In case of 32bit version of MATLAB R2011b or later, set path to e.g. C:\opencv\build\x86\vc10\bin
%   In case of 64bit version of MATLAB R2011b or later, set path to e.g. C:\opencv\build\x64\vc10\bin

%
%   Copyright 2012 The MathWorks, Inc.
%


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

    case 1 % execute prompt based set up
        [openCV_dir] = PromptBasedSetUp(varargin{1});

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

disp('### Checking MATLAB version...');
mv = ver('MATLAB');
if str2double(mv.Version) >= 7.13 % 7.13 = R2011b
    disp('MATLAB version is OK with Simulink for PCV.');
else
    error('Simulink for PCV works with only MATLAB R2011b or later.');
end

disp('### Confirming Point Cloud Viewer installations with OpenCV...');
% set MATLAB path to Lib directory and doc directory 
disp(['### Setting MATLAB path to .\Lib and .\Lib\doc_en directory.']);
pcv_doc = 'doc_en';
addpath([pwd '\Lib']);
addpath([pwd '\Lib\' pcv_doc]);
savepath;

% generate simulinkfornidopencvinfo.m in Lib directory
setupinfo = [pwd  '\Lib\simulinkfornidopencvinfo.m'];
disp(['### Generating ' setupinfo]);
try
    fid = fopen(setupinfo, 'w');

    fprintf(fid, '%% This file is automatically generated by setup_opencv.m\n');
    fprintf(fid, sprintf('SIMULINKFORNIDOPENCVPATH = ''%s'';\n', regexprep(openCV_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. 
% OpenCV should be installed by user and cmex file should be compiled by user. 
disp('### Generating C MEX file for Point Cloud Viewer (OpenCV)...');
cd('.\Lib');
makecmexfile4pcv;
cd('..');

disp('### Successful completion of Point Cloud Viewer installations with OpenCV.');
disp('### Furthermore, manually, it needs to set Windows path to the folder which OpenCV dll stored.');
disp('### In case of 32bit version of MATLAB R2011b or later,'); 
disp('### set path to e.g. C:\opencv\build\x86\vc10\bin');
disp('### In case of 64bit version of MATLAB R2011b or later,');
disp('### set path to e.g. C:\opencv\build\x64\vc10\bin');

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. OpenCV-2.3.1-win-superpack.exe\n']), ...
        'Did you install all necessity 3rd party software?', ...
        'Yes', 'No', 'No');
else
    error('ERROR: Point Cloud Viewer (OpenCV) unsupported platform.');
end

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


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

% check OpenCV path
if strcmp(computer, 'PCWIN') || strcmp(computer, 'PCWIN64')
    openCV_dir = uigetdir('C:\','Specify OpenCV installation path (e.g. C:\opencv).');
else
    error('ERROR: Point Cloud Viewer (OpenCV) unsupported platform.');
end
end % End of sub function


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

% check OpenCV path
if dir1 == 0
    error('### ERROR: OpenCV path is not specified.');
else
    if strcmp(computer, 'PCWIN') || strcmp(computer, 'PCWIN64')
        openCV_dir = dir1;
    else
        error('ERROR: Point Cloud Viewer (OpenCV) unsupported platform.');
    end
end

end % End of sub function


% [EOF]

Contact us