为什么 ARFaceAnchor 有负 Z 位置? [英] Why does ARFaceAnchor have negative Z position?

查看:16
本文介绍了为什么 ARFaceAnchor 有负 Z 位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ARKit 的 ARFaceTrackingConfiguration

<块引用>

因此,ARFaceAnchor 也将被放置在 Z 轴正方向.

当您使用 ARFaceTrackingConfigurationARWorldTrackingConfiguration 时,需要考虑两件事:

  • 后置摄像头沿负 Z 轴(正 X 轴在右侧)向物体移动.

  • 前置摄像头沿正 Z 轴(正 X 轴在左侧)朝向人脸移动.

<块引用>

因此,当您寻找"时通过TrueDepth Camera,一个4x4 Matrix镜像.

I am using ARKit's ARFaceTrackingConfiguration with ARConfiguration.WorldAlignment.camera alignment, but I found that the documentation (seemingly) does not reflect the reality;

Based on the excerpt of documentation below, I would expect that the face anchor's transform is expressed in right handed coordinate system. However, when I tried moving my head, I noticed that the Z coordinate of the face anchor is always negative (i.e. faceAnchor.transform.columns.3.z < 0). Note that moving head in the X and Y directions corresponds to expected outcome (unlike Z coordinate).

Camera alignment defines a coordinate system based on the native sensor orientation of the device camera. Relative to a AVCaptureVideoOrientation.landscapeRight-oriented camera image, the x-axis points to the right, the y-axis points up, and the z-axis points out the front of the device (toward the user).

I want the transform to behave as per the documentation, i.e. the Z coordinate of face anchor should be positive given that documentation says "the z-axis points out the front of the device (toward the user)". So far it seems the Z-axis points out the back of the device…

Am I missing something obvious?

I tried to repair the rotation by the following code, but I am not sure if it's correct way to fix this:

// Repair rotation
let oldFaceRotation = simd_quatf(face.transform) // get quaternion from 
let repairedFaceRotation = simd_quatf(ix: oldFaceRotation.axis.y, iy: oldFaceRotation.axis.x, iz: -oldFaceRotation.axis.z, r: oldFaceRotation.real)

// Repair translation
var repairedPosition = face.transform.columns.3
repairedPosition.z *= -1

// Combine
var correctedFaceTransform = float4x4(repairedFaceRotation)
correctedFaceTransform.columns.3 = repairedPosition

解决方案

It seems quite obvious:

When ARSession is running and ARCamera begins tracking environment, it places WorldOriginAxis in front of your face at (x: 0, y: 0, z: 0). Just check it using:

 sceneView.debugOptions = [.showWorldOrigin]

So your face's position must be at positive part of Z axis of World Coordinates.

Thus, ARFaceAnchor will be placed at positive Z-axis direction, as well.

And when you use ARFaceTrackingConfiguration vs ARWorldTrackingConfiguration there's two things to consider:

  • Rear Camera moves towards objects along negative Z-axes (positive X-axis is on the right).

  • Front Camera moves towards faces along positive Z-axes (positive X-axis is on the left).

Hence, when you are "looking" through TrueDepth Camera, a 4x4 Matrix is mirrored.

这篇关于为什么 ARFaceAnchor 有负 Z 位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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