# 读取数据 import cv2 cam_port_num = 0 # 定位对象 video = cv2.VideoCapture(cam_port_num) while (True): # 收集 video frame # 采用frame result, frame = video.read() # 显示结果 cv2.imshow('video', frame) # 按s保存图片 if cv2.waitKey(1) & 0xFF == ord('s'): cv2.imwrite("img.png", frame) print('ok') continue # 按q退出 if cv2.waitKey(1) & 0xFF == ord('q'): break # 使用循环loop指令后 release 视频 video.release() # Destroy all the windows cv2.destroyAllWindows()