我在python3里有以下代码。
import cv2
import sys
import os
import requests
while True:
try:
stream = cv2.VideoCapture(0)
except Exception as e:
print(e)
return
但cv2.VideoCapture(0)在命令行-in red-中返回一个错误,而且从来没有跟随except语句。
我想在cam失败后从程序中返回,如何做到?
一旦摄像机失败,它的状态就不会被打开。
while True:
try:
stream = cv2.VideoCapture(0)
if not stream.isOpened():
return
except Exception as e:
print(e)
return
OpenCV Python是在CPyton中实现的。该 try...catch...
如果本地代码不支持,将无法工作。