Python调起摄像头拍照示例
2023年11月19日小于 1 分钟
- 安装opencv库
pip3 install opencv-python
- 示例代码
import cv2
# 打开摄像头
cap = cv2.VideoCapture(0)
if not cap.isOpened():
print("无法打开摄像头")
exit(1)
# 读取一帧图像
ret, frame = cap.read()
if not ret:
print("无法读取图像")
exit(1)
# 保存图像到文件
file_path = './image.png'
cv2.imwrite(file_path, frame)
# 关闭摄像头
cap.release()
原创声明
平台文章均为原创文章,未经许可,禁止转载。
如需转载,请联系作者获取授权,并注明来源及原文链接。