Skip to content
This repository has been archived by the owner on Jan 25, 2022. It is now read-only.

Installation (Windows, MATLAB, OpenCV 2)

Amro edited this page Oct 4, 2018 · 5 revisions

Building mexopencv on Windows

1) Configure a C/C++ compiler for MEX-files in MATLAB

To build mexopencv MEX-files, you need a standard-compliant C++ compiler supported by MATLAB. For an up-to-date list of supported compilers for different versions of MATLAB, see this page.

At the time of writing, Visual Studio 2010 is the recommended version to build mexopencv on Windows platforms. If you are building for a 64-bit target, you have two options:

  • use Visual Studio Professional edition (make sure "X64 Compilers and Tools" component is chosen during installation)
  • use Visual C++ Express edition along with latest Windows SDK, both available to download for free.

To select a compiler configuration in MATLAB, type the following command, and follow the instructions (this should be done only once):

>> mex -setup

2) Install OpenCV library

  1. Download the latest pre-built OpenCV 2.4 binaries (mexopencv was last tested against v2.4.11)
  2. Extract/unpack the archive into a destination of your choosing. For example C:\OpenCV
  3. Add the bin folder containing the DLL files to the system PATH environment variable. You should choose the correct binaries depending on your platform and compiler. Example C:\OpenCV\build\x86\vc10\bin. Be careful that the architecture (x86 or x64) should match your MATLAB architecture but not your OS. Also VC version (vc10 or vc11) should match the MEX setup (and probably MATLAB's internal runtime). For example, if you're running MATLAB 32-bit in Windows 7 64-bit with Visual Studio 2010 Express, you should use x86 and vc10. You might need to reboot for changes to take effect.

Alternatively, you can build OpenCV from the sources. Follow this tutorial in the OpenCV documentation for detailed instructions. Just make sure to organize the output in the same directory layout described before, with a structure similar to:

OpenCV
|
+- build
    |-- $ARCH (x86, x64)
    |    |-- $COMPILER (vc10, vc11, vc12, ..)
    |          |-- bin
    |          |    |-- opencv_core2411.dll
    |          |    |-- opencv_core2411d.dll
    |          |    +-- ...
    |          +-- lib
    |               |-- opencv_core2411.lib
    |               |-- opencv_core2411d.lib
    |               +-- ...
    +-- include
         |-- opencv
         |    |-- cv.h
         |    +-- ...
         +-- opencv2
              |-- opencv.hpp
              +-- ...

3) Build mexopencv

Once you satisfy the above requirements, you can proceed to build all MEX functions. Browse to mexopencv root folder, and type the following in the MATLAB command window (you need to specify the path where OpenCV library is installed):

>> mexopencv.make('opencv_path','C:\OpenCV\build')

Note that if you build OpenCV from source, this path specification might not work out of the box. Follow the directory layout described above to arrange the OpenCV .DLL and .LIB files to correctly compile and link your MEX-files with the library.

To remove existing mexopencv binaries, use the following command.

>> mexopencv.make('clean',true)