Install Matlab OpenCV C++/CUDA/MEX support
To use OpenCV from Matlab via vision Support Packages as integrated by the Mathworks using MEX.
Select “Computer Vision System Toolbox OpenCV Interface by MathWorks Computer Vision System Toolbox Team” and install.
Note: the examples require particular compilers depending on Matlab version and operating system.
Examples directory contains Computer Vision Toolbox examples from the Mathworks. Find the Matlab OpenCV example directory, in Matlab:
fileparts(which('mexOpenCV'))
The examples below assume you’re starting from this directory. See the README.txt in each directory for compilation details. Some examples require a CUDA GPU.
Foreground Detector: build example
cd ForegroundDetector
mexOpenCV backgroundSubtractorOCV.cpp
If the example fails to compile due to compiler mismatch, follow the instructions given in the error message.
Run the OpenCV Matlab demo:
testBackgroundSubtractor
You will see a Video Player window pop up with cars driving by, with the cars detected outlined in white rectangles.