我尝试了这段代码,我内置的网络摄像头打开了,我正在预览窗口但是没有显示视频。它只是说没有响应。
我尝试使用OpenCV 2.4.10,python 2.7甚至OpenCV 3.0,3.1但没有结果。
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")