“Nonmatching transport in server reply” when cv2.VideoCapture rtsp onvif camera, how to fix?

前端 未结 4 1834
滥情空心
滥情空心 2021-01-06 15:17

I\'m on windows 10 using python 3.6.4, installed opencv (3.4) through pip. Here\'s the code I\'m using:

import numpy as np
import cv2
cap = cv2.VideoCapture(         


        
4条回答
  •  余生分开走
    2021-01-06 15:59

    1. Set env variable OPENCV_FFMPEG_CAPTURE_OPTIONS
    2. Create and start a process with video capture code
    3. Join the process
    # file package/__main__.py
    
    import os
    from multiprocessing import Process
    from package.main import run
    
    if __name__ == '__main__':
        os.environ["OPENCV_FFMPEG_CAPTURE_OPTIONS"] = "rtsp_transport;udp"
        p = Process(target=run)
        p.start()
        p.join()
    
    
    # file package/main.py
    
    import numpy as np
    import cv2
    
    
    def run():
        capture = cv2.VideoCapture("rtsp://192.168.1.150/onvif1", cv2.CAP_FFMPEG)
        while True:
            result, frame = capture.read()
            cv2.imshow('video', frame)
    
            if cv2.waitKey(16) == ord("q"):
                break
    
    

提交回复
热议问题