Installing OpenCV on Mac OS X Snow Leopard
November 19, 2010 4 Comments
OpenCV (Open Source Computer Vision) is a library of programming functions for real time computer vision. Version 2 ships with Python bindings and simply you can “import cv” module in Python after you’ve installed it.
The easiest way to install OpenCV on Mac is to use package management systems like port, fink or homebrew. They will automatically download, compile and install needed packages for you.
In this tutorial I’ll use brew, how ever you can use your preferred package manager.
Here is the short explanation of the installation process (every thing will be done on Terminal.app)
1. Install brew package manager. (instructions here)
2. Update brew formulas:
brew install git brew update
3. Install opencv:
brew install opencv
and brew will automatically installs CMake and checks out opencv repository, Builds and installs it.
Note that you should edit your PYTHONPATH to make opencv working with Python. I wrote a simple script to do this automatically for Python 2.6 (Also brew should be installed on it’s default location).
RND=/tmp/$RANDOM PYTHONPATH=`echo $PYTHONPATH | sed -e 's/\/usr\/local\/lib\/python2.6\/site-packages\/://g'` cat ~/.bash_profile | grep -Ev "PYTHONPATH" > $RND echo export PYTHONPATH="/usr/local/lib/python2.6/site-packages/:"'$PYTHONPATH' >> $RND mv $RND ~/.bash_profile
Just copy the script above and type:
pbpaste | sh
Close the Terminal and reopen it.
Now you can simply open your Python interpreter and type “import cv”.
Done.



