Install OpenCV 2.3.1a in Mac OS X 10.6

Download OpenCV 2.3.1a and unpack it:

curl -L -O http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.3.1/OpenCV-2.3.1a.tar.bz2
tar xzvpf OpenCV-2.3.1a.tar.bz2

Then configure and compile it:

cd OpenCV-2.3.1
mkdir build
cd build
cmake -G "Unix Makefiles" ..
make
sudo make install

You can use different options when executing cmake:

  • -D BUILD_EXAMPLES=ON -> Compile example programs.
  • -D BUILD_TESTS=OFF -> Don’t compile tests.
  • -D BUILD_NEW_PYTHON_SUPPORT=OFF -> Don’t compile new Python support.
  • -D WITH_CARBON=ON -> (mostly for Leopard and below) To use Carbon instead of Cocoa (since version r2909).
  • -D WITH_QUICKTIME=ON -> (mostly for Leopard and below) To use QuickTime for the I/O of Video instead of QTKit (since version r2924). If you use Snow Leopard and need Carbon and QuickTime, you must also specify -D CMAKE_OSX_ARCHITECTURES=i386, -D CMAKE_C_FLAGS=-m32 and -D CMAKE_CXX_FLAGS=-m32.

If you don’t have cmake installed download a “binary distribution” from cmake.org. For example http://www.cmake.org/files/v2.8/cmake-2.8.7-Darwin64-universal.dmg.

You can compile OpenCV for an specific architecture using CMAKE_OSX_ARCHITECTURES with those values:

i386
x86_64
ppc
ppc64

For example:

cmake -G "Unix Makefiles" -D CMAKE_OSX_ARCHITECTURES=i386 ..

To create a “universal build” use both i386 and ppc:

cmake -G "Unix Makefiles" -D CMAKE_OSX_ARCHITECTURES=i386 ppc ..

If you want to compile for a 32 bit architecture is mandatory to add -m32 to C and CXX flags. If you don’t add it you could end up with this warning:

created and used with differing settings of '-m32'

To solve this use -m32 option in CMAKE_C_FLAGS and CMAKE_CXX_FLAGS:

cmake -G "Unix Makefiles" -D CMAKE_OSX_ARCHITECTURES=i386 -D CMAKE_C_FLAGS=-m32 -D CMAKE_CXX_FLAGS=-m32 ..

You might also like

Install OpenCV in Ubuntu 10.10
If you want to install OpenCV 2.1 you can just use apt-get to do the work: sudo apt-get install libcv-dev...

Install OpenCV in Ubuntu 10.10
If you want to install OpenCV 2.1 you can just use apt-get to do the work: sudo apt-get install libcv-dev...

Install OpenCV in Ubuntu 10.10
If you want to install OpenCV 2.1 you can just use apt-get to do the work: sudo apt-get install libcv-dev...

Install OpenCV 2.3.1a in Ubuntu 11.10
If you want to install OpenCV 2.1 you can just use apt-get to do the work: sudo apt-get install libcv-dev...

Leave a comment ?

14 Comments.

  1. cmake -G “Unix Makefiles” -D CMAKE_OSX_ARCHITECTURES=i386 ..
    results an error :
    ” CMake Error at CMakeLists.txt:69 (message):
    CMake fails to deterimine the bitness of target platform.

    Please check your CMake and compiler installation. If you are crosscompiling then ensure that your CMake toolchain file correctly sets the compiler details. ”

    I’m using opencv-2.4.2
    Any idea ?!

  2. After compiling opencv how do I use it on a xcode project?
    thanks

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.