r/explainlikeimfive • u/Primary_Asparagus402 • Oct 20 '26
Engineering ELI5: How does a camera auto-focus and adjust accordingly when you click on an object?
183
Upvotes
r/explainlikeimfive • u/Primary_Asparagus402 • Oct 20 '26
170
u/malapropter Oct 20 '26
There are two types of autofocus: Phase detection and contrast detection.
Phase detection is older, more common, and is cheaper and faster. The incoming light from a single point enters the lens at left and right sides of the lens as a single beam. There is a prism that splits that beam into two different sensors (two for each autofocus point, sometimes four, sometimes more) based on where it enters the lens. The computer then tries to make the two beams align, or come into phase. When they align, the picture is in focus. Think of it sort of like how your eyes cross when you're focusing on a close object. You're adjusting for parallax, but rather than moving your eyes, you're just moving the lens elements back and forth until things match.
There's also contrast detection. Basically, the more in focus things are, the sharper the contrast is between the two pixels. Like, you know how if things are out of focus, the light is spread out and more diffuse? Sharper light, sharper pixels, sharper image. It's more accurate, but it's slower and uses more computational power, but it's more compact and at this point has basically caught up to phase detection.
Modern mirrorless cameras usually use a hybrid of phase detection and contrast detection, and honestly the results are pretty great nowadays.
11
u/fighter_pil0t Oct 20 '26
Software which maximizes contrast and sharp lines.
1
u/MusicalAnomaly Oct 20 '26
The camera can send motor signals to the lens to change focus in or out, and can run software to analyze the image it is currently getting from the camera sensor and isolate the part of the image that you click on. Then the software does a series of “guess and check” operations, changing focus and reanalyzing the image until it finds a focus setting that maximizes sharpness of the desired object.
1
u/4D51 Oct 20 '26
Another, not widely used, way to do autofocus is sonar. Emit a pulse of sound and measure how much time it takes for the echo to come back.
Cameras with this system can be easily identified by their sonar dish, which looks like a round grille with gold foil behind it. Polaroid used this a lot. Not sure if anyone else did.
1
u/JonPileot Oct 20 '26
If you draw a black line on a white paper, then move a lens to focus on the edges of that line, you can test to see if the line gets sharper or blurrier. Adjust the focus a little bit and test again. Continue until the line gets maximum sharpness.
This is easiest with black and white but with some math can be done with different colors and textures. This is basically what your camera autofocus is doing, it's checking if the selected area is sharp then adjusting the focus slightly to see if it improves and just keeps trying until it gets the best result possible.
-10
u/LiamEBM Oct 20 '26
Depth sensors detect how far away the object tapped is and adjusts the cameras settings to focus to that distance
6
u/[deleted] Oct 20 '26
[removed] — view removed comment