Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

opencv python osx

(Step 1)

I'm trying to get openCV to run from python on my mac using the MacPorts install http://opencv.willowgarage.com/wiki/Mac_OS_X_OpenCV_Port, and also trying to follow The Petite Geek's guide:

sudo port -v install opencv +python26

It runs for about 10 minutes without errors.

(Step 2)

I download ctypes-opencv source and demo files. I navigate to the src directory and run:

sudo python setup.py install

I see like 50 lines almost all of the form: copying ... -> ..., which looks good to me. No errors here.

(Step 3)

I add export DYLD_FALLBACK_LIBRARY_PATH=/opt/local/lib to the end of my ~/.profile.

(Step 4)

I open a new terminal to test my install. From my home folder:

$ python

Python 2.6.2 (r262:71600, Apr 16 2009, 09:17:39) 
[GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named cv
>>> 

Does not work.


I read somewhere that opencv installs python bindings with the default version of python for OSX, and I am probably running a non-default version, but this is not actionable information to me.

like image 813
dsg Avatar asked May 01 '11 05:05

dsg


People also ask

Can I use OpenCV with Python?

OpenCV is a great tool for image processing and performing computer vision tasks. It is an open-source library that can be used to perform tasks like face detection, objection tracking, landmark detection, and much more. It supports multiple languages including python, java C++.


2 Answers

I struggled for a while with Python on Mac. Here is how I finally (and easily!) installed it. Remove all the things Python you have on there already. They will probably be located at /Library/Frameworks/Python.Framework and /opt/local/var/macports/software/py26*

First download Python with Macports.

sudo port install python27

Then make sure your system is using this version with:

sudo port select --set python python27

Next install numpy with:

sudo port install py27-numpy

Now install opencv:

sudo port install opencv +python27

Now edit your ~/.bash_profile with:

sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit ~/.bash_profile

or

open -t ~/.bash_profile

and add the line:

export PYTHONPATH=/opt/local/var/macports/software/opencv/2.2.0_0+python27/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages:$PYTHONPATH

or where ever your version of the cv.so file is hidden....

Now restart terminal and try:

%python
>>>import cv

I'm using Netbeans for opencv and python and it works really nice. Good luck.

like image 84
Ferguzz Avatar answered Oct 03 '22 15:10

Ferguzz


$ brew search opencv
        homebrew/science/opencv
$ brew install homebrew/science/opencv

after installed, there is warning:

==> Caveats If you need Python to find the installed site-packages:

mkdir -p ~/Library/Python/2.7/lib/python/site-packages

echo '/usr/local/lib/python2.7/site-packages' > ~/Library/Python/2.7/lib/python/site-packages/homebrew.pth

so, just do

  mkdir -p ~/Library/Python/2.7/lib/python/site-packages
  echo '/usr/local/lib/python2.7/site-packages' > ~/Library/Python/2.7/lib/python/site-packages/homebrew.pth
like image 30
lbsweek Avatar answered Oct 03 '22 13:10

lbsweek