网络摄像头 + 打开简历 Python |黑屏 [英] Webcam + Open CV Python | Black screen

查看:90
本文介绍了网络摄像头 + 打开简历 Python |黑屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用下面的代码,但我得到了一个黑色图像.你能帮我纠正错误吗?

I am using the code below, but I get a black image. Could you please help me rectify the error?

import cv2
import numpy as np
c = cv2.VideoCapture(0)

while(1):
    _,f = c.read()
    cv2.imshow('e2',f)
    if cv2.waitKey(5)==27:
        break
cv2.destroyAllWindows()

推荐答案

更新:参见 github.com/opencv/opencv/pull/11880 和链接的对话,只有少数后端支持 -1 作为索引.

Update: See github.com/opencv/opencv/pull/11880 and linked conversations, only few backends support -1 as index.

虽然这是一个旧帖子,但这个答案可以帮助仍然面临同样问题的人.如果您有一个单个网络摄像头,但它呈现全黑,请使用cv2.VideoCapture(-1).这将为您提供工作相机.

Although this is an old post, this answer can help people who are still facing the same problem. If you have a single webcam but it renders all black, use cv2.VideoCapture(-1). This will get you the working camera.

这篇关于网络摄像头 + 打开简历 Python |黑屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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