1. Install Opencv Linux
  2. Opencv Mac Os Install
  3. Install Opencv In Windows

If you are only interested in using the library under Matlab, now there is a precompiled mex-library for 64-bit systems available. You can download it from:

These versions have been added around March 2016, so please be aware that later additions may not be included in this distribution. You can go immediately to Use under Matlab to receive further instructions on the Matlab interface.

OpenGV is freely available under

Get a Free Trial: Pricing Info: Ready to Buy: Use the OpenCV interface to bring OpenCV b. Hey everyone, I've got following problem, I want to use sift/surf feature detection with Python OpenCV 3. I followed the install-guide for installing 'OpenCV from source' and built the ALLBUILD and the INSTALL project. But nothing happened to my Python27 directory (no errors in the builds, everything was successful). My question is: how can I install the INSTALL project to my python directory. There is a way to use opencv from matlab without compiling any mex files, and without using the computer vision toolbox. You can call opencv through matlab via python commands. 1) Download and install the CPython distribution, not Anaconda.

That's a linking issue; ippicv is Intel IPP library (to be exact it's a free subset of the library specifically for OpenCV). The library is an optional optimization but I think that IPP-ICV should be downloaded by default by the CMake build scripts on supported platforms. I'm not very familiar with homebrew stuff, so try recompiling opencv from source this time using the explicit -DWITHIPP=ON.

You may first have to register on github.com. You can just download a zip-file with the code, but we strongly recommend that you make yourself familiar with git. Git is a distributed version-control and source code management system. By using git to clone the repository locally, you can easily get updates at a later stage, and also facilitate the integration of own improvements or extensions into the original repository on github. This is done using the pull-request mechanism.

To clone the library under Mac OSX or Linux, simply type (assuming that git is installed):

Under Windows you probably have a similar option. More information about git can be found here:

Follow the 'Try git' link for an amazing interactive tutorial.

  • Setup the required tools for compilation of standard libraries under Linux (gcc compiler etc). Type:

  • Install cmake. CMake is a cross-platform, open-source build system used for pretty much anything in the compilation process for the compilation/linking of the library. Type:

  • Install eigen3. Eigen3 is a powerful linear algebra library used for all computations in OpenGV. You can either use an installed version of a local install (unzipped version of Eigen3 downloaded from Eigen website).

  • Go to the top-level directory of OpenGV. Type:

    If a message like 'Could NOT find Eigen (missing: EIGEN_INCLUDE_DIR EIGEN_VERSION_OK)' appears. It's certainly because that you does not have Eigen3 installed on your computer system path. You can specify to cmake the path where Eigen is located by adding:

  • Done. The default configuration does not build the tests or python-wrappers, please set the according variables in CMakeLists.txt to ON if you desire the tests or python-wrappers to be built as well.
  • We need a suitable compiler for C++. We chose Visual Studio Express, which is free. Google for 'Microsoft Visual Studio Express', it should be one of the first links. Make sure you download and install the 'Windows Desktop version'. If you are in a school setting without Administrator rights, just go to your local IT guy and ask him to install Microsoft Visual Studio on your machine.

  • We also need CMake under Windows. Go to:

    and download the latest version. In a school setting without administrator rights, chose to download the zip-file. Extract it somewhere.

  • Open a new Developer Command Prompt for VS2012 and make sure all VS path variables are correctly set by checking the output of PATH. We also need to add the cmake-tools to the path. Add it by typing

  • Go to the opengv directory and add a build folder
  • Now go to the

    directory, and setup the build process by typing:

    You need to add the correct generator for your Visual Studio version. I downloaded Visual Studio 2012, so it's 11 :)

  • Now build the library by typing:

    inside the build directory. While there is not a single warning under Linux, there are thousands of warnings under Windows :) If anyone knows the reason, please let us know.

  • Note that we Eigen dependency is not longer included. It is better to get a fresh download of Eigen on your computer, and specify to cmake the Eigen include path with -DEIGEN_INCLUDE_DIR='path'.

Has been succesfully tested as well.

  • Install homebrew: http://brew.sh/
  • Type: 'brew install cmake eigen'
  • Compile using normal cmake procedure.

Installation on the host OS (including the headers) can be activated by simply launching the install target. By using 'sudo make install' on Linux and OSX and by compiling the install target on the opengv Visual Studio solution in Windows. Sudo is required for system install. You can choose to have a local installation path by setting the cmake variable CMAKE_INSTALL_PREFIX to the path of your choice by using -DCMAKE_INSTALL_PREFIX:STRING='YourInstallPath' in the cmake command line.

  • First setup the compiler from Matlab. Go to the matlab console and type

    and chose the right compiler by following the instructions. You will have to chose the same compiler than the one you used for compiling the opengv library before-hand. Under Windows you might also run into the following problem. Depending on the distribution (e.g. R2012b), Matlab does not yet 'know' your compiler (e.g. Visual Studio 2012), so you will have to additionally follow the instructions under

    to get things running. Also note that the Express compilers are not supported by Matlab, we ran into some issues when trying to use them. Please report if you have a solution to that.

  • Once this is done, you can compile the mex-file by going to the opengv/matlab folder and typing in the console

  • An additional note on 64-bit Windows/Matlab systems: If you have a Matlab version that is 64-bit, you will have to also compile OpenGV in 64-bit. You will have to follow two steps for this under Windows. The first one is to make sure that you open an x64 native tools command prompt to make the x64 Visual Studio compiler visible. The second one is to-when running cmake-extend the generator name by ' Win64'. The final command to run cmake finally looks as follows:

    The actual build command stays the same.

The following has been tested under Ubuntu 12.04 and a recent Matlab edition (>2013) (thanks to Oliver Dunkley for providing this information).

  • Install Matlab with the provided installer, and then add the matlab-support package through the package-repositories. This basically takes care of setting all the compiler stuff, adding a launcher, etc.
  • In order to make Matlab know about the shared object opengv.so, the path to opengv.so has to be added to LD_LIBRARY_PATH. Open .bashrc and add the line

    and then start Matlab from the terminal, it'll know about opengv ...

  • Go to the opengv/matlab-folder inside Matlab, and issue the command

    Note the lib directory does not contain a Release subfolder under linux, and that the -cxx option has to be added.

To compile the Matlab interface under OSX, use the same command as under Windows, with adapted library folder (-L../build/lib instead of -L../build/lib/Release). You of course need to make sure again that Matlab knows where to find the library, and that a suitable compiler is set up in Matlab as well.

The compliation of the Python wrappers can be enabled by setting the option BUILD_PYTHON to ON. Note that the python wrappers depend additionally on boost, and that the wrapper currently only allows access to the central methods.

Once your have a system or local install of opengv you can use it in your own project. In your cmake file, add the search for the opengv library:

Then run cmake for your project (if you are using a local install of opengv, you can specify where the library is located by using -Dopengv_DIR:

Last Updated: 2014/08/26

This tutorial documents step by step how to install Xcode, OpenCV (with homebrew) and mexopencv (for use of OpenCV in MATLAB). There are also two coding examples that instruct how to setup and run a C++ example in Xcode and an m-file example in MATLAB.

I am fairly confident the same procedure will work on other versions of Mac OS X and MATLAB as well. Contact Eric Cristofalo (emc73@bu.edu) for questions or comments.

____________________________________________________________________________
____________________________________________________________________________

System Requirements

Mac OS X 10.9.4
MATLAB_R2014a

What Will Be Installed

Apple Xcode 5.1.1
Homebrew
OpenCV 2.9.4
mexopencv

____________________________________________________________________________
____________________________________________________________________________

OpenCV Download and Installation Instructions

1) Download Apple Xcode 5.1.1
Available for free in the Apple App Store
Install Command Line Tools
In Terminal type:
xcode-select —install

2) Download and install Homebrew
In Terminal, type:
ruby -e '$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)'

3) Download and install the latest copy of OpenCV
In Terminal, type:
brew tap homebrew/science
brew install opencv

OpenCV and all necessary packages are now located in:
usr/local/Cellar

4) Ensure OpenCV is functional with Xcode (See the following Xcode instructions)

____________________________________________________________________________
____________________________________________________________________________

Instructions for OpenCV with Xcode

1) Create New Xcode Project in C++
File -> New Project
Create a C++ Project

2) Add Libraries To Project
Right-click on project
Select “Add Files to “project name” … “
Navigate to /usr/local/lib
Select all libopencv_*.2.4.9.dylib files
Select OK

3) Change Build Settings
a) Header Search Paths
/usr/local/include
b) Library Search Paths
/usr/local/lib
c) Apple LLVM 5.1 – Language – C++
libc++ (LLVM C++ standard library with C++11 support)

4) Sample main.cpp code for Xcode Project

/*--------------------------------------------------------------------------
File Name: main.cpp
Date Created: 2014/08/21
Date Modified:
Author: Eric Cristofalo
Contact: eric.cristofalo@gmail.com
Description: Testing OpenCV
Inputs:
Outputs:
Example:
---------------------------------------------------------------------------*/
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
if( argc != 1)
{
cout <<' Usage: display_image ImageToLoadAndDisplay' << endl;
return -1;
}

// Initialize Image Matrix
Mat image;

// Read the File
image = imread(“PathToAnyImage/NameOfAnyImage.jpg”,CV_LOAD_IMAGE_COLOR);

// Check For Invalid Input
if(! image.data )
{
cout << “Could not open or find the image” << endl;
return -1;
}

// Create a Window For Display
namedWindow( “Display window”, WINDOW_AUTOSIZE );

// Show Our Image Inside It
imshow( “Display window”, image );

// Wait For a Keystroke in the Window
waitKey(0);
return 0;
}

____________________________________________________________________________
____________________________________________________________________________

OPTIONAL: Fix MATLAB’s Java Version

Only for MacBook Retina Screen Resolution Problem

1) Navigate to MATLAB’s current java directory:
/Applications/MATLAB_R2014a.app/sys/java/jre/maci64/jre

2) Copy the contents of this folder to some other folder for safe keeping

3) Copy the contents of the following folder to MATLAB’s java directory from step 1:
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home

____________________________________________________________________________
____________________________________________________________________________

mexopencv Download and Compile Instructions

1) Download the latest version of mexopencv
https://github.com/kyamagu/mexopencv
Place the unzipped folder anywhere on machine

2) Edit MATLAB MEX Options
Open mexopts.sh with Xcode:
/Applications/MATLAB_R2014a.app/bin/mexopts.sh
Type the following in MATLAB if no mexopts.sh file exits
mex -setup
Make the following changes:

Change
CC=’xcrun -sdk macosx10.7 clang’
to
CC=’clang’

Remove the line
MW_SDKROOT_TMP=”findxcode-select -print-path-name MacOSX10.7.sdk”

Change
MW_SDKROOT=`$MW_SDKROOT_TMP`
to
MW_SDKROOT=’/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/’

After
CFLAGS=”$CFLAGS -fexceptions”
add a new line
CFLAGS=”$CFLAGS -Dchar16_t=uint16_t”

Change
CXX=’xcrun -sdk macosx10.7 clang++’
to
CXX=’clang++’

After
CXXFLAGS=”-fno-common -fexceptions -arch $ARCHS -isysroot $MW_SDKROOT -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET”
add a new line
CXXFLAGS=”$CXXFLAGS -std=c++11 -stdlib=libc++”

3) Select this Mex Options file with MATLAB
Copy and paste mexopts.sh into the following directory:
/Users/ericcristofalo/.matlab/R2014a

In MATLAB, type:
mex -setup
Type ‘1’ to select the recently updated configuration file
Type ‘y’ to accept

4) Compile mexopencv
Navigate to your mexopencv folder in Terminal and type:
make MATLABDIR=/Applications/MATLAB_R2014a.app clean
make MATLABDIR=/Applications/MATLAB_R2014a.app

5) Ensure OpenCV is functional with MATLAB (See the MATLAB instructions)

____________________________________________________________________________
____________________________________________________________________________

Create .app to Open MATLAB with Correct libtiff Libraries

1) Create a new AppleScript project with the following text:

(*
--------------------------------------------------------------------------
File Name: main.scpt
Date Created: 2014/08/20
Date Modified: 2014/08/26
Author: Eric Cristofalo
Contact: eric.cristofalo@gmail.com
Description: MATLAB Launcher
Adds non-MATLAB version of libtiff, launches MATLAB
--------------------------------------------------------------------------
*)
# Open MATLAB with Correct Libraries
do shell script 'DYLD_INSERT_LIBRARIES=/usr/local/lib/libtiff.5.dylib /Applications/MATLAB_R2014a.app/bin/matlab -desktop'

2) Save the AppleScript program as an Application.

Install Opencv Linux

3) Place this application on the dock to open MATLAB this way from now on.

4) Change the application icon to a MATLAB icon
Copy and paste the “MATLAB.icns” document from:
/Applications/MATLAB_R2014a.app/Contents/Resources
to:
/PATH_TO_YOUR_APP/YOUR_APP.app/Contents/Resources
Rename the pasted “MATLAB.icns” to “applet.icns”

____________________________________________________________________________
____________________________________________________________________________

Instructions for OpenCV with MATLAB

1) Add mexopencv to your MATLAB path
Edit “startup.m” located in:
/Applications/MATLAB_R2014a.app/toolbox/local
Create “startup.m” if you don’t have one already

Opencv Mac Os Install

Add the line:
addpath(genpath(‘/PathToMexopencvFolder’));

Install Opencv In Windows

2) sample mexopencvTest.m file to test mexopencv functionality

%--------------------------------------------------------------------------
%
% File Name: mexopencvTest.m
% Date Created: 2014/08/26
% Date Modified: 2014/08/26
%
% Author: Eric Cristofalo
% Contact: eric.cristofalo@gmail.com
%
% Description: Basic functions used to test the mexopencv install
%
% Inputs: N/A
%
% Outputs: N/A
%
% Example: N/A
%
%--------------------------------------------------------------------------
clear all; close all; clc;
%% Load a Test Image
im = imread('test.jpg');
figure(1); imshow(im);
%% Blur Filter
dst = cv.blur(im, 'KSize', [10,10]);
figure(2),imshow(dst);
%% Transform to Grayscale
gr = cv.cvtColor(im, 'RGB2GRAY');
figure(3),imshow(gr);
%% Find Corners
corners = cv.goodFeaturesToTrack(gr);
figure(4),imshow(im); hold on;
for i = 1:length(corners)
c = corners{i};
plot(c(1),c(2),'ro');
end
hold off;
%% Threshold
thresh = cv.threshold(gr, 'auto','Method','Binary');
figure(5),imagesc(thresh);
%% Contour Detection
contours = cv.findContours(thresh);
imC = cv.drawContours(gr, contours);
figure(6),imshow(imC);
%% Edge Detection
edges = cv.Canny(gr, 200);
figure(7),imshow(edges);
%% Hough Transform
% Probabilistic Hough Transform
minLineLength = 10;
maxLineGap = 10;
lines = cv.HoughLinesP(edges,'MinLineLength',minLineLength,...
'MaxLineGap',maxLineGap);
% XY Point Data
linesM = zeros(length(lines),4);
for i = 1:length(lines)
x = lines(i);
linesPlot(i,:) = x{1};
end
figure(8),imshow(edges);
hold on;
% Plot Line Segments
for i = 1:length(linesPlot)
plot([linesPlot(i,1),linesPlot(i,3)],[linesPlot(i,2),linesPlot(i,4)],...
'r','LineWidth',2)
end
hold off;

____________________________________________________________________________
____________________________________________________________________________

Happy coding!