Main Content

Build MEX-Files for OpenCV Interface

Use the OpenCV Interface files to integrate your OpenCV C++ code into MATLAB® and build MEX-files that call OpenCV functions.

The mexOpenCV interface utility functions convert data between OpenCV and MATLAB. These functions support CPP-linkage only. GPU support is available on glnxa64, win64, and Mac platforms. The GPU-specific utility functions support CUDA enabled NVIDIA GPU. See the Parallel Computing Toolbox™ System Requirements and GPU Support by Release (Parallel Computing Toolbox). The GPU utility functions require the Parallel Computing Toolbox software.

The Computer Vision Toolbox™ Interface for OpenCV in MATLAB API supports OpenCV version 4.2.0.

Create MEX-File from OpenCV C++ file

This example creates a MEX-file from a wrapper C++ file and then tests the newly created file. The example uses the OpenCV template matching algorithm wrapped in a C++ file, which is located in the example/TemplateMatching folder.

  1. Change your current working folder to the example/TemplateMatching folder:

    cd(fullfile(fileparts(which('mexOpenCV')),'example',filesep,'TemplateMatching'))

  2. Create the MEX-file from the source file:

    mexOpenCV matchTemplateOCV.cpp

  3. Run the test script, which uses the generated MEX-file:

    testMatchTemplate

Create Your Own OpenCV MEX-files

Call the mxArray function with your source file.

mexOpenCV yourfile.cpp

For help creating MEX files, at the MATLAB command prompt, type:

help mexOpenCV

Run OpenCV Examples

Each example subfolder in the Computer Vision Toolbox Interface for OpenCV in MATLAB support package contains all the files you need to run the example. To run an example, you must call the mexOpenCV function with one of the supplied source files.

 Run Template Matching Example

 Run Foreground Detector Example

 Run Oriented FAST and Rotated BRIEF (ORB) Detector Example

See Also

|

Related Topics