欢迎您访问365答案网,请分享给你的朋友!
生活常识 学习资料

python+opencv实现USB摄像头图片存储

时间:2023-04-28

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()

Copyright © 2016-2020 www.365daan.com All Rights Reserved. 365答案网 版权所有 备案号:

部分内容来自互联网,版权归原作者所有,如有冒犯请联系我们,我们将在三个工作时内妥善处理。