Using neural networks to build an automatic number plate recognition system. See mattherwearl's blog post for an explanation.
NOTE: This is an experimental project and is incomplete in a number of ways. This project is for be test it in Windows 10 64bits, and the code has been modify to generate licence plate patterns from Ecuador.
- Python v3.6.+ (64bits)
- NumPy v1.14.+
- Pillow v5.+
- OpenCV v3.14.+ (for cv2)
- MatPlotLib v2.1.+
- TensorFlow v1.+
Note: For install libraries use CMD terminal.
- Download Python 3.6.+ (last version of 64bits), and install it. Guide Video
- Installing numpy library (if not included)
py -m pip install numpy
- Installing OpenCV library
py -m pip install opencv-python
- Installing Pillow library
py -m pip install Pillow
- Installing MatPlotLib
py -m pip install matplotlib
- Installing TensorFlow (CPU or GPU) library
#*CPU version*
py -m pip install --upgrade tensorflow==1.8.0
or
#*GPU version*
py -m pip install --upgrade tensorflow-gpu==1.8.0
For GPU Nvidia, must install CUDA v9.0 and all its patchs, and then copy cuDNN v9.0 files into CUDA folder (for cuDNN follow this steps)
warning!! Other version of python, tensorflow, CUDA or cuDNN must cause problems
For python 3.7.* (last version of 64bits). Install tensorflow-gpu==2.0.0-rc0. For GPU Nvidia, must install CUDA v10.0 and all its patchs, and then copy cuDNN v10.0 files into CUDA folder (for cuDNN follow this steps)
Create a folder name anpr
and copy the following py files and folders:
bgs\
(backgrounds images)fonts\
(ttf files)test\
(generated licence plate, empty)common.py
(Common variables)model.py
(py dependencie)gen.py
(For generate test set images)train.py
(For train the model with generate images)detect.py
(For test result)
Usage is as follows:
-
(optional but recommended)
./extractbgs.py SUN397.tar.gz
: Extract ~3GB of background images from the SUN database intobgs/
(bgs/
must have only enumerate images in jpg format). The tar file (36GB) can be downloaded here. This step may take a while as it will extract 108,634 images. -
./gen.py
: Locate variablegenerate_amount
and set the number you want (default 100), it will safe the test set images intest/
(test/
must be empty). This step requires a.ttf
files to be in thefonts/
directory. -
./train.py
: Train the model. A GPU is recommended for this step. It will take around 100,000 batches to converge. When you're satisfied that the network has learned enough press Ctrl+C once and the process will create aCPUweights.npz
file and write the weights (ypu can run several time your training and it will keep learning from it stop). -
./detect.py in.png CPUweights.npz out.png
: Detect number plates in an image and give and output image. if get a tensorflow gpu error, you should uninstall itpy -m pip unistall tensorflow-gpu
Reproduce: mattherwearl's deep-anpr