0. Test environment
- ubuntu v14.04 x86_64 (VirtualBox VM)
- tesseract v3.0.4
- openalpr v2.2.0
- opencv v3.0.0
1. Install dependencies library
- sudo apt-get install libpng12-dev libjpeg-dev libtiff5-dev zlib1g-dev
- sudo apt-get install build-essential
- sudo apt-get install autoconf automake libtool
- sudo apt-get install git-core
- sudo apt-get install cmake
2. cross compile opencv
You can reference this article "opencv-cross-compilation-for-arm-based".
3. download leptonica and tesseract-ocr
$ sudo mkdir -p /usr/local/src/openalpr
$ sudo chown your_name /usr/local/src/openalpr
$ cd /usr/local/src/openalpr
$ wget http://www.leptonica.com/source/leptonica-1.73.tar.gz
$ git clone https://github.com/tesseract-ocr/tesseract.git tesseract-ocr
$ tar xvf leptonica-1.73.tar.gz
4. cross compile leptonica and install
$ cd /usr/local/src/openalpr/leptonica-1.73/
$ ./configure --host=arm-linux-gnueabihf --prefix=/usr/local
$ make
$ sudo make install
NOTE: make sure the library was built for arm platform
$ file /usr/local/lib/liblept.so.5.0.0
liblept.so.5.0.0: ELF 32-bit LSB shared object,
ARM, EABI5 version 1 (SYSV), dynamically linked, BuildID[sha1]=011cf04446f97adadb67ed8182d333e652125418, not stripped
5. compile tesseract:
$ cd /usr/local/src/openalpr/tesseract-ocr/
$ git tag -l $ git checkout tags/3.04.00
$ ./autogen.sh
$ ./configure --host=arm-linux-gnueabihf \ --prefix=/usr/local \ --with-extra-includes=/usr/local/include \ --with-extra-libraries=/usr/local/lib
$ make
$ sudo make install
$ export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
NOTE: make sure the library was built for arm platform
$ file /usr/local/lib/libtesseract.so.3.0.4
libtesseract.so.3.0.4: ELF 32-bit LSB shared object,
ARM, EABI5 version 1 (SYSV), dynamically linked,
BuildID[sha1]=36109d2407faf447424bd92041c11a05428b043b, not stripped
6. install openalpr
$ cd /usr/local/src/openalpr/
$ git clone https://github.com/openalpr/openalpr.git
$ cd /usr/local/src/openalpr/openalpr/src/
$ gedit arm-linux-gnueabihf.cmake
The content of arm-linux-gnueabihf.cmake list below
# this one is important
SET(CMAKE_SYSTEM_NAME Linux)
#this one not so much
SET(CMAKE_SYSTEM_VERSION 1)
# specify the cross compiler
SET(CMAKE_C_COMPILER /usr/local/linaro-multilib-2014.06-gcc4.9/bin/arm-linux-gnueabihf-gcc)
SET(CMAKE_CXX_COMPILER /usr/local/linaro-multilib-2014.06-gcc4.9/bin/arm-linux-gnueabihf-g++)
# where is the target environment
SET(CMAKE_FIND_ROOT_PATH /usr/local /usr)
# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
SET(OpenCV_DIR "/usr/local/arm-opencv")
SET(Tessract_DIR "/usr/local")
# for log4cplus
SET(WITH_DAEMON OFF)
# For ffmpeg library with libopencv_world.so
SET(CMAKE_EXE_LINKER_FLAGS "-lpthread -ldl -lm -L/usr/local/lib/ -lavutil -lswscale -lavformat -lavcodec")
$ cmake ./ -DCMAKE_TOOLCHAIN_FILE=arm-linux-gnueabihf -DCMAKE_INSTALL_PREFIX:PATH=/usr/local -DCMAKE_INSTALL_SYSCONFDIR:PATH=/usr/local/etc
$ make
7. testing
a. copy all libraries from /usr/local/lib to /lib of the target platform
b. copy /usr/local/bin/alpr to the target platform
c. copy openalpr, tessdata from /usr/local/share to the target platform
d. copy openalpr from /usr/local/etc to the target platform
e. run "./alpr -c us ea7the.jpg", the expected result is
plate0: 10 results - EA7THE confidence: 92.4795 - EA7TBE confidence: 84.0421 - EA7TRE confidence: 83.1932 - EA7TE confidence: 82.0527 - EA7T8E confidence: 81.7845 - EA7TME confidence: 80.8062 - EA7THB confidence: 76.6468 - EA7TH6 confidence: 76.6153 - EA7TH confidence: 75.2232 - EA7TBB confidence: 68.2095
8. conclusion
In arm cortex-a9, the time to recognize ea7the.jpg is around 8 seconds. I think it is too slow, there are still many optimization need to do if I want to use it in my APP.
Reference:
- http://plates.openalpr.com/ea7the.jpg
- http://www.leptonica.com/download.html
- https://github.com/openalpr/openalpr/wiki/Compilation-instructions-(Ubuntu-Linux)