Skip to content

Instantly share code, notes, and snippets.

@braitsch
Created July 25, 2019 03:41
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save braitsch/ee5434f91744026abb6c099f98e67613 to your computer and use it in GitHub Desktop.
Save braitsch/ee5434f91744026abb6c099f98e67613 to your computer and use it in GitHub Desktop.
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
$ 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
$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  
$ 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

Copy link

ghost commented Oct 4, 2019

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

@Qub3k
Copy link

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
Copy link

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
Copy link

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
Copy link

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
Copy link

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
Copy link

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
Copy link

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
Copy link

@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.

@promotion
Copy link

anyone can make a script for installing latest versions in 2023 ? :)

@lachi3
Copy link

lachi3 commented Apr 24, 2023

anyone can make a script for installing latest versions in 2023 ? :)

Second this ^

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