Installing OpenCV 2.4.8 on Mac OSX with Python Support
This is now outdated as Brew finally added opencv 2.4.9, See here
1. First of all I’ll be using the package manager Homebrew to simplify things, you can get it here: http://brew.sh/
The reason I’ve decided to use Homebrew was because it installs packages into their own directory which makes everything nice and easy to find. I tried macports but didn’t like it.
2. Once you have brew installed you can go ahead and and add homebrew/science which is where OpenCV is located using:
brew tap homebrew/science
3. As of the time of writing Homebrew only supports OpenCV 2.7.1 so we need to make a few changes:
brew edit opencv
The ‘formula’ for OpenCV should now be open in whatever you set the default editor to be, it’s vim by default but if you want to change it you can run the following replacing ’emacs’ with whatever your favorite text editor is.
echo 'export EDITOR=emacs' >> ~/.bash_profile source ~/.bash_profile
4. Look for the following lines
require 'formula' class Opencv < Formula homepage 'http://opencv.org/' url 'https://github.com/Itseez/opencv/archive/126.96.36.199.tar.gz' sha1 'b6b0dd72356822a482ca3a27a7a88145aca6f34c' option '32-bit'
Go ahead and replace the highlighted lines with
url 'https://github.com/Itseez/opencv/archive/2.4.8.tar.gz' sha1 '61b95974bf9689b94b169c39aed6c85a2e124837'
5. If you want to see other possible options such as when compiling (such as using tbb) you can use info
brew info opencv
Go ahead and install OpenCV now
brew install opencv
6. You’re done! You can find OpenCV at
Setting up Python
1. Navigate to your python path, if you don’t know where it is when you installed Python you can find it in your .bash_profile or using
cat ~/.bash_profile | grep PYTHONPATH
in my case we’ll be using
2. Once there we need to link our compiled OpenCV files, create a symlink using
ln -s /usr/local/Cellar/opencv/2.4.8/lib/python2.7/site-packages/cv.py cv.py ln -s /usr/local/Cellar/opencv/2.4.8/lib/python2.7/site-packages/cv2.so cv2.so
3. You’re done! You can make sure it works by running python and typing