首页 > 解决方案 > 为什么我们在 Apple 的“使用场景深度可视化点云”示例代码中需要“rotateToARCamera”?

问题描述

示例代码:https ://developer.apple.com/documentation/arkit/visualizing_a_point_cloud_using_scene_depth

在代码中,当将深度图非投影到世界点时,我们使用正 z 值(深度值)。但据我了解,ARKit 使用右手坐标系,这意味着 z 值为正的点位于相机后面。所以也许我们需要做一些额外的工作来对齐坐标系(使用rotateToARCamera矩阵?)。但我不明白为什么我们需要翻转 Y 和 Z 平面。

static func makeRotateToARCameraMatrix(orientation: UIInterfaceOrientation) -> matrix_float4x4 {
    // flip to ARKit Camera's coordinate
    let flipYZ = matrix_float4x4(
        [1, 0, 0, 0],
        [0, -1, 0, 0],
        [0, 0, -1, 0],
        [0, 0, 0, 1] )

    let rotationAngle = Float(cameraToDisplayRotation(orientation: orientation)) * .degreesToRadian
    return flipYZ * matrix_float4x4(simd_quaternion(rotationAngle, Float3(0, 0, 1)))
}

更新:我猜关键点是用于相机内在矩阵的针孔模型的坐标系与 ARKit 中的正常相机空间相比具有相反的方向。

标签: iosgraphicscomputer-visionarkitmetal

解决方案


Depth Map 是像图像数据一样,Y 坐标在顶部较小而在底部较大的坐标系,但 ARKit 是 Y 坐标从底部较小而在顶部较大的坐标系。

出于这个原因,我认为有必要反转 Y 坐标。


推荐阅读