为什么Unity的ARFoundation API无法访问我在CPU上的摄像机图像?

时间:2019-05-09 07:23:19

标签: c# unity3d arkit arcore

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

1 个答案:

答案 0 :(得分:0)

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

我不知道到底是什么问题,所以我无法明确说明到底什么是重要的,但是例如,如果您通过代码加载和实例化AR游戏对象预制件,如果您已启用剥离。