13

I am trying to find distance between iOS device's front-facing camera and user's face in the real world.

So far, I have tried ARKit/SceneKit, and using ARFaceAnchor I am able to detect user's face distance from camera; but it works only in close proximity (up to about 88 cm). My application requires face distance detection up to 200 cms.

I am assuming this could be achieved without the use of trueDepth data (which is being used in ARFaceAnchor).

Can you put me in the right direction?

Karthick Ramesh
  • 1,361
  • 16
  • 25
Kashif
  • 4,074
  • 6
  • 39
  • 82
  • 2
    Please check this :- https://github.com/evermeer/EVFaceTracker – VDPurohit Oct 26 '18 at 06:14
  • That's interesting to know about this 88cm limitation of ARFaceAnchor! I would suggest using VNDetectFaceRectanglesRequest to detect faces and VNTrackObjectRequest to track them if necessary. Not sure though they will perform better on bigger distances though. – Maxim Volgin Oct 26 '18 at 11:41
  • You are right it can be done without trueDepth data. I have seen no of apps doing the same with back camera. I was also searching for the same but couldn't succeeded good luck to you !! – Prashant Tukadiya Nov 19 '18 at 04:41

1 Answers1

7

In order to get the distance between the device and the user's face you should convert position of the detected user's face into camera's coordinate system. To do this, you will have to use the convertPosition method from SceneKit to switch coordinate space, from face coordinate space to camera coordinate space.

let positionInCameraSpace = theFaceNode.convertPosition(pointInFaceCoordinateSpace, to: yourARSceneView.pointOfView)

theFaceNode is the SCNNode created by ARKit representing the user's face. The pointOfView property of your ARSCNView returns the node from which the scene is viewed, basically the camera.

pointInFaceCoordinateSpace could be any vertices of the face mesh or just the position of theFaceNode (which is the origin of the face coordinate system). Here, positionInCameraSpace is a SCNVector3, representing the position of the point you gave, in camera coordinate space. Then you can get the distance between the point and the camera using the x,y and z value of this SCNVector3 (expressed in meters).

these are some links that may help you :

-Distance between face and camera using ARKit

-https://github.com/evermeer/EVFaceTracker

-https://developer.apple.com/documentation/arkit/arfacetrackingconfiguration

-How to measure device distance from face with help of ARKit in iOS?

YD-
  • 306
  • 2
  • 8
  • Awarding bounty as the community seems to think this is the answer. However, I am busy with another project right now. Once I am back, I will validate the answer. – Kashif Nov 23 '18 at 12:57