在python + openCV中使用网络摄像头时出现问题 [英] Problems using webcam in python + openCV

查看:790
本文介绍了在python + openCV中使用网络摄像头时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码通过openCV + python访问我的网络摄像头...

I am using the following code to access my webcam using openCV + python...

import cv

cv.NamedWindow('webcam_feed', cv.CV_WINDOW_AUTOSIZE)

cam = cv.CaptureFromCAM(-1)

然后我在控制台中收到以下错误...

I am then getting the following error in the console...

VIDIOC_QUERYMENU: Invalid argument
VIDIOC_QUERYMENU: Invalid argument
VIDIOC_QUERYMENU: Invalid argument

我最初使用的是

cv.CaptureFromCAM(0)

要访问相同且具有相同问题的设备,并使用-1,因为它假设是要拾取任何网络摄像头.

to access the same and had the same issue and used -1 because it is suppose to pick up any webcam.

我还测试了Ubuntu是否可以识别网络摄像头,并且可以识别.我正在使用v4l2作为网络摄像头.

I also tested to see if Ubuntu recognizes the webcam and it does. I am using v4l2 for the webcam.

{编辑}

我正在使用以下代码显示视频源,似乎只显示了网络摄像头捕获的一个图像,而不是连续的视频源...

I am using the following code to display a video feed, it seems to only be showing just one image the web cam captured instead of a continuous video feed...

import cv
cv.NamedWindow('webcam_feed', cv.CV_WINDOW_AUTOSIZE)
cam = cv.CaptureFromCAM(-1)
feed = cv.QueryFrame(cam)
cv.ShowImage("webcam_feed", feed)
cv.WaitKey(-1)

推荐答案

WOW,在我发布此内容后,在15分钟内回答了我自己的问题.我进行了一些研究,网络摄像头仅捕获一张图像的原因是由于...

WOW, answered my own question in 15 after me posting this. I did some research and the reason for the web cam only grabbing one image is because of the...

cv.WaitKey(-1)

这不允许刷新窗口的内容.我将数字设置为10 ...

This doesn't allow the contents of the window to refresh. I set the number to 10...

cv.WaitKey(10)

效果很好.我也尝试了100,但没什么区别.当数字为1000时,我只会看到一个差异.我使用1是因为它看起来运行得最顺畅.

and it worked beautifully. I also tried 100, but saw no difference. I only saw a difference when the number was 1000. I use 1 because seems that it runs the smoothest.

这是显示网络摄像头的完整代码

Here is the full code to display a web cam feed

import cv

cv.NamedWindow("webcam", 1)

cam = cv.CaptureFromCAM(-1)

While True:
feed = cv.QueryFrame(cam)
cv.ShowImage("webcam", feed)
cv.WaitKey(1)

这篇关于在python + openCV中使用网络摄像头时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆