在会话之间保存 ARCore 图像数据库

Saving ARCore Image Database between sessions

第一次发帖。

我正在尝试保存在运行时创建的增强图像数据库,以便在以后的会话中使用。我环顾四周,但没有发现与此相关的问题。

提前致谢。

EDIT 应该提到,我正在使用 Unity(抱歉,我是新手)。

您可以使用序列化函数创建字节数组或输出流,具体取决于您使用的是 Android 还是 Android NDK。

对于 NDK:

void ArAugmentedImageDatabase_serialize(
      const ArSession *session,
      const ArAugmentedImageDatabase *augmented_image_database,
      uint8_t **out_image_database_raw_bytes,
      int64_t *out_image_database_raw_bytes_size
    )

对于Android:

public void serialize (OutputStream outputStream)

对于 Unity:首先您必须导入图像,在导入设置中您应该选中 Read/Write 已启用。 然后,您必须将图像转换为 RGBA32 或 RGB24。因为 ARCore 只支持这两种格式。

        Texture2D empty = new Texture2D(ImportedImage.width,ImportedImage.height, TextureFormat.RGBA32, false);
        empty.SetPixels(ImportedImage.GetPixels());
        empty.Apply();

然后你可以使用 databaseTest.AddImage("first",empty); 但是,这个数据库必须在你的 ARCoreSessionConfig 增强图像数据库字段中使用,如下所示:

否则应用程序会挂起,我不确定为什么。祝你好运!