简体   繁体   中英

Trying to use opencv with python on mac os x 10.6

I'm new to python and I'm trying to use the openCV libraries. After lots of reading and lots of trial and error I decided to ask here.

I installed the openCV with macports, still I keep getting the same error (as I did when installing using the setup.py file inside openCV pkg). My script is a "Hello world" script I wrote (copied) from http://www.neuroforge.co.uk/index.php/getting-started-with-python-a-opencv and the "import cv" is not working. Is that because of path? I tried adding:

import sys 
sys.path.append('/opt/local/include/opencv')

but no change...

Thanks, Yonathan

the full script is:

import cv

cv.NamedWindow('a_window', cv.CV_WINDOW_AUTOSIZE)
image = cv.LoadImage('picture.png', cv.LOAD_IMAGE_COLOR)

font = cv.InitFont(cv.CV_FONT_HERSHEY_SIMPLEX, 1, 1, 0, 3, 8) 

x = 200
y = 200

cv.PutText(frame,"Hello World!!!", (x,y),font, 255) 

cv.ShowImage('a_window', image)

cv.Waitkey(10000)
cv.SaveImage('image.png', image)

I also had trouble getting the Python OpenCV bindings to work with a MacPorts OpenCV installation.

But, I got OpenCV installed on a mac using Homebrew, and I can import cv and import cv2 in Python.

I installed Homebrew , then did brew install opencv , and then everything worked properly.

If installing via MacPorts make sure that you add the python variant when you install.

sudo port install opencv +python27

Then make sure that you are running the MacPorts version of python (usually /opt/local/bin/python2.7), not the default OSX version.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM