opencv读取rtsp流(python)

使用opencv读取rtsp流方法,因其简单将不在解释:

import cv2
def read_rtsp():
    cap = cv2.VideoCapture('rtsp://admin:Vrc123456@192.168.2.226:554')
    fourcc = cv2.VideoWriter_fourcc(*'XVID')
    size = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)), int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))
    out = cv2.VideoWriter('./rtsp_video.avi', fourcc,10.0, size)
    while True:
        ret, frame = cap.read()
        out.write(frame)
    
        cv2.imshow('frame', frame)
        cv2.waitKey(1)

    cap.release()
    out.release()
    cv2.destroyAllWindows()
if __name__ == '__main__':
    read_rtsp()

 

posted @ 2022-10-17 17:52  tangjunjun  阅读(1034)  评论(0编辑  收藏  举报
https://rpc.cnblogs.com/metaweblog/tangjunjun