首页 > 图灵资讯 > 技术篇>正文
python摄像头读取图片并保存为图片帧格式
2023-05-19 09:15:45
import cv2import timecap = cv2.VideoCapture(0)width = 1280 #定义摄像头获取图像宽度heightht = 720 #定义摄像头获取图像长度capp.set(6, cv2.VideoWriter_fourcc('M','J','P','G'))# cap视频流格式.set(5, 10)# 帧率cap.set(cv2.CAP_PROP_FRAME_WIDTH, width) #设置宽度cap.set(cv2.CAP_PROP_FRAME_HEIGHT, height) #设置长度while True: ret, frame = cap.read() if ret: now = time.perf_counter() print(cap.get(cv2.CAP_PROP_FPS))# 得到帧率 cv2.imshow('frame',frame) cv2.waitKey(1) end = time.perf_counter() print('total time:%s'%(end-now))# 打印每个循环所需的时间 else: print(‘摄像头未打开’)