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.

The Computer Vision Toolbox™ Interface for OpenCV in MATLAB API supports OpenCV version 4.2.0, 4.5.0 and 4.7.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:


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

    mexOpenCV matchTemplateOCV.cpp

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


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