问题描述
所以我正在尝试开始在 OpenCV 中进行图像检测.我在用 Python 编程.
So I'm trying to get started with image detection in OpenCV. I'm programming in Python.
我从 openCV2 的人脸检测示例开始.但是,即使打开了相机设备,也不会返回任何图像.
I started out with the face-detect example for openCV2. However, even though a camera device is opened, no images will be returned.
违规代码:
cam = cv2.VideoCapture(0)
print cam.isOpened()
while True:
ret, img = cam.read()
print img
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
gray = cv2.equalizeHist(gray)
使用时,打印语句会说我的相机已打开.但是,当调用 cam.read() 时,它将返回 False, NoneType.
when used, the print statement will say that my camera is opened. However, when cam.read() is called it will return False, NoneType.
很明显,它无法将不存在的图像转换为灰度.有没有人有任何关于如何做到这一点的指示?
So obviously it won't be able to convert a non-existing image to grayscale. Does anyone have any pointers on how to do this?
我使用的是嵌入式网络摄像头,因此网络摄像头为0".
I'm using my embedded webcam, hence the "0" for webcam.
推荐答案
我遇到了同样的问题.
有时视频/网络摄像头驱动程序是一个问题,它返回无效的前几帧.检查 的返回值以处理错误情况.还要重新启动内核,它应该可以工作.
Sometimes video/webcam driver is a problem and it returns invalid first few frames.Check the return value of the to handle the error condition.Also restart your kernel and it should work.
并且可能是由于之前的一些错误情况,您的 cap.release() 没有被调用.
And may be due to some previous error conditions, your cap.release() was not called.
这篇关于OpenCV 的视频捕获不返回图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!