In the past, I have used Raspberry boards and cameras for art installations involving multiple videos.Not sure if I'm answering the right question, which I assume to be how you change the preview image coming out of the camera system, not simply a question of rendering it to the display in a squashed or stretched manner....
Maybe some of the camera dev team folks who hang out here could answer that one.
Anyway, the scaler crop is the usual way to change which part of the camera image will be used. By default, libcamera calculates and applies the scaler crop that will give you 1:1 (unsquished) pixels. But you can override this directly. Note that the scaler crop is always specified in the coordinates of the sensor's native full resolution image (check "picam2.sensor_resolution"). This means you can use the same calculations whatever mode the sensor is running in.
Here's an example:We've asked for a square output image so we start off seeing just a horizontal crop from what's available. That is, we don't see the extreme left and right of the field of view (FoV). The "set_control" changes this, so that the entire FoV (this is a Camera Module 3) gets squished into the square output.Code:
from picamera2 import Picamera2picam2 = Picamera2()config = picam2.create_preview_configuration({"size": (1000, 1000)})picam2.start(config, show_preview=True)picam2.set_controls({'ScalerCrop': (0, 0, 4608, 2592)})
Once you've started the camera, looking at "picam2.camera_controls['ScalerCrop']" is quite informative. The second value is the largest FoV you could actually ask for and represents the entirety of what is being output by the sensor. In my example above this will be (0, 0, 4608, 2592), so this is a full FoV camera mode. The third value is the default value libcamera calculated, and which gives you 1:1 pixels. In this case it is (1008, 0, 2592, 2592) indicating that this is discarding 1008 pixels on the left (and right), before the result is scaled to 1000x1000.
I think I understand what you are saying: the preview_configuration sets the window frame — and in your example is 1000 x 1000 square — and then the camera.controls.ScalerCrop=(1008, 0, 2592, 2592) — or whatever I put there — sets what is placed into that frame. If the frame is wider than the ScalerCrop, then the output image gets stretched; if narrower, then squished; if the same, then normal.
Now, how do I alter the 1000 x 1000 preview when the camera is live? Is there something like camera.preview_configuration_size=(1500, 1000) where I might stretch the window when the preview is running?
Statistics: Posted by therealahm — Wed Jan 17, 2024 1:51 pm