Thanks therealdavidpHi again, I did have a go at running your code. It complained about a couple of lines so I just deleted them!
For zooming in, it seems to be asking for a 1000x1000 pixel crop from the image which I didn't understand. This doesn't match the aspect ratio of ScalerCropMaximum so you're going to get squished images.
When zooming out, it's asking for a 20000x20000 crop from the image. This doesn't make sense because these are supposed to be pixels in the units of PixelArraySize, and none of our cameras have sensors that large! I also saw it coming up with negative offsets, which is not meaningful.
The important thing to look at is the ScalerCropMaximum which defines what the camera mode can crop out of the PixelArraySize (and does, by default). Whatever values you send *must* define a rectangle in the PixelArraySize which is contained in the ScalerCropMaximum.
For example, to zoom in by a factor of 4, I would expect something like this:and to zoom all the way out againCode:
scaler_crop_maximum = picam2.camera_properties['ScalerCropMaximum']full_res = picam2.camera_properties['PixelArraySize']size = [s // 4 for s in scaler_crop_maximum[2:]]offset = [(r - s) // 2 for r, s in zip(full_res, size)]picam2.set_controls({'ScalerCrop': offset + size})
Does that help?Code:
picam2.set_controls({'ScalerCrop': scaler_crop_maximum})
I understand a little better.
The zoom in is now in a ratio that respects the ratio of the original image.
However, for the zoom out, using this line :
picam2.set_controls({'ScalerCrop': scaler_crop_maximum})
I get for an image ratio :
- format 1.33: config = picam2.create_video_configuration({'size': (2028, 1524)}, transform=Transform(hflip=1, vflip=1))
When I dezoome the image ratio is well respected.
- format 1.37 : config = picam2.create_video_configuration({'size': (2028, 1480)}, transform=Transform(hflip=1, vflip=1))
When I dezoome the image ratio is not respected, the image is slightly stretched. The scaler_crop_maximum = (0,0,4056,3040) when it should be (0,40,4056,2960) to respect the ratio.
- format 2.35: config = picam2.create_video_configuration({'size': (2028, 795)}, transform=Transform(hflip=1, vflip=1))
When I dezoome the image ratio is not respected, the image is very stretched. The scaler_crop_maximum = (0.440,4056,2160) when it should be (0.726,4056,1588) to respect the ratio.
And so on for other formats, where the image is more or less distorted when dezoomed. If the width/height ratio is large, the distortion is large.
This is where my understanding ends. I'd like to be able to zoom in while respecting the selected ratio.
Statistics: Posted by davebixby — Fri Mar 01, 2024 11:13 am