使用Py的CV2录制视频与拍摄图片

it2025-06-16  14

import numpy as np import cv2 #保存自拍 cap = cv2.VideoCapture(0) cap.set(3,2480) cap.set(4,1960) print(str(cap.get(3))+" "+str(cap.get(4))) time = 0 while time<1000: ret,frame = cap.read() # frame = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY) cv2.namedWindow("clip",cv2.WINDOW_NORMAL) cv2.imshow("clip",frame) cv2.imwrite("C:\\Users\\Administrator\\DeskTop\\jack.jpg",frame) cv2.waitKey(100) time+=1 cap.release() cv2.destroyAllWindows() #保存视频 import cv2 cap = cv2.VideoCapture(0) fourCC = cv2.VideoWriter_fourcc(*'MJPG') #指定视频的名字,编码方式,每秒播放的帧数,每帧的大小 out = cv2.VideoWriter("jack.avi",fourCC,5,(640,480)) while(cap.isOpened()): ret,frame = cap.read() out.write(frame) cv2.imshow("jack",frame) code = cv2.waitKey(100) if code == ord('A'): break; else: continue; cap.release() out.release() cv2.destroyAllWindows()
最新回复(0)