Archive

Posts Tagged ‘MacOS’

Install OpenCv with Python Binding on MacOS

April 4, 2012 1 comment

I had tried several versions of install opencv on my mac that can be used in python.

Here are lessons — use the python provided by MacOS, you may have the following problem if you are using other versions.

Steps:

– Use python by MacOS, which you should be able to finda and locate, e.g. the link /usr/bin/python    (my version is Python 2.7)

I found that I can not use the python I installed somewhere else, such as </Library/Frameworks/Python.framework/Versions/2.7/>

– I used the brew to install opencv:

http://opencv.willowgarage.com/wiki/Mac_OS_X_OpenCV_Port?highlight=%28%28InstallGuide%29%29

   $sudo brew install opencv  

It enventually install it to  </usr/local/Cellar/opencv/2.3.1a>

– Next step, you need to add the path </usr/local/Cellar/opencv/2.3.1a/lib/python2.7/site-packages> to your PYTHONPATH

If you check the sit-packages folder, it should include two files: cv.py and cv2.so

So, change your ~/.profile to include the following line:

export PYTHONPATH=”/usr/local/Cellar/opencv/2.3.1a/lib/python2.7/site-packages:${PYTHONPATH}”

Otherwise, whenever you would like to import the cv, you will have to first include the path in your python code, something like this:

sys.path.append(‘/usr/local/Cellar/opencv/2.3.1a/lib/python2.7/site-packages’)

Now, time to do the test:

I couldn’t find the example folder of python by the package installed by brew.

So I went ahead and use the previous download one, which is a full package opencv:

$ls ~/Documents/OpenCV-2.3.1/samples/python             (where you will be able to find the delaunay.py file, then go ahead to run it)

$ python ~/Documents/OpenCV-2.3.1/samples/python/delaunay.py

Nice , now it’s running, finally 🙂

Advertisements