Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
OpenALPR for Ubuntu 18.04

OpenALPR for Ubuntu 18.04

This is a slightly modified update to Daniel Kornev's excellent post which goes into more detail about why building from source is necessary on 18.04. His post was missing a few dependencies that I didn't have installed namely cmake, opencv and pkg-config. The following steps should get you a working build of openalpr on a fresh install of Ubuntu 18.04.


If you're not working with a fresh install, this might be a good time to clean and update your system before proceeding. (Optional)
$ sudo apt update #fetch list of available updates
$ sudo apt upgrade #install updates – does not remove packages
$ sudo apt autoremove #removes unused/outdated packages

1. Remove any previously installed versions of Tesseract & Leptonica and install all required dependencies and build tools.

# remove any tesseract binaries and languages
$ sudo apt-get remove tesseract-ocr*

# remove any previously installed leptonica
$ sudo apt-get remove libleptonica-dev

# make sure other dependencies are removed too
$ sudo apt-get autoclean
$ sudo apt-get autoremove --purge

# install libtool m4 automake cmake & pkg-config
$ sudo apt-get install libtool m4 automake cmake pkg-config

# install opencv
$ sudo apt-get install libopencv-dev

# install liblog4cplus-dev, liblog4cplus-1.1-9 and build-essential:
$ sudo apt-get install liblog4cplus-1.1-9 liblog4cplus-dev build-essential

2. Download & install leptonica 1.74.1

$ wget https://github.com/DanBloomberg/leptonica/archive/1.74.1.tar.gz

# unpack tarball and cd into leptonica directory
$ tar -xvzf 1.74.1.tar.gz
$ cd leptonica-1.74.1

# build leptonica
$ ./autobuild
$ ./configure
$ sudo make
$ sudo make install

3. Download & install tesseract 3.0.5

$wget https://github.com/tesseract-ocr/tesseract/archive/3.05.02.tar.gz

# unpack tarball and cd into tesseract directory
$ tar -xvzf
$ cd tesseract-3.05.02/

# build tesseract
$ ./autogen.sh
$ ./configure --enable-debug LDFLAGS="-L/usr/local/lib" CFLAGS="-I/usr/local/include"
$ sudo make
$ sudo make install
$ sudo make install-langs
$ sudo ldconfig

# check everything worked
$ tesseract --version

# you should see
tesseract 3.05.02
 leptonica-1.74.1

4. Install libcurl3 & update libcurl4

$ sudo add-apt-repository ppa:xapienz/curl34
$ sudo apt-get update
$ sudo apt-get install libcurl4 libcurl4-openssl-dev  

5. Download and install OpenALPR

$ git clone https://github.com/openalpr/openalpr.git
$ cd openalpr/src 
$ mkdir build
$ cd build

# setup the compile environment
$ cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_INSTALL_SYSCONFDIR:PATH=/etc ..

# and compile the library
$ make && sudo make install

6. Check if everything worked! 🎉

$ wget http://plates.openalpr.com/h786poj.jpg -O lp.jpg 
$ alpr lp.jpg
# if everything worked you should see:
 plate0: 10 results
    - 786P0      confidence: 89.6593
    - 786PO      confidence: 85.9889
    - 786PQ      confidence: 85.8115
    - 786PD      confidence: 85.7408
    - 786PG      confidence: 84.4258
    - 786P       confidence: 83.0879
    - 7B6P0      confidence: 72.5012
    - 7B6PO      confidence: 68.8309
    - 7B6PQ      confidence: 68.6534
    - 7B6PD      confidence: 68.5827

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Oct 4, 2019

getting error in the make command. Can anybody help?
The error is: cvtColor( img, grayImg, CV_BGR2GRAY );

@Qub3k

This comment has been minimized.

Copy link

@Qub3k Qub3k commented Jan 15, 2020

In Step 2. you do not need root privileges to run make. I would thus suggest to change the $ sudo make line into $ make. The same is true for Step 3. as well.

@Qub3k

This comment has been minimized.

Copy link

@Qub3k Qub3k commented Jan 15, 2020

I had successfully applied this tutorial to install OpenALPR with tesseract 4.1.1 and leptonica-1.79.0.

@priyankasaini24

This comment has been minimized.

Copy link

@priyankasaini24 priyankasaini24 commented Mar 9, 2020

I had successfully applied this tutorial to install OpenALPR with tesseract 4.1.1 and leptonica-1.79.0.

did you install OpenCV? and which version did you install? I'm getting error:
‘CV_BGR2GRAY’ was not declared in this scope.
cvtColor( img, grayImg, CV_BGR2GRAY );

@MattCurryCom

This comment has been minimized.

Copy link

@MattCurryCom MattCurryCom commented Mar 30, 2020

error: CV_BGR2GRAY’ was not declared in this scope
       cvtColor( img, grayImg, CV_BGR2GRAY );
                               ^~~~~~~~~~~
openalpr/CMakeFiles/openalpr.dir/build.make:86: recipe for target 'openalpr/CMakeFiles/openalpr.dir/alpr_impl.cpp.o' failed
make[2]: *** [openalpr/CMakeFiles/openalpr.dir/alpr_impl.cpp.o] Error 1
CMakeFiles/Makefile2:623: recipe for target 'openalpr/CMakeFiles/openalpr.dir/all' failed
make[1]: *** [openalpr/CMakeFiles/openalpr.dir/all] Error 2
Makefile:151: recipe for target 'all' failed
make: *** [all] Error 2
@rolotumazi

This comment has been minimized.

Copy link

@rolotumazi rolotumazi commented Jun 17, 2020

Great! It worked! Thank you very much! I thought the following warning might be an issue but it wasn't in the end...
"Could NOT find JNI (missing: JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH)
JAVA JNI library not found, skipping openalprjni compilation"

@Qub3k

This comment has been minimized.

Copy link

@Qub3k Qub3k commented Jul 22, 2020

I had successfully applied this tutorial to install OpenALPR with tesseract 4.1.1 and leptonica-1.79.0.

did you install OpenCV? and which version did you install? I'm getting error:
‘CV_BGR2GRAY’ was not declared in this scope.
cvtColor( img, grayImg, CV_BGR2GRAY );

@priyankasaini24 Yes, I did install OpenCV 4.0.0 (building it from the sources).

@rafael-pereira-atman

This comment has been minimized.

Copy link

@rafael-pereira-atman rafael-pereira-atman commented Aug 3, 2020

Is this tutorial works just in terminal like check example or it's possible run the code below as well using an IDE?

from openalpr import Alpr
import sys

alpr = Alpr("us", "/path/to/openalpr.conf", "/path/to/runtime_data")
if not alpr.is_loaded():
    print("Error loading OpenALPR")
    sys.exit(1)
    
alpr.set_top_n(20)
alpr.set_default_region("md")

results = alpr.recognize_file("/path/to/image.jpg")

i = 0
for plate in results['results']:
    i += 1
    print("Plate #%d" % i)
    print("   %12s %12s" % ("Plate", "Confidence"))
    for candidate in plate['candidates']:
        prefix = "-"
        if candidate['matches_template']:
            prefix = "*"

        print("  %s %12s%12f" % (prefix, candidate['plate'], candidate['confidence']))

# Call when completely done to release memory
alpr.unload()
@maemresen

This comment has been minimized.

Copy link

@maemresen maemresen commented Nov 7, 2020

@braitsch Nice job 👏 It worked successfully.

I made a few small additions and combine the steps you wrote here as one single script.
It could be found on my fork.
Hope, it helps.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment