Calculate distance from iPhone x to an object using ir

Hello,


Is it possible to get the distance from the iphone x ir projection points to an object ?


Using Kinect, this can be done like this: https://pterneas.com/2016/08/11/measuring-distances-kinect/


I can't find any api to do that in the iphone x sdk.


Sorry for my bad english.

Thank you in advance for your help.

Replies

If you set up an ARKit configuration, or use AVFoundation, each captured frame has an associated AVDepthData object, which contains an attached depth buffer indicating distance in meters from camera per pixel. You can use this depth buffer to find the distance of a given pixel in the associated frame pixel buffer.


Read up on AVDepthData: https://developer.apple.com/documentation/avfoundation/avdepthdata

And this is a good tutorial with an AVFoundation example: https://www.raywenderlich.com/168312/image-depth-maps-tutorial-ios-getting-started


Hope this helps!