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



arfoundation是Unity的统一API,可通过AR-KIT和ARTROID通过AR核访问iOS上的增强现实功能。

上下文:

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

WAT我尝试过:

我设置了一个简约的场景,如教程中所述,除了方向性的光,武器和一个带有ArplaneManager和ArparticleManager的杂志。

i然后在此处添加文档脚本中给出的示例脚本:https://docs.unity3d.com/packages/com.unity.xr.arfoundation@1.0/manual/manual/cpu-camera-image.html#synchonchonchronichinchonchonchronichinchonchonchronicly--转换为式颜色

仅替换

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-api-not-working-on--Android.663979/#POST-4510765

问题:

Arcamerabackground正确显示了网络摄像头馈电,CameratrackedPosedriver可以正确更新虚拟相机位置,因为我可以正确地看到ArplaneManager的和ArpointCloudManage的效果(平面被检测到并正确显示,并且在特征点上被视为特征点,并且在特征点上显示出颗粒的效果。相机被移动(

但是:即使AR体验正常运行,我也会对错误日志进行垃圾邮件,但我从未超过这一点。这意味着该事件一遍又一遍地调用,但是获得最新图像的尝试总是失败。

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

*编辑:它实际上对我有效,但在iOS

上不适用于

与构建设置相关的问题接缝。如果您遇到此问题,请使用构建设置。

我不知道对我有什么问题,所以我不能具体说明什么是确切重要的,但是例如,如果您正在加载和实例化AR Game对象通过代码预制,那么Unity可能会剥离它们,如果它们可能会剥离它们。您已启用剥离。

最新更新