Monday, September 01, 2014

Set up OpenCV for Python in MacOS X

Install/update Xcode from App Store and launch it to pass through terms agreement prompts.

Install Xcode Command Line Tools for easing later processes.
xcode-select --install
c.f. Stack Overflow thread

Install OpenCV.
$ brew install gcc
$ brew install opencv3
Now install python modules for OpenCV.
$ pip install cv2

You have to provide a shared library for it.  This is the key step. 
$ pushed /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
$ ln -s /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/cv2.so
$ popd
Test if it works.
$ python
>>> import cv2
>>>  
It should finish without showing any error.

If this is for your virtualenv, do similarly in your venv directory.

No comments: