如何在camera2 api,android中锁定焦点? [英] How to lock focus in camera2 api, android?

查看:65
本文介绍了如何在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 在任何设备上都可以正常工作.锁定 AF 正在 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()<只请求一次 AF_TRIGGER/code> 而不是 repeatingRequest()(如果不是,它会进入一个 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)

所以,正确的顺序是:

  • CONTROL_AF_MODE 设置为 CONTROL_AF_MODE_AUTO(通过 session.setRepeatingRequest())和 AF_REGIONSAE_REGIONS 如果你愿意

  • Set CONTROL_AF_MODE to CONTROL_AF_MODE_AUTO (via session.setRepeatingRequest()) and the AF_REGIONS and the AE_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_STARTCONTROL_AF_MODE_AUTO 但这次不是使用 session.setRepeatingRequest() 而是使用 <代码>session.capture().

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

紧接着,设置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_LOCKEDNOT_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),但在那之后始终记得将触发器置于 IDLEsession.repeatingRequest()

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

这篇关于如何在camera2 api,android中锁定焦点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆