Hi there, I'd like to accurately determine the current person's head pose in ARKit's face recognition. Here is my code, but it was not precise.
fileprivate func getCurrentDirection(faceAnchor: ARFaceAnchor) -> CommandDirection?{
let transform = faceAnchor.transform
let pitch = atan2(-transform.columns.2.y, transform.columns.2.z)
let yaw = atan2(transform.columns.2.x, transform.columns.2.z)
var direction: CommandDirection?
var horizontalTurn = false
if yaw > 0.5 {
horizontalTurn = true
direction = .right
} else if yaw < -0.3 {
horizontalTurn = true
direction = .left
}
if(!horizontalTurn){
if pitch > 0.5 {
direction = .down
} else if pitch < -0.1 {
direction = .up
}
}
return direction
}
func renderer(_ renderer: SCNSceneRenderer, didUpdate node: SCNNode, for anchor: ARAnchor) {
guard let faceAnchor = anchor as? ARFaceAnchor, let currentRotationDirection = getCurrentDirection(faceAnchor: faceAnchor) else {
return
}
}