在 ARKit 中调整相机焦点

Adjust camera focus in ARKit

我想在增强现实中调整设备的物理相机焦点。 (我不是在谈论 SCNCamera 对象。)
Apple Dev forum post 中,我了解到自动对焦会干扰 ARKit 的对象检测,这对我来说很有意义。

现在,我正在开发一款应用程序,用户可以在其中靠近他们正在查看的对象。默认情况下,相机的焦点使距离物体比 10 厘米左右更近时,一切看起来都非常模糊。

我可以在初始化场景之前或最好在场景中调整相机的焦距吗?


2018.01.20
显然,这个问题仍然没有解决方案。您可以在 this reddit post and this developer forum post 阅读更多相关信息,了解私人 API 解决方法和其他(无帮助)信息。


25.01.2018
@AlexanderVasenin 提供了指向 Apple 文档的有用更新。它表明从 iOS 11.3 开始 ARKit 不仅可以支持对焦,还可以支持 自动对焦
请参阅下面我的使用示例。

更新:从 iOS 11.3 开始,ARKit 支持自动对焦,并且默认启用 (more info)。手动对焦仍然不可用。


iOS11.3 之前的 ARKit 既不支持手动调焦也不支持自动对焦。

以下是 Apple 对该主题的回复(2017 年 10 月):

ARKit does not run with autofocus enabled as it may adversely affect plane detection. There is an existing feature request to support autofocus and no need to file additional requests. Any other focus discrepancies should be filed as bug reports. Be sure to include the device model and OS version. (source)

another thread on Apple forums where a developer claims he was able to adjust autofocus by calling AVCaptureDevice.setFocusModeLocked(lensPosition:completionHandler:) method on private AVCaptureDevice used by ARKit and it appears it's not affecting tracking. Though the method 本身是 public,ARKit 的 AVCaptureDevice 不是,所以在生产中使用这个 hack 很可能会导致 App Store 拒绝。

作为 ,iOS 11.3 为 ARKit 带来了自动对焦。
corresponding documentation site 显示了它是如何声明的:

var isAutoFocusEnabled: Bool { get set }

您可以通过以下方式访问它:

var configuration = ARWorldTrackingConfiguration()
configuration.isAutoFocusEnabled = true // or false

但是,由于它默认为 true,您甚至不必手动设置它,除非您选择退出。