如何在 Python 中捕获 RaspberryPi 相机 10 位原始图像
你可以使用 picamera Python 库捕获通过 CSI 连接到 Raspberry Pi 的相机的原始传感器图像:
capture_raw_rawimg.py
#!/usr/bin/env python3
import picamera
import picamera.array
import numpy as np
# 捕获图像
print("正在捕获图像...")
with picamera.PiCamera() as camera:
with picamera.array.PiBayerArray(camera) as stream:
camera.capture(stream, 'jpeg', bayer=True)
# 去马赛克数据并写入 rawimg
# (stream.array 包含未去马赛克的数据)
rawimg = stream.demosaic()rawimg 是维度为 (w, h, 3)(例如 (1944, 2592, 3))的 numpy uint16 数组,包含从 0 到 1023 的整数值。
例如,你可以使用以下命令将其保存为 NumPy 文件
save_rawimg_npy.py
np.save("rawimg.npy", rawimg) # Reload with np.load("rawimg.npy")或使用以下命令以压缩格式保存
save_rawimg_npz.py
np.savez_compressed("rawimg.npz", rawimg) # Reload with np.load("rawimg.npz")Check out similar posts by category:
Python, Raspberry Pi
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow