Hi, is there any way to set the focus of the 16MP Autofocus Camera to a specific distance from the camera? I’ve been experimenting with it and found that 4095 seems to be the closest focusing distance, which I’m assuming is 10 cm. I’d like to focus at 221 cm (that’s my hyperfocal distance). Is there a formula to calculate the value I need for a given distance, instead of guessing?
Thanks for reaching out. At this time we can’t provide a specific formula for mapping a focus value to a distance. That relationship isn’t something we’ve documented, so you’ll need to take actual measurements to work out which values correspond to the distances you want.
OK, thanks. Different issue now. I’m trying to figure out whether this camera is usable for video streaming that feeds into AI processing, but the 1080p video I save is really low quality - very blurry compared to the preview I get from libcamera-hello.
A few things I noticed:
- libcamera-hello doesn’t actually select 1920x1080, it picks 3840x2160. But even then, the recording shouldn’t be that much worse than the preview scaled down to 1920x1080.
- I compared two libcamera-still captures, one at 4656x3496 and one at 2328x1748, same settings otherwise. Displayed at the same size in Microsoft Photos (76% and 38%), the 2328x1748 shot is incredibly blurry while the full resolution one is perfectly sharp.
- The 4656x3496 image shouldn’t be sharper when Microsoft Photos scales it down than when the camera natively scales it down to 2328x1748. That doesn’t add up.
Why can’t I get the same quality video/image when using a lower resolution?
Commands I used:
libcamera-vid --shutter 20000 --gain 2 -o 1080p.h264 --width 1920 --height 1080 --framerate 30 --rotation 180 -t 5000
libcamera-hello --width 1920 --height 1080 --mode 1920:1080 --preview 0,0,1920,1080 --framerate 30 --shutter 20000 --gain 2 -t 100000000 --rotation 180
Two libcamera-still captures with identical settings except the resolution (4656x3496 and 2328x1748).
Thanks for the detailed report and the commands. We are testing the problem you encountered and will inform you as soon as the results are available. The lower-resolution quality difference compared to full resolution is something we want to reproduce on our side first.
Any update on this? I’m stuck deciding whether this camera is usable for my streaming use case, so it’d really help to know whether the low-resolution quality is expected behavior or a bug.
We ran your libcamera-hello command and found that the default resolution it selects is 2328x1748. So the resolution the preview uses and the resolution of your image don’t actually match - that’s likely a big part of what you’re seeing.
To preview at your requested resolution, use --viewfinder-width and --viewfinder-height, e.g.:
libcamera-hello --viewfinder-width 1920 --viewfinder-height 1080
For getting the same quality of images at low resolution, have a look at the official libcamera documentation here:
https://www.raspberrypi.com/documentation/accessories/camera.html#libcamera-and-libcamera-apps
You can also run:
libcamera-still -h
which lists the available parameters and usually helps you find the option you need.
So the takeaway is: specify the preview resolution explicitly with --viewfinder-width/–viewfinder-height so the preview and image resolutions line up, and check the docs for matching low-resolution image quality. We’ll follow up if our testing turns up anything else.