Compile for Android with NDK

1,029 views
Skip to first unread message

Rino Seminara A-Tono

unread,
Jan 23, 2014, 8:23:13 AM1/23/14
to open...@googlegroups.com
Is there a way to compile this library for Android with Android NDK (ndk-build)?

Matt

unread,
Jan 26, 2014, 11:43:14 PM1/26/14
to open...@googlegroups.com
Absolutely, it should work fine.  Both Tesseract and OpenCV will compile via Android NDK.  OpenALPR should have no problem compiling as well.  

Rino Seminara A-Tono

unread,
Jan 31, 2014, 6:54:54 AM1/31/14
to open...@googlegroups.com
Can you indicate me a guide or a tutorial to create correct Android.mk file?

Simon Eriksson

unread,
Feb 23, 2014, 5:10:56 AM2/23/14
to open...@googlegroups.com
Hello Rino/Matt,

Have you had any luck with building openalpr and dependencies for Android? I have found the RPi too slow for processing and wanted to test out detection speed on Android but my NDK/JNI skills are very lacking.

Matt

unread,
Feb 24, 2014, 2:10:41 PM2/24/14
to open...@googlegroups.com
I haven't looked at this yet.  Although, I have gotten a number of messages about people working on compiling this.  I haven't heard of anyone completing the process yet, though.


On Thursday, January 23, 2014 6:23:13 AM UTC-7, Rino Seminara A-Tono wrote:

Simon Eriksson

unread,
Feb 24, 2014, 5:31:26 PM2/24/14
to open...@googlegroups.com
Hi Matt,

Good news others are working on it. I will keep at it and let you know if I have any success. I have a small personal project that could benefit from alpr and the RPi just wont cut it processing time wise. I will make sure I let the group know if I get any wins.

So far I have cloned and compiled this fork of tesseract-android-tools and have that working. Next step is opencv for android, and then on to OpenALPR.

ps. thank you for all your hard work, it's a great tool!

Leo Sapucaia

unread,
Mar 7, 2014, 8:55:13 PM3/7/14
to open...@googlegroups.com
Wondering if anyone had any luck compiling OpenANPR for Android. 
I tried but still could not reach a solution.

Matt

unread,
Mar 8, 2014, 8:39:43 AM3/8/14
to open...@googlegroups.com
If anyone wants to post their attempts on Github or something similar, I can take a look at it.  I am familiar with Android and the NDK, I just haven't had much time to work on this lately.

Luis Nani

unread,
May 29, 2014, 7:51:42 PM5/29/14
to open...@googlegroups.com
Dear Matt,

I only need oct.cpp and ocr.h in android ndk project.
I tried to include these file into jni folder with native tesseract, but i have an error  at this line :

tesseract::ResultIterator* ri = tesseract->GetIterator();

it cannot recognise ResultIterator.

Do you have any idea how to solve this problem?

Matt

unread,
Jun 3, 2014, 10:00:23 PM6/3/14
to open...@googlegroups.com
I've seen that error before when I tried linking against Tesseract 3.02 dynamically.  It needed to be linked statically since the ResultIterator class is not exposed in the Tesseract header.

In Tesseract 3.03 this seems to have changed, and I have no problem linking dynamically.

Jérémy VIENNE

unread,
Jun 19, 2014, 11:08:09 AM6/19/14
to open...@googlegroups.com
Hi, I achieved compiling it for Android, but the process was so tricky that i don't know how to start the explanations ... i just posted some guidelines on stackoverflow for that, as a reply to Rino Seminara.
Anyway thank you very much Matt, I would also like to know if i could use your library for a company project that i am working on ? The Android application using your library is not a commercial project, but will be intensively used by members of my company. What consideration should i take care of ?
Thanks and thanks again !

jav974

Matt

unread,
Jun 20, 2014, 9:06:32 AM6/20/14
to open...@googlegroups.com
Jeremy,

That is awesome.  What kind of performance are you seeing on the Android device?  How much work was it to get it working?  I am wondering how difficult it would be to maintain an Android wrapper with the official OpenALPR distribution.

You can use the library freely as long as your project abides by the terms of the AGPL.  If you want to use it in proprietary code, please e-mail me at ma...@ndu.com and we can work out a license.  I just need to know generally what the app will do and how much you will charge for it (it sounds like $0 in this case).

Jérémy VIENNE

unread,
Jun 21, 2014, 6:55:19 AM6/21/14
to open...@googlegroups.com
It takes about 1 and a half second to find a plate number on my Samsung Galaxy TAB Pro T900, Video recording and feedback process fluently at 17 fps@1920*1080 average while sending frames to OpenALPR. I think it is reasonably good performance, but i should try with a lower resolution as your library scale down the images to the size it can process natively in openalpr.conf

It took me one whole week to get to compile OpenALPR for Android (armeabi-v7a), and 3 days to make a good Android.mk and Native C++ code to use the library (but i had no experience neither on Android nor on NDK so it may explain why it took me so long). Finally it took me another couple days to get the assets working (openalpr.conf + runtime_data directory had to be added to the Assets folder, then on first run i copy the files onto the SD card). So approximately 2 weeks to get OpenALPR working.

In the end, the goal of my application is to gather information of vehicles in our database based on plate numbers, since we have a lot of vehicles to maintain status up to date, the process of finding which vehicle it is had to be time optimized. That is why and how i found your library, as i was going to write one down and realized i would take lot more time to do it. Thanks for your work and to make it free !!

Our project is going to be proprietary code (company obligations...), but will be used internally and won't be sold on the market. I will email you for that :)

Although it is proprietary work, I can share parts of it like everything concerning the OpenALPR part (C++ and Java Wrappers). Can you tell me how to share this ?

Thanks,
Jérémy

Matt

unread,
Jun 21, 2014, 10:02:31 AM6/21/14
to open...@googlegroups.com
Jeremy,

That performance actually sounds quite good for Android -- I was expecting much slower.  1920*1080 screenshots barely process faster than half a second on my Intel i7.  I bet if you dropped that down a bit (960x540) you would get performance ~500-700ms and probably similar accuracy.  Just adjust the max_detection_input_width/height values would be your best bet.

If you want to upload the project, just fork the OpenALPR main project and commit everything somewhere in there --  I can reorganize it once I have the code.  If it's not easy to integrate, then, at the very least, it would be an example for others to follow.

The main purpose for charging money for commercial licenses is to compel companies that use the library to also contribute to the project.  Some companies don't have the staff resources or incentive to do that.  In your case, your Android code contributions would offset the price.

-Matt

Jérémy VIENNE

unread,
Jul 31, 2014, 6:04:36 AM7/31/14
to open...@googlegroups.com
Hi every one, I posted a guide to compile the lbrary on stackoverflow, here is the link : http://stackoverflow.com/questions/21309592/compile-openalpr-for-android-with-ndk
There are 2 answers : one is the step by step tutorial, the other is a sample of Android.mk to use the library after generating it.
Please let me know if you get it right.

jav974

Matt

unread,
Jul 31, 2014, 8:44:08 PM7/31/14
to open...@googlegroups.com
Awesome!  I added your guide to the wiki: https://github.com/openalpr/openalpr/wiki/Android-compilation

Hopefully I'll have some time some day to follow your instructions and put together a pre-compiled ARM binary for each release.
Message has been deleted

Arnaud Thomas

unread,
Nov 1, 2014, 5:33:15 AM11/1/14
to open...@googlegroups.com
Hello Everyone,

I tried the test-app for Android and it is working fine. But I don't find any documentation about the functions I can use to OCR an image (I'm new to Android development).
Is anybody able to help me?

Regards
Arnaud


Le jeudi 23 janvier 2014 14:23:13 UTC+1, Rino Seminara A-Tono a écrit :

Matt

unread,
Nov 2, 2014, 9:24:53 AM11/2/14
to open...@googlegroups.com
The alpr.h file contains all the public functions that you can use to interact with OpenALPR.  The API has changed from v1.2.0 to the latest on the master branch (currently marked v2.0.0).  So it's best to check the alpr.h file in your code repo.  It will have a "recognize" function that you can call to start detecting plates from images.

-Matt

Arnaud Thomas

unread,
Nov 6, 2014, 9:10:27 AM11/6/14
to open...@googlegroups.com
Thank you Matt, I was able to compile the library and use it in my Android code. 
Regards
Arnaud

Abhijit Srivastava

unread,
Nov 24, 2014, 12:34:17 AM11/24/14
to open...@googlegroups.com
Hi Arnaud/Matt,

Thanks for compiling the library for Android. We are using the prebuilt android sample at : https://github.com/openalpr/openalpr-testapp.

Currently the NativeAplr.cpp is calling getVersion() from openAlpr but in actual I would need to call recognize("/car.jpg") method with the path of the image. I tried a lot but not able to compile the NativeAlpr.cpp after making the changes and I am not able to find help in this regard in the forum on google groups as well. 

Kindly provide me the steps that I need to follow after making changes to call recognize method from NativeAlpr.cpp or otherwise kindly help me by making the required changes and compiling the sample with those changes.

Many Thanks,
Abhijit 

Jérémy VIENNE

unread,
Nov 24, 2014, 5:11:54 AM11/24/14
to open...@googlegroups.com
Hi,

in fact i'm not using NativeAlpr to load images directly from storage, but instead i read the image in java and provide a pointer to the mem reference of that loaded Mat. Perhaps you could try that as well.
Here is the sample code i use in NativeAlpr.cpp

#include "opencv2/opencv.hpp"
#include "alpr.h"
#include "support/filesystem.h"
#include "support/timing.h"
#include "NativeAlpr.h"
 

 
Alpr* g_alpr = NULL;
 std
::string g_path;
 

 JNIEXPORT
void JNICALL Java_fr_alcopa_rec_NativeAlprWorker_init(JNIEnv* env, jobject obj, jstring sdPath) {
 g_path
= env->GetStringUTFChars(sdPath, JNI_FALSE);
 g_alpr
= new Alpr("eu", g_path + "openalpr.conf", g_path + "runtime_data");
 g_alpr
->setTopN(1);
 g_alpr
->setDefaultRegion("eu");
 

 
if (g_alpr->isLoaded() == false) {
 std
::cout << "Could not load ALPR" << std::endl;
 
}
 
}
 

 std
::string detectandshow( Alpr* alpr, cv::Mat frame, std::string region, bool writeJson)
 
{
 std
::vector<uchar> buffer;
 cv
::imencode(".bmp", frame, buffer);
 

 std
::vector<AlprResult> results = alpr->recognize(buffer);
 

 
if (writeJson) {
 
return alpr->toJson(results);
 
}
 
else {
 
if (results.size() > 0 && results[0].topNPlates.size() > 0) {
 
return results[0].topNPlates[0].characters;
 
}
 
}
 

 
return "Détection en cours...";
 
}
 

 JNIEXPORT jstring JNICALL
Java_fr_alcopa_rec_NativeAlprWorker_getPlateNumber(JNIEnv *env, jobject obj, jstring photoPath)
 
{
 cv
::Mat frame;
 std
::string nativePhotoPath = g_path + env->GetStringUTFChars(photoPath, JNI_FALSE);
 

 
if (fileExists(nativePhotoPath.c_str())) {
 frame
= cv::imread(nativePhotoPath);
 std
::string plate = detectandshow(g_alpr, frame, "", false);
 

 
return env->NewStringUTF(plate.c_str());
 
} else {
 
return env->NewStringUTF("Photo does not exist !");
 
}
 

 
return env->NewStringUTF("Détection en cours...");
 
}
 

 JNIEXPORT jstring JNICALL
Java_fr_alcopa_rec_NativeAlprWorker_getPlateNumberFromMat(JNIEnv* env, jobject obj, jlong matAddr)
 
{
 cv
::Mat& frame = *(cv::Mat*)matAddr;
 
return env->NewStringUTF(detectandshow(g_alpr, frame, "", false).c_str());
 
}

Smart Projects

unread,
Jun 9, 2016, 12:47:11 AM6/9/16
to OpenALPR
Hi!
Colud someone help me?
Almost everything is ok, but:
ndk-build
[armeabi-v7a] Install        : liblept.so => libs/armeabi-v7a/liblept.so
[armeabi-v7a] Compile++ thumb: openalpr-native <= AlprJNIWrapper.cpp
[armeabi-v7a] SharedLibrary  : libopenalpr-native.so
/openalpr/openalpr-master/openalpr-droidapp-native-master/orig/jni/AlprJNIWrapper.cpp:16: error:
 undefined reference to 'alpr::Alpr::setDetectRegion(bool)'
/openalpr/openalpr-master/openalpr-droidapp-native-master/orig/jni/AlprJNIWrapper.cpp:22: error:
 undefined reference to 'alpr::Alpr::Alpr(std::string, std::string, std::string)'
/openalpr/openalpr-master/openalpr-droidapp-native-master/orig/jni/AlprJNIWrapper.cpp:23: error:
 undefined reference to 'alpr::Alpr::setTopN(int)'
/openalpr/openalpr-master/openalpr-droidapp-native-master/orig/jni/AlprJNIWrapper.cpp:24: error:
 undefined reference to 'alpr::Alpr::setDefaultRegion(std::string)'
/openalpr/openalpr-master/openalpr-droidapp-native-master/orig/jni/AlprJNIWrapper.cpp:29: error:
 undefined reference to 'alpr::Alpr::isLoaded()'
/openalpr/openalpr-master/openalpr-droidapp-native-master/orig/jni/AlprJNIWrapper.cpp:39: error:
 undefined reference to 'alpr::Alpr::recognize(std::string)'
/openalpr/openalpr-master/openalpr-droidapp-native-master/orig/jni/AlprJNIWrapper.cpp:43: error:
 undefined reference to 'alpr::Alpr::toJson(alpr::AlprResults)'
collect2.exe: error: ld returned 1 exit status
make: *** [/openalpr/openalpr-master/openalpr-droidapp-native-master/orig/obj/local/armeabi-v7a/
libopenalpr-native.so] Error 1

What is the problem? 
Latest openalpr, latest android ndk.
Thanks a lot
Reply all
Reply to author
Forward
0 new messages