OpenCV cv2.VideoCapture() stopping to read RTSP IP camera

青春壹個敷衍的年華 提交于 2021-02-10 04:45:09

问题


Hello im learning opencv and im reading a ip camera through rtsp://

videoStream = "rtsp://admin:123456@10.0.0.1:554/Streaming/Channels/1"
capture = cv2.VideoCapture(videoStream)

im reading this stream and im making a facial detection in opencv but after 1 or 2 minutes my script crashes whit a h264 message and my opencv code gives me a error:

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

and if i use a webcan it not happening

some one can help me whit how is the best way to get a ip camera streaming for facial detection?


回答1:


Before you process any frames, you can ensure that the camera is open and that obtained frames are valid.

videoStream = "rtsp://admin:123456@10.0.0.1:554/Streaming/Channels/1"
capture = cv2.VideoCapture(videoStream)

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

If you are unable to access the camera or get corrupted frames, you can catch this with cv2.error.

try:
   ...
except cv2.error as e:
   ...


来源:https://stackoverflow.com/questions/54754291/opencv-cv2-videocapture-stopping-to-read-rtsp-ip-camera

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!