UPDATE: Mavericks users were likely frustrated for the last few weeks trying to install OpenCV. It appears the problem has been fixed, and these instructions should work without issue.
My previous post on installing OpenCV for Mac users is one of the most popular on this site (which is simultaneously surprising and fantastic). However, I recently switched from using MacPorts to Homebrew – users that need to migrate existing installs can check out this guide.
Still complicated but thoroughly do-able, here is how to install OpenCV on a Mac running Mountain Lion:
- Open Applications > Utilities > Terminal…
- Install Homebrew by typing the following into Terminal
1ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install) - Run the command brew doctor to check for any errors
- While normal installations using Homebrew are very straightforward, for some reason OpenCV requires an extra step – you need to install an add-on called
science:
1brew tap homebrew/science - Then you can run the usual Homebrew command to install OpenCV:
1brew install opencv
If this fails, it may be that you have ffmpeg installed – if so, try this instead:
1brew install opencv --env=std - This may take several minutes, so be patient!
- Homebrew may tell you that you have to update PYTHONPATH – if so, open your favorite text editor, click File > Open… and hit command+shift+. to see hidden files
- Navigate up to your home folder and open the .bash_profile file – if it doesn’t exist, create it yourself
- Add the line suggested by Homebrew, probably something like:
1export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH - Save the file and close it – you may also have to exit Terminal and open it again
- Test by opening Python:
1python
Then try to import OpenCV:
1import cv - If you don’t get any errors, you’re all set! Now go enjoy a real beer!
Hope this helps! Problems, suggestions – leave them in the comments.