Search code examples
androidarcore

Saving ARCore Image Database between sessions


first time posting.

I’m trying to save an augmented image database made during runtime, for using in a later session. I have looked around but found no questions related to this.

Thanks in advance.

EDIT should have mentioned, I am using Unity(sorry, I'm new).


Solution

  • You can use serialize function to create a byte array or an output stream depending on whether you use Android or Android NDK.

    For 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
        )
    

    For Android:

    public void serialize (OutputStream outputStream)
    

    For Unity: First you have to import your image and in import settings you should check Read/Write Enabled. Then, you have to convert your image to either RGBA32 or RGB24. Because ARCore only supports these two formats.

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

    Then you can use databaseTest.AddImage("first",empty); However, this database has to be used in your ARCoreSessionConfig Augmented Image Database field like this:

    enter image description here

    Otherwise app hangs i am not sure why. Good luck!