1

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)?

adroid
  • 25
  • 4
  • Have you tried setting up a RAM disk and saving the files to that? Then you can copy them to non-volatile storage later. – Andrew Morton Jul 12 '21 at 11:31
  • No, I haven't tried it yet, since I'm not too experienced. I will try it asap and see if it solves my problem, thank you! – adroid Jul 12 '21 at 11:39

1 Answers1

0

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')
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • Thank you very much! Your answer worked for me. I could add the below-mentioned part of your answer to save the images. While the old recording method took about 6 Minutes and 5 secounds, your solution took about 2 minutes and 15 secounds from recording to saving. – adroid Jul 15 '21 at 12:16
  • Cool - I'm glad it worked for you. Good luck with your project. – Mark Setchell Jul 15 '21 at 12:56