Fixed lens position causes blurry video background images

On quite a few of our test devices (various iPhones 6/6s/7 and iPad Pros), ARKit's video background appears blurry and noticeably out of focus. I did a bit of investigating (using private APIs to access the underlying AVCaptureDevice) and found that ARKit will always set camera's lens position (*) to a fixed value of 0.752941.



(*) https://developer.apple.com/documentation/avfoundation/avcapturedevice/1624643-lensposition



As the SDK documentation explicitly states, the same lens position value does not "represent a consistent focus distance from device to device". So, I wonder what motivated the decision to use this specific lens position value across all devices...?



Calling setFocusModeLocked(lensPosition:completionHandler:) (**) does enable me to change the lens position to a more appropriate value, causing the video background to appear crisp and in focus, which incidentally doesn't seem to affect tracking stability at all. But I obviously we're not allowed to use this "workaround" in the App Store as it relies on private API methods.



(**) https://developer.apple.com/documentation/avfoundation/avcapturedevice/1624617-setfocusmodelocked


So, I guess my question is: Is there any way at all to re-focus the camera in ARKit (without the need for private API calls)? And if not, why not?

Replies

Have you found a solution for this?


I am having the same issue trying to use the camera in ARKit to take a photo with the AR scene.

This seems to only be on the iPhone 7/8 plus as far as I can tell... tested on a 6s/7 and the background is sharp. Any resolution?

This ***** and makes ARKit really un-fun for me. Everything more than a foot away is blurry.

THANK YOU for pointing this out. It's been driving me mad on my iPhone X... The cameras take amazing photos and videos, and then ARKit looks bad.


I guess it makes sense, though, to the original point here: ARKit probably provides a fixed focus so that the real-world tracking can work better. That's my assumption, anyway. It would be awesome for devs to be able to set this focus, though... Or even allow the cameras to autofocus like they normally do. I guess that would throw off all kinds of stuff, though.