python处理RSTP视频流

强颜欢笑 提交于 2019-12-03 16:55:20

python链接海康摄像头,并以弹出框的方式播放实时视频流,

@shared_task
def parse_video(rtsp_address=None):
    winname = 'Video'
    if not rtsp_address:
        raise exceptions.ParseError('摄像头rstp地址错误!')

    cap = cv2.VideoCapture(rtsp_address)
    if not cap.isOpened():
        raise exceptions.ParseError('视频播放失败!')

    while cap.isOpened():
        ret, frame = cap.read()
        if not ret:
            break

        cv2.putText(frame, 'Please press "ESC" to close the window', (900, 20), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (55, 255, 155), 1)
        cv2.imshow(winname, frame)
        k = cv2.waitKey(1)

        if cv2.getWindowProperty(winname, cv2.WND_PROP_AUTOSIZE) < 1:
            break
        if k == 27:
            break

    cap.release()
    cv2.destroyAllWindows()

 

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