Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find distance between iOS Device Camera and user's face

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?

like image 942
Kashif Avatar asked Oct 26 '18 01:10

Kashif


1 Answers

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?

like image 170
YD- Avatar answered Oct 23 '22 04:10

YD-