在cv2.VideoCapture(0)失败后,python-返回。

问题描述 投票:0回答:1

我在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失败后从程序中返回,如何做到?

python camera multiprocessing video-streaming cv2
1个回答
1
投票

一旦摄像机失败,它的状态就不会被打开。

while True:
    try:
        stream =  cv2.VideoCapture(0)
        if not stream.isOpened():
            return
    except Exception as e:
        print(e)
        return

OpenCV Python是在CPyton中实现的。该 try...catch... 如果本地代码不支持,将无法工作。

© www.soinside.com 2019 - 2024. All rights reserved.