Is there a fast way to record images with raspistill on a Raspberry Pi 4B and HQ Camera module?

791 views Asked by At

I'd like to record multiple images (e.g. 50) with the Raspberry Pi HQ Camera module. These images are recorded with the simple command line raspistill -ss 125 -ISO 400 -fli auto -o test.png -e png. Since I have to record .png files, the image dimensions are 3040x4056. If I run a simple bash script, which contains 50 of those command lines, it seems like there is a very long "processing time" between the images.

So is there a way to record 50 of those images one after another without any delay (or at least very short delay)?

1

There are 1 answers

2
Mark Setchell On BEST ANSWER

I doubt you can do this with raspistill on the command line - especially with trying to write PNG images fast. I think you'll need to move to Python along the following lines - adapted from here. Note that the images are acquired in the RAM so there is no disk I/O during the acquisition phase.

Save the following as 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)

Then make it executable with:

chmod +x acquire.py

And run with:

./acquire.py

If you want to write the image list to disk as PNG, you can use something like this (untested) with PIL added to the end of the above code:

from PIL import Image

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