Installing and Using OpenCV 2.1.1 in Snow Leopard


Update 2011/07/26:

It is easier to install homebrew and then install opencv using it:
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.github.com/gist/323731)"
$ brew install opencv
And you are done!
Now add the headers to your project as shown in step 3 and 4 :)


I use OpenCV very often for my projects. I like it because it has some interesting and very useful implementations. What I don't like is kind of messy and docs update are slow. Specially documentation for Macs is slow!

So I just followed some instructions from here, read some other info from here and realized opencv's new structure by looking at the installed files.

This post shows how to run the sample code I got from here

Step 1: Get and Configure OpenCV 2.1.1:


In the Terminal,
$ svn co https://code.ros.org/svn/opencv/trunk/opencv
$ cd opencv
$ mkdir build
$ cd build
$ cmake ..
Optionally you can configure some flags using cmake configure tool

Step 2: Build and Install OpenCV 2.1.1:

$ make -j8
$ sudo make install

And we are done!

Step 3: Create a Xcode Project:

(I am using Xcode 3.2.2)

In Xcode, create a Standard C++ project by doing: File>New Project...
Select "Application" from MacOS X left menu and "Command line tool" type: "C++ stdc".

Step 4: Use OpenCV 2.1.1


Add OpenCV 2.1.1 Headers Path

  • Select Project>Edit Project Settings...
  • Set Configuration to "All Configurations"
  • In the "Architectures" section, double-click "Valid Architectures" and remove all PPC architectures
  • In "Search Paths" section set "Header Search Paths" to /usr/local/include/
    (What we are doing is add the path where opencv's headers folder is)
  • Close the Project Info window


Add OpenCV 2.1.1 Libraries (Dylibs)

  • Select Project -> New Group and create a group called OpenCV Frameworks
  • With the new group selected, select Project -> Add to Project…
  • Press the "/" key to get the Go to the folder prompt
  • Enter /usr/local/lib
  • Select the libraries needed or all of them:
    libopencv_calib3d.2.1.1.dylib
    libopencv_contrib.2.1.1.dylib
    libopencv_core.2.1.1.dylib
    libopencv_features2d.2.1.1.dylib
    libopencv_highgui.2.1.1.dylib
    libopencv_imgproc.2.1.1.dylib
    libopencv_legacy.2.1.1.dylib
    libopencv_ml.2.1.1.dylib
    libopencv_objdetect.2.1.1.dylib
    libopencv_video.2.1.1.dylib
    


Uncheck "Copy resources" when  asked, importing a reference is enough.

Include OpenCV 2.1.1 headers in your code:


In prior versions of OpenCV we would have written:
#include "cv.h"; or depending on your header search path #include "opencv/cv.h"; but in OpenCV2.1.1 file structure is changed, so including headers like that will cause at least some warnings. (Because those headers are deprecated) So let's do it the new way:

#include "opencv2/imgproc/imgproc.hpp" //for image processing
#include "opencv2/highgui/highgui.hpp" //for GUI

You will need to include more headers if you are doing other stuff like machine learning, etc. If you are not sure what headers you should include just check directory:
/usr/local/include/opencv2/
You will realize that OpenCV 2.1.1 is now divided in modules!



Now build and Run and you should have your program running ;)
You can download my sample project from here.

I hope it helps ;)

This work is licensed under BSD Zero Clause License | nacho4d ®