import cv2 cap = cv2.VideoCapture(0) i = 0 while 1: ret, frame = cap.read() k = cv2.waitKey(1) if k == 27: break elif k == ord('s'): cv2.imwrite('E:/OpencvVideo/'+str(i)+'.jpg', frame) i += 1 cv2.imshow("capture",frame) cap.release() cv2.destroyAllWindows()
按下s键就会保存照片到指定文件夹
按下esc就会退出程序
程序可以直接运行,如果是笔记本自带的摄像头就是VideoCapture(0),如果是外接的摄像头就把0改成1.