androidunity-game-engineaugmented-realityarcoreandroid-augmented-reality

ARCore 1.2 Unity Create AugmentedImageDatabase on the fly


I am trying to dynamically create an image database using arcores new image tracking feature.

Currently I have a server serving me image locations which I download to the persistent data path of my device. I use these images to then create new database entries like below:

Public Variables:

public AugmentedImageDatabase newBD;
public AugmentedImageDatabaseEntry newEntry;

Here I do regex matching to get the images from the datapath and convert them to texture2D's in order to populate the AugmentedImageDatabaseEntry values.

        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);
        }

To get this to work on android I had to modify the source of ARCore's unity implementation a little so that the database.Add() function would work outside of the editor.

All of this seems to work seamlessly as I don't get any errors yet. Once I change scenes to the ARCore scene I instantiate an ARCore Camera and create a new sessionconfig which holds a reference to the database populated above.

Here is that code:

public class 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);
    }

}

When I run in the editor, I dont get errors untill I view the database in the editor, thats when I get this error:

ERROR: flag '--input_image_path' is missing its argument; flag description: Path of image to be evaluated. Currently only supports *.png, *.jpg and *.jpeg.

When I debug and look in the memory of the AugmentedImageDatabase. Everything seems to be there and working fine. Also once I build for android I get no errors whatsoever, as well as when I use 'adb logcat -s Unity' in the command line, no exceptions are thrown.

Could this be a limitation with the new ARCore feature? Are the AugmentedImageDatabases not allowing for dynamic creation on android? If so than why are there built in functions for creating them?

I understand the features are brand new and there is not much documentation anywhere so any help would be greatly appreciated.


Solution

  • I posted an Issue on ARCore's Github page, and got a response that the feature you're talking about isn't yet exposed in the Unity API : https://github.com/google-ar/arcore-unity-sdk/issues/256