|
1 | 1 | # openalpr-android
|
2 |
| -Android Automatic License Plate Recognition library based on http://www.openalpr.com |
| 2 | + |
| 3 | +OpenALPR is an open source Automatic License Plate Recognition library written in C++ with bindings in C#, Java, Node.js, and Python. This project ports this library to Android. |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +# Gradle Dependency |
| 8 | + |
| 9 | +## Repository |
| 10 | + |
| 11 | +First, add the following to your app's `build.gradle` file: |
| 12 | + |
| 13 | +```Gradle |
| 14 | +repositories { |
| 15 | + maven { url "https://jitpack.io" } |
| 16 | +} |
| 17 | +``` |
| 18 | + |
| 19 | +Them include the openalpr-android dependency: |
| 20 | + |
| 21 | +```gradle |
| 22 | +dependencies { |
| 23 | +
|
| 24 | + // ... other dependencies here. |
| 25 | + // Set the transitive = false if you already have the Design Support Library dependency. |
| 26 | + compile('com.github.SandroMachado:openalpr-android:1.0.0@aar') { |
| 27 | + transitive = true |
| 28 | + } |
| 29 | +} |
| 30 | +``` |
| 31 | + |
| 32 | +# Usage |
| 33 | + |
| 34 | +## Code |
| 35 | + |
| 36 | +Copy the [OpenALPR configuration file](./openalpr.conf) to your android project assets directory `/main/assets/runtime_data/openalpr.conf` and update the `runtime_dir` to your project directory (for instance, for the sample project the directory is: `runtime_dir = /data/data/com.sandro.openalprsample/runtime_data`). After that just follow the code example bellow. To see a full example check the [sample application](./Sample/OpenALPRSample/app/src/main/java/com/sandro/openalprsample/MainActivity.java). |
| 37 | + |
| 38 | +```Java |
| 39 | + |
| 40 | +static final String ANDROID_DATA_DIR = "/data/data/com.sandro.openalprsample"; |
| 41 | + |
| 42 | +final String openAlprConfFile = ANDROID_DATA_DIR + File.separatorChar + "runtime_data" + File.separatorChar + "openalpr.conf"; |
| 43 | + |
| 44 | +String result = OpenALPR.Factory.create(MainActivity.this, ANDROID_DATA_DIR).recognizeWithCountryRegionNConfig("us", "", image.getAbsolutePath(), openAlprConfFile, 10); |
| 45 | +``` |
| 46 | + |
| 47 | +## Interface |
| 48 | + |
| 49 | +```Java |
| 50 | +/* |
| 51 | + Method interface. |
| 52 | +*/ |
| 53 | + |
| 54 | +/** |
| 55 | + * Recognizes the licence plate. |
| 56 | + * |
| 57 | + * @param country - Country code to identify (either us for USA or eu for Europe). Default=us. |
| 58 | + * @param region - Attempt to match the plate number against a region template (e.g., md for Maryland, ca for California). |
| 59 | + * @param imgFilePath - Image containing the license plate. |
| 60 | + * @param configFilePath - Config file path (default /etc/openalpr/openalpr.conf) |
| 61 | + * @param topN - Max number of possible plate numbers to return(default 10) |
| 62 | + * |
| 63 | + * @return - JSON string of results |
| 64 | + */ |
| 65 | + |
| 66 | +public String recognizeWithCountryRegionNConfig(String country, String region, String configFilePath, String imgFilePath, int topN); |
| 67 | + |
| 68 | +``` |
| 69 | +# Sample Application |
| 70 | + |
| 71 | +The repository also includes a [sample application](./Sample/OpenALPRSample) that can be tested with Android Studio. |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | +# Credits |
| 76 | + |
| 77 | + - [https://github.com/openalpr/openalpr](https://github.com/openalpr/openalpr) (the project repository) |
| 78 | + - [https://github.com/sujaybhowmick/OpenAlprDroidApp](https://github.com/sujaybhowmick/OpenAlprDroidApp) (for the compiled sources and for the sample that helped me to port the project to an android library) |
| 79 | + |
| 80 | + |
0 commit comments