在ARKit的3D Facemesh中获取双眼的3D坐标

时间:2018-04-27 04:45:29

标签: ios swift scenekit augmented-reality arkit

我希望从 ARKit 3D Facemesh 中获取双眼的真实3D坐标。

到目前为止,我已尝试过以下代码;

func renderer(_ renderer: SCNSceneRenderer, didUpdate node: SCNNode, for anchor: ARAnchor) {
    guard let faceAnchor = anchor as? ARFaceAnchor else { return }

    let geometry = virtualFaceNode.geometry as! ARSCNFaceGeometry

    let pointOfView = SCNNode()

    // Determine Adjusted Position for Right Eye
    let orientation : SCNQuaternion = node.orientation
    let orientationQuaternion : GLKQuaternion = GLKQuaternionMake(orientation.x, orientation.y, orientation.z, orientation.w)
    let eyePos : GLKVector3 = GLKVector3Make(1.0, 0.0, 0.0)
    let rotatedEyePos : GLKVector3 = GLKQuaternionRotateVector3(orientationQuaternion, eyePos)
    let rotatedEyePosSCNV : SCNVector3 = SCNVector3Make(rotatedEyePos.x, rotatedEyePos.y, rotatedEyePos.z)

    let mag : Float = 0.066 // This is the value for the distance between two pupils (in metres). The Interpupilary Distance (IPD).
    pointOfView.position.x += rotatedEyePosSCNV.x * mag
    pointOfView.position.y += rotatedEyePosSCNV.y * mag
    pointOfView.position.z += rotatedEyePosSCNV.z * mag

    DispatchQueue.main.async {

        self.updateValue.text = "x= " + String(describing: pointOfView.position.x) + "y= " + String(describing: pointOfView.position.y) + "z= " + String(describing: pointOfView.position.z)

  }

    geometry.update(from: faceAnchor.geometry)
}

我不确定此代码是否正常。如果不是以另一种方式获得眼睛坐标?我想计算眼睛的大小,距离。

感谢您的帮助,提前致谢...

0 个答案:

没有答案