将ARFaceAnchor从左手坐标系切换到右手坐标系 [英] Flip ARFaceAnchor from left-handed to right-handed coordinate system

查看:297
本文介绍了将ARFaceAnchor从左手坐标系切换到右手坐标系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在通过打印faceAnchor.transform.columns.3进行一些测试之后,在SO中进行挖掘: ARFaceAnchor有负Z位置?和Apple文档: ARFaceAnchor ,我意识到z轴实际上是翻转的,并且不是文档中的右手坐标系. ARFaceAnchor声明坐标:

After some testings by printing faceAnchor.transform.columns.3, digging in SO: ARFaceAnchor have negative Z position? and Apple's documentation: ARFaceAnchor, I realized that the z axis is actually flipped and it is not the right-handed coordinate system as in the documentation. The ARFaceAnchor claims the coordinate:

x的正方向指向观看者的右侧(即脸部自己的左手),y的正方向指向上(相对于脸部本身,而不是世界),z的正方向则指向观看者的外侧.面对(面向观众)

the positive x direction points to the viewer’s right (that is, the face’s own left), the positive y direction points up (relative to the face itself, not to the world), and the positive z direction points outward from the face (toward the viewer)


萨拉斯瓦蒂(Sarasvati)对进行改造提出了建议:


Sarasvati has given a suggestion on doing the transformation:

    func faceAnchorPoseToRHS(_ mat: float4x4) -> float4x4 {
    let correctedPos = float4(x: mat.columns.3.x, y: mat.columns.3.y, z: -mat.columns.3.z, w: 1)

    let quat = simd_quatf(mat)
    let newQuat = simd_quatf(angle: -quat.angle, axis: float3(quat.axis.x, quat.axis.y, -quat.axis.z))
    var newPose = float4x4(newQuat)
    newPose.columns.3 = correctedPos

    return newPose
}


基于Andy Fedoroff的更新:


Updates based on Andy Fedoroff:

extension ViewController: ARSCNViewDelegate {
    func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
        guard let faceAnchor = anchor as? ARFaceAnchor else { return }
        currentFaceAnchor = faceAnchor
        if node.childNodes.isEmpty, let contentNode = selectedContentController.renderer(renderer, nodeFor: faceAnchor) {
            node.addChildNode(contentNode)
        }
        selectedContentController.session = sceneView?.session
        selectedContentController.sceneView = sceneView
    }
    /// - Tag: ARFaceGeometryUpdate
    func renderer(_ renderer: SCNSceneRenderer, didUpdate node: SCNNode, for anchor: ARAnchor) {
        guard anchor == currentFaceAnchor,
            let contentNode = selectedContentController.contentNode,
            contentNode.parent == node
            else { return }
        sceneView.session.currentFrame!.anchors.first!.transform
        print(currentFaceAnchor!.transform.columns.3)
        selectedContentController.session = sceneView?.session
        selectedContentController.sceneView = sceneView
        selectedContentController.renderer(renderer, didUpdate: contentNode, for: anchor)
    }
}


但是,我打印了faceAnchor.transform.columns.3,并使用True Depth相机获得了z负片.下面显示了x,y,z,w轴:


However, I printed faceAnchor.transform.columns.3 and obtained the z negative with True Depth camera. Below show x,y,z,w axis:

关于如何校正z轴的任何建议?预先谢谢你

Any suggestions on how to correct the z-axis? Thank you in advance

推荐答案

首先,让我们看看默认的矩阵值是什么.

At first, let's see what a default matrix values are.


这是具有默认值的Identity 4x4 matrix.

如果您需要有关4x4 matrices元素的其他信息,请阅读

If you need additional info on elements of 4x4 matrices read this post.

 // 0  1  2  3
 ┌              ┐
 |  1  0  0  0  |  x
 |  0  1  0  0  |  y
 |  0  0  1  0  |  z
 |  0  0  0  1  |
 └              ┘


要翻转实体的Z axisX axis,以便将轴从面部"跟踪环境重定向到世界"跟踪环境,请使用以下形式的4x4 transform matrix.

To flip entity's Z axis and X axis, in order to reorient axis from Face tracking environment to World tracking environment, use the following form of 4x4 transform matrix.

 // 0  1  2  3
 ┌              ┐
 | -1  0  0  0  |  x
 |  0  1  0  0  |  y
 |  0  0 -1  0  |  z
 |  0  0  0  1  |
 └              ┘


4x4 transform matrices中,旋转是 combination of scale and skew .要选择右旋方向,顺时针(CW)或逆时针(CCW),对cos表达式使用+-.

In 4x4 transform matrices rotation is a combination of scale and skew. To choose a right rotation's direction, clockwise (CW) or counter-clockwise (CCW) use + or - for cos expressions.

这是一个正Z旋转表达式(CCW).

Here's a positive Z rotation expression (CCW).

正数+cos(a):

 ┌                    ┐
 | cos -sin   0    0  |
 | sin  cos   0    0  |
 |  0    0    1    0  |
 |  0    0    0    1  |
 └                    ┘


这是一个负Z旋转表达式(CW).

And here's a negative Z rotation expression (CW).

负数-cos(a):

 ┌                    ┐
 |-cos -sin   0    0  |
 | sin -cos   0    0  |
 |  0    0    1    0  |
 |  0    0    0    1  |
 └                    ┘

这篇关于将ARFaceAnchor从左手坐标系切换到右手坐标系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆