22 August

Today I (again) installed OpenCV 2.4.2 on OS X (Apple MacBook Pro under Darwin). As we all know, OpenCV is that great computer vision and image processing library that is also integrated into ROS. Getting it to compile on OS X, and to work with Apple's Python, can be a hassle (even with macports or homebrew, both of which have had problems when in comes to OpenCV).

The following special tricks were needed to get OpenCV to compile:

  • 1) Download OpenCV.

  • You need to have XCode and CMake installed.
    Go to the OpenCV folder.
    Edit CMakeLists.txt to add these lines( as per blog.yageek.net)

    list(APPEND HIGHGUI_LIBRARIES ${BZIP2_LIBRARIES} -lmp3lame -lbz2 -lfaac)

  • 2) Install libfaad

  • curl -L -o faad2-2.7.tar.gz http://sourceforge.net/projects/faac/files/faad2-src/faad2-2.7/faad2-2.7.tar.gz/download
    tar xvzf faad2-2.7.tar.gz
    cd faad2-2.7
    ./configure --disable-dependency-tracking CFLAGS="-arch i386 -arch x86_64" LDFLAGS="-arch i386 -arch x86_64"
    sudo make install
    cd ..

  • 3) Install lame from http://lame.sourceforge.net/:

  • tar xzvf lame-3.99.5.tar.gz
    cd lame-3.99.5
    sudo make install

  • 4) Install/update ffmpeg

  • curl -O http://ffmpeg.org/releases/ffmpeg-0.11.1.tar.gz
    tar xzvf ffmpeg-0.11.1.tar.gz
    cd ffmpeg-0.11.1
    ./configure --enable-libmp3lame --enable-libfaac --enable-nonfree --enable-shared --enable-pic --disable-mmx --arch=x86_64
    sudo make install
    cd ..

  • 5) Now, for Python compatibility...

  • Use ccmake -G "Unix Makefiles"

    Hit "t" for advanced mode.

    change PYTHON_LIBRARY value to /opt/local/lib/libpython2.6.dylib
    PYTHON_INCLUDE_DIR to /opt/local/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6.
    within ccmake.

    For me to have it work with Python, I also had to assure that the architecture was x86_64 not i386. When done, hit "c" to create the configuration, then "g"to go and create the Makefile.

  • 6) make; make install

  • Many of the special configuration issues for OS X and MacPorts seem to be automatically handled, but
    for MacPorts users, Taylor Squared Designs has a nice post on the issues involved in installing OpenCV.

    By Gregory Dudek at | Read (1) or Leave a comment |    
    Re: Compiling OpenCV on OS X Lion 10.6.8

    Thank you, thank you, thank you! I have been beating my head against the wall off and on for a week trying to get opencv with python bindings installed on Mac OS X 10.7. This method worked, with the only addition that I got an error when configuring ffmpeg that it couldn't find the libfaac files (note that I had, as you suggested, installed the libfaad files.

    I just downloaded from http://sourceforge.net/projects/faac/files/faac-src,
    and followed the basic installation they suggest:
    sudo make install

    Then, ffmpeg configured and installed fine, as did opencv

    Thanks again!

    [Thanks for the positive feedback. Greg]

    Posted by: Erich Phillips at March 19,2013 16:25
    Post your own response

    Each comment is manually screened for the presence of appropriate and substantive content, due to a constant onslaught of comment-spam. This means there may be a delay before your comment appears.

    (Some kind of name is required, will be visible)

    Required, whatever you enter will be visible to other users.

    (Optional, used for "mailto" link)

    Your email address is not required, but if you insert it it will be displayed so people can contact you.

    Answer this question correctly to demonstrate that you are not a dumb spambot.

    The title for your comment.

    Your comment goes here. All relevant comments are welcome, except for those that simply promote an irrelevant product or else are used to fraudulently inflate the link count to an irrelevant web page. They appear after moderation. Don't forget to also fill in the captcha below or your text will be rejected automatically!

    You must answer this question to prove you are human
    The governator said (when in a movie as T2): 'I'll be ... (pick a number): 1:tuckered, 2:broke, 3:back, 4:broken, 5:swartzneggered, 6:eaten, 7:you?

    Answer this question correctly to demonstrate that you are not a dumb spambot.