File Exchange

image thumbnail

Computer Vision System Toolbox OpenCV Interface

Use OpenCV algorithms in MATLAB

107 Downloads

Updated 12 Sep 2018

The Computer Vision System Toolbox OpenCV Interface enables you to bring existing OpenCV files and projects into MATLAB using MEX. The support package includes:
• Data type conversions between MATLAB and OpenCV
• Examples showing how to interface OpenCV and MATLAB
Opening the .mlpkginstall file from your operating system or from within MATLAB will initiate the installation process available for the release you have. This .mlpkginstall file is functional for R2014b and beyond.
Watch this video to learn more about the package: http://youtu.be/BasC2jkgyaM

Comments and Ratings (26)

Ying Wang

It is really helpful, I followed the video and got the add-on work.
but there is no subtitles which is unfriendly to non-English speakers......

arusa khan

I've got Matlab R2016a and MEX configured to use 'Microsoft Visual C++ 2015 Professional (C)'.
I managed to compile the test files detectORBFeaturesOCV.cpp and extractORBFeaturesOCV.cpp into mexw64 files, but running testORBFeaturesOCV.m crashes Matlab badly at calling any of the above functions. Is it due to 2015 C++ compiler?
kindly help me to solve this problem.
I also used R2014b and R2017a, but it gave me same error when i run TestORBFeaturesOCV.m file.
Thanks!

I'm also getting error on compiling:

>> mexOpenCV backgroundSubtractorOCV.cpp
Building with 'MinGW64 Compiler (C++)'.
Error using mexOpenCV (line 136)
C:\Users\PERIG~1.VEN\AppData\Local\Temp\mex_329972900989911_14272\backgroundSubtractorOCV.obj:backgroundSubtractorOCV.cpp:(.text+0x365): undefined reference to `ocvMxArrayToImage_uint8(mxArray_tag const*, bool)'
C:\Users\PERIG~1.VEN\AppData\Local\Temp\mex_329972900989911_14272\backgroundSubtractorOCV.obj:backgroundSubtractorOCV.cpp:(.text+0x3c3): undefined reference to `ocvMxArrayFromImage_bool(cv::Mat const&)'
C:\Users\PERIG~1.VEN\AppData\Local\Temp\mex_329972900989911_14272\backgroundSubtractorOCV.obj:backgroundSubtractorOCV.cpp:(.text+0x453): undefined reference to `cv::fastFree(void*)'
C:\Users\PERIG~1.VEN\AppData\Local\Temp\mex_329972900989911_14272\backgroundSubtractorOCV.obj:backgroundSubtractorOCV.cpp:(.text+0x4c0): undefined reference to `cv::fastFree(void*)'
C:\Users\PERIG~1.VEN\AppData\Local\Temp\mex_329972900989911_14272\backgroundSubtractorOCV.obj:backgroundSubtractorOCV.cpp:(.text+0x4d5): undefined reference to `cv::Mat::deallocate()'
C:\Users\PERIG~1.VEN\AppData\Local\Temp\mex_329972900989911_14272\backgroundSubtractorOCV.obj:backgroundSubtractorOCV.cpp:(.text+0x4e4): undefined reference to `cv::Mat::deallocate()'
C:\Users\PERIG~1.VEN\AppData\Local\Temp\mex_329972900989911_14272\backgroundSubtractorOCV.obj:backgroundSubtractorOCV.cpp:(.text$_ZN2cv3MatD1Ev[_ZN2cv3MatD1Ev]+0x22): undefined reference to `cv::Mat::deallocate()'
C:\Users\PERIG~1.VEN\AppData\Local\Temp\mex_329972900989911_14272\backgroundSubtractorOCV.obj:backgroundSubtractorOCV.cpp:(.text$_ZN2cv3MatD1Ev[_ZN2cv3MatD1Ev]+0x86): undefined reference to `cv::fastFree(void*)'
C:\Users\PERIG~1.VEN\AppData\Local\Temp\mex_329972900989911_14272\backgroundSubtractorOCV.obj:backgroundSubtractorOCV.cpp:(.text.startup+0x3b): undefined reference to `cv::createBackgroundSubtractorMOG2(int,double, bool)'
collect2.exe: error: ld returned 1 exit status

arusa khan

>>mex -setup c++
it gave me this error using mex
No supported compiler or SDK was found. You can install the freely available MinGW-w64 C/C++ compiler; see Install
MinGW-w64 Compiler. For more options, visit http://www.mathworks.com/support/compilers/R2016a/win64.html.

I used the matlab r2016a and have already installed the VS2015 and TDM-GCC-4.9.2.
Anyone please help me to solve this problem

>> mex -setup c++
MEX configured to use 'Microsoft Visual C++ 2015' for C++ language compilation.
Warning: The MATLAB C and Fortran API has changed to support MATLAB
variables with more than 2^32-1 elements. You will be required
to update your code to utilize the new API.
You can find more information about this at:
https://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html.

To choose a different C++ compiler, select one from the following:
Microsoft Visual C++ 2015 mex -setup:C:\Users\maksa\AppData\Roaming\MathWorks\MATLAB\R2018a\mex_C++_win64.xml C++
Microsoft Visual C++ 2017 mex -setup:'C:\Program Files\MATLAB\R2018a\bin\win64\mexopts\msvcpp2017.xml' C++
>> mexOpenCV detectORBFeaturesOCV.cpp
Error using mexOpenCV (line 63)
The OpenCV libraries were built using 'Microsoft Visual C++ 2015'.
Your compiler is 'Microsoft Visual C++ 2017 (C)'.
These compilers may not be compatible.
Note that you can select a compiler using 'mex -setup' command.

Please help me with this problem.. Thanks

Siyuan Li

The OpenCV libraries were built using 'Microsoft Visual C++ 2015'.
Your compiler is 'Microsoft Visual C++ 2017 (C)'.
These compilers may not be compatible.
Note that you can select a compiler using 'mex -setup' command.

Can not be used in Matlab2018a

Amith Kamath

Cui: We have updated the supported compiler on Windows to be Visual Studio 2015. You will not have compatibility issues here on.
Madhu: I do not fully understand what you would like to visualize within the MEX routine. Yes, the libraries you listed are not included. You could consider running each iteration in your MEX file, and returning to MATLAB to use imshow/imread to display or read a new image. If this doesn't answer your question, please consider contacting Technical Support with more details.
In terms of OpenCV versions, until R2017a, version 2.4.9 was used. From R2017a onwards, we use version 3.1.0. This is likely to change in a future release.
Thanks!

Question: In mexOpenCV.m, there is note that some libraries (opencv_highgui, opencv_imgcodecs, etc.) are not included. If we would like to visualize results within a mex routine, e.g. with opencv's imshow during an iteration, would including opencv_imgcodecs in mexOpenCV.m work ? Or do we have to use Matlab's imread with 'mexCallMATLAB' ?

Thuong HD

Thank you for supporting!

Thuong HD

maisam sakr

cui

cui (view profile)

Warning: The OpenCV libraries were built using 'Microsoft Visual C++ 2012'.
Your compiler is 'Microsoft Visual C++ 2015 Professional'.
These compilers may not be compatible. how I do?

Inge Coudron

Finally got it working on R2016b. It will only compile with the Visual Studio Professional 2012 C++ Compiler (not the free Express versions!). Thankfully I have access to it via my university.

Also I can't find any info on which OpenCV versions are supported.

Benny

Benny (view profile)

Hello
I am using an offline computer which can't be connected to the internet. Is it possible to get an offline installer for this package anywhere?

Appreciate your response.

Benny

Miguel Simão

What version are the OpenCV libraries included in this package?

yang bin

Can not be used in Matlab2016

yang bin

Karel Lebeda

When trying to open in file-roller, I get the error message:
Could not open "opencvinterface-1.mlpkginstall". Archive type not supported.

Eslam Foad

Good!

I get the following error in R2015a, and I am using Xcode 7. If I remove the cv::imdecode() function. it compiles, but I need to use the cv::imdecode() function!

Error using mexOpenCV (line 120)
Undefined symbols for architecture
x86_64:
"cv::imdecode(cv::_InputArray const&,
int)", referenced from:
_mexFunction in decodeUDPimg.o
ld: symbol(s) not found for architecture
x86_64
clang: error: linker command failed with
exit code 1 (use -v to see invocation)

What is the problem?

Royi Avital

Please,
Make it available in a regular form (Not only a Toolbox).

Thank You.

Sergey

Sergey (view profile)

Hi!
I've got Matlab R2015b and MEX configured to use 'Microsoft Visual C++ 2015 Professional (C)'.
I've managed to compile the test files detectORBFeaturesOCV.cpp and extractORBFeaturesOCV.cpp into mexw64 files, but running testORBFeaturesOCV.m crashes Matlab badly at calling any of the above functions. Is it due to 2015 C++ compiler? Should I use 2012 version only or I can use some keys/flags to make it work?
Thanks!

I just cannot understand the reason it is working only on 2014b or beyond. As a home edition user of 2014a, it would be a lot easier for me to transit matlab code to opencv with this package, but I can't do that because of the one letter difference. In order to use newer version, I have to buy matlab and all toolbox again.

Andres garcia

I start to work in openCV i see that will be easy to use

MATLAB Release Compatibility
Created with R2014b
Compatible with R2014b to R2018b
Platform Compatibility
Windows macOS Linux

Discover Live Editor

Create scripts with code, output, and formatted text in a single executable document.


Learn About Live Editor