Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to lock focus in camera2 api, android?

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?

like image 988
mudin Avatar asked Feb 09 '17 02:02

mudin


People also ask

How do you lock a 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.

How do you lock the focus on a pixel camera?

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.

What is Level 3 Camera2 API?

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).


2 Answers

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_AUTObut 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()

like image 179
Yamidragut Avatar answered Sep 21 '22 07:09

Yamidragut


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

like image 40
Francisco Durdin Garcia Avatar answered Sep 22 '22 07:09

Francisco Durdin Garcia