HoloLens 2获取空间坐标系的正确方法

Correct method to acquire the spatial coordinate system with HoloLens 2

因此,我正在努力思考从通过 MediaFrameReference class 获取的帧进行的转换。我得到的是一张带有相关空间坐标系和相机内在参数的图像。 要计算图像 (U, V) 中像素的真实世界坐标 (X, Y, Z),我认为访问 4x4Matrix 就足够了,它表示从 RGB 相机到世界的变换矩阵。

为此,我找到了 TryGetTransformTo(SpatialCoordinateSystem target) 方法。如果我正确理解文档,我会将图像坐标系附加到图像上,所以我会调用

image.CoordinateSystem.TryGetTransformTo(worldCoordinateSystem)

我的问题是,获取我需要的空间坐标系的最有效方法是什么。 我使用的是 Unity 2018.4.22f1 和 Visual Studio 2019.

非常感谢任何帮助。亲切的问候。

推荐使用PhotoCapture class抓图,PhotoCaptureFrame的TryGetCameraToWorldMatrix方法可以很方便的获取拍照时Camera填充到world Matrix的Matrix4x4捕获。您可以参考这个 link 了解更多使用方法:UnityEngine.Windows.WebCam.PhotoCapture

按照指南,当您在此参数上调用异步方法时 TakePhotoAsync(onCapturedPhotoToMemoryCallback), you need to pass in a function as a parameter, it will be invoked once the photo has been stored to memory. And in this function, you will get a PhotoCaputrerFrame instance as a parameter. Finally, invoke PhotoCaptureFrame.TryGetCameraToWorldMatrix 获取一个矩阵,该矩阵将在拍摄照片时由相机填充到世界矩阵。

此外,对于早期版本的 MR 文档,它已经演示了如何使用着色器代码在相机图像上的特定 3d 位置查找或绘制,您可以在 GitHub 提交历史中找到它: mixed-reality-docs/locatable-camera.md.