opencv调用摄像头保存图片
import cv2
cap=cv2.VideoCapture(1)
count=0
while (cap.isOpened()):
ret,frame=cap.read()
if ret:
cv2.imshow('frame',frame)
key=cv2.waitKey(1)
if key==ord('w'):
cv2.imwrite("C:/Users/Desktop/0527_%s.jpg"%(count),frame)
count+=1
if key==ord('q'):
break
else:
break
cap.release()
cv2.destroyAllWindows()