有没有一种在 Raspberry Pi 4B 和 HQ 相机模块上使用 raspistill 记录图像的快速方法?

问题描述

我想使用 RaspBerry Pi HQ 摄像头模块录制多张图像(例如 50 张)。这些图像是用简单的命令行 raspistill -ss 125 -ISO 400 -fli auto -o test.png -e png 记录的。由于我必须记录 .png 文件,因此图像尺寸为 3040x4056。 如果我运行一个包含 50 个命令行的简单 bash 脚本,图像之间的“处理时间”似乎很长。

那么有没有办法在没有任何延迟(或至少非常短的延迟)的情况下一个一个地记录 50 个图像?

解决方法

我怀疑您是否可以在命令行上使用 raspistill 执行此操作 - 特别是在尝试快速编写 PNG 图像时。我认为您需要按照以下几行转向 Python - 改编自 here。请注意,图像是在 RAM 中获取的,因此在获取阶段没有磁盘 I/O。

将以下内容另存为 acquire.py

#!/usr/bin/env python3

import time
import picamera
import picamera.array
import numpy as np

# Number of images to acquire
N = 50

# Resolution
w,h = 1024,768

# List of images (in-memory)
images = []

with picamera.PiCamera() as camera:
    with picamera.array.PiRGBArray(camera) as output:
        camera.resolution = (w,h)
        for frame in range(N):
            camera.capture(output,'rgb')
            print(f'Captured image {frame+1}/{N},with size {output.array.shape[1]}x{output.array.shape[0]}')
            images.append(output.array)
            output.truncate(0)

然后使用以下命令使其可执行:

chmod +x acquire.py

并运行:

./acquire.py

如果你想将图像列表以 PNG 格式写入磁盘,你可以使用这样的东西(未经测试)并将 PIL 添加到上述代码的末尾:

from PIL import Image

for i,image in enumerate(images):
    PILimage = Image.fromarray(image)
    PILImage.save(f'frame-{i}.png')