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

Installation (Windows, Octave, OpenCV 3)

Amro edited this page Oct 4, 2018 · 12 revisions

This page is a guide on how to install mexopencv on Octave for Windows. It covers Octave 4, OpenCV 3 (v3.4.1), and latest mexopencv from master branch.

The instructions below demonstrate building opencv/mexopencv 32-bit binaries for Octave x86. It should be easy to adapt for building 64-bit binaries for the x64 version of Octave.

1) Dependencies

First download all of the following (replace * with the latest version):

Then extract the files to get the following directory structure:

  • C:\dev\octave\bin\octave.exe
  • C:\dev\cmake\bin\cmake.exe
  • C:\dev\ninja\ninja.exe
  • C:\dev\opencv\README.md
  • C:\dev\opencv_contrib\README.md
  • C:\dev\mexopencv\README.markdown
  • C:\dev\build\

Next set up the path environment variable to expose all the necessary tools:

> set "PATH=C:\dev\ninja;C:\dev\cmake\bin;C:\dev\octave\bin;%PATH%"
> set OCTAVE_HOME=C:\dev\octave

NOTE: In v3.4.1, we need to apply some temporary fixes for proper MinGW support:

$ cd C:\dev\opencv
$ wget https://gist.github.com/amroamroamro/de4ac4155f35451ebc6300f87cec1f06/raw/a601f191592793134a0f21f3eba31c86fd401bbf/mingw.patch
$ git apply mingw.patch
$ wget https://github.com/opencv/opencv/pull/10936.patch
$ git apply 10936.patch

2) OpenCV

Here we configure and build OpenCV using MinGW (included with Octave):

> cd C:\dev\build
> cmake -G Ninja -DBUILD_DOCS:BOOL=OFF -DBUILD_EXAMPLES:BOOL=OFF -DBUILD_PACKAGE:BOOL=OFF -DBUILD_PERF_TESTS:BOOL=OFF -DBUILD_TESTS:BOOL=OFF -DBUILD_JAVA:BOOL=OFF -DENABLE_PRECOMPILED_HEADERS:BOOL=OFF -DWITH_CUDA:BOOL=OFF -DWITH_CUBLAS:BOOL=OFF -DWITH_CUFFT:BOOL=OFF -DWITH_NVCUVID:BOOL=OFF -DWITH_IPP:BOOL=OFF -DWITH_MSMF:BOOL=OFF -DWITH_MATLAB:BOOL=OFF -DWITH_VTK:BOOL=OFF -DBUILD_opencv_apps:BOOL=OFF -DBUILD_opencv_cudaarithm:BOOL=OFF -DBUILD_opencv_cudabgsegm:BOOL=OFF -DBUILD_opencv_cudacodec:BOOL=OFF -DBUILD_opencv_cudafeatures2d:BOOL=OFF -DBUILD_opencv_cudafilters:BOOL=OFF -DBUILD_opencv_cudaimgproc:BOOL=OFF -DBUILD_opencv_cudaobjdetect:BOOL=OFF -DBUILD_opencv_cudalegacy:BOOL=OFF -DBUILD_opencv_cudaoptflow:BOOL=OFF -DBUILD_opencv_cudastereo:BOOL=OFF -DBUILD_opencv_cudawarping:BOOL=OFF -DBUILD_opencv_cudev:BOOL=OFF -DBUILD_opencv_java:BOOL=OFF -DBUILD_opencv_java_bindings_generator:BOOL=OFF -DBUILD_opencv_js:BOOL=OFF -DBUILD_opencv_python2:BOOL=OFF -DBUILD_opencv_python3:BOOL=OFF -DBUILD_opencv_python_bindings_generator:BOOL=OFF -DBUILD_opencv_ts:BOOL=OFF -DBUILD_opencv_viz:BOOL=OFF -DBUILD_opencv_world:BOOL=OFF -DBUILD_opencv_matlab:BOOL=OFF -DBUILD_opencv_cvv:BOOL=OFF -DBUILD_opencv_hdf:BOOL=OFF -DBUILD_opencv_sfm:BOOL=OFF -DCMAKE_BUILD_TYPE:STRING=Release -DOPENCV_ENABLE_NONFREE:BOOL=ON -DOPENCV_EXTRA_MODULES_PATH:PATH="C:/dev/opencv_contrib/modules" C:\dev\opencv
> cmake --build .
> cmake --build . --target install
> copy /y "c:\dev\build\unix-install\opencv.pc" "c:\dev\build\install"

You should now add OpenCV binaries to the system path:

> set OPENCV_DIR=C:\dev\build\install
> set "PATH=C:\dev\build\install\x86\mingw\bin;%PATH%"

3) mexopencv

Finally we build mexopencv in Octave using mexopencv.make:

>> more off
>> warning('off', 'Octave:shadowed-function') % HACK
>> setenv('PATH', ['C:\dev\build\install\x86\mingw\bin' pathsep getenv('PATH')])

>> cd('C:\dev\mexopencv')
>> addpath('C:\dev\mexopencv')
>> addpath('C:\dev\mexopencv\opencv_contrib')
>> addpath('C:\dev\mexopencv\+cv\private')                % HACK
>> addpath('C:\dev\mexopencv\opencv_contrib\+cv\private') % HACK
>> mexopencv.make('opencv_path','C:\dev\build\install', 'opencv_contrib',true);

Alternatively we can also build mexopencv using the Makefile:

> set PKG_CONFIG_PATH=C:\dev\build\install
> cd C:\dev\mexopencv
> make MATLABDIR=/c/dev/octave WITH_OCTAVE=true WITH_CONTRIB=true all contrib

You can now call OpenCV functions in Octave as:

>> cv.getBuildInformation()

To verify the installation, you can optionally run the full test suite:

>> addpath('C:\dev\mexopencv\test')
>> UnitTest('ContribModules',true);