首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Opencv:使用python导入highgui

Opencv:使用python导入highgui
EN

Stack Overflow用户
提问于 2011-04-29 19:56:47
回答 2查看 6.5K关注 0票数 1

使用以下代码:

代码语言:javascript
复制
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()

回溯(最近一次调用):文件"pycam.py",第21行,在repeat()文件"pycam.py",第12行,在repeat c= highgui.cvWaitKey(10) NameError:全局名称'highgui‘没有定义清理摄像机。

EN

回答 2

Stack Overflow用户

发布于 2011-05-03 17:28:02

新的API有相当多的变化。下面的方法将会起作用:

代码语言:javascript
复制
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 = cv.WaitKey(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()

这是一个更简单、更清晰的语法!

票数 6
EN

Stack Overflow用户

发布于 2011-04-29 20:06:32

这意味着highgui并不存在。尝试这样导入:from opencv import *

如果这不起作用,试着检查一下你的opencv安装。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5831693

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档