Swift ARKit:获取相对于相机的面部锚点变换

3

我正在开发一个Swift ARKit应用程序,需要获取面部相对于前置摄像头的位置和方向。如果我设置ARConfiguration.worldAlignment = .camera,那么我所需要做的就是调用faceAnchor.transform,它可以完美运行;但我需要在默认模式下运行worldAlignment = .gravity。在这种模式下,我可以获取到以世界坐标为基准的faceAnchor.transformcamera.transform。如何使用这些变换来获得以相机坐标系为基准的面部锚点?我尝试过将这些乘起来,也尝试过将一个变换与另一个变换的逆矩阵相乘,所有四种组合方式都试过了,但是这些结果都不正确。我对矩阵运算不够了解,无法成功解决问题。有人能帮我理清思路吗?


你找到答案了吗?我正在尝试重新创建这个滤镜https://www.instagram.com/stories/highlights/17849968714897293/,我需要弄清楚头部的倾斜位置。 - undefined
还没有答案,@DesperateLearner,但已在Apple开发者论坛上发布了[https://forums.developer.apple.com/message/416269#416269]。 - undefined
1个回答

8

最终我使用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)

希望这能帮助其他人!

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接