如何在Android的Camera2 API中锁定焦点? [英] 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);
在触摸预览后,它会找到对焦距离,我必须使用以下代码锁定AF和AE:
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);
锁定AE在任何设备上都可以正常工作.在Nexus5和Nexus 5x上,锁定自动对焦功能有效.但是对于三星S5和S6,它一直试图寻找焦点.
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?
推荐答案
要锁定AF,您必须使用capture()
而不是repeatingRequest()
来仅请求一次AF_TRIGGER
(如果不是,则为进入af请求循环并始终始终尝试聚焦,但是有些关系在其固件中对此进行了修复,因此Nexus 5
的某些设备很好地聚焦,即使它不应该)
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:
-
根据需要将
CONTROL_AF_MODE
设置为CONTROL_AF_MODE_AUTO
(通过session.setRepeatingRequest()
),然后将AF_REGIONS
和AE_REGIONS
设置为
Set
CONTROL_AF_MODE
toCONTROL_AF_MODE_AUTO
(viasession.setRepeatingRequest()
) and theAF_REGIONS
and theAE_REGIONS
if you want
等待直到通过从CaptureCallback
中检查totalCaptureRequest
来检查CONTROL_AF_MODE
已经处于自动状态.
Wait until you check that the CONTROL_AF_MODE
is already in auto by checking the totalCaptureRequest
from the CaptureCallback
.
在构建器中同时设置AF_TRIGGER_START
和CONTROL_AF_MODE_AUTO
,但这一次不使用session.setRepeatingRequest()
而是使用session.capture()
.
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()
.
此后,立即设置AF_TRIGGER
来设置AF_TRIGGER_IDLE
(不可取消!),再次使用session.setRepeatingRequest()
和CONTROL_AF_MODE_AUTO
.
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
.
请等到焦点对准后,您会收到FOCUSED_LOCKED
或NOT_FOCUSED_LOCKED
.
Wait until it has focused,you will receive FOCUSED_LOCKED
or NOT_FOCUSED_LOCKED
.
PASSIVE_FOCUSED
状态仅在CONTROL_AF_MODE
处于连续画面而不处于自动状态时显示!
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.
您应始终对所有触发器使用session.capture()
(也对CONTROL_AE_PRECAPTURE_TRIGGER
使用),但在此之后始终要记住将触发器置于session.repeatingRequest()
中的IDLE
(而不是取消)
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()
这篇关于如何在Android的Camera2 API中锁定焦点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!