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

查看:21
本文介绍了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 附加到 ARFaceAnchorcameraNode 代表 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天全站免登陆