License Plate Recognition with a Jetson Nano
I live in a downtown Chicago apartment and like many living in a city, I park in a parking garage. The garage recently upgraded their radio-frequency identified device system to a license plate recognition system. I was intrigued by the announcement but, being pessimistic, I expected the system to fail and hinder me from entering or exiting the garage. I was wrong and the solution that was implemented has worked with 100% success. Even when, I don’t follow the laws by having a license plate on my front bumper or follow good car hygiene. Being a flatfooder, I decided to build my own License Plate Detector using OpenALPR and a Jetson Nano.
Later I will extend the functionality to the cloud and utilize some AWS services to really scale out any potential this POC has. One that comes to mind is a system-of-record. If I automated the entrance of a parking garage then I would want to track each and every data change with a complete and verifiable history. Especially if I owned multiple parking garages around the country. More to come…
Disclamer — Provided is not an optimal solution, it is a working solution. If you are reading this and can recommend enhancements or corrections. Please do so by leaving a comment.
Bill of materials
- Jetson Nano Developers Kit
- MicroSD card — I used a 32GB found here.
- Power Adapter — A 5V 2.5A power adapter like this one will work but it is recommended to use a 4A supply like this one. Direction on how to get the barrel adapter to work can be found here.
- Raspberry Pi Camera Module V2–8 Megapixel, 1080p *Version 1 module will not work with the Jetson Nano at the time of this writing.
- Monitor, keyboard, mouse, and ethernet cable.
- Computer to flash image.
- A parking structure with integrated License Plate Recognition — Just kidding :)
Get started with the Nano
This step is quite simple.
Just plug all cables into in the device but don’t forget to bridge the pins if using a barrel power supply. Be careful when plugging in the Pi camera because I broke my connector and had to deal with that.
Before powering on, follow these steps to flash the MicroSD card.
Insert the MicroSD, plug in and enjoy.
Install OpenALPR
I encountered several issues during this step and wasted many hours troubleshooting. This is mainly because the OpenALPR docs were for Ubuntu 16.04 and the Jetson Nano image is with Ubuntu 18.04. Some required packages have been depreciated.
The steps below are referenced from the OpenALPR’s Github docs here, and a tutorial that I came across from TechExpert TIPS here.
Prerequisites:
Start with a clean install. If you have already installed OpenALPR is easiest to reflash the MicroSD card and start from Scratch. Check for installs with bellow command.
apt list --installed | grep alpr
- Install dependencies and required tools.
sudo apt-get update
sudo apt-get install libopencv-dev
sudo apt-get install libtesseract-dev
sudo apt-get install git
sudo apt-get install cmake
sudo apt-get install build-essential
sudo apt-get install libleptonica-dev
sudo apt-get install liblog4cplus-dev
sudo apt-get install libcurl3-dev
sudo apt-get install beanstalkd
sudo apt-get install curl
sudo apt-get install python-pip
sudo apt-get install libcanberra-gtk-module
A one-liner for convenience.
sudo apt-get update -y && sudo apt-get install libopencv-dev libtesseract-dev git cmake build-essential libleptonica-dev liblog4cplus-dev libcurl3-dev beanstalkd curl python-pip libcanberra-gtk-module -y
2. Download leptonica-1.80 or a different version from here. Compile with make.
wget http://www.leptonica.org/source/leptonica-1.80.0.tar.gz
tar xvf leptonica-1.80.0.tar.gz leptonica-1.80.0
cd leptonica-1.80.0
./configure
make -j $(($(nproc)-1))
sudo make install
cd ~
3. Download Tesseract and compile. Don’t try and download it from here, it has nothing to do with this blog. Change nproc-1 to nproc-3 if you have other applications running on your nano.
git clone https://github.com/tesseract-ocr/tesseract.git
cd tesseract
./autogen.sh
./configure
make -j $(($(nproc)-1))
sudo make install
sudo ldconfig
cd ~
4. Clone and compile OpenALPR. Change to nproc-3 if needed.
git clone https://github.com/openalpr/openalpr.git
cd openalpr/src
sed -i '13iSET(Tesseract_DIR "/usr/local/bin/tesseract")' CMakeLists.txt
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_INSTALL_SYSCONFDIR:PATH=/etc ..
make -j $(($(nproc)-1))
sudo make install
cd ~
Install pickledb
Pickledb is very easy to use for simple applications. pickledb will be used as a local database on the nano.
sudo pip install pickledb requests
Run a python script
Run the script with an -IN or -OUT argument. -IN will play as a camera inside the parking garage while -OUT will play as a camera outside the parking garage.
The game is, if the camera detects a vehicle that is outside of the garage and identified a registered license plate. Then the gate for the garage will open. If the inside camera detects a resisted and previously entered vehicle. Then the gate will open.
Simply run
python license_plate_detect.py -OUTand thenpython license_plate_detect.py -IN
The license plate “ANYNAME” will be adde to pickledb on first run by this line. `regdb.set(‘ANYNAME’, str(time.time()))`. The same method can be applied for any other license plate number.
If you would like to see a still frame capture of the license plate when it is detected. Add -SF as an argument to the python script. Adding the still frame capture can cause processing errors. Executing `sudo systemctl restart nvargus-daemon` can help during trouble shooting.
python license_plate_detect.py -OUT -SF
I hope you enjoy and please share any modifications to the program in the comments below.
Information in this writing is for personal expression and not as a representative of my employer.