Sunday, 12 September 2010

binding opencv2.1 and python2.6.6 in mac os x snow leopard

Here is my way to solve the Opencv binding problem in Mac, it is not easy to bind Python and Opencv together, and hope it will help for your own mac. and you better have macports install in your computer.

First, you need to download and install Python(i use python2.6.6). and make sure the python locate at /usr/bin, not /opt/local/bin( you can type " which python"), I suggest not to use the python installed via macports, but from the, or the python locate will be "opt/local/bin", which make the opencv binding fail, also the numpy&scipy lib can't be installed from dmg. And you can check the python locations by typing "type -a python". It is said that you can change the python locate using python_select(which can be installed using macports), but seems it don't work for me, so i just simply type "sudo rm /opt/local/bin/python" to remove it, then the python come to "/urs/bin/python".

Second, you need to download the sourcecode of Opencv2.1 follow the second way( don't use the mac port), Use cmake and build, if there are any dependency problem, you can use macports to download the required lib. I am not sure whether numpy for python is required for opencv building, but it only be successful built while i have numpy installed.

Third, after python and opencv are correctly installed, you can find out the "" in your opencv folder, for me is "/Users/flydreamersu/opencv/lib", then in your python, you can write:
>>> import sys
>>> sys.path.append("/Users/flydreamersu/opencv/lib")
>>> import cv

I think opencv is loaded without error.

No comments:

Post a Comment