• This repository has been archived on 25/Jan/2022
  • Stars
    star
    660
  • Rank 68,297 (Top 2 %)
  • Language
    MATLAB
  • License
    Other
  • Created almost 13 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Collection and a development kit of matlab mex functions for OpenCV library

mexopencv

Travis AppVeyor License

Collection and development kit of MATLAB MEX functions for OpenCV library.

The package provides MATLAB MEX functions that interface with hundreds of OpenCV APIs. Also the package contains a C++ class that converts between MATLAB's native data type and OpenCV data types. The package is suitable for fast prototyping of OpenCV application in MATLAB, use of OpenCV as an external toolbox in MATLAB, and development of custom MEX functions.

The current version of mexopencv is compatible with OpenCV 3.4.1.

For previous OpenCV 3.x versions, checkout the corresponding tags:

For OpenCV 2.x, checkout these older branches:

Consult the wiki for help.

Table of Contents

Structure

The project tree is organized as follows:

+cv/             OpenCV or custom API directory
+mexopencv/      mexopencv utility API directory
doc/             directory for documentation
include/         header files
lib/             directory for compiled C++ library files
samples/         directory for sample application codes
src/             directory for C++ source files
src/+cv/         directory for MEX source files
src/+cv/private/ directory for private MEX source files
test/            directory for test scripts and resources
opencv_contrib/  directory for sources/samples/tests of additional modules
utils/           directory for utilities
Doxyfile         config file for doxygen
Makefile         make script
README.markdown  this file

Build

Prerequisite

Depending on your platform, you also need the required build tools:

  • Linux: g++, make, pkg-config
  • OS X: Xcode Command Line Tools, pkg-config
  • Windows: Visual Studio

Refer to the Makefile and make.m scripts for a complete list of options accepted for building mexopencv across supported platforms.

Refer to the wiki for detailed build instructions.

OpenCV

Currently, mexopencv targets the final 3.4.1 stable version of OpenCV. You must build it against this exact version, rather than using the bleeding-edge dev-version of opencv and opencv_contrib. UNIX users should consider using a package manager to install OpenCV if available.

DO NOT use the "master" branch of opencv and opencv_contrib! Only the 3.4.1 release is supported by mexopencv.

Linux

First make sure you have OpenCV 3.4.1 installed in the system:

  • if applicable, install OpenCV 3 package available in your package manager (e.g., libopencv-dev in Debian/Ubuntu, opencv-devel in Fedora). Note that these packages are not always up-to-date, so you might need to use older mexopencv versions to match their opencv package version.

  • otherwise, you can always build and install OpenCV from source:

      $ cd <opencv_build_dir>
      $ cmake <options> <opencv_src_dir>
      $ make
      $ sudo make install
    

At this point, you should make sure that the pkg-config command can identify and locate OpenCV libraries (if needed, set the PKG_CONFIG_PATH environment variable to help it find the opencv.pc file):

$ pkg-config --cflags --libs opencv

If you have all the prerequisites, go to the mexopencv directory and type:

$ make

This will build and place all MEX functions inside +cv/. Specify your MATLAB directory if you installed MATLAB to a non-default location:

$ make MATLABDIR=/opt/local/MATLAB/R2017a

You can also work with Octave instead of MATLAB by specifying:

$ make WITH_OCTAVE=true

To enable support for contributed modules, you must build OpenCV from both opencv and opencv_contrib sources. You can then compile mexopencv as:

$ make all contrib

Finally you can test mexopencv functionality:

$ make test

Developer documentation can be generated with Doxygen if installed:

$ make doc

This will create HTML files under doc/.

Refer to the wiki for detailed instructions on how to compile OpenCV for both MATLAB and Octave.

OS X

Currently, the recommended approach to install OpenCV in OS X is Homebrew. Install Homebrew first, and do the following to install OpenCV 3:

$ brew install pkg-config homebrew/science/opencv3
$ brew link opencv3

Otherwise, you can build OpenCV from source, similar to the Linux case.

If you have all the prerequisites, go to the mexopencv directory and run (modifying the options as needed):

$ make MATLABDIR=/Applications/MATLAB_R2016a.app PKG_CONFIG_MATLAB=opencv3 LDFLAGS=-L/usr/local/share/OpenCV/3rdparty/lib -j2

Replace the path to MATLAB with your version. This will build and place all MEX functions inside +cv/.

Windows

Refer to the wiki for detailed instructions on how to compile OpenCV on Windows, and build mexopencv against it.

In a nutshell, execute the following in MATLAB to compile mexopencv:

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

Replace the path above with the location where OpenCV binaries are installed (i.e location specified in CMAKE_INSTALL_PREFIX while building OpenCV).

Contrib modules are enabled as:

>> addpath('C:\path\to\mexopencv')
>> addpath('C:\path\to\mexopencv\opencv_contrib')
>> mexopencv.make('opencv_path','C:\OpenCV\build', 'opencv_contrib',true)

If you have previously compiled mexopencv with a different configuration, don't forget to clean old artifacts before building:

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

Usage

Once MEX functions are compiled, you can add path to the project directory and call MEX functions within MATLAB using package name cv.

addpath('/path/to/mexopencv');
addpath('/path/to/mexopencv/opencv_contrib');

% recommended
out = cv.filter2D(img, kern);  % with package name 'cv'

% not recommended
import cv.*;
out = filter2D(img, kern);     % no need to specify 'cv' after imported

Note that some functions such as cv.imread will overload MATLAB's built-in imread function when imported. Use the scoped name when you need to avoid name collision. It is also possible to import individual functions. Check help import in MATLAB.

Check a list of functions available by help command in MATLAB.

>> help cv;              % shows list of functions in package 'cv'

>> help cv.VideoCapture; % shows documentation of VideoCapture

Look at the samples/ directory for examples.

Documentation

mexopencv includes a simple documentation utility that generates HTML help files for MATLAB. The following command creates HTML user documentation under doc/matlab/ directory.

addpath('/path/to/mexopencv/utils');
MDoc;

On-line documentation is available.

Unit Testing

You can test the functionality of compiled files by UnitTest class located inside test directory.

addpath('/path/to/mexopencv/test');
UnitTest;

Look at the test/unit_tests/ directory for all unit-tests.

License

The code may be redistributed under the BSD 3-Clause license.

More Repositories

1

js-segment-annotator

Javascript image annotation tool based on image segmentation.
JavaScript
524
star
2

faiss-wheels

Unofficial faiss wheel builder
Python
286
star
3

skia-python

Python binding to Skia Graphics Library
Jupyter Notebook
240
star
4

bbox-annotator

A bounding box annotation widget written in CoffeeScript.
HTML
162
star
5

mexplus

C++ Matlab MEX development kit.
C++
99
star
6

paperdoll

Paper doll parser implementation from ICCV 2013
Jupyter Notebook
83
star
7

matlab-json

Use official API: https://mathworks.com/help/matlab/json-format.html
Java
52
star
8

psd2svg

PSD to SVG converter.
Python
52
star
9

matlab-lmdb

Matlab LMDB wrapper
C
38
star
10

js-graph-annotator

Javascript widget to draw a graph annotation on an image.
JavaScript
37
star
11

matlab-sqlite3-driver

Matlab driver for SQLite3 database
C
35
star
12

sge-gpuprolog

Scripts to manage NVIDIA GPU devices in SGE 6.2u5
Shell
25
star
13

photoshop-connection

Python package to remotely execute ExtendScript in Adobe Photoshop.
Python
22
star
14

pf-segmentation

Image segmentation algorithm of [P Felzenszwalb 2004] for Matlab
C++
16
star
15

matlab-leveldb

Matlab LevelDB wrapper
C++
11
star
16

matlab-tcpip

TCP/IP server and client for Matlab
MATLAB
11
star
17

matlab-fscache

File-system based cache for Matlab.
MATLAB
4
star
18

matlab-bson

Matlab BSON encoder based on libbson.
C
4
star
19

lda-matlab

Latent Dirichlet Allocation for Matlab
C++
4
star
20

matlab-bdb

Persistent key-value storage for matlab.
C++
3
star
21

matlab-batch

Distributed Matlab job execution library.
MATLAB
3
star
22

matlab-serialization

Matlab object serialization functions
C++
2
star
23

matlab-ejdb

EJDB Matlab binding
C++
1
star