LearnOpenCV - Saving network flow pictures

实时保存网络流图片

import cv2

'''
HTTP协议:客户端发出请求,服务端响应
RTSP协议:客户端和服务端都可以发出请求

RTSP (Real Time Streaming Protocol):实时流传输协议,该协议是一个应用层协议,这个协议定义了,多个应用程序如何通过IP网络传输多媒体数据(即视频流)
RTSP协议是一个双向的

rtsp协议的IP: rtsp://YourIp:8554/live
http协议的IP: http://YourIp:8081/video

URL说明:
    http:       传输协议
    admin:      用户名,默认为admin
    Password:   密码,默认就是123456
    @IP:        @符号后面跟摄像头的局域IP地址
    :port:      冒号后面跟端口号
'''

if __name__ == "__main__":

    # 建个窗口并命名
    cv2.namedWindow("look", 1)

    # IP视频地址
    # url = "http://admin:123456@YourIp:8081/video"
    url = "rtsp://admin:123456@YourIp:8554/live"

    capture = cv2.VideoCapture(url)  # 读取视频流
    print('start work ~~')
    print('Press "esc" exit')
    print('Press "s" save img')

    num = 0
    filepath = './img/'
    while capture.isOpened():
        # Capture frame-by-frame
        ret, frame = capture.read()
        
        # Display the resulting frame
        cv2.imshow('look', frame)

        key = cv2.waitKey(3)
        if key == 27:
            # exit
            print("Esc break")
            break

        if key == ord('s'):
            # save
            num = num + 1
            filename = "img_%s.jpg" % num
            cv2.imwrite(filepath + filename, frame)
            print('save ' + filename)

    # When everything done, release the capture
    capture.release()
    cv2.destroyAllWindows()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

__steve_yee

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值