1.python+opencv实现USB摄像头图片存储
import cv2import timeif __name__ == '__main__': # SunplusIT Inc 摄像头 cap = cv2.VideoCapture(0) cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter.fourcc('M', 'J', 'P', 'G')) # 视频流格式 cap.set(cv2.CAP_PROP_frame_WIDTH, 1960) cap.set(cv2.CAP_PROP_frame_HEIGHT, 1080) width = cap.get(3) height = cap.get(4) print(width, height, cap.get(5)) i = 0 while True: ret, frame = cap.read() if not ret: print("get camera frame is empty") break cv2.imshow("image", frame) "展示图片" cv2.imwrite(r"D:picture\" + str(i) + "screenshot.jpg", frame) "保存图片" i = i + 1 if i == 50: time.sleep(100) print(time.time()) key = cv2.waitKey(1) & 0xff "每帧数据延时 1ms,延时不能为 0,否则读取的结果会是静态帧" if key == ord('q'): break cap.release() cv2.destroyAllWindows()