ARKit:如何判断用户的面部是否与相机平行 [英] ARKit: How to tell if user's face is parallel to camera

查看:127
本文介绍了ARKit:如何判断用户的面部是否与相机平行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Swift/ARKit/SceneKit项目中,我需要确定前置摄像头中用户的脸部是否与摄像头平行.

In my Swift / ARKit / SceneKit project, I need to tell if the user's face in front-facing camera is parallel to the camera.

通过比较左眼和右眼距离(使用faceAnchor.leftEyeTransformworldPosition属性),我能够分辨出水平方向的平行度.

I was able to tell horizontal parallel by comparing the left and right eyes distance (using faceAnchor.leftEyeTransform and the worldPosition property) from the camera.

但是我被困在垂直平行线上.有什么想法,如何实现?

But I am stuck on vertical parallel. Any ideas, how to achieve that?

推荐答案

假定您在应用程序中使用ARFaceTrackingConfiguration,则实际上可以检索ARFaceAnchor和相机的变换以确定它们的方向.您可以使用ARFaceAnchor.transform属性获得世界空间中头部方向的simd_float4x4矩阵.同样,您可以获取场景的SCNCameraARCamera的变换.

Assuming you are using ARFaceTrackingConfiguration in your app, you can actually retrieve the transforms of both the ARFaceAnchor and the camera to determine their orientations. You can get a simd_float4x4 matrix of the head's orientation in world space by using ARFaceAnchor.transform property. Similarly, you can get the transform of the SCNCamera or ARCamera of your scene.

要在SceneKit应用中比较相机和脸部的相对方向(尽管ARKit方面有相似的功能),我得到了附着在它们各自上的节点的世界变换,我们称之为它们faceNode附加到ARFaceAnchor,并且cameraNode代表ARSCNView.pointOfView.例如,要找到相机和脸部之间的角度,可以执行以下操作:

To compare the camera's and face's orientations relative to each other in a SceneKit app (though there are similar functions on the ARKit side of things), I get the world transform for the node that is attached to each of them, let's call them faceNode attached to the ARFaceAnchor and cameraNode representing the ARSCNView.pointOfView. To find the angle between the camera and your face, for example, you could do something like this:

let faceOrientation: simd_quatf = faceNode.simdWorldTransform
let cameraOrientation: simd_quatf = cameraNode.simdWorldTransform
let deltaOrientation: simd_quatf = faceOrientation.inverse * cameraOrientation

通过查看deltaOrientation.angledeltaOrientation.axis,您可以确定面部和相机之间每个轴上的相对角度.如果您执行类似deltaOrientation.axis * deltaOrientation.angles的操作,则您会得到一个simd_float3矢量,使您可以感觉到相对于摄像机的头部的俯仰,偏航和侧倾(以弧度为单位).

By looking at deltaOrientation.angle and deltaOrientation.axis you can determine the relative angles on each axis between the face and the camera. If you do something like deltaOrientation.axis * deltaOrientation.angles, you have a simd_float3 vector giving you a sense of the pitch, yaw and roll (in radians) of the head relative to the camera.

您可以通过多种方式使用面部锚和摄影机转换来执行此操作,但是这种simd四元数方法对我来说效果很好.希望这可以帮助!

There are a number of ways you can do this using the face anchor and camera transforms, but this simd quaternion method works quite well for me. Hope this helps!

这篇关于ARKit:如何判断用户的面部是否与相机平行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆