Opencv:用python导入highgui
使用以下代码:
import cv
cv.NamedWindow("w1", cv.CV_WINDOW_AUTOSIZE)
camera_index = 0
capture = cv.CaptureFromCAM(camera_index)
def repeat():
global capture #declare as globals since we are assigning to them now
global camera_index
frame = cv.QueryFrame(capture)
cv.ShowImage("w1", frame)
c = highgui.cvWaitKey(10)
if(c=="n"): #in "n" key is pressed while the popup window is in focus
camera_index += 1 #try the next camera index
capture = cv.CaptureFromCAM(camera_index)
if not capture: #if the next camera index didn't work, reset to 0.
camera_index = 0
capture = cv.CaptureFromCAM(camera_index)
while True:
repeat()
Traceback(最近一次调用最后一次): 文件“pycam.py”,第 21 行,位于 重复() 文件“pycam.py”,第 12 行,重复 c = highgui.cvWaitKey(10) NameError:未定义全局名称“highgui” 清理了相机。
With the following code:
import cv
cv.NamedWindow("w1", cv.CV_WINDOW_AUTOSIZE)
camera_index = 0
capture = cv.CaptureFromCAM(camera_index)
def repeat():
global capture #declare as globals since we are assigning to them now
global camera_index
frame = cv.QueryFrame(capture)
cv.ShowImage("w1", frame)
c = highgui.cvWaitKey(10)
if(c=="n"): #in "n" key is pressed while the popup window is in focus
camera_index += 1 #try the next camera index
capture = cv.CaptureFromCAM(camera_index)
if not capture: #if the next camera index didn't work, reset to 0.
camera_index = 0
capture = cv.CaptureFromCAM(camera_index)
while True:
repeat()
Traceback (most recent call last):
File "pycam.py", line 21, in
repeat()
File "pycam.py", line 12, in repeat
c = highgui.cvWaitKey(10)
NameError: global name 'highgui' is not defined
Cleaned up camera.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
新的 API 发生了相当多的变化。以下内容将起作用:
这是一种更简单、更清晰的语法!
There have been quite a few changes in the new API. The following will work:
It is a simpler, cleaner syntax!
这意味着
highgui
不存在。尝试通过以下方式导入:from opencv import *
。如果这不起作用,请尝试检查您的 opencv 安装。
This means that
highgui
doesn't exist. Try importing this way:from opencv import *
.If that doesn't work try and check your opencv instalation.