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:
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)
if(APPLE)
list(APPEND HIGHGUI_LIBRARIES ${BZIP2_LIBRARIES} -lmp3lame -lbz2 -lfaac)
endif(APPLE)
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"
make
sudo make install
cd ..
tar xzvf lame-3.99.5.tar.gz
cd lame-3.99.5
./configure
make
sudo make install
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
make
sudo make install
cd ..
Use ccmake -G "Unix Makefiles"
Hit "t" for advanced mode.
change PYTHON_LIBRARY value to /opt/local/lib/libpython2.6.dylib
and
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.
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.