import cv2 cap = cv2.VideoCapture(0) if not cap.isOpened(): print("无法打开摄像头") while True: ret, frame = cap.read() print("无法接受帧,请退出") break cv2.imshow("Camera", frame) if cv2.waitKey(1) & 0xFF == ord('q'): break cap.release() cv2.destroyAllWindows()