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 file inside openCV pkg). My script is a "Hello world" script I wrote (copied) from and the "import cv" is not working. Is that because of path? I tried adding:

import sys 

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.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.

This video can help you solving your question :)
By: admin