Question: how does a camera know when it's in focus?
Answer: A computer inside the camera evaluates the signal from the autofocus sensor and commands the lens to adjust the focusing elements inside the lens until the two images appear identical. Once the two images match, the image is in focus. Early sensors just evaluated vertical details in the image.