google-ar / arcore-android-sdk

ARCore SDK for Android Studio
https://developers.google.com/ar
Other
4.92k stars 1.2k forks source link

Augmented images load time. #672

Open PolarisNation opened 5 years ago

PolarisNation commented 5 years ago

Hi, I add the some of images about 10 at assets folder and add image using suggested function

https://developers.google.com/ar/develop/java/augmented-images/guide

Bitmap bitmap;
try (InputStream inputStream = getAssets().open("dog.jpg")) {
  bitmap = BitmapFactory.decodeStream(inputStream);
} catch (IOException e) {
  Log.e(TAG, "I/O exception loading augmented image bitmap.", e);
}
int index = imageDatabase.addImage("dog", bitmap, imageWidthInMeters);

like this,
private boolean setupAugmentedImageDb(Config config) {
        Log.i(TAG, "setupAugmentedImageDb 진입");
        AugmentedImageDatabase augmentedImageDatabase;
        augmentedImageDatabase = new AugmentedImageDatabase(mSession);

        for (int i = 0 ; i < arList.length ; i++){
            String name = arList[i];
            Bitmap augmentedImageBitmap = loadAugmentedImage(name);
            if (augmentedImageBitmap == null) {
                //bring image fail
            }else{
                //bring image success
                augmentedImageDatabase.addImage(name, augmentedImageBitmap);
            }
        }//end of for
        config.setAugmentedImageDatabase(augmentedImageDatabase);
        return true;
    }
private Bitmap loadAugmentedImage(String name){

    try (InputStream is = getAssets().open("image_ar/"+name)){
        return BitmapFactory.decodeStream(is);
    }
    catch (IOException e){
        Log.e("ImageLoad", "IO Exception while loading", e);
    }
    return null;

}

so it success bring the image and add imagedatabase.

but it has problem. It takes time more and more when I add the image. Is there any way to reduce set imagedatabase?

inio commented 5 years ago

We recommend pre-computing the augmented image database using the command line arcoreimg tool. This will both result in a much smaller data size for your app and not require processing at startup to load the images.