google-ar / arcore-android-sdk

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

AugmentedImageDatabase can't multiple AddImage from App folder #748

Closed vsavdeev closed 5 years ago

vsavdeev commented 5 years ago

SPECIFIC ISSUE ENCOUNTERED

Failed to create AR Session

VERSIONS USED

APP LOGIC

  1. Download Files from URL to getFilesDir()
  2. Create AR Session
  3. Find files StartWith("arimage") - this is jpg/png files
  4. Make AugmentedImageDatabase.AddImage all Image files from folder

GITHUB PROJECT

https://github.com/vsavdeev/LivePhotos

PROBLEM CODE BUT BUILD IS SUCCESSFUL

 public boolean setupDatabase(Config config, Session session) {
        AugmentedImageDatabase aid = new AugmentedImageDatabase(session);
        Intent intent = getIntent ();
        String filepath = intent.getStringExtra ("filepath");
        Log.d ("AID", "Veriable:" + filepath);
        File directory = new File (filepath);
        File[] files = directory.listFiles ();
        Log.d ("AID", "Size: " + files.length);
        for (int i = 0; i < files.length; i++)
        {

            if (files[i].getName().startsWith("arimage"))
            {

                String filename = files[i].getName ();
                Log.d ("AID", "FileName:" + filename);
                Bitmap arcontentBitmap = BitmapFactory.decodeFile (files[i].getAbsolutePath ());
                Log.d ("AID", "FilePath:" + files[i].getPath ());
                if (arcontentBitmap == null) {
                    return false;
                }

                Log.d ("AID", "Files:" + files[i].getPath ());
                String imagename = filename.substring(0, filename.length() - 4);
                Log.d ("AID", "NameImage:" + imagename);

                aid.addImage(imagename, arcontentBitmap);

            }

        }

        config.setAugmentedImageDatabase(aid);
        return true;
    }
fredsa commented 5 years ago

What is the actual error message you get?

AlienJim commented 5 years ago

I think I am having the same problem, when loading images and adding them to the database from bitmap the images never get recognized. There was no error that I could find in logcat it just seems to not work. So unless I am missing something it seems database.addImage(string, Bitmap) is currently broken. The function even returns 0 as if it was a success.

vsavdeev commented 5 years ago

I actually solve problem

public void setupDatabase(Config config, Session session) {
        AugmentedImageDatabase aid = new AugmentedImageDatabase(session);
        SharedPreferences getPrefs = PreferenceManager.getDefaultSharedPreferences (this);
        filepath = getPrefs.getString ("filepath", null);
        Log.d ("AID", "Veriable:" + filepath);
        File directory = new File (filepath);
        File[] files = directory.listFiles ();
        Log.d ("AID", "Size: " + files.length);
        imageNames = new String[files.length];
        for (int i = 0; i < files.length; i++)
        {
            if (files[i].getName().endsWith (".json"))
            {
                jsonpath = files[i].getPath ();
                Log.d ("JSON", "is found");
                jsonParse (jsonpath);
                break;
            }
            else
                Log.d ("JSON", "no file");
        }
        for (int i = 0; i < files.length; i++)
        {
            for (HashMap<String, String> map : imageVideoMap)
            {
                for (Map.Entry<String, String> mapEntry : map.entrySet ())
                {
                    key = mapEntry.getKey ();

                    if (files[i].getName ().equals (key)) {

                        String filename = files[i].getName ();
                        Log.d ("AID", "FileName:" + filename);
                        Bitmap arcontentBitmap = loadAugmentedImage (files[i].getPath ());
                        Log.d ("AID", "FilePath:" + files[i].getPath ());
                        Log.d ("AID", "Files:" + files[i].getAbsolutePath ());
                        String imagename = filename.substring (0, filename.length () - 4);
                        aid.addImage (imagename, arcontentBitmap);
                    }
                }
            }
        }
        config.setAugmentedImageDatabase(aid);
    }