OpenCV cv2.VideoCapture()停止读取RTSP IP摄像机

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

您好我正在学习opencv并通过rtsp:http阅读ip camera

videoStream = "rtsp://admin:[email protected]:554/Streaming/Channels/1"
capture = cv2.VideoCapture(videoStream)

我正在阅读这个流,我正在opencv进行面部检测,但在1或2分钟后,我的脚本崩溃了一个h264消息,我的opencv代码给了我一个错误:

[h264 @ 0x27e49570] error while decoding MB 55 12, bytestream -12
no video

如果我使用网络摄像头没有发生

有人可以帮助我如何获得ip camera流媒体进行面部检测的最佳方法?

opencv face-detection ip-camera opencv4
1个回答
0
投票

在处理任何帧之前,您可以确保相机处于打开状态且获得的帧有效。

videoStream = "rtsp://admin:[email protected]:554/Streaming/Channels/1"
capture = cv2.VideoCapture(videoStream)

while True:
    if capture.isOpened():
        status, frame = capture.read()
        if status:
            # Process frames here
            ...

如果您无法访问相机或损坏的帧,您可以使用cv2.error来捕获它。

try:
   ...
except cv2.error as e:
   ...
© www.soinside.com 2019 - 2024. All rights reserved.