工作需要获取摄像头的视频流,原本通过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()

 

相关文章:

  • 2021-11-18
  • 2022-01-30
  • 2022-01-20
  • 2022-12-23
  • 2021-11-27
  • 2022-12-23
  • 2021-12-25
猜你喜欢
  • 2021-12-22
  • 2021-12-21
  • 2021-08-07
  • 2021-10-01
  • 2021-12-15
  • 2021-09-29
  • 2021-10-19
相关资源
相似解决方案