[HOW-TO] speed up still image capture_array?

Open
#914 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
28/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python, raspberry-pi

Research direction

Start with the capture_array.py example and the Picamera2 capture_array entry point, then reproduce the reported 0.12-second timings using the shown still configuration on the Raspberry Pi Camera Module 3. Compare the measured behavior with the requested 480x270 output and determine whether a supported configuration change can improve it; document the result and evidence when done.

Written by the indexing model from the issue text.

Description

Hi there, I'm using a Raspberry Pi Camera Module 3 with a Raspberry pi 4b. I'm trying to capture still images with the full field of view of the camera, but then scale them down to a smaller size. I'm trying to do this as fast as possible.

Here's my code:

import picamera2
import time

picam2 = picamera2.Picamera2()
config = picam2.create_still_configuration(
    main={"size": (480, 270)}, # scale down the 4608x2592 image, but maintain the full field of view
    raw={'size': picam2.sensor_resolution}, # 4608x2592
    buffer_count=2
)
picam2.configure(config)
picam2.start()

while True:
    loop_start = time.time()
    output_orig = picam2.capture_array()
    img_capture_elapsed_s = round(time.time() - loop_start, 3)

    print(f"Image capture took {img_capture_elapsed_s} s. {output_orig.shape}")

I'm seeing capture_array performance timings of about 0.12 seconds. Is there any way to speed this up, or is this as fast as it goes? Here are the logs that this program generates:

% python3 capture_array.py
[1:10:13.600190093] [2801]  INFO Camera camera_manager.cpp:297 libcamera v0.0.5+83-bde9b04f
[1:10:13.717678717] [2804]  INFO RPI vc4.cpp:437 Registered camera /base/soc/i2c0mux/i2c@1/imx708@1a to Unicam device /dev/media4 and ISP device /dev/media1
[1:10:13.717763491] [2804]  INFO RPI pipeline_base.cpp:1101 Using configuration file '/usr/share/libcamera/pipeline/rpi/vc4/rpi_apps.yaml'
[1:10:13.725368945] [2801]  INFO Camera camera.cpp:1033 configuring streams: (0) 480x270-BGR888 (1) 4608x2592-SBGGR10_CSI2P
[1:10:13.726000376] [2804]  INFO RPI vc4.cpp:565 Sensor: /base/soc/i2c0mux/i2c@1/imx708@1a - Selected sensor format: 4608x2592-SBGGR10_1X10 - Selected unicam format: 4608x2592-pBAA
Image capture took 0.693 s. (270, 480, 3)
Image capture took 0.12 s. (270, 480, 3)
Image capture took 0.12 s. (270, 480, 3)
Image capture took 0.119 s. (270, 480, 3)
Image capture took 0.12 s. (270, 480, 3)
Image capture took 0.122 s. (270, 480, 3)
Image capture took 0.118 s. (270, 480, 3)
...

Thanks!

Dominant language
Python
Stars
1.2k
Forks
258
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from raspberrypi/picamera2

All issues in raspberrypi/picamera2

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.