gpt4 book ai didi

python - Opencv:使用 python 导入 highgui

转载 作者:太空宇宙 更新时间:2023-11-03 21:58:53 24 4
gpt4 key购买 nike

使用以下代码:

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 行,位于 重复() 重复文件“pycam.py”,第 12 行 c = highgui.cvWaitKey(10)NameError:未定义全局名称“highgui”清理相机。

最佳答案

新的 API 发生了很多变化。以下将起作用:

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()

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

关于python - Opencv:使用 python 导入 highgui,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5831693/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com