简体   繁体   English

在Mac OS X 10.6上尝试在Python中使用OpenCV

[英]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. 我是python的新手,正在尝试使用openCV库。 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). 我安装了OpenCV的与MacPorts的,我还是继续得到同样的错误(我使用OpenCV的PKG里面的setup.py文件安装时所做的那样)。 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. 我的脚本是我从http://www.neuroforge.co.uk/index.php/getting-started-with-python-a-opencv编写(复制)的“ Hello world”脚本,而“ import cv”不是工作。 Is that because of path? 那是因为道路吗? I tried adding: 我尝试添加:

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

but no change... 但没有变化...

Thanks, Yonathan 谢谢,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. 我也很难使Python OpenCV绑定与MacPorts OpenCV安装一起使用。

But, I got OpenCV installed on a mac using Homebrew, and I can import cv and import cv2 in Python. 但是,我使用Homebrew在Mac上安装了OpenCV,并且可以在Python中import cvimport cv2

I installed Homebrew , then did brew install opencv , and then everything worked properly. 安装了Homebrew ,然后brew install opencv ,然后一切正常。

If installing via MacPorts make sure that you add the python variant when you install. 如果通过MacPorts安装,请确保在安装时添加python变体。

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. 然后确保您运行的是MacPorts版本的python(通常是/opt/local/bin/python2.7),而不是默认的OSX版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 pygame OpenGL窗口在Mac OS X 10.6,Python 2.7上不刷新 - pygame OpenGL windows not refreshing on Mac OS X 10.6, Python 2.7 无法在 Mac OS X 10.6 上的 Python 中的 Matplotlib 中将字体更改为 Helvetica - cannot change font to Helvetica in Matplotlib in Python on Mac OS X 10.6 如何在Mac OS X 10.6上使用Python 3和Xcode 3安装PyObjC - How to install PyObjC with Python 3 and Xcode 3 on Mac OS X 10.6 在Mac OS X 10.6上缺少Python.h头文件 - Python.h header file missing on Mac OS X 10.6 在 Mac OS X 10.6 上重新安装 Python 2.6 - Re-install Python 2.6 on Mac OS X 10.6 如何在Mac OS X 10.6上编译Mac OS X 10.5的python扩展? - How do I compile python extensions for Mac OS X 10.5, on Mac OS X 10.6? Python 3-Mac OS X 10.6.x-如何捕获麦克风输入的原始样本数据? - Python 3 - Mac OS X 10.6.x - How to capture microphone input raw sample data? 在Mac OS X 10.6上为Apache 2.2.21和Python 2.5.4安装mod_python - Install mod_python for Apache 2.2.21, Python 2.5.4 on Mac OS X 10.6 如何在Mac OS X 10.6上使用virtualenv与Google App Engine SDK - How to use virtualenv with Google App Engine SDK on Mac OS X 10.6 Python MySQL在Mac OS X 10.6 i386上安装错误 - Python MySQL installing wrongly on Mac OS X 10.6 i386
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM