Openalpr on android - path to config and runtime_data

I want to use the open library alpr (automatic plate recognition) in my android project. I compiled everything successfully and now it's time to use open alpr in the application, but ...

to create the Alpr class object correctly, I have to provide the path to the config file and the path to the runtime_data folder, which contains some of the required files needed to open alpr (ocr and prepared data).

I've tried something like:

Alpr alpr = new Alpr("eu", "android_assets/alpr.conf", "android_assets/runtime_data");

      

but Alpr.isLoaded()

returns false, which means config or runtime_data was not found.

Folder "Path to assets" in the project: src / main / assets .

Can someone explain to me how the path to the " runtime_data

" and " alpr.conf

" directory should look visible with open alpr?

Thanks in advance.

+3


source to share


3 answers


I am not familiar with the specific library, but on newer Android devices (Android 6 and up) you cannot rely on your app files located in /data/data/your.package.name

The actual library name still includes your application's package name, but some base64- formatted identifier has also been added to it . This ID is unique for each installation and will change if you uninstall and reinstall the app on the same device.

So, if your library needs to use a config file with a path to some other files, there are 2 options:



  1. Correct way:
    Get the real address of the application file folder using Context.getFilesDir()

    .
    Unzip the files from the assets

    APK folder on the device using the AssetManager .
    Programmatically overwrite your config file with the path returned getFilesDir()

    .

  2. A hackish but simpler way: Use a public repository to unpack your files.
    You will need to add the WRITE_EXTERNAL_STORAGE permission to your application and unzip the resource files to external storage.
    For backward compatibility, this will be available in a folder /sdcard

    on most Android devices, even with the latest Android.

The second method is deprecated as using /sdcard

directly is deprecated and strongly discouraged by Google.
Also, not all Android devices have a link /sdcard

to their public storage, but this is the only way to avoid dynamically editing the config file after installation.

+1


source


Important note before proceeding with these steps. This library only supports processor architecture arm

. The good news is that most likely your physical device is using an architecture arm

, but to be sure, just double check it before following these steps.

I have recompiled this library into a new wrapper library. In the source library, you need to manually configure the file openalpr.conf

and edit its contents to provide the correct path to your data directory. Manual configuration is cumbersome since multiple user accounts are supported since Android 5 and we cannot just hard-code the data directory as /data/data/com.your.packagename/....

. Because each user gets their own symbolic link to the data directory as /data/user/0/com.your.packagename/....

. All these manual steps are skipped in the recompiled shell library.

Implementation Add this to your root build.gradle at the end of the repository:

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

      

Add the dependency to the application module:

dependencies {
    ...
    implementation 'com.github.mecoFarid:openalpr:1.0.0'
}

      

And you're done. Please check this sample app to get started with the user interface.




Troubleshooting:

If your target SDK is targetSdkVersion >= 24

and you run the app on a device with Android API 24+, you will receive the following error:

android.os.FileUriExposedException: file:///storage/emulated/0/OpenALPR/2019-09-21-01-32-13.jpg exposed beyond app through ClipData.Item.getUri()

      

To fix this error: you can add the following lines in onCreate()

your Activity as a workaround, or you can use this thread for an official solution:

if(Build.VERSION.SDK_INT>=24){
        try{
            Method m = StrictMode.class.getMethod("disableDeathOnFileUriExposure");
            m.invoke(null);
        }catch(Exception e){
            e.printStackTrace();
        }
    }

      




TEST:

You can use this image to test your application.

0


source


"/data/data/yourpackagename" + File.separatorChar + "runtime_data"
                             + File.separatorChar + "openalpr.conf"; 

      

-3


source







All Articles