zoukankan      html  css  js  c++  java
  • python opencv获取摄像头视频流

    工作需要获取摄像头的视频流,原本通过sdk 接入很稳定,也没有延迟,但后来需要改造成python,

    通过opencv 处理来获取,记录下例子来学习

    import cv2
    import time

    def getTime():
    return time.strftime("%Y%m%d%H%M%S", time.localtime())

    if __name__ == "__main__":

    video_full_path = "RTSP流"
    cap = cv2.VideoCapture(video_full_path)
    cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc('M', 'J', 'P', 'G'))
    out_path = 'test/'
    print(cap.isOpened())
    frame_count = 1
    n = 1
    success = True
    # 摄像头fps=25 逐帧读取,即每秒25张
    while True:
    if(success):
    success, frame = cap.read()
    print('Read a new frame: ', success)
    print('流状态'+str(success))
    params = []
    #params.append(cv.CV_IMWRITE_PXM_BINARY)
    params.append(1)

    #if (n % 25 == 0): # 每隔5帧保存一张图片
    #cv2.imwrite(out_path + getTime() + "_%d.jpg" % frame_count, frame, params)
    #frame_count +=1
    #print('完成截图')
    #n += 1

    else:
    print('无法获取视频流,尝试重新连接,重连次数')
    cap = cv2.VideoCapture(video_full_path)
    steamingstate = cap.isOpened()
    print('连接状态'+str(steamingstate))
    success = steamingstate
    cap.release()

  • 相关阅读:
    zoj 3233 容斥原理 + 双条件
    bzoj 1038 瞭望塔 半平面交 + 最小值 枚举
    linux 常用命令
    Vue路由
    luffycity项目开发
    Vue组件化开发
    Vue对象提供的属性功能
    Vue快速入门
    Django-DRF(路由与扩展功能)
    Django-DRF(视图相关)
  • 原文地址:https://www.cnblogs.com/mlwork/p/12744012.html
Copyright © 2011-2022 走看看