import cv2 as cv
cap = cv.VideoCapture(0)
while True:
sucess, img = cap.read()
cv.imshow(“img”, img)
key = cv.waitKey(1)
# 如果点击ESC,则退出
if key == 27:
cv.destroyAllWindows()
break
# 如果点击‘s’保存当前图像
elif key == ord(‘s’):
cv.imwrite(“image.jpg”, img)
cv.destroyAllWindows()
break
cap.release()