-
Notifications
You must be signed in to change notification settings - Fork 319
Installation (Windows, Octave, OpenCV 3)
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.
First download all of the following (replace *
with the latest version):
-
octave-4.*-w32.zip
from https://ftp.gnu.org/gnu/octave/windows/ -
cmake-*-win32-x86.zip
from https://cmake.org/download/ -
ninja-win.zip
from https://github.com/ninja-build/ninja/releases/latest -
opencv-3.4.1.zip
from https://github.com/opencv/opencv/archive/3.4.1.zip -
opencv_contrib-3.4.1.zip
from https://github.com/opencv/opencv_contrib/archive/3.4.1.zip -
mexopencv-master.zip
from https://github.com/kyamagu/mexopencv/archive/master.zip
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
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%"
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);
Help: Stack Overflow (MATLAB, OpenCV) | MATLAB Answers | OpenCV Answers
- Windows + MATLAB
- Windows + Octave
- Linux + MATLAB
- Linux + Octave
- macOS + MATLAB
- macOS + Octave
- Windows + MATLAB
- Linux + MATLAB
- macOS + MATLAB