Camera Module 3 Preview is Cropped

I am working with a Raspberry Pi camera for the first time and have become ‘stuck’.

Setup:
Raspberry Pi Zero 2 W
Raspberry Pi OS Lite (32 bit) Bookworm
Camera Module 3

If I run the command rpicam-hello –timeout 0, as expected, I get a preview which shows the full image in 16:9 format. See attached image.

If I run the code preview_drm.py (down loaded from the ‘Picamera2Library’ examples, see below), the preview is displayed in 16:9 format but is significantly cropped to the size of the black rectangle in the attached image.

I have tried a variety of variations to the parameters in the preview definitions but cannot get the preview from the Python program to display the full image.

Could someone suggest what variations to the Python code are required to present the full image in preview?

Thanks, Fred

preview_drm.py

#!/usr/bin/python3

For use from the login console, when not running X Windows.

import time

from picamera2 import Picamera2, Preview

picam2 = Picamera2()

picam2.start_preview(Preview.DRM, x=100, y=100, width=640, height=480)

preview_config = picam2.create_preview_configuration({“size”: (640, 360)})

picam2.configure(preview_config)

picam2.start()

time.sleep(60)

HI @Frederick60798

You would need to change the line

picam2.start_preview(Preview.DRM, x=100, y=100, width=640, height=480)

to be the resolution that you’re expecting, for a Camera Module 3 this would be

picam2.start_preview(Preview.DRM, x=100, y=100, width=4608, height=2592)

Note you may need to bump this back as your Pi Zero might struggle with capturing an image of this size

To add to what Dan’s advice you can check what your default capture size is with the following code:

resolution = picam2.get_resolution()
print(f"Resolution: {resolution}")

Hope this helps!

Dan,
Thanks for your feedback.
As suggested, I changed the line to

picam2.start_preview(Preview.DRM, x=100, y=100, width=4608, height=2592)

This failed to execute, referencing the above line of code with the final message
Value Error: drmModeAddFB2 failed: Invalid argument

I halved the width and height values to 2304 and 1296 and tried again, but with the same result.

I again halved the width and height values to 1152 and 648 and tried again. This executed successfully, but the preview was cropped as per my original post.

Do you have any further suggestions? I have been able to capture still images in RAW format at a resolution of 4608 x 2592, so it would seem logical that there must be someway to have an uncropped preview of the same image.

Samuel,

Thanks for the feedback.

I tried running you suggested code but it failed with the error mesage :-

AttributeError: ‘Picamera2’ object has no attribute ‘get_resolution’

Hi @Frederick60798

You may also need to change the values in the below to the desired resolution that you’re wanting for your preview.

preview_config = picam2.create_preview_configuration({“size”: (640, 360)})

Dan,
Thanks for your additional suggestion. I tried a variety of size values in this line but could still not get an uncropped preview.
After further searching I found he following discussion on the Raspberry Pi Forum.
https://forums.raspberrypi.com/viewtopic.php?p=2211919&hilit=preview+cropped#p2211919

As explained in the response from JetForMe Sat Apr 13, 2024 9:49 pm the correct ‘mode’ has to be set to get an uncropped preview. By running their suggested code where mode is set to 2 I get an uncropped preview.
Regards,

Fred

Hey @Frederick60798,

Good find! We’ll keep that one in our back pockets for the next time someone runs into this issue.

Glad to hear everything is working now!