python摄像头读取图片并保存为图片帧格式

import cv2
import time

cap = cv2.VideoCapture(0)

width = 1280  #定义摄像头获取图像宽度
height = 720   #定义摄像头获取图像长度
cap.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('摄像头没有打开')

你可能感兴趣的:(opencv,python,opencv,计算机视觉)