我想用Raspberry Pi HQ相机模块记录多幅图像(例如50张)。这些图像是用简单的命令行raspistill -ss 125 -ISO 400 -fli auto -o test.png -e png记录的。因为我必须记录.png文件,所以图像尺寸是3040x4056。如果我运行一个简单的bash脚本,其中包含50行命令行,那么图像之间似乎有很长的“处理时间”。
那么,有没有办法一个接一个地记录50幅这样的图像,而不加任何延迟(或者至少是很短的延迟)?
发布于 2021-07-12 14:19:45
我怀疑您能否在命令行上使用raspistill来完成这一任务--尤其是尝试快速编写PNG图像。我认为您需要按照以下思路迁移到Python --从这里改编而来。注意,图像是在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')https://stackoverflow.com/questions/68346580
复制相似问题