├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── Sample └── OpenALPRSample │ ├── .gitignore │ ├── app │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── assets │ │ └── runtime_data │ │ │ └── openalpr.conf │ │ ├── ic_launcher-web.png │ │ ├── java │ │ └── com │ │ │ └── sandro │ │ │ └── openalprsample │ │ │ └── MainActivity.java │ │ └── res │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ └── wrapper │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── settings.gradle ├── app ├── .gitignore ├── .idea │ ├── .name │ ├── compiler.xml │ ├── copyright │ │ └── profiles_settings.xml │ ├── gradle.xml │ ├── misc.xml │ ├── modules.xml │ ├── vcs.xml │ └── workspace.xml ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── assets │ └── runtime_data │ │ ├── keypoints │ │ ├── eu │ │ │ ├── au.jpg │ │ │ ├── be.jpg │ │ │ ├── bg.jpg │ │ │ ├── cy.jpg │ │ │ ├── de.jpg │ │ │ ├── dk.jpg │ │ │ ├── eng.jpg │ │ │ ├── es2000.jpg │ │ │ ├── es2006.jpg │ │ │ ├── est.jpg │ │ │ ├── fr.jpg │ │ │ ├── gb2000.jpg │ │ │ ├── gb2006.jpg │ │ │ ├── it.jpg │ │ │ ├── nl.jpg │ │ │ ├── pl2000.jpg │ │ │ ├── pl2006.jpg │ │ │ ├── pt1992.jpg │ │ │ └── pt1998.jpg │ │ └── us │ │ │ ├── ak2008.jpg │ │ │ ├── al2002.jpg │ │ │ ├── ar2006.jpg │ │ │ ├── az1996.jpg │ │ │ ├── ca1993.jpg │ │ │ ├── co2000.jpg │ │ │ ├── ct2000.jpg │ │ │ ├── dc2003.jpg │ │ │ ├── de1970.jpg │ │ │ ├── fl2004.jpg │ │ │ ├── ga2007.jpg │ │ │ ├── hi1991.jpg │ │ │ ├── ia1997.jpg │ │ │ ├── id2006.jpg │ │ │ ├── il2002.jpg │ │ │ ├── in2009.jpg │ │ │ ├── ks2007b.jpg │ │ │ ├── ky2005.jpg │ │ │ ├── la2006.jpg │ │ │ ├── ma1987.jpg │ │ │ ├── md2006.jpg │ │ │ ├── md2006b.jpg │ │ │ ├── md2006c.jpg │ │ │ ├── me1999.jpg │ │ │ ├── me1999b.jpg │ │ │ ├── mi2007.jpg │ │ │ ├── mn2000.jpg │ │ │ ├── mo2006b.jpg │ │ │ ├── mo2009.jpg │ │ │ ├── ms2003.jpg │ │ │ ├── mt2010.jpg │ │ │ ├── nc1982.jpg │ │ │ ├── nd1993.jpg │ │ │ ├── ne2005.jpg │ │ │ ├── nh1999.jpg │ │ │ ├── nj1993.jpg │ │ │ ├── nm2010.jpg │ │ │ ├── nv2001.jpg │ │ │ ├── ny2010.jpg │ │ │ ├── oh2004.jpg │ │ │ ├── ok2009.jpg │ │ │ ├── or1990.jpg │ │ │ ├── pa2004.jpg │ │ │ ├── ri1996.jpg │ │ │ ├── sc2008.jpg │ │ │ ├── sd2007.jpg │ │ │ ├── tn2007.jpg │ │ │ ├── tx2009.jpg │ │ │ ├── ut2009.jpg │ │ │ ├── va2003.jpg │ │ │ ├── vt1985.jpg │ │ │ ├── wa1998.jpg │ │ │ ├── wi2007.jpg │ │ │ ├── wv1995.jpg │ │ │ └── wy2000.jpg │ │ ├── ocr │ │ └── tessdata │ │ │ ├── leu.traineddata │ │ │ └── lus.traineddata │ │ ├── postprocess │ │ ├── eu.patterns │ │ ├── readme.txt │ │ └── us.patterns │ │ └── region │ │ ├── eu.xml │ │ └── us.xml │ ├── java │ └── org │ │ └── openalpr │ │ ├── AlprJNIWrapper.java │ │ ├── OpenALPR.java │ │ ├── model │ │ ├── Candidate.java │ │ ├── Coordinate.java │ │ ├── Result.java │ │ ├── Results.java │ │ └── ResultsError.java │ │ └── util │ │ └── Utils.java │ └── jniLibs │ └── armeabi-v7a │ ├── liblept.so │ ├── libopenalpr-native.so │ ├── libopencv_java.so │ └── libtess.so ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── images ├── screencast.gif └── screenshot.png ├── openalpr.conf └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Gradle files 2 | .gradle/ 3 | build/ 4 | 5 | # Log Files 6 | *.log 7 | 8 | # Android Studio / IntelliJ IDEA 9 | *.iws 10 | .idea/ 11 | *.iml 12 | local.properties 13 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## [1.1.2](https://github.com/SandroMachado/openalpr-android/tree/1.1.2) (2017-03-09) 4 | [Full Changelog](https://github.com/SandroMachado/openalpr-android/compare/1.1.1...1.1.2) 5 | 6 | **Closed issues:** 7 | 8 | - Error initializing OpenALPR [\#42](https://github.com/SandroMachado/openalpr-android/issues/42) 9 | - I'm getting an error [\#40](https://github.com/SandroMachado/openalpr-android/issues/40) 10 | - Can I specify country settings in openalpr.config [\#39](https://github.com/SandroMachado/openalpr-android/issues/39) 11 | - Error :\( [\#38](https://github.com/SandroMachado/openalpr-android/issues/38) 12 | - I don't know why it doesn't work... [\#36](https://github.com/SandroMachado/openalpr-android/issues/36) 13 | - Upgrade the dependency `Libpng library` to allow submission to `Play Store` [\#35](https://github.com/SandroMachado/openalpr-android/issues/35) 14 | - Openalpr is Apache 2.0 but original openalpr is AGPL 3.0. Which license affects me? [\#32](https://github.com/SandroMachado/openalpr-android/issues/32) 15 | - issue in changing package name [\#29](https://github.com/SandroMachado/openalpr-android/issues/29) 16 | - seems couldn't recognize words? [\#21](https://github.com/SandroMachado/openalpr-android/issues/21) 17 | - How to pass multiple country code? [\#20](https://github.com/SandroMachado/openalpr-android/issues/20) 18 | - Pass image as byte array not as file path [\#18](https://github.com/SandroMachado/openalpr-android/issues/18) 19 | - No module found [\#17](https://github.com/SandroMachado/openalpr-android/issues/17) 20 | - Failed to resolve: com.github.SandroMachado:openalpr-android:1.1.0 [\#16](https://github.com/SandroMachado/openalpr-android/issues/16) 21 | - libopenalpr-native.so & libopencv\_java.so [\#15](https://github.com/SandroMachado/openalpr-android/issues/15) 22 | - library "libopencv\_java.so" not found [\#14](https://github.com/SandroMachado/openalpr-android/issues/14) 23 | - library "libopencv\_java.so" not found [\#13](https://github.com/SandroMachado/openalpr-android/issues/13) 24 | 25 | **Merged pull requests:** 26 | 27 | - Update libpng library [\#44](https://github.com/SandroMachado/openalpr-android/pull/44) ([SandroMachado](https://github.com/SandroMachado)) 28 | - Multiple code quality fix-2 [\#28](https://github.com/SandroMachado/openalpr-android/pull/28) ([faisal-hameed](https://github.com/faisal-hameed)) 29 | - Code quality fix - Utility classes should not have public constructors. [\#26](https://github.com/SandroMachado/openalpr-android/pull/26) ([faisal-hameed](https://github.com/faisal-hameed)) 30 | - Code quality fix - Method names should comply with a naming convention. [\#25](https://github.com/SandroMachado/openalpr-android/pull/25) ([faisal-hameed](https://github.com/faisal-hameed)) 31 | - Code quality fix - Declarations should use Java collection interfaces such as "List" rather than specific implementation. [\#24](https://github.com/SandroMachado/openalpr-android/pull/24) ([faisal-hameed](https://github.com/faisal-hameed)) 32 | - Update README.md [\#23](https://github.com/SandroMachado/openalpr-android/pull/23) ([gas83](https://github.com/gas83)) 33 | - Update README.md [\#22](https://github.com/SandroMachado/openalpr-android/pull/22) ([gas83](https://github.com/gas83)) 34 | 35 | ## [1.1.1](https://github.com/SandroMachado/openalpr-android/tree/1.1.1) (2016-01-14) 36 | [Full Changelog](https://github.com/SandroMachado/openalpr-android/compare/1.1.0...1.1.1) 37 | 38 | **Merged pull requests:** 39 | 40 | - Update JitPack badge [\#11](https://github.com/SandroMachado/openalpr-android/pull/11) ([SandroMachado](https://github.com/SandroMachado)) 41 | - Add portuguese licence plate key points [\#10](https://github.com/SandroMachado/openalpr-android/pull/10) ([SandroMachado](https://github.com/SandroMachado)) 42 | - \#4 Added new keypoint folder for Europe with Polish LP placeholders [\#9](https://github.com/SandroMachado/openalpr-android/pull/9) ([JerzyPuchalski](https://github.com/JerzyPuchalski)) 43 | - Created a folder on /sdcard/ for all images captured [\#8](https://github.com/SandroMachado/openalpr-android/pull/8) ([ZKjellberg](https://github.com/ZKjellberg)) 44 | 45 | ## [1.1.0](https://github.com/SandroMachado/openalpr-android/tree/1.1.0) (2016-01-06) 46 | [Full Changelog](https://github.com/SandroMachado/openalpr-android/compare/1.0.1...1.1.0) 47 | 48 | **Fixed bugs:** 49 | 50 | - \[Sample Application\] State Lost on Rotation [\#6](https://github.com/SandroMachado/openalpr-android/issues/6) 51 | - \[Sample Application\] Crash on Invalid Submission [\#5](https://github.com/SandroMachado/openalpr-android/issues/5) 52 | 53 | **Closed issues:** 54 | 55 | - Crash during EU recognizing [\#4](https://github.com/SandroMachado/openalpr-android/issues/4) 56 | - Crash caused by missing libopenalpr-native.so [\#1](https://github.com/SandroMachado/openalpr-android/issues/1) 57 | 58 | **Merged pull requests:** 59 | 60 | - Long list of improvements [\#7](https://github.com/SandroMachado/openalpr-android/pull/7) ([ZKjellberg](https://github.com/ZKjellberg)) 61 | - IntelliJ Files Cleanup [\#3](https://github.com/SandroMachado/openalpr-android/pull/3) ([ZKjellberg](https://github.com/ZKjellberg)) 62 | 63 | ## [1.0.1](https://github.com/SandroMachado/openalpr-android/tree/1.0.1) (2015-12-17) 64 | [Full Changelog](https://github.com/SandroMachado/openalpr-android/compare/1.0.0...1.0.1) 65 | 66 | **Merged pull requests:** 67 | 68 | - Implemented permission check [\#2](https://github.com/SandroMachado/openalpr-android/pull/2) ([ZKjellberg](https://github.com/ZKjellberg)) 69 | 70 | ## [1.0.0](https://github.com/SandroMachado/openalpr-android/tree/1.0.0) (2015-12-13) 71 | 72 | 73 | \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)* -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # openalpr-android 2 | [![Release](https://jitpack.io/v/SandroMachado/openalpr-android.svg)](https://jitpack.io/#SandroMachado/openalpr-android) 3 | 4 | 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. You can find the demo application `apk` at the [releases](https://github.com/SandroMachado/openalpr-android/releases) tab. 5 | 6 | ![Screenshot](images/screenshot.png "Main Activity Sample application") 7 | 8 | # Gradle Dependency 9 | 10 | ## Repository 11 | 12 | First, add the following to your app's `build.gradle` file: 13 | 14 | ```Gradle 15 | repositories { 16 | maven { url "https://jitpack.io" } 17 | } 18 | ``` 19 | 20 | Them include the openalpr-android dependency: 21 | 22 | ```gradle 23 | dependencies { 24 | 25 | // ... other dependencies here. 26 | compile 'com.github.SandroMachado:openalpr-android:1.1.2' 27 | } 28 | ``` 29 | 30 | # Usage 31 | 32 | ## Code 33 | 34 | Copy the [OpenALPR configuration file](./openalpr.conf) to your android project assets directory `/main/assets/runtime_data/openalpr.conf`, open it 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). 35 | 36 | ```Java 37 | 38 | static final String ANDROID_DATA_DIR = "/data/data/com.sandro.openalprsample"; 39 | 40 | final String openAlprConfFile = ANDROID_DATA_DIR + File.separatorChar + "runtime_data" + File.separatorChar + "openalpr.conf"; 41 | 42 | String result = OpenALPR.Factory.create(MainActivity.this, ANDROID_DATA_DIR).recognizeWithCountryRegionNConfig("us", "", image.getAbsolutePath(), openAlprConfFile, 10); 43 | ``` 44 | 45 | ## Interface 46 | 47 | ```Java 48 | /* 49 | Method interface. 50 | */ 51 | 52 | /** 53 | * Recognizes the licence plate. 54 | * 55 | * @param country - Country code to identify (either us for USA or eu for Europe). Default=us. 56 | * @param region - Attempt to match the plate number against a region template (e.g., md for Maryland, ca for California). 57 | * @param imgFilePath - Image containing the license plate. 58 | * @param configFilePath - Config file path (default /etc/openalpr/openalpr.conf) 59 | * @param topN - Max number of possible plate numbers to return(default 10) 60 | * 61 | * @return - JSON string of results 62 | */ 63 | 64 | public String recognizeWithCountryRegionNConfig(String country, String region, String configFilePath, String imgFilePath, int topN); 65 | 66 | ``` 67 | # Sample Application 68 | 69 | The repository also includes a [sample application](./Sample/OpenALPRSample) that can be tested with Android Studio. 70 | 71 | ![Screencast](images/screencast.gif "Main Activity Sample application screencast") 72 | 73 | # Credits 74 | 75 | - [OpenALPR](https://github.com/openalpr/openalpr) Parent Project 76 | - [OpenAlprDroidApp](https://github.com/sujaybhowmick/OpenAlprDroidApp) for the compiled sources and sample that helped port the project to an android library 77 | -------------------------------------------------------------------------------- /Sample/OpenALPRSample/.gitignore: -------------------------------------------------------------------------------- 1 | # Gradle files 2 | .gradle/ 3 | build/ 4 | 5 | # Log Files 6 | *.log 7 | 8 | # Android Studio / IntelliJ IDEA 9 | *.iws 10 | .idea/ 11 | *.iml 12 | local.properties 13 | -------------------------------------------------------------------------------- /Sample/OpenALPRSample/app/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | /build 3 | -------------------------------------------------------------------------------- /Sample/OpenALPRSample/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.1" 6 | 7 | defaultConfig { 8 | applicationId "com.sandro.openalprsample" 9 | minSdkVersion 16 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.1.2" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | compile project(':OpenALPR') 25 | compile 'com.android.support:appcompat-v7:23.1.1' 26 | compile 'com.google.code.gson:gson:2.5' 27 | compile 'com.squareup.picasso:picasso:2.5.2' 28 | } 29 | -------------------------------------------------------------------------------- /Sample/OpenALPRSample/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/sandromachado/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | -keep class org.openalpr.model.** { *; } 20 | -------------------------------------------------------------------------------- /Sample/OpenALPRSample/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Sample/OpenALPRSample/app/src/main/assets/runtime_data/openalpr.conf: -------------------------------------------------------------------------------- 1 | [common] 2 | 3 | ; Specify the path to the runtime data directory 4 | runtime_dir = /data/data/com.sandro.openalprsample/runtime_data 5 | 6 | 7 | ocr_img_size_percent = 1.33333333 8 | state_id_img_size_percent = 2.0 9 | 10 | ; detection will ignore plates that are too large. This is a good efficiency technique to use if the 11 | ; plates are going to be a fixed distance away from the camera (e.g., you will never see plates that fill 12 | ; up the entire image 13 | max_plate_width_percent = 100 14 | max_plate_height_percent = 100 15 | 16 | ; detection_iteration_increase is the percentage that the LBP frame increases each iteration. 17 | ; It must be greater than 1.0. A value of 1.01 means increase by 1%, 1.10 increases it by 10% each time. 18 | ; So a 1% increase would be ~10x slower than 10% to process, but it has a higher chance of landing 19 | ; directly on the plate and getting a strong detection 20 | detection_iteration_increase = 1.1 21 | 22 | ; The minimum detection strength determines how sure the detection algorithm must be before signaling that 23 | ; a plate region exists. Technically this corresponds to LBP nearest neighbors (e.g., how many detections 24 | ; are clustered around the same area). For example, 2 = very lenient, 9 = very strict. 25 | detection_strictness = 3 26 | 27 | ; The detection doesn't necessarily need an extremely high resolution image in order to detect plates 28 | ; Using a smaller input image should still find the plates and will do it faster 29 | ; Tweaking the max_detection_input values will resize the input image if it is larger than these sizes 30 | ; max_detection_input_width/height are specified in pixels 31 | max_detection_input_width = 1280 32 | max_detection_input_height = 720 33 | 34 | opencl_enabled = 0 35 | multithreading_cores = 1 36 | 37 | 38 | 39 | max_plate_angle_degrees = 15 40 | 41 | ocr_min_font_point = 6 42 | 43 | ; Minimum OCR confidence percent to consider. 44 | postprocess_min_confidence = 65 45 | 46 | ; Any OCR character lower than this will also add an equally likely 47 | ; chance that the character is incorrect and will be skipped. Value is a confidence percent 48 | postprocess_confidence_skip_level = 80 49 | 50 | ; Reduces the total permutations to consider for scoring. 51 | postprocess_max_substitutions = 2 52 | 53 | ; Results with fewer characters will be discarded 54 | postprocess_min_characters = 4 55 | postprocess_max_characters = 8 56 | 57 | [debug] 58 | general = 0 59 | timing = 0 60 | state_id = 0 61 | plate_lines = 0 62 | plate_corners = 0 63 | char_regions = 0 64 | char_segment = 0 65 | char_analysis = 0 66 | color_filter = 0 67 | ocr = 0 68 | postprocess = 0 69 | show_images = 0 70 | pause_on_frame = 0 71 | 72 | ;;; Country Specific variables ;;;; 73 | 74 | [us] 75 | 76 | ; 30-50, 40-60, 50-70, 60-80 77 | char_analysis_min_pct = 0.30 78 | char_analysis_height_range = 0.20 79 | char_analysis_height_step_size = 0.10 80 | char_analysis_height_num_steps = 4 81 | 82 | segmentation_min_box_width_px = 4 83 | segmentation_min_charheight_percent = 0.5; 84 | segmentation_max_segment_width_percent_vs_average = 1.35; 85 | 86 | plate_width_mm = 304.8 87 | plate_height_mm = 152.4 88 | 89 | char_height_mm = 70 90 | char_width_mm = 35 91 | char_whitespace_top_mm = 38 92 | char_whitespace_bot_mm = 38 93 | 94 | template_max_width_px = 120 95 | template_max_height_px = 60 96 | 97 | ; Higher sensitivity means less lines 98 | plateline_sensitivity_vertical = 25 99 | plateline_sensitivity_horizontal = 45 100 | 101 | ; Regions smaller than this will be disqualified 102 | min_plate_size_width_px = 70 103 | min_plate_size_height_px = 35 104 | 105 | ocr_language = lus 106 | 107 | [eu] 108 | 109 | ; 35-50; 45-60, 55-70, 65-80, 75-90 110 | char_analysis_min_pct = 0.35 111 | char_analysis_height_range = 0.15 112 | char_analysis_height_step_size = 0.10 113 | char_analysis_height_num_steps = 5 114 | 115 | segmentation_min_box_width_px = 5 116 | segmentation_min_charheight_percent = 0.4; 117 | segmentation_max_segment_width_percent_vs_average = 2.0; 118 | 119 | plate_width_mm = 520 120 | plate_height_mm = 110 121 | 122 | char_height_mm = 80 123 | char_width_mm = 53 124 | char_whitespace_top_mm = 10 125 | char_whitespace_bot_mm = 10 126 | 127 | template_max_width_px = 184 128 | template_max_height_px = 46 129 | 130 | ; Higher sensitivity means less lines 131 | plateline_sensitivity_vertical = 18 132 | plateline_sensitivity_horizontal = 55 133 | 134 | ; Regions smaller than this will be disqualified 135 | min_plate_size_width_px = 100 136 | min_plate_size_height_px = 20 137 | 138 | ocr_language = leu 139 | -------------------------------------------------------------------------------- /Sample/OpenALPRSample/app/src/main/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SandroMachado/openalpr-android/793b1362753a0dd5c32d26a1ebfb6b8102a82749/Sample/OpenALPRSample/app/src/main/ic_launcher-web.png -------------------------------------------------------------------------------- /Sample/OpenALPRSample/app/src/main/java/com/sandro/openalprsample/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.sandro.openalprsample; 2 | 3 | import android.Manifest; 4 | import android.app.Activity; 5 | import android.app.ProgressDialog; 6 | import android.content.Context; 7 | import android.content.Intent; 8 | import android.content.pm.PackageManager; 9 | import android.graphics.Bitmap; 10 | import android.graphics.BitmapFactory; 11 | import android.graphics.Canvas; 12 | import android.graphics.Color; 13 | import android.graphics.Paint; 14 | import android.graphics.Rect; 15 | import android.graphics.RectF; 16 | import android.graphics.Typeface; 17 | import android.graphics.drawable.BitmapDrawable; 18 | import android.graphics.drawable.Drawable; 19 | import android.net.Uri; 20 | import android.os.AsyncTask; 21 | import android.os.Bundle; 22 | import android.os.Environment; 23 | import android.provider.MediaStore; 24 | import android.support.v4.app.ActivityCompat; 25 | import android.support.v4.content.ContextCompat; 26 | import android.support.v7.app.AppCompatActivity; 27 | import android.transition.Explode; 28 | import android.util.Log; 29 | import android.view.View; 30 | import android.view.ViewGroup; 31 | import android.widget.EditText; 32 | import android.widget.ImageView; 33 | import android.widget.TableLayout; 34 | import android.widget.TableRow; 35 | import android.widget.TextView; 36 | import android.widget.Toast; 37 | 38 | import com.google.gson.Gson; 39 | import com.google.gson.JsonSyntaxException; 40 | import com.squareup.picasso.Picasso; 41 | 42 | import org.openalpr.OpenALPR; 43 | import org.openalpr.model.Candidate; 44 | import org.openalpr.model.Coordinate; 45 | import org.openalpr.model.Result; 46 | import org.openalpr.model.Results; 47 | import org.openalpr.model.ResultsError; 48 | 49 | import java.io.File; 50 | import java.text.SimpleDateFormat; 51 | import java.util.ArrayList; 52 | import java.util.Date; 53 | import java.util.HashMap; 54 | import java.util.List; 55 | import java.util.Locale; 56 | import java.util.Map; 57 | 58 | 59 | public class MainActivity extends AppCompatActivity { 60 | 61 | private final int REQUEST_IMAGE = 100; 62 | private final int REQUEST_FILE = 42; 63 | private final int STORAGE = 1; 64 | 65 | private String ANDROID_DATA_DIR; 66 | private File imgFolder; 67 | private File imageFile; 68 | 69 | private Context appCtx; 70 | private ImageView imageView; 71 | private EditText txtCountry; 72 | private EditText txtRegion; 73 | private EditText txtCandidatesNum; 74 | private TableLayout resultTable; 75 | 76 | @Override 77 | protected void onCreate(Bundle savedInstanceState) { 78 | super.onCreate(savedInstanceState); 79 | setContentView(R.layout.activity_main); 80 | checkPermission(); 81 | 82 | appCtx = this; 83 | ANDROID_DATA_DIR = this.getApplicationInfo().dataDir; 84 | 85 | txtCandidatesNum = (EditText) findViewById(R.id.txtCandidatesNum); 86 | txtCountry = (EditText) findViewById(R.id.txtCountry); 87 | txtRegion = (EditText) findViewById(R.id.txtRegion); 88 | 89 | resultTable = (TableLayout) findViewById(R.id.resultTable); 90 | imageView = (ImageView) findViewById(R.id.imageView); 91 | 92 | findViewById(R.id.btnTakePicture).setOnClickListener(new View.OnClickListener() { 93 | @Override 94 | public void onClick(View view) { 95 | takePicture(); 96 | } 97 | }); 98 | 99 | findViewById(R.id.btnLoad).setOnClickListener(new View.OnClickListener() { 100 | @Override 101 | public void onClick(View view) { 102 | loadPicture(); 103 | } 104 | }); 105 | 106 | findViewById(R.id.btnClear).setOnClickListener(new View.OnClickListener() { 107 | @Override 108 | public void onClick(View view) { 109 | resultTable.setVisibility(View.GONE); 110 | int count = resultTable.getChildCount(); 111 | for (int i = 1; i < count; i++) { 112 | View child = resultTable.getChildAt(i); 113 | if (child instanceof TableRow) ((ViewGroup) child).removeAllViews(); 114 | } 115 | Toast.makeText(appCtx, "Result table cleared!", Toast.LENGTH_LONG).show(); 116 | } 117 | }); 118 | 119 | findViewById(R.id.btnFlushDir).setOnClickListener(new View.OnClickListener() { 120 | @Override 121 | public void onClick(View view) { 122 | int cont = 0; 123 | for (File file : imgFolder.listFiles()) { 124 | if (file.delete()) ++cont; 125 | } 126 | Toast.makeText(appCtx, cont + " files deleted successfully!", Toast.LENGTH_LONG).show(); 127 | } 128 | }); 129 | 130 | imgFolder = new File(Environment.getExternalStorageDirectory() + "/OpenALPR/"); 131 | if (!imgFolder.exists()) { 132 | imgFolder.mkdir(); 133 | } 134 | } 135 | 136 | @Override 137 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 138 | if ((requestCode == REQUEST_IMAGE || requestCode == REQUEST_FILE) && resultCode == Activity.RESULT_OK) { 139 | final long startTime = System.currentTimeMillis(); 140 | final long[] endTime = new long[1]; 141 | final ProgressDialog progress = ProgressDialog.show(this, "Loading", "Parsing result...", true); 142 | final String openAlprConfFile = ANDROID_DATA_DIR + File.separatorChar + "runtime_data" + File.separatorChar + "openalpr.conf"; 143 | BitmapFactory.Options options = new BitmapFactory.Options(); 144 | options.inSampleSize = 10; 145 | 146 | if (requestCode == REQUEST_FILE) { 147 | if (data != null && data.getData() != null) { 148 | String path = Environment.getExternalStorageDirectory().getPath() + "/" + data.getData().getLastPathSegment().split(":")[1]; 149 | imageFile = new File(path); 150 | Picasso.with(MainActivity.this).invalidate(imageFile); 151 | } 152 | } 153 | 154 | final int[] x1 = { 0 }; 155 | final int[] x2 = { 0 }; 156 | final int[] y1 = { 0 }; 157 | final int[] y2 = { 0 }; 158 | final String[] plate = {""}; 159 | 160 | AsyncTask.execute(new Runnable() { 161 | 162 | @Override 163 | public void run() { 164 | 165 | int candidates = txtCandidatesNum.getText().toString().isEmpty()? 5 : Integer.parseInt((txtCandidatesNum.getText().toString())); 166 | String result = OpenALPR.Factory.create(MainActivity.this, ANDROID_DATA_DIR).recognizeWithCountryRegionNConfig(txtCountry.getText().toString(), txtRegion.getText().toString(), imageFile.getAbsolutePath(), openAlprConfFile, candidates); 167 | Log.d("OPEN ALPR", result); 168 | 169 | try { 170 | final Results results = new Gson().fromJson(result, Results.class); 171 | runOnUiThread(new Runnable() { 172 | @Override 173 | public void run() { 174 | resultTable.setVisibility(View.VISIBLE); 175 | if (results == null || results.getResults() == null || results.getResults().size() == 0) { 176 | Toast.makeText(MainActivity.this, "It was not possible to detect the licence plate.", Toast.LENGTH_LONG).show(); 177 | } else { 178 | endTime[0] = System.currentTimeMillis(); 179 | TableLayout.LayoutParams rowLayoutParams = new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT); 180 | TableRow.LayoutParams cellLayoutParams = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); 181 | 182 | List resultsList = results.getResults(); 183 | for(int i = 0; i < resultsList.size(); ++i) { 184 | Result result = resultsList.get(i); 185 | 186 | if (i == 0) { // save rectangle coordinates and plate of best result 187 | x1[0] = result.getCoordinates().get(0).getX(); 188 | y1[0] = result.getCoordinates().get(0).getY(); 189 | x2[0] = result.getCoordinates().get(2).getX(); 190 | y2[0] = result.getCoordinates().get(2).getY(); 191 | plate[0] = result.getPlate(); 192 | } 193 | 194 | TableRow tableRow = new TableRow(appCtx); 195 | tableRow.setLayoutParams(rowLayoutParams); 196 | 197 | if (result.getConfidence() < 60) 198 | tableRow.setBackgroundColor(Color.RED); 199 | else if (result.getConfidence() < 85) 200 | tableRow.setBackgroundColor(Color.YELLOW); 201 | else if (result.getConfidence() >= 85) 202 | tableRow.setBackgroundColor(Color.GREEN); 203 | 204 | TextView cellValue = new TextView(appCtx); 205 | cellValue.setTypeface(null, Typeface.BOLD); 206 | cellValue.setText(result.getPlate()); 207 | cellValue.setLayoutParams(cellLayoutParams); 208 | tableRow.addView(cellValue); 209 | 210 | cellValue = new TextView(appCtx); 211 | cellValue.setTypeface(null, Typeface.BOLD); 212 | cellValue.setText(String.format("%.2f", result.getConfidence())+"%"); 213 | cellValue.setLayoutParams(cellLayoutParams); 214 | tableRow.addView(cellValue); 215 | 216 | String region = txtCountry.getText().toString()+"_"+txtRegion.getText().toString(); 217 | cellValue = new TextView(appCtx); 218 | cellValue.setTypeface(null, Typeface.BOLD); 219 | cellValue.setText(region.length() == 1? "n/a" : region); 220 | cellValue.setLayoutParams(cellLayoutParams); 221 | tableRow.addView(cellValue); 222 | 223 | cellValue = new TextView(appCtx); 224 | cellValue.setTypeface(null, Typeface.BOLD); 225 | cellValue.setText(String.format("%.2f", result.getMatchesTemplate())); 226 | cellValue.setLayoutParams(cellLayoutParams); 227 | tableRow.addView(cellValue); 228 | 229 | cellValue = new TextView(appCtx); 230 | cellValue.setTypeface(null, Typeface.BOLD); 231 | cellValue.setText(String.format("%.2f", ((result.getProcessingTimeMs() / 1000.0) % 60)) + " s"); 232 | cellValue.setLayoutParams(cellLayoutParams); 233 | tableRow.addView(cellValue); 234 | 235 | resultTable.addView(tableRow); 236 | List candidates = result.getCandidates(); 237 | for (int j = 1; j < candidates.size(); ++j) { 238 | Candidate candidate = candidates.get(j); 239 | tableRow = new TableRow(appCtx); 240 | tableRow.setLayoutParams(rowLayoutParams); 241 | tableRow.setBackgroundColor(Color.LTGRAY); 242 | 243 | cellValue = new TextView(appCtx); 244 | cellValue.setText(candidate.getPlate()); 245 | cellValue.setLayoutParams(cellLayoutParams); 246 | tableRow.addView(cellValue, 0); 247 | 248 | cellValue = new TextView(appCtx); 249 | cellValue.setText(String.format("%.2f", candidate.getConfidence())+"%"); 250 | cellValue.setLayoutParams(cellLayoutParams); 251 | tableRow.addView(cellValue, 1); 252 | 253 | tableRow.addView(new TextView(appCtx), 2); 254 | 255 | cellValue = new TextView(appCtx); 256 | cellValue.setText(String.valueOf(candidate.getMatchesTemplate())); 257 | cellValue.setLayoutParams(cellLayoutParams); 258 | tableRow.addView(cellValue, 3); 259 | resultTable.addView(tableRow); 260 | } 261 | } 262 | resultTable.invalidate(); 263 | Toast.makeText(appCtx, "Processing time: " + String.format("%.2f", (((endTime[0]-startTime) / 1000.0) % 60)) + " s", Toast.LENGTH_LONG).show(); 264 | } 265 | } 266 | }); 267 | 268 | } catch (JsonSyntaxException exception) { 269 | final ResultsError resultsError = new Gson().fromJson(result, ResultsError.class); 270 | 271 | runOnUiThread(new Runnable() { 272 | @Override 273 | public void run() { 274 | Toast.makeText(appCtx, resultsError.getMsg(), Toast.LENGTH_LONG).show(); 275 | } 276 | }); 277 | } 278 | 279 | progress.dismiss(); 280 | 281 | runOnUiThread(new Runnable() { 282 | @Override 283 | public void run() { 284 | // Picasso requires permission.WRITE_EXTERNAL_STORAGE 285 | Picasso.with(MainActivity.this).load(imageFile).fit().centerCrop().into(imageView); 286 | if (imageView.getDrawable() != null) { 287 | Bitmap bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap(); 288 | Bitmap originalBitmap = BitmapFactory.decodeFile(imageFile.getAbsolutePath(), new BitmapFactory.Options()); 289 | 290 | float viewWidth = bitmap.getWidth(); 291 | float viewHeigth = bitmap.getHeight(); 292 | float originalWidth = originalBitmap.getWidth(); 293 | float originalHeigth = originalBitmap.getHeight(); 294 | 295 | Canvas canvas = new Canvas(bitmap); 296 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); 297 | paint.setColor(Color.GREEN); 298 | paint.setStyle(Paint.Style.STROKE); 299 | paint.setStrokeWidth(8); 300 | 301 | // map rectangle coordinates to imageview 302 | int p1_x = (int)((x1[0] * viewWidth) / originalWidth); 303 | int p1_y = (int)((y1[0] * viewHeigth) / originalHeigth); 304 | int p2_x = (int)((x2[0] * viewWidth) / originalWidth); 305 | int p2_y = (int)((y2[0] * viewHeigth) / originalHeigth); 306 | canvas.drawRect(new Rect(p1_x, p1_y, p2_x, p2_y), paint); 307 | 308 | paint.setTextSize(75); 309 | paint.setStyle(Paint.Style.FILL); 310 | paint.setTypeface(Typeface.DEFAULT_BOLD); 311 | paint.setColor(Color.YELLOW); 312 | canvas.drawText(plate[0], p1_x, p1_y-10, paint); 313 | imageView.setImageBitmap(bitmap); 314 | } 315 | } 316 | }); 317 | } 318 | }); 319 | } 320 | } 321 | 322 | private void checkPermission() { 323 | List permissions = new ArrayList<>(); 324 | if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { 325 | permissions.add(Manifest.permission.WRITE_EXTERNAL_STORAGE); 326 | } 327 | if (!permissions.isEmpty()) { 328 | Toast.makeText(this, "Storage access needed to manage the picture.", Toast.LENGTH_LONG).show(); 329 | String[] params = permissions.toArray(new String[permissions.size()]); 330 | ActivityCompat.requestPermissions(this, params, STORAGE); 331 | } 332 | } 333 | 334 | @Override 335 | public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { 336 | switch (requestCode) { 337 | case STORAGE:{ 338 | Map perms = new HashMap<>(); 339 | // Initial 340 | perms.put(Manifest.permission.WRITE_EXTERNAL_STORAGE, PackageManager.PERMISSION_GRANTED); 341 | // Fill with results 342 | for (int i = 0; i < permissions.length; i++) 343 | perms.put(permissions[i], grantResults[i]); 344 | // Check for WRITE_EXTERNAL_STORAGE 345 | Boolean storage = perms.get(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED; 346 | if (storage) { 347 | // permission was granted, yay! 348 | } else { 349 | // Permission Denied 350 | Toast.makeText(this, "Storage permission is needed to analyse the picture.", Toast.LENGTH_LONG).show(); 351 | } 352 | } 353 | default: 354 | break; 355 | } 356 | } 357 | 358 | public String dateToString(Date date, String format) { 359 | SimpleDateFormat df = new SimpleDateFormat(format, Locale.getDefault()); 360 | 361 | return df.format(date); 362 | } 363 | 364 | public void takePicture() { 365 | // Generate the path for the next photo 366 | String name = dateToString(new Date(), "yyyy-MM-dd-hh-mm-ss"); 367 | imageFile = new File(imgFolder, name + ".jpg"); 368 | 369 | Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 370 | intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imageFile)); 371 | startActivityForResult(intent, REQUEST_IMAGE); 372 | } 373 | 374 | public void loadPicture() { 375 | Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); 376 | intent.addCategory(Intent.CATEGORY_OPENABLE); 377 | intent.setType("image/*"); 378 | startActivityForResult(intent, REQUEST_FILE); 379 | } 380 | 381 | @Override 382 | protected void onResume() { 383 | super.onResume(); 384 | if (imageFile != null) {// Picasso does not seem to have an issue with a null value, but to be safe 385 | Picasso.with(MainActivity.this).load(imageFile).fit().centerCrop().into(imageView); 386 | } 387 | } 388 | 389 | } 390 | -------------------------------------------------------------------------------- /Sample/OpenALPRSample/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 18 | 19 | 26 | 27 | 31 | 32 | 39 | 40 | 47 | 48 | 49 | 53 | 54 |