No License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

3.8 | 5 ratings Rate this file 36 Downloads (last 30 days) File Size: 314 KB File ID: #21818 Version: 1.0

OpenCV And MEX Files quick guide



20 Oct 2008 (Updated )

How to use openCV library in MATLAB

| Watch this File

File Information

This document was created as part of a final project for a BSc degree at the Academic College of Tel-Aviv Yaffo, by Rachely Esman and Yoad Snapir, under the supervision of Tal Hassner.
As part of the project, we used Intel's OpenCV library, calling its functions from MATLAB. We found the subject tricky and thus decided to share the experience of our work with others describing the common pitfalls.
 You can use this document freely according to the copyrights noted below but under your sole responsibility.


This file inspired Image Aquisition.

MATLAB release MATLAB 7.5 (R2007b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (12)
16 May 2013 rana

rana (view profile)

I am using opencv 245 but i can't find the library cv245.lib

Comment only
15 May 2013 SenyaLab

15 May 2013 SenyaLab

Adding _SECURE_SCL=1 to COMPFLAGS in mexopts.bat file solved this problem for me.

I am using Matalb2012b-64bit, VS2010-Professional, and OpenCV 2.4.5.

31 Jul 2012 Pouye Sedighian

31 Jul 2012 Pouye Sedighian

I am getting this error, would you please let me know what I need to do? I am using matlab 2010a and visual studio 2008, OpenCV 2.4.2

mex OpenCVTest2.cpp
OpenCVTest2.cpp(2) : fatal error C1083: Cannot open include file: 'cv.hpp': No such file or directory

C:\PROGRA~2\MATLAB\R2010A\BIN\MEX.PL: Error: Compile of 'OpenCVTest2.cpp' failed.

??? Error using ==> mex at 222
Unable to complete successfully.

Comment only
23 Feb 2012 Gareth Bell


while it lasts.

Comment only
13 Jul 2011 Aakash

Aakash (view profile)

13 Apr 2011 Zhou

Zhou (view profile)

First I copied your method without any modification but I failed. Then I found my directories are different from yours. I used Visual Studio 8.0 as the compiler and I built a debug and release version respectively. Then the .lib files should be in OPENCVDIR\VS2005\lib\debug,OPENCVDIR\VS2005\lib\release,OPENCVDIR\VS2005\bin\debug,OPENCVDIR\VS2005\bin\release respectively.
(Btw, the VS2005 directory is not there at first place, but was built when I used CMake to make the files, containing the built .sln and other files. You can name it differently, but the you should refer to compiled .libs.)
Also the .h files are in different places, possibly because I use a different version of OpenCV(I use 2.0). In this case it's in OPENCVDIR\include\opencv.

I still thank the author for making the principle right. All you have to pay attetion to is the concrete path names.

05 Jul 2010 Art

Art (view profile)

I have read this paper and try it. I use Matlab 2010, OpenCV1.1 and Visual Studio 2008. There is a big trouble: when I call mex-function, that contains a call of OpenCV functions ( such as cvNamedWindow, cvLoadImage and cvDestroyAllWindows, cvReleaseImage, etc. ) it's look all right, but there is a fail later, when I call matlab functions of Calibration Toolbox for Matlab. For example, I call one mex-function and after that the toolbox loads images and crush comes, but crush comes not at the momemnt of mex-function calling, but much later. In fact Matlab crushes on that code:
mask = exp(-((-wintx:wintx)'/(wintx)).^2) * exp(-((-winty:winty)/(winty)).^2);
In other words, it looks like crush happens, when there were computing intensive operations =)
It looks very strange that during the time after a calling mex-function and before crush, windows are creating and some matlab code works fine.
Could anybody help me solve this problem? Thanks

Comment only
05 Mar 2009 Joaquim Luis

It was me who removed all contribs from FEX.
I got too pissed off with TMW. See

Anyway, cvlib_mex as well as my other files are now available at

Comment only
18 Dec 2008 Fabio Caponetti

Hi, I was looking for the wrapper lib cvlib_mex, but I cannot find a working link to download it!

I would like to test it under Linux and the newest Matlab version...


Comment only
20 Oct 2008 Joaquim Luis

You would have saved yourself s a lot of work if you had searched the FEX and found "cvlib_mex" wich, BTW, uses only C (not C++).

Comment only

Contact us