2

我正在尝试使用 arcores 新的图像跟踪功能动态创建图像数据库。

目前,我有一个服务器为我提供图像位置,我将其下载到设备的持久数据路径中。我使用这些图像然后创建新的数据库条目,如下所示:

公共变量:

public AugmentedImageDatabase newBD;
public AugmentedImageDatabaseEntry newEntry;

在这里,我进行正则表达式匹配以从数据路径获取图像并将它们转换为 texture2D 以填充 AugmentedImageDatabaseEntry 值。

        Regex r1 = new Regex(@"https?://s3-([^.]+).amazonaws.com/([^/]+)/([^/]+)/(.*)");


        // Match the input for file name
        Match match = r1.Match(input);
        if (match.Success)
        {
            string v = match.Groups[4].Value;
            RegexMatch = v;

            Texture2D laodedTexture = LoadTextureToFile(v);
            laodedTexture.EncodeToPNG();

            AugmentedImageDatabaseEntry newEntry = new AugmentedImageDatabaseEntry(v, laodedTexture, Application.persistentDataPath + "/" + v);
            newEntry.Name = v;
            newEntry.Texture = laodedTexture;
            newEntry.TextureGUID = Application.persistentDataPath + "/" + v;

            Debug.Log(newEntry.Name);
            Debug.Log(newEntry.Texture);
            Debug.Log(newEntry.TextureGUID);
            newBD.Add(newEntry);
        }

为了让它在 android 上工作,我必须稍微修改 ARCore 的统一实现的源代码,以便 database.Add() 函数可以在编辑器之外工作。

所有这些似乎都可以无缝运行,因为我还没有收到任何错误。一旦我将场景更改为 ARCore 场景,我将实例化一个 ARCore 相机并创建一个新的 sessionconfig,其中包含对上面填充的数据库的引用。

这是该代码:

公共类 NewConfigSetup : MonoBehaviour {

    public GameObject downloadManager;
    public GameObject arcoreDevice;

    // Use this for initialization
    void Start () {

        downloadManager = GameObject.Find("DownlaodManager");

        TestModelGenerator generator = downloadManager.GetComponent<TestModelGenerator>();

        GoogleARCore.ARCoreSessionConfig newconfig = new GoogleARCore.ARCoreSessionConfig();
        GoogleARCore.ARCoreSessionConfig config = ScriptableObject.CreateInstance<GoogleARCore.ARCoreSessionConfig>();

        config.AugmentedImageDatabase = generator.newBD;
        Debug.Log("transfered db size --------------- " + config.AugmentedImageDatabase.Count);

        arcoreDevice.GetComponent<GoogleARCore.ARCoreSession>().SessionConfig = config;

        Instantiate(arcoreDevice,new Vector3(0,0,0), Quaternion.identity);
    }

}

当我在编辑器中运行时,直到我在编辑器中查看数据库时才会出现错误,这就是我收到此错误的时候:

错误:标志“--input_image_path”缺少其参数;标志描述:要评估的图像路径。目前仅支持 *.png、*.jpg 和 *.jpeg。

当我调试并查看 AugmentedImageDatabase 的内存时。一切似乎都在那里并且工作正常。同样,一旦我为 android 构建,我就没有任何错误,当我在命令行中使用“adb logcat -s Unity”时,也不会抛出任何异常。

这可能是新 ARCore 功能的限制吗?AugmentedImageDatabases 是否不允许在 android 上动态创建?如果是这样,那么为什么会有用于创建它们的内置函数?

我了解这些功能是全新的,并且任何地方都没有太多文档,因此我们将不胜感激。

4

1 回答 1

1

我在 ARCore 的 Github 页面上发布了一个问题,并得到回复说您正在谈论的功能尚未在 Unity API 中公开: https ://github.com/google-ar/arcore-unity-sdk/issues /256

于 2018-06-12T13:06:47.803 回答