python opencv 摄像头_使用OpenCV和Python显示网络摄像头

尝试添加行c = cv.WaitKey(10)在你的底部repeat()方法。

这将等待用户输入密钥的10毫秒。即使你根本没有用钥匙,把这个放进去。我想只是需要一些延迟,所以time.sleep(10)也可能有效。

关于相机索引,您可以这样做:for i in range(3):

capture = cv.CaptureFromCAM(i)

if capture: break

这将找到第一个“工作”捕获设备的索引,至少对于0-2的索引是这样的。计算机中可能有多个设备被认为是正确的捕获设备。我知道的唯一确认你有正确的方法是手动看你的光。也许能得到一张图像并检查它的属性?

要将用户提示添加到进程中,可以绑定一个键以切换重复循环中的摄像机: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()

免责声明:我还没有测试过这一点,所以它可能有错误,或者只是没有工作,但至少可以给您一个解决办法的想法。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值