how to capture a photo automatically at focus in android using camera2 api ? There is no callback like onAutoFocused() from api 21 and above.
Asked
Active
Viewed 302 times
1 Answers
1
You have to trigger AF and AE manually. The standard pipeline is:
- set
CONTROL_AF_TRIGGER
toCONTROL_AF_TRIGGER_START
in theCaptureRequest.Builder
that you use for preview and submit to the session throughCameraCaptureSession capture
method. After you have called capture remember to resetCONTROL_AF_TRIGGER
toCONTROL_AF_TRIGGER_IDLE
in the CaptureRequest.Builder for preview; - Wait for AF to finish checking if
CaptureResult.CONTROL_AF_STATE of TotalCaptureResult
in the preview callback isCONTROL_AF_STATE_FOCUSED_LOCKED || CONTROL_AF_STATE_NOT_FOCUSED_LOCKED || CONTROL_AF_STATE_PASSIVE_FOCUSED || CONTROL_AF_STATE_PASSIVE_UNFOCUSED
- When AF is finished trigger AE setting
CONTROL_AE_PRECAPTURE_TRIGGER
toCONTROL_AE_PRECAPTURE_TRIGGER_START
in theCaptureRequest.Builder
that you use for preview and submit to the session throughCameraCaptureSession capture
method. After you have called capture remember to resetCONTROL_AE_PRECAPTURE_TRIGGER
toCONTROL_AE_PRECAPTURE_TRIGGER_IDLE
in the CaptureRequest.Builder for preview; - Wait for AE to finish checking if
CaptureResult.CONTROL_AE_STATE of TotalCaptureResult
in the preview callback isCONTROL_AE_STATE_CONVERGED || CONTROL_AE_STATE_FLASH_REQUIRED || CONTROL_AE_STATE_LOCKED
- Now you can take the picture, focused and well exposed
I have experienced also that is possible to trigger AF e AE at the same time (steps 1-3) and wait for them simultaneously (steps 2-4).

Marco Righini
- 506
- 2
- 12