https://www.stereolabs.com/blog/index.php/tag/matlab/

 

아래 설명에 나온것처럼 cmake로 mex파일을 생성할때는, visual studio sln파일을 만든 후, 그 프로젝트를 빌드한 후, INSTALL을 빌드해주면 mex파일이 생성된다.

 

 

 

  • Right click on the project named ‘mexZED’ and select ‘Build’
  • Right click on the project named ‘INSTALL’ and select ‘Build’
  • ---------------------------------------------------

     

    Introduction

    The purpose of this post is to explain how to use the ZED stereo camera and its SDK to capture depth maps with Matlab. We use the ability of Matlab to execute C++ code through an intermediate file called MEXA file.

    You will find the complete source code on Stereolabs’ Github page.

    If you simply want to use the ZED stereo camera with Matlab (without the ZED SDK) you can refer to this article.

    Prerequisites

    You must have Matlab installed on your system and of course, the ZED SDK needs to be installed too.

    Code

    When downloading the source code from GitHub, you will find two subfolders. The first one, ‘matlab’, contains a file named ‘ZED_Camera.m’, a standard Matlab file wich will call the ZED functions. The second subfolder, ‘src’, contains the files to build the application.
    In the ‘mex’ subfolder, there is a file named ‘mexZED.cpp’ which contains the ZED SDK functions and interoperability with the Matlab format. This file is referred to as a MEX file. It re-implements the majority of the ZED SDK functions. This file is provided as a basic container and can be complemented with your own functions. Since Matlab does not handle image representation the same way the ZED SDK does, we need additional formatting functions.In the file ‘ZED_Camera.m’ the ZED functions are reachable through mexZED(‘..’). Check the ‘mexZED.cpp’ to see the list of functions available.

    Build procedure

    You now want to compile the mexZED.cpp file in a MEXA file format which can be used by Matlab. Usually, MEX files are compiled directly by Matlab but since we need to link several libraries (ZED, OpenCV) it is better to use CMake.
    On Linux

    Open a terminal in zed-Matlab directory and execute the following command:

    export MATLAB_ROOT=/usr/local/MATLAB/R2012b
    mkdir build
    cd build
    cmake ../src
    make
    make install
    On Windows

    You need to set the environment variable ‘MATLAB_ROOT’, to do this you can use an editor such as ‘Rapid Environment Editor’ or use the following procedure:

     

    • Click the Start button, right-click on ‘Computer’ and select ‘Properties’.
    • Click the ‘Advanced System Settings’ link in the left column.
    • In the System Properties window, click on the ‘Advanced’ tab, then click the ‘Environment Variables…’ button in the bottom of the window.
    • In the upper part of the window, add your definition to ‘User variables for..’
    • Click ‘New…’
    • Set ‘Variable name’ as MATLAB_ROOT
    • Set ‘Variable value’ to your own matlab root directory e.g. ‘C:\Program Files\MATLAB\R2014b’
    • Restart your computer.

     

     

     

    Then a common build procedure is used:

    • Open cmake-gui.
    • In “Where is the source code”, enter the path of the sources (e.g. ‘C:\Users\Peter\Documents\zed-matlab\src’)
    • In “Where to build the binaries”, enter the build directory (e.g. ‘C:\Users\Peter\Documents\zed-matlab\build’), and click the “Configure” button.
    • A dialog window asks you if CMAKE can create the folder “build” itself. Say yes.
    • Another dialog window will ask you the generator of your project. Choose Visual Studio. For example, we choose “Visual Studio 12 2013”. Click the “Finish” button.
    • CMAKE may take few seconds to configure the project. Then, some red lines should be displayed in the cmake-gui window.
    • Make sure that the message ‘MATLAB Found, MATLAB MEX will be compiled.’ is print, if not the variable environment MATLAB_ROOT can not be found, and you can not compile the project.
    • Click the “Generate” button.
    • CMAKE has just generated your project in the build folder. Now, you can close the cmake-gui window and go to the build folder.
    • Visual Studio files has been generated and a Visual Studio project file named “MEX.sln” too. Open it with Visual Studio.
    • Right click on the project named ‘mexZED’ and select ‘Build’
    • Right click on the project named ‘INSTALL’ and select ‘Build’

     

    Run the sample

    You can now find the generated MEXA file in the matlab directory (e.g. ‘\zed-matlab\matlab’), you can launch Matlab and run the ZED_Camera.m file.

    matlab

    Read More

    Posted by uniqueone
    ,