I am trying to lock focus after my custom camera finds focus. First it AF mode set to auto:
builder.set(CaptureRequest.CONTROL_AF_MODE,
CaptureRequest.CONTROL_AF_MODE_AUTO);
And After touching the preview it finds focus distance, and I have to lock AF and AE using this code:
builder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
builder.set(CaptureRequest.CONTROL_AE_LOCK, true);
Locking AE works fine in any devices. Locking AF is working on Nexus5 and Nexus 5x. But as for Samsung S5 and S6, it keeps try to search focus.
What is the best way to lock focus?
This is where focus lock comes in. To use it, point your camera at the subject and half press the shutter button. You should hear a beep and see a light come on in the viewfinder to let you know the camera has focused. The focus will now remain locked while your finger is still holding the shutter button half down.
Make a manual adjustment - it auto-locks and you will see a new icon appear - it looks like an "undo" icon. Tap that icon to release the lock. For focus - tap on an object and it will lock focus on that object, as long as the object stays visible on the screen.
Level_3: These devices support YUV reprocessing and RAW image capture, along with additional output stream configurations on top of full Camera2 API support. External: Similar to LIMITED devices with some exceptions (e.g. some sensor or lens information may not be reported or have less stable frame rates).
In order to lock the AF you have to take care of requesting the AF_TRIGGER
only once by using capture()
instead of repeatingRequest()
(if not it enters in an af request loop and remains always trying to focus, but some nexus fix this in its FW, so some devices as Nexus 5
focus well even it shouldn't)
So, the correct order will be:
Set CONTROL_AF_MODE
to CONTROL_AF_MODE_AUTO
(via session.setRepeatingRequest()
) and the AF_REGIONS
and the AE_REGIONS
if you want
Wait until you check that the CONTROL_AF_MODE
is already in auto by checking the totalCaptureRequest
from the CaptureCallback
.
Set the AF_TRIGGER_START
in the builder along with the CONTROL_AF_MODE_AUTO
but this time instead of using session.setRepeatingRequest()
use session.capture()
.
Inmediately after that, set the AF_TRIGGER
to set the AF_TRIGGER_IDLE
(not cancel!) an use again session.setRepeatingRequest()
along with the CONTROL_AF_MODE_AUTO
.
Wait until it has focused,you will receive FOCUSED_LOCKED
or NOT_FOCUSED_LOCKED
.
The PASSIVE_FOCUSED
state is only when the CONTROL_AF_MODE
is in continuous picture not in auto!
Take care of being really in auto focus mode before performing the trigger.
You should use always session.capture()
with all triggers (with CONTROL_AE_PRECAPTURE_TRIGGER
too) but always after that remember to put the triggers to IDLE
(not cancel) in a session.repeatingRequest()
You can't locus the focus on CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE
.
You should put your AF mode on CONTROL_AF_MODE_AUTO
adn wait for FOCUSED_LOCKED
state during your AF trigger. You can check how the Android focus machine works on enter link description here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With