-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Build instructions for Ubuntu Linux
- Install prerequisites
sudo apt install -y libopencv-dev libtesseract-dev git cmake build-essential libleptonica-dev liblog4cplus-dev libcurl3-dev
1.1. Install beanstalkd to use alprd
(to use as daemon for video stream etc.)
sudo apt install beanstalkd
- Clone the latest code from GitHub
git clone https://github.com/openalpr/openalpr.git
- Setup the build directory
cd openalpr/src
mkdir build
cd build
- setup the compile environment
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_INSTALL_SYSCONFDIR:PATH=/etc ..
- compile the library
make
- Install the binaries/libraries to your local system (prefix is /usr)
sudo make install
You should now have the executables alpr
in the build folder as well as openalpr-utils-benchmark
, openalpr-utils-binarizefontsheet
, openalpr-utils-sortstate
, openalpr-utils-calibrate
, openalpr-utils-tagplates
, openalpr-utils-classifychars
, openalpr-utils-benchmark
, and openalpr-utils-prepcharsfortraining
in build/misc_utilities
# US Plate
wget http://plates.openalpr.com/ea7the.jpg
alpr -c us ea7the.jpg
# EU Plate
wget http://plates.openalpr.com/h786poj.jpg
alpr -c eu h786poj.jpg
# GB Plate
wget https://images.cdn.circlesix.co/image/1/640/0/uploads/posts/2021/07/b22c2b504ab94949ea0df2a8789d0727.jpg
alpr -c gb b22c2b504ab94949ea0df2a8789d0727.jpg
- Make sure that dependencies and required tools are installed
sudo apt-get install -y libpng12-dev libjpeg62-dev libtiff4-dev zlib1g-dev build-essential autoconf automake libtool git-core cmake
- Install opencv
- download and install leptonica and tesseract-ocr (tesseract-ocr requires leptonica and at least one language package)
cd /usr/local/src/openalpr/
wget https://github.com/DanBloomberg/leptonica/archive/v1.70.tar.gz
wget https://github.com/tesseract-ocr/tesseract/archive/refs/tags/3.02.02.tar.gz -O tesseract-ocr-3.02.02.tar.gz
wget https://sourceforge.net/projects/tesseract-ocr-alt/files/tesseract-ocr-3.02.eng.tar.gz
- unpack the tarballs:
tar xf tesseract-ocr-3.02.02.tar.gz
tar xf tesseract-ocr-3.02.eng.tar.gz
tar xf leptonica-1.70.tar.gz
- compile leptonica:
cd /usr/local/src/openalpr/leptonica-1.70/
./configure --prefix=/usr/local
make
make install
- compile tesseract:
cd /usr/local/src/openalpr/tesseract-ocr/
./autogen.sh
./configure
make
sudo make install
sudo ldconfig
- clone the openalpr repo to '/usr/local/src/openalpr/' directory
cd /usr/local/src/openalpr/
git clone https://github.com/openalpr/openalpr.git
- update CMakeLists.txt compile openalpr
cd /usr/local/src/openalpr/openalpr/
gedit CMakeLists.txt &
SET(OpenCV_DIR "/usr/local/lib")
SET(Tesseract_DIR "/usr/local/src/openalpr/tesseract-ocr")
cmake ./
make
Note: For Tesseract 3.03 the source files can be downloaded from the main svn branch or https://drive.google.com/folderview?id=0B7l10Bj_LprhQnpSRkpGMGV2eE0&usp=sharing#list.
There are many things which could go possibly wrong if we slightly move in a different direction while installing this package. Follow these instructions for Ubuntu machines to scale this package for real-time detection with OpenCV and Python. (Mac HomeBrew
is broken too but above the scope of this answer)
- Start from a clean state, remove every apt-package you've installed for
openaplr
if you've already messed it up. Remove the python binding, if you've set up that too.
apt list --installed | grep alpr
sudo apt-get purge libopenalpr
sudo rm -rf /usr/local/lib/python3.5/dist-packages/openalpr*
-
Follow the official instructions for installing the package on an Ubuntu machine here. Now, this is the catch. Don't follow
The Easiest Way
described. Follow theThe Easy Way (Ubuntu 14.04+)
. Because, the version whichThe Easiest Way
provides is an older one, which doesn't supportrecognize_ndarray
functionality for python bindings. -
Once you've completed the steps, go to the git repo you've cloned to your machine during the above installation and install the python bindings.
runtime_data
folder is also available in this repo, which will be helpful for next step.
cd openalpr/src/bindings/python/
sudo python3 setup.py install
- While declaring the
Alpr
object in the script, what they actually meant by
alpr = Alpr("us", "/path/to/openalpr.conf", "/path/to/runtime_data")
is
alpr = Alpr("us", "/etc/openalpr/openalpr.conf", "openalpr/runtime_data/")
- Now you're all set to grab a video or webcam using
cv2.VideoCapture()
, feed each frame toalpr.recognize_ndarray()
and life is good 💯