为什么用于访问 CPU 上的相机图像的 Unity ARFoundation API 对我不起作用?

Why is Unity's ARFoundation API for accessing the camera image on CPU not working for me?

ARfoundation 是 Unity 的统一 API,可通过 ar-Kit 在 iOS 和通过 ar-Core Android 访问增强现实功能。

上下文:

他们有一个 API 可以访问 CPU 上的相机图像,我们可以在这里找到:https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@1.0/manual/cpu-camera-image.html

我试过的:

我按照教程中的描述设置了一个极简场景,只有一个定向光、一个 ArSession 和一个带有 ArPlaneManager 和 ArParticleManager 的 ArSessionRoot。

然后我在此处添加文档脚本中给出的示例脚本:https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@1.0/manual/cpu-camera-image.html#synchronously-convert-to-grayscale-and-color

仅替换

if (!cameraSubsystem.TryGetLatestImage(out image))
return;

if (!cameraSubsystem.TryGetLatestImage(out image))
{
    Debug.LogError("getting latest image failed again");
    image.Dispose();

    /*/ image is a struct, so it's never null.
    Probably it only needs to be disposed of if it has properly been used
    which would explain why they didn't dispose of it in the example code.
    Still, since it might be that trying-to-get-the-latest-image fails the first couple of times and would after that work,
    I'd still like to make sure it doesn't fail because there are too many image instances

    The documentation says: The CameraImage is a struct which represents a native resource. When you are finished using it, you must call Dispose on it to release it back to the system. Although you may hold a CameraImage for multiple frames, most platforms have a limited number of them, so failure to Dispose them may prevent the system from providing new camera images.
    //*/

    return;
}
Debug.Log("getting latest image succeeded for once");

其他人好像和我有同样的问题,所以我也在这个论坛问了这个问题:https://forum.unity.com/threads/arfoundation-camera-api-not-working-on-android.663979/#post-4510765

问题:

arCameraBackground 正确显示网络摄像头源,cameraTrackedPoseDriver 正确更新虚拟相机位置,因为我可以正确看到 arPlaneManager 和 arPointCloudManage 的效果(平面被检测并正确显示,深度明显感知,特征点显示为移动相机时的粒子)

但是:尽管 AR 体验运行良好,但我收到了错误日志的垃圾邮件,而且我永远也无法克服它。 这意味着该事件会被一遍又一遍地调用,但获取最新图像的尝试总是失败。

我需要访问 CPU 上的相机图像,我尝试了同步和异步示例,当我尝试获取最新图像时都返回 false。非常感谢任何帮助或提示,谢谢 =)

*编辑: 它对我来说实际上适用于 android,但不适用于 iOS

问题与构建设置相关联。 如果您遇到此问题,请尝试构建设置。

我不知道我到底出了什么问题,所以我不能具体说出什么是最重要的,但是例如,如果您通过代码加载和实例化 AR 游戏对象预制件,unity 可能会剥离如果您启用了剥离功能。