1

I have a Pi 4 with the High Quality Camera. I'm trying to capture raw frames with Picamera2 using the camera's 2028x1520 2x2 binning mode.

I'm using camera.sensor_modes[2], which says it has a maximum FPS of 40.

{'format': SRGGB12_CSI2P, 'unpacked': 'SRGGB12', 'bit_depth': 12, 'size': (2028, 1520), 'fps': 40.01, 'crop_limits': (0, 0, 4056, 3040), 'exposure_limits': (60, 674181621, None)}

Here's my test code. It captures and discards 100 frames and calculates the FPS.

from picamera2 import Picamera2
import time

# Configure camera for 2028x1520 mode
camera = Picamera2()
config = camera.create_preview_configuration({"size": (2028, 1520)}, raw = camera.sensor_modes[2])
camera.configure(config)

# Start camera
camera.start()
time.sleep(1)

# Capture 100 frames and calculate FPS
startTime = time.time()
for i in range(100):
    camera.capture_array("raw")
print(1 / (time.time() - startTime) * 100)

I ran it a few times and got values between 15.11 and 15.12 FPS. I think the actual framerate is exactly 15 FPS, but the first frame is already buffered and is returned instantly. It being so close to 15 FPS makes me think the problem lies in a camera configuration issue, not Picamera2 dropping frames.

How can I capture frames at the full 40 FPS?

(I know the micro SD card isn't capable of saving raw frames at 40 FPS. I plan to capture for a few seconds into RAM, then write it slowly to the micro SD card).

3

1 Answer 1

2

I added

camera.set_controls({"FrameRate": 40})

between camera.configure(config) and camera.start() and it fixed the problem. Apparently the camera defaults to a lower framerate.

3
  • Can you mark your own answer as correct - assume that's possible?
    – CoderMike
    Commented Jun 28, 2023 at 20:45
  • Yeah, but I need to wait 24 hours.
    – LostXOR
    Commented Jun 29, 2023 at 1:24
  • 1
    Alright just did that.
    – LostXOR
    Commented Jun 29, 2023 at 22:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.