google-ar / arcore-unity-sdk

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

Augmented image calculate quality when the image is added at runtime #682

Open carlosefrias opened 4 years ago

carlosefrias commented 4 years ago

SPECIFIC ISSUE ENCOUNTERED

Good morning I'm creating an AR app using augmented images. I want to be able for the user to add images as targets (either by taking a picture or selecting a photo from the gallery). This is done and working fine. My issue is that I want to provide feedback to the user of the quality of the target (value from 0 to 100) and by adding the image at run-time the quality property is set to an empty string. But, when we add a new image to the augmented images database on the editor the quality property is set by calling (running a shell command) one of the executable files (depending on the OS) on the folder GoogleARCore/CLI/

like this:

.\augmented_image_cli_win.exe eval-img --input_image_path ..\..\Resources\Targets\000.jpg

My question is:

VERSIONS USED

carlosefrias commented 4 years ago

I've managed to create a work around for this by creating a nodejs webserver where I send the picture from the smartphone and on the server side call the arcoreimg tool for the image and return the score back to the smartphone.

But even though it would be nice to have an offline solution for this.

AhmedBarahim commented 4 years ago

How did you managed to let the user be able to add images as targets?

carlosefrias commented 4 years ago

How did you managed to let the user be able to add images as targets?

private async void AddTargetToDatabase(string imagePath)
        {
            //Adding the image as a target to the augmented images database
            var texture2D = SpriteCreator.LoadTexture(imagePath);
            if (texture2D == null) return;
            //Make sure that all the images which you are using, have Read/Write enabled and format = RGB 32 bit.
            //Make sure that there's a delay between the start of your scene and the call of the function newDatabase.AddImage(name, image).
            //You can do this by passing a counter check-in Update function and delay the addition of images by around 40-50 frames.
            //Due to some reason, if you add the images in start function, most of the times, it returns -1 because I think that native session is still not initialised (LifecycleManager.Instance.NativeSession).
            var texture2DNewFormat = texture2D.ChangeFormat(TextureFormat.RGBA32);
            var database = AppManager.instance.arCoreSession.SessionConfig.AugmentedImageDatabase;
            var targetName = Path.GetFileName(imagePath);
            var val = database.AddImage(targetName, texture2DNewFormat);
            print(val);
            //Checking image quality...
            var nodeJsApiController = DatabaseAndApiController.Instance;
            var score = await nodeJsApiController.SendImageToCheckQuality(imagePath);
            Common.SendNotification(val >= 0
                ? $"Successfully added image to augmented images database with a score of {score}/100"
                : "Unable to add image as a target");
        }

So basically load the image you want as a Texture2D, change its format to RGBA32, grab the AugmentedImageDatabase object and call the AddImage function passing a filename and the Texture2D. In my case I have extra stuff because I have a nodeJs API that returns me the image score (1-100).

AhmedBarahim commented 4 years ago

How did you managed to let the user be able to add images as targets?

private async void AddTargetToDatabase(string imagePath)
        {
            //Adding the image as a target to the augmented images database
            var texture2D = SpriteCreator.LoadTexture(imagePath);
            if (texture2D == null) return;
            //Make sure that all the images which you are using, have Read/Write enabled and format = RGB 32 bit.
            //Make sure that there's a delay between the start of your scene and the call of the function newDatabase.AddImage(name, image).
            //You can do this by passing a counter check-in Update function and delay the addition of images by around 40-50 frames.
            //Due to some reason, if you add the images in start function, most of the times, it returns -1 because I think that native session is still not initialised (LifecycleManager.Instance.NativeSession).
            var texture2DNewFormat = texture2D.ChangeFormat(TextureFormat.RGBA32);
            var database = AppManager.instance.arCoreSession.SessionConfig.AugmentedImageDatabase;
            var targetName = Path.GetFileName(imagePath);
            var val = database.AddImage(targetName, texture2DNewFormat);
            print(val);
            //Checking image quality...
            var nodeJsApiController = DatabaseAndApiController.Instance;
            var score = await nodeJsApiController.SendImageToCheckQuality(imagePath);
            Common.SendNotification(val >= 0
                ? $"Successfully added image to augmented images database with a score of {score}/100"
                : "Unable to add image as a target");
        }

So basically load the image you want as a Texture2D, change its format to RGBA32, grab the AugmentedImageDatabase object and call the AddImage function passing a filename and the Texture2D. In my case I have extra stuff because I have a nodeJs API that returns me the image score (1-100).

Thank You..