You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I guess this may just be a quick question rather than an issue report. I have been playing around with picamera for a week now. One thing I notice is that when I crop an image and try to preview it, either by fullscreen or using preview_window, the display image always shown with wrong aspect ratio. For example: if I set resolution to 1972x976 and set crop=(0.0, 0.0, 0.1, 0.5), I can't find a way to make preview to properly display it at 197x488 pixel, instead, the preview images seems to always resize/scale the cropped image into 4:3 aspect ratio.
Do you know how to fix this? Or am I doing anything wrong?
Thanks for the great work!
The text was updated successfully, but these errors were encountered:
What the camera will do in this case is set its mode to 1296x972@30fps (because that's the closest mode it has given the requested resolution and framerate), and crop the result to 197x488.
What's slightly tricky to understand about the crop attribute is that it represents the portion of the sensor that will be used by the camera for input, and that it's already scaled (by the GPU) so a width and height of 100%, given by a crop value of (0.0, 0.0, 1.0, 1.0) represents a normal undistorted image. So, if you wanted to zoom in on the central portion of your 197x488 display you still need to specify a "square" aspect ratio for the width and height, e.g.:
Thank your for your answer. I think I understand it better now. Basically I tried to select a small region out of FOV but I confused "resolution" with "camera mode". When I set resolution = (1296,972), I was hoping that I forced the camera mode to 1296x972, but that was not the case.
Am I correct to say that "camera mode" is chosen not only from frame rate and resolution, but also crop width & height?
Setting frame rate aside, considering 2 cases below, in case1, camera mode should be 640x480 while in case 2, camera mode should be 1276x972. Am I right?
Unfortunately no, there's a few misconceptions there:
Firstly, the crop (region of interest/zoom) has nothing to do with the camera mode selection - it's purely down to resolution and framerate (controlled by the like-named properties in PiCamera).
In the first case you give, assuming framerate is 30 (the default), then the camera mode won't be 640x480. Notice that in the table in camera modes the two 640x480 modes have a framerate range of 42.1-60.0fps and 60.1-90fps. However, the camera's framerate is 30 which is outside those ranges, so instead the camera will select the 1296x972 mode and downscale the output (it'll select this mode instead of 1296x730 because the aspect ratio is closer).
In your second case the same will happen (because crop doesn't affect the mode and the resolution and presumably framerate are the same).
Hi Dave, Thanks for help clearing up things for me. I guess one more thing that add to my confusion is how crop works more like zoom when it still keep the resolution of the cropped image the same as original image, not smaller. Here's my final code that's try to capture and crop a small portion in the top left (or anywhere other than the central area) of the FOV and obtain a smaller resolution image using resize parameter during capturing. Hope I'm doing it right this time :-)
camera.framerate=42# force camera mode to 1296 x 972, capturing full FOVcamera.crop= (0,0,0.3,0.2)
# Need only 389 x 194 pixel (30% x 20% of FOV) on the top left of the FOVcamera.capture('test.jpg',use_video_port=True,resize=(389,194))
By doing so, I was able to achieve my desired goal. In this case, preview of cropped image still be in 4:3 ratio, which is in a wrong portion. But the test.jpg come out correctly.
Yup ... as mentioned, crop is dreadfully badly named (which is my fault). I think for 1.8 I really should rename it to zoom as there seems to be a consensus (amongst the various people that have mentioned this) that that's a sensible alternative. I'll keep crop there as a deprecated alias until I get around to working on 2.0. So, for now I'll relabel this as a rename task for 1.8.