Low resolution preview, full resolution capture, & frame rate

I’m building a system using a raspberry pi zero 2, the 16Mp autofocus camera, and the Pimoroni Display Hat Mini (an SPI 320x240 LCD with 4 buttons linked to GPIO)

I’m running bullseye lite, so I don’t have the desptop installed.

I’m writing things in python and I’m using your libcamera wrapper. I initialise with

cam.initCamera(DisplayHATMini.WIDTH, DisplayHATMini.HEIGHT, libcamera.PixelFormat.BGR888, buffercount=1, rotation=0)
ret = cam.startCamera()
focuser = Focuser('/dev/v4l-subdev1')

The console shows this output:

[0:54:52.169938939] [3479]  INFO Camera camera_manager.cpp:293 libcamera v0.0.0
[0:54:52.183039069] [3480]  WARN CameraSensorProperties camera_sensor_properties.cpp:141 No static properties available for 'imx519'
[0:54:52.183136671] [3480]  WARN CameraSensorProperties camera_sensor_properties.cpp:143 Please consider updating the camera sensor properties database
[0:54:52.183202450] [3480] ERROR CameraSensor camera_sensor.cpp:551 'imx519 10-001a': Camera sensor does not support test pattern modes.
[0:54:52.246997780] [3480]  WARN RPI raspberrypi.cpp:1233 Mismatch between Unicam and CamHelper for embedded data usage!
[0:54:52.247942703] [3480] ERROR DelayedControls delayed_controls.cpp:87 Delay request for control id 0x009a090a but control is not exposed by device /dev/v4l-subdev0
[0:54:52.248237591] [3480]  INFO RPI raspberrypi.cpp:1356 Registered camera /base/soc/i2c0mux/[email protected]/[email protected] to Unicam device /dev/media3 and ISP device /dev/media0
[0:54:52.249146578] [3479]  INFO Camera camera.cpp:1028 configuring streams: (0) 320x240-BGR888
[0:54:52.249638649] [3480]  INFO RPI raspberrypi.cpp:751 Sensor: /base/soc/i2c0mux/[email protected]/[email protected] - Selected sensor format: 1280x720-SRGGB10_1X10 - Selected unicam format: 1280x720-pRAA

If I try an capture at full resolution (4656x3496) the frame rate is far too low, the 320x240 frame rate is fine, but not awesome. From the above logging, it looks like it’s capturing at 1280x720 and then downscadling.

The line INFO Camera camera.cpp:1028 configuring streams: (0) 320x240-BGR888 seems to indicate I can setup multiple streams.
Is it possible to configure multiple streams?

I’m capturing the preview with:

    ret, data = cam.readFrame()
    if not ret:
        continue
    frame = data.imageData
    buffer.paste(Image.fromarray(frame, 'RGB')) # paste captured image into the display buffer
    cam.returnFrameBuffer(data)
    display_hat_mini.display()

My questions are:

  1. Can I set up multiple streams, one for preview another for capture?
  2. Is there a better/faster way to capture the preview?
  3. Do I need to call cam.stop() then cam.initCamera(...) to capture the image, then do it again to go back to the preview?
  4. Is there a faster way to capture the full image? cam.readFrame() takes a while.

I’m planning on capturing a series of frames, adjusting the focus a little between each shot, and then I’ll use the output for focus stacking, so maximising the frame rate is important.

Thanks

hi, baralong

  1. You can modify the buffercount parameter during initCamera. Increase the number of request buffers. This can speed up the capture of images.

  2. Currently frames can only be read via the readFrame method. You can start a child thread that just reads the frame and saves it to the queue without doing any other processing.

  3. I think you shouldn’t need to close the camera.