Install OpenCv with Python Binding on MacOS
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.
– 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:
$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:
Otherwise, whenever you would like to import the cv, you will have to first include the path in your python code, something like this:
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 🙂