-2

how to capture a photo automatically at focus in android using camera2 api ? There is no callback like onAutoFocused() from api 21 and above.

vish
  • 1
  • 2

1 Answers1

1

You have to trigger AF and AE manually. The standard pipeline is:

  1. set CONTROL_AF_TRIGGER to CONTROL_AF_TRIGGER_START in the CaptureRequest.Builder that you use for preview and submit to the session through CameraCaptureSession capture method. After you have called capture remember to reset CONTROL_AF_TRIGGER to CONTROL_AF_TRIGGER_IDLE in the CaptureRequest.Builder for preview;
  2. Wait for AF to finish checking if CaptureResult.CONTROL_AF_STATE of TotalCaptureResult in the preview callback is CONTROL_AF_STATE_FOCUSED_LOCKED || CONTROL_AF_STATE_NOT_FOCUSED_LOCKED || CONTROL_AF_STATE_PASSIVE_FOCUSED || CONTROL_AF_STATE_PASSIVE_UNFOCUSED
  3. When AF is finished trigger AE setting CONTROL_AE_PRECAPTURE_TRIGGER to CONTROL_AE_PRECAPTURE_TRIGGER_START in the CaptureRequest.Builder that you use for preview and submit to the session through CameraCaptureSession capture method. After you have called capture remember to reset CONTROL_AE_PRECAPTURE_TRIGGER to CONTROL_AE_PRECAPTURE_TRIGGER_IDLE in the CaptureRequest.Builder for preview;
  4. Wait for AE to finish checking if CaptureResult.CONTROL_AE_STATE of TotalCaptureResult in the preview callback is CONTROL_AE_STATE_CONVERGED || CONTROL_AE_STATE_FLASH_REQUIRED || CONTROL_AE_STATE_LOCKED
  5. 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