Mac OS X OpenCV Port

This page is devoted to information specific to the OS X build of OpenCV. Things are changing quickly due to recent work by Willow Garage, and the transition to the CMake build system.

1. Easy build via Macports

For Snow Leopard users who can live without quicktime (iSight and perhaps other external cameras) and carbon (GUI) support, you can now build OpenCV 2.0.0 easily as a 64-bit library. The problems mentioned in this Macports ticket was fixed in revision r64069. Assuming Macports installed, first use:

sudo port selfupdate

to update the Macports base and the port tree. Then, simply:

sudo port install opencv

to build OpenCV 2.0.0 in 64-bit.

If you encounter errors, try installing its dependents with +universal whenever possible.

By default OpenCV is installed to /opt/local/ according to Macports conventions. The opencv_xxxx utilities are located in /opt/local/bin/, the dynamic libraries in /opt/local/lib/ and the header files in /opt/local/include/opencv/.

To use the libraries, include the required files with standard includes. For example:

#include <cv.h>
#include <highgui.h>

If you use Xcode, the instructions are similar to the ones in method 2. It only differs that /usr/local becomes /opt/local.

2. Build from source using the CMake build system (new)

The GNU autotools methods (configure, make, make install) are being obsoleted. OpenCV has now switched to the CMake build system.

Getting the source code

Make sure you have subversion installed (built-in since Snow Leopard). If Macports is your primary package manager, use:

sudo port install subversion

if not using macports or it gives an error, try:

sudo fink install svn-ssl

Make sure you have cmake installed. This can also be installed with Macports:

sudo port install cmake

Check out the source code into a clean directory and cd into the source directory after the download is complete:

svn co https://code.ros.org/svn/opencv/trunk/opencv
cd opencv

svn co https://code.ros.org/svn/opencv/trunk/opencv -r 3059
cd opencv

Use CMake to build

To use CMake to generate Unix Makefiles, type:

sudo cmake -G "Unix Makefiles" .

You can specify many configuration options in the above command. For examples:

For the case you need the CMake GUI for other options, replace cmake with ccmake. If the arrow keys fail, you can use the following commands instead:

  ctrl + N : next option
  ctrl + P : previous options
  ctrl + D : down one page
  ctrl + U : up one page

To compile with Intel Threading Building blocks, use ccmake (the Cmake GUI) to specify the lib and include paths to your installation of TBB.

After setting the build options, hit 'c' to configure. Hit 'g' to generate the config file and exit ccmake.

Finally, follow the usual "make, make install" method:

sudo make -j8
sudo make install

Using the OpenCV libraries in an Xcode OS X project

These instructions were written for Xcode 3.1.x

Now you should be able to include the OpenCV libraries, compile, and run your project

3. Building as an Xcode Framework using the make_frameworks.sh script (obsoleted)

Note: the CMake build system should ultimately make this obsolete, one may remove this section when the CMake building is mature on the Mac. By the way, the make_framework.sh script has been removed since revision 2528. The last revision where make_framework.sh successfully builds, as I tested, is r2492.

OpenCV can now be built as a Mac OS X Framework useable with XCode. Just invoke the './make_frameworks.sh' script and you will obtain a Universal Framework named "OpenCV.framework" meant as a Private Framework.

Additionally, a pre-built version (universal binary Private Framework, again together with a demo application) is available. See the PrivateFramework wiki page or directly download it from http://www.ient.rwth-aachen.de/~asbach/OpenCV-Private-Framework-1.1.dmg .

A more recent version of the framework can be found here http://www.ient.rwth-aachen.de/cms/software/opencv/ or downloaded directly from http://www.ient.rwth-aachen.de/~asbach/OpenCV-Private-Framework-1.2.dmg

OpenCV 2.0 Universal Framework (tested on ppc and i386 Leopard and Snow Leopard): Here is an universal Framework for Mac ppc/i386 built from the OpenCV 2.0 released in September09. By the way, I also fixed some bugs and add some improvements:

-> a bug on Mac (carbon) that prevented cvCloseWindow/cvCloseAllWindow from working.
-> a bug when 2 cameras capture images simultaneously (black bands) (see picture bellow)
-> The trackbar now displays its current value (see picture bellow) and is resized according to its name.

Those fix/improvements are added to this framework.

http://vislab.cs.vt.edu/~vislab/wiki/images/9/9b/Comp.png http://vislab.cs.vt.edu/~vislab/wiki/images/7/79/Picture_1.png

4. Building the old UNIX way

The following shows you how to compile OpenCV CVS for Mac OS X, using QuickTime video I/O and Carbon windowing. Image I/O is currently done via external libraries.

External dependencies

The code relied on external libraries for image loading and saving as well as video reading / writing. You can still enable reading JPEG, PNG and TIFF images 'the traditional way' with external libraries installed via Fink or DarwinPorts. However, this is no longer required nor recommended.

Unfortunately, we still have no working (i.e. native) video writer for Mac OS X. If you need video writing, you should currently configure for ffmpeg or xine and disable QuickTime. The downside of this is that you will lose QuickTime video input at the same time. And still ffmpeg video writing support is as buggy on Mac OS X as it is on Linux (for OpenCV). Volunteers?

Configuring

To configure the code for your environment, go into the source directory. It’s a good idea to first make a special build directory:

mkdir build; cd build

Then run the provided configure script, giving it the location of the external libraries. For Fink, use:

../configure CPPFLAGS="-I/sw/include" LDFLAGS="-L/sw/lib"

For MacPorts users, the line reads:

../configure CPPFLAGS="-I/opt/local/include" LDFLAGS="-L/opt/local/lib"

You can add additional tuning parameters as well, e.g. CXXFLAGS="-mcpu=G5 -mtune=G5". See also the output of ../configure --help for additional arguments.

Compiling and Installing

Finally, compile and install the code:

make
sudo make install

The install goes into /usr/local by default; of course you can change that with the usual --prefix argument to configure. You might also want to run the tests with make check.

Other Resources

Links:

Attachments:

Collected Information

Compiling Universal Binaries

The --enable-universal-build switch has been removed again since it doesn't allow building on intel machines ... You can still try out what it did by configuring with:

./configure CFLAGS="-arch i386 -arch ppc" CXXFLAGS="-arch i386 -arch ppc" --disable-dependency-tracking

As an alternative, we now have a small build script that configures and builds twice (once for ppc, once for intel) and then merges the binaries with lipo. We can and will extend this to more architectures whenever Mac OS X 10.5 Leopard is released, since it finally comes with 64bit compilers for intel. In addition to those then natural 4 platforms (intel/ppc * 32/64), it might be nice to provide specially optimized variants for G5, G4, G3 (-mcpu=...) to maximize speed on older hardware. This however requires additional testing (and performance testing).

See also: Compiling for Multiple Architectures in http://developer.apple.com/documentation/Porting/Conceptual/PortingUnix/

A (very old) list of supported quicktime codecs can be found at QuickTimeCodecs


OpenCVWiki: Mac_OS_X_OpenCV_Port (last edited 2010-07-09 04:54:39 by RyanLeiTaiwan)