Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

openalpr on android - path to config and runtime_data

Tags:

android

assets

I want to use open alpr (automatic licences plate recognition) library in my android project. I compiled everything successfully and now it is time to use open alpr in app but...

to create Alpr class object properly I have to provide path to config file and path to runtime_data folder which contains some mandatory files needed by open alpr (ocr and trained data).

I tried something like:

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

but Alpr.isLoaded() returns false which means that config or runtime_data have not been found.

Path to assets folder in project is: src/main/assets.

Can someone explain to me how path to "runtime_data" directory and "alpr.conf" should looks to be visible by open alpr?

Thanks in advance.

like image 538
user2311165 Avatar asked Apr 14 '26 03:04

user2311165


1 Answers

I am not familiar with the specific library, but on newer Android devices (Android 6 and up), you can not rely on your application files residing under /data/data/your.package.name

The actual library name still includes the package name of your app, but also has some identifier appended to it in base64 format. This identifier is unique per installation, and it will change if you uninstall and reinstall the app on the same device.

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

  1. The right way:
    Get the real address of your application files folder using Context.getFilesDir().
    Unpack you files from the assets folder of the APK on the device using AssetManager.
    Programmatically rewrite your configuration file with the path returned by getFilesDir().

  2. The "hacky" but simpler way: Use public storage to unpack your files.
    You will need to add WRITE_EXTERNAL_STORAGE permission to your app, and unpack the assets files to the external storage.
    For backwards compatibility this will be available under /sdcard folder on most Android devices, even with the latest Android version.

The second method is not recommended since using /sdcard directly is deprecated and strongly discouraged by Google.
Also, not all Android devices have /sdcard link to their public storage, but this is the only way to avoid dynamically editing the configuration file after installation.

like image 134
Lev M. Avatar answered Apr 16 '26 16:04

Lev M.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!