16
votes

I want to adjust the device's physical camera focus while in augmented reality. (I'm not talking about the SCNCamera object.)
In an Apple Dev forum post, I've read that autofocus would interfere with ARKit's object detection, which makes sense to me.

Now, I'm working on an app where the users will be close to the object they're looking at. The focus the camera has by default makes everything look very blurry when closer to an object than around 10cm.

Can I adjust the camera's focus before initializing the scene, or preferably while in the scene?


20.01.2018
Apparently, there's still no solution to this problem. You can read more about this at this reddit post and this developer forum post for private API workarounds and other (non-helping) info.


25.01.2018
@AlexanderVasenin provided a useful update pointing to Apple's documentation. It shows that ARKit will be able to support not just focusing, but also autofocusing as of iOS 11.3.
See my usage sample below.

2
have you managed to find any solution for this one ?Adam Roszyk
Nope. The post keeps getting upvoted but no one has answered or even commented so far so I'm guessing there's no solution at this point.LinusGeffarth

2 Answers

4
votes

As stated by Alexander, iOS 11.3 brings autofocus to ARKit.
The corresponding documentation site shows how it is declared:

var isAutoFocusEnabled: Bool { get set }

You can access it this way:

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

However, as it is true by default, you should not even have to set it manually, unless you chose to opt out.

3
votes

UPDATE: Starting from iOS 11.3 ARKit supports autofocusing, and it's enabled by default (more info). Manual focusing still aren't available.


Prior to iOS 11.3 ARKit did not supported neither manual focus adjust nor autofocusing.

Here is Apple's reply on the subject (Oct 2017):

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)

There is 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 itself is public, the ARKit's AVCaptureDevice is not, so using this hack in production would most likely result in App Store rejection.