Swift:使用ARKit前置摄像头获取位于“面部坐标”的z向量上的1m向量的x和y“世界坐标”

时间:2018-04-26 17:44:39

标签: swift arkit

我正在尝试计算z矢量(面部坐标)的x和y世界坐标,但结果不准确。我做错了吗?

由于 这是代码。

public func renderer(_ renderer: SCNSceneRenderer, didUpdate node: 
SCNNode, for anchor: ARAnchor) {
    guard let faceAnchor = anchor as? ARFaceAnchor else { return }
    let blendShapes = faceAnchor.blendShapes
    DispatchQueue.main.async {
        let eyeParameter = blendShapes[.eyeBlinkRight]
        let eyeParameterFloat = CGFloat(truncating: eyeParameter!)

        //Obtain transform matrix (World coordinates -> Face coordinates)
        let faceMatrix = faceAnchor.transform //Transform property inherent from ARAnchor!

        //Inverse the matrix (Face coordinates -> World coordinates)
        let inverseFaceMatrix = faceMatrix.inverse

        //Convert inverse matrix to inverse SCN Matrix
        let scnInvMatrix = SCNMatrix4(inverseFaceMatrix)

        //Create 1m SCNVector on the z axe of the face coordinates
        let scnVector = SCNVector4(0.0,0.0,1.0,0.0)

        //Multiply Vector and Inv Matrix
        let FaceVector = self.multiplyMatrixVector(matrix: 
        scnInvMatrix, vector: scnVector)

0 个答案:

没有答案