相机不能在python opencv中工作

时间:2017-11-27 06:29:59

标签: python opencv camera

这是代码:

import cv2

cv2.namedWindow("preview")
 vc = cv2.VideoCapture(0)

if vc.isOpened(): # try to get the first frame
rval, frame = vc.read()
else:
rval = False

 while rval:
cv2.imshow("preview", frame)
rval, frame = vc.read()
key = cv2.waitKey(20)
if key == 27: # exit on ESC
    break
cv2.destroyWindow("preview")

但相机预览完全是黑色

它可能是驱动程序问题,请问是驱动程序问题,我该如何解决?

1 个答案:

答案 0 :(得分:0)

您只需要安装支持您设备的摄像头驱动程序,否则代码可以很好地重新安装该驱动程序,或者可以从PC厂商网站的官方网站上安装其他驱动程序