Android camera 2 click to focus

Trying to switch to focus using camera2api .

  CaptureRequest.Builder afBuilder = mPreviewBuilder; Rect newRect=new Rect(0,0,200,200); MeteringRectangle meteringRectangle=new MeteringRectangle(newRect,METERING_WEIGHT_DONT_CARE); MeteringRectangle[] areas = afBuilder.get(CaptureRequest.CONTROL_AF_REGIONS); mPreviewBuilder.set(CaptureRequest.CONTROL_AF_REGIONS,areas); mPreviewBuilder.set(CaptureRequest.CONTROL_AF_MODE, CameraMetadata.CONTROL_AF_MODE_AUTO); mPreviewBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_START); mPreviewSession.setRepeatingRequest(mPreviewBuilder.build(), mCaptureCallback, mBackgroundHandler); 

In my callback, I am constantly stuck in the ACTIVE_SCAN state and sometimes go into the FOCUS_NOT_LOCKED state. I can never get into FOCUS_LOCKED state, and the view will never be focused.

Using samsung galaxy note 3.

+5
source share
1 answer

First, you do not actually set the autofocus area - you just reuse the default area from mPreviewBuilder.

Secondly, even if you set the area to [(0,0,200,200), METERING_WEIGHT_DONT_CARE], which is in the upper left corner of the image and probably not what you want?

Third, and most importantly, you set up an autofocus trigger to repeat. This means that on each frame you ask the camera to restart focusing. Thus, it will never end because you never allow it.

You need to set AF_TRIGGER to START for only one capture; you still want to set AF_REGION and AF_MODE to repeat the request so that it is consistent across the entire autofocus you run.

+2
source

Source: https://habr.com/ru/post/1257685/


All Articles