How to measure the face width from ARKit face data?

487 Views Asked by At

I am trying to measure the width of a person's face using ARKit.

ARKit provides ARSCNFaceGeometry that has a bounding box property. It is mentioned that the bounding box is in local coordinate space My understanding is that if I can get the width of the bounding box around the face mesh, that should equate to the width of the face.

func renderer(_ renderer: SCNSceneRenderer, didUpdate node: SCNNode, for anchor: ARAnchor) {
        guard let faceAnchor = anchor as? ARFaceAnchor, 
              let faceGeometry = node.geometry as? ARSCNFaceGeometry else {return}

        faceGeometry.update(from: faceAnchor.geometry)

        let width = faceGeometry.boundingBox.max.x - faceGeometry.boundingBox.min.x
        print(width)
}

When I used this, I felt like I got the face width, but for some reason, the face value never changes even if I am detecting different faces.

I also tried converting the coordinates from the local space to world space by

        let (localMin, localMax) = faceGeometry.boundingBox
        
        let min = node.convertPosition(localMin, to: nil)
        let max = node.convertPosition(localMax, to: nil)
        let width = max.x - min.x

In this case the width value is still incorrect.

Any thoughts on how to get the width accurately?

0

There are 0 best solutions below