
def capture_photo(): # 打开摄像头 cap = cv2.VideoCapture(0)
# 检查摄像头是否打开成功 if not cap.isOpened(): raise Exception("Failed to open camera") # 图片为黑,必须 sleep 一下!!! sleep(0.1) # 读取一帧图像 ret, frame = cap.read() # 检查图像是否读取成功 if not ret: raise Exception("Failed to capture frame") # 释放摄像头 cap.release() # 保存图像到当前目录 cv2.imwrite("captured_photo.jpg", frame) return "Photo captured successfully" 1 kyonn 2024-04-17 09:51:27 +08:00 via Android 不休眠多读几帧试下,看下是第几帧图像正常了 |