Swift ARKit:获取相对于摄影机的面锚定变换

Swift ARKit:获取相对于摄影机的面锚定变换,swift,arkit,Swift,Arkit,我的Swift ARKit应用程序需要脸部相对于前置摄像头的位置和方向。如果我设置了ARConfiguration.worldAlignment=.camera,我所需要做的就是调用faceAnchor.transform,它工作得很好;但是我需要在默认的worldAlignment=.gravity中运行。在这种模式下,我可以得到faceAnchor.transform和camera.transform,它们都是以世界坐标提供的。如何使用这些变换在摄影机坐标中获取面锚定?在所有四阶组合中,我尝

我的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)

希望这对其他人有帮助

你找到答案了吗?我正在尝试重新创建这个过滤器,我需要计算头部的倾斜位置。目前还没有答案@DesprateLearner,但发布在Apple dev论坛上[