google-ar / arcore-unity-sdk

ARCore SDK for Unity
https://developers.google.com/ar
Other
1.4k stars 400 forks source link

Updating AugmentedImageDatabase at runtime #319

Closed ryan-motive closed 6 years ago

ryan-motive commented 6 years ago

I need to be able to update the augmented image database at runtime. I've taken a swing at doing this outside of the current plug-in, but it doesn't seem to be working. Note this is happening after the session is configured by the current code. Here's what I'm currently trying:

Get the session:

ArPresto_getSession

Create a new database:

ArAugmentedImageDatabase_create

Add an image:

ArAugmentedImageDatabase_addImage

Then I update the config:

ArConfig_create
ArSession_getConfig
ArConfig_setAugmentedImageDatabase
ArSession_configure

For brevity I haven't included all of the code, but each of these calls is succeeding. When I call ArAugmentedImageDatabase_getNumImages it correctly reports that the database has one image. However when I call

Session.GetTrackables<AugmentedImage>();

I'm not getting any tracked images. If I use the static database, this call works.

I guess the part I'm uncertain about, and I can't find any documentation for, is whether I can actually update the config the way I've described above at runtime when the database is updated. Do I need to pause/resume the session or something similar? I'm also wondering whether the "Presto" API (which I can't find docs for) is possibly overriding the config in some way that is preventing me from updating it at runtime.

Are there any ARCore-level diagnostics that I can enable that might help me understand where this is breaking down?

ryan-motive commented 6 years ago

Ah, scratch that! It turns out I'm generating a mirror image when I create the grayscale. I had printed it out to make sure it looked correct, but didn't notice that it was a mirror image of the original. Seems to be working now.

Phanou36 commented 5 years ago

Hello I try to add image in runtime to my AugmentedImageDatabase. I use the code below but nothing happen . In my code "camera" is my ARCoreSession. Have you solve your problem ?

public class test : MonoBehaviour {

     public Sprite monimage;
     public ARCoreSession masession;
     public List<AugmentedImage> m_TempAugmentedImages = new List<AugmentedImage>();

     void Start ()
     {
         masession.SessionConfig.AugmentedImageDatabase.AddImage("test", monimage.texture, 0);
         Session.GetTrackables<AugmentedImage>(m_TempAugmentedImages, TrackableQueryFilter.Updated);
         Debug.Log(m_TempAugmentedImages.Count + " image in the AugmentedImageDatabase"); // ==0
     }

 }