Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adjust camera focus in ARKit

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.

like image 794
LinusGeffarth Avatar asked Sep 10 '17 21:09

LinusGeffarth


People also ask

Does ARKit work with front camera?

The ARKit API supports simultaneous world and face tracking via the back and front cameras, but unfortunately due to hardware limitations, the new iPad Pro 2020 is unable to use this feature (probably because the LIDAR camera takes a lot more power).

Can I manually focus my iPhone camera?

If you want to manually adjust the focus and exposure, do the following: Open Camera. Tap the screen to show the automatic focus area and exposure setting. Tap where you want to move the focus area.

Does ARKit use lidar?

Using the LiDAR sensor, ARKit scene reconstruction scans the environment to create mesh geometry representing the real world environment. Additionally, ARKit provides an optional classification of each triangle in the scanned mesh.

How do I change the camera focus on my iPhone?

Your camera focuses and adjusts exposure automatically based on what you're pointing it towards. You can tap a different area in the viewfinder to change the focus and exposure. If you want to keep the focus and exposure in the same spot, press and hold on the screen until you see AE/AF Lock.


2 Answers

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.

like image 110
LinusGeffarth Avatar answered Sep 28 '22 06:09

LinusGeffarth


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.

like image 43
Alexander Vasenin Avatar answered Sep 28 '22 08:09

Alexander Vasenin