我需要来自网络摄像头的视频。在带有 python-3.6 和 OpenCV-3 的 Anaconda 上,它工作得很好。然后我在 Idle 中使用 python-3.6 和 OpenCV-4.1.0 尝试了相同的代码,但它在 anaconda 中不起作用。我有两个黑色的上下边缘,我只能看到图像的中间。我尝试修改一些 OpenCV 设置,但情况变得更糟,现在只有在强光照射下,我在图像上几乎看不到任何东西。两条边并没有消失。
import cv2
capture = cv2.VideoCapture(0)
capture.set(cv2.CAP_PROP_SETTINGS, 0)
while(True):
ret, frame = capture.read()
cv2.imshow('video', frame)
if cv2.waitKey(1) == 27:
break
capture.release()
cv2.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud)
该行capture.set(cv2.CAP_PROP_SETTINGS, 0)会打开一个小的设置对话框,但还有许多其他对话框,如下所示: