我的Swift ARKit应用需要人脸相对于前置摄像头的位置和方向。如果我将 ARConfiguration.worldAlignment = .camera
我需要做的就是打电话给 faceAnchor.transform
但我需要在默认的 worldAlignment = .gravity
. 在这种模式下,我可以得到 faceAnchor.transform
和 camera.transform
这两个都是以世界坐标提供的。我如何使用这些变换来获得相机坐标中的人脸锚?我试过将它们乘在一起,也试过将其中一个乘以另一个的反值,四种顺序组合,但这些结果都不成功。我只是对矩阵运算理解不深,在这里无法成功。谁能给我指点一下?
我终于用SceneKit的函数解决了这个问题!
let currentFaceTransform = currentFaceAnchor!.transform
let currentCameraTransform = frame.camera.transform
let newFaceMatrix = SCNMatrix4.init(currentFaceTransform)
let newCameraMatrix = SCNMatrix4.init(currentCameraTransform)
let cameraNode = SCNNode()
cameraNode.transform = newCameraMatrix
let originNode = SCNNode()
originNode.transform = SCNMatrix4Identity
//Converts a transform from the node’s local coordinate space to that of another node.
let transformInCameraSpace = originNode.convertTransform(newFaceMatrix, to: cameraNode)
let faceTransformFromCamera = simd_float4x4(transformInCameraSpace)
希望这能帮助到其他人