Compile OpenALPR for Android with NDK

6k Views Asked by At

Is there a way to compile the library OpenALPR (https://github.com/openalpr/openalpr) for Android using NDK (ndk-build)?

4

There are 4 best solutions below

3
On BEST ANSWER

This is a guide to compile the library for android :

Tutorial for compiling OpenALPR for Android devices

[Step 0]

  • Download and deploy android-ndk
  • Make a symbolic link to android-ndk root folder to /opt

[Step 1]

[Step 2]

[Step 3]

  • Download and install the Android CMake project (https://code.google.com/p/android-cmake/) You should end up with a toolchain for generating android projects. If you got to choose which compiler to use, I recommend the gcc4.6 as I did not achieve compiling OpenALPR with a toolchain pointing to the gcc4.8 compiler...

  • Make a symbolic link to android-toolchain folder inside /opt (ie : sudo ln -s PATH_TO_ANDROID_TOOLCHAIN /opt/android-toolchain). (The android-toolchain folder is generated during the deployment of Android CMake project !)

[Step 4]

  • Download the openalpr-master from github (https://github.com/openalpr/openalpr)
  • Create a folder "build" inside openalpr-master directory
  • Go to the src directory and edit the CMakeLists.txt file :

    • Replace this line : SET(OpenCV_DIR "${CMAKE_SOURCE_DIR}/../libraries/opencv/")
    • with : SET(OpenCV_DIR "path_to_OpenCV4Android/sdk/native/jni")

    Then comment the section for generating alprd (or just remove it) :

    Compile the alprd library on Unix-based OS

    IF (NOT WIN32) ADD_EXECUTABLE( alprd daemon.cpp videobuffer.cpp daemon/beanstalk.c daemon/beanstalk.cc daemon/uuid.cpp )

    TARGET_LINK_LIBRARIES(alprd openalpr support uuid curl log4cplus ${OpenCV_LIBS} ${Tesseract_LIBS} ) ENDIF()

  • Open CMake

  • Point the Source code to the openalpr-master/src directory
  • Point the Build path to the openalpr-master/build directory
  • Press the "Configure" button
  • Choose "Unix Makefiles" (default) and select "Specify toolchain for cross-compiling" then click "Next"
  • Specify the toolchain file to use : if you achieved step 3, it should be located under $ANDROID_CMAKE/toolchain/android.toolchain.cmake (be sure to replace the $ANDROID_CMAKE with its corresponding absolute path)
  • Click on finish

There should not be any error but some warnings... it's ok

  • Press Generate

[Step 5]

  • Go to the build directory and edit this file : misc_utilities/CMakeFiles/benchmark.dir/link.txt : remove the -lpthread option (there should be only one line like this). Save and exit.
  • Open a file explorer and go to path_to_tess-two/tess-two/jni/com_googlecode_tesseract_android/src
  • Now search every header file (Press the search button and type in ".h" )
  • Copy and paste every header file to openalpr-master/src/openalpr/tesseract (you should create this directory first)
  • Creates these directories "libraries/tesseract-ocr/api/.libs" in the root path of openalpr-master (mkdir -p libraries/tesseract-ocr/api/.libs)
  • Copy and paste path_to_tess-two/tess-two/libs/armeabi-v7a/libtess.so to openalpr-master/libraries/tesseract-ocr/api/.libs/libtesseract.so (be sure to rename it from libtess.so to libtesseract.so !)
  • Open a terminal and go to the build folder (openalpr-master/build)
  • Do "make"

Everything should compile smoothly. You can find the alpr library in the openalpr-master/src/libs/armeabi-v7a

That's all, let me know your successes and failures, i'll try to help you as best as possible

1
On

Yes it should be possible. You'll need to get the Android version of OpenCV and Tesseract setup first. But once that's done, OpenALPR should compile cleanly under Android.

I suspect the performance will not be great, though, on a mobile phone. License plate recognition is a computationally intensive process.

0
On

Here is the Android.mk content i use :

LOCAL_PATH := $(call my-dir)
LIB_PATH := $(LOCAL_PATH)/../libs/armeabi-v7a

include $(CLEAR_VARS)

LOCAL_MODULE := leptonica
LOCAL_SRC_FILES := liblept.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE := tesseract
LOCAL_SRC_FILES := libtess.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE := simpleini
LOCAL_SRC_FILES := libsimpleini.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE := support
LOCAL_SRC_FILES := libsupport.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE := openalpr
LOCAL_SRC_FILES := libopenalpr-static.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)

OPENCV_INSTALL_MODULES:=on
OPENCV_CAMERA_MODULES:=off

include path_to_opencv4android/OpenCV.mk

LOCAL_MODULE := nativealpr
LOCAL_SRC_FILES := NativeAlpr.cpp
LOCAL_SHARED_LIBRARIES += tesseract leptonica
LOCAL_STATIC_LIBRARIES += openalpr support simpleini

include $(BUILD_SHARED_LIBRARY)

Here is the Application.mk

APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi-v7a

In the Android.mk file, the NativeAlpr.cpp file contains the necessary native code to use the OpenALPR library

2
On

If you are still looking to achieve it, here are the steps i followed in order to use OpenAlpr on Android device :

I tried it on Windows 8.1 And Ubuntu 13.10/14.04, both work perfectly

Well these are the main steps to build the library, you will also need to write an Android.mk file to use the library.

If you're interested (or anyone else) let me know and I'll write a proper step by step tutorial