You will learn about Automatic number-plate recognition. We will use the Tesseract OCR An Optical Character Recognition Engine (OCR Engine) to automatically recognize text in vehicle registration plates.
Py-tesseract is an optical character recognition (OCR) tool for python. That is, it’ll recognize and “read” the text embedded in images. Python-tesseract is a wrapper for Google’s Tesseract-OCR Engine. It is also used as an individual script, because it can read all image types like jpeg, png, gif, bmp, tiff, etc. Additionally, if used as a script, Python-tesseract will print the recognized text rather than writing it to a file. It has ability to recognize more than 100 languages.
pip install pytesseract
OpenCV is an open source computer vision library. The library has more than 2500 optimized algorithms. These algorithms are often used to search and recognize faces, identify objects, recognize scenery and generate markers to overlay images using augmented reality, etc.
pip install opencv-python
Note: make sure you installed pytesseract and OpenCV-python modules properly
Note: you should have the dataset ready and all images should be as shown below in image processing techniques for best performance; dataset folder should be in same folder as you are writing this python code in or you will have to specify the path to dataset manually wherever needed.
Note: the name of image files has to be the exact number in respective license plate image. example: if you have a with license plate having number as “FTY349U” then name the image file as “FTY349U.jpg”.
Code: Perform OCR using the Tesseract Engine on license plates
Now we have the plates predicted but we haven’t seen what is the prediction, so to view the data and prediction we do a bit of visualization as shown below. we are also calculating the accuracy of prediction without using any built-in function.
We see that the Tesseract OCR engine mostly predicts all of the license plates correctly with 100% accuracy. For the license plates, the Tesseract OCR Engine predicted incorrectly (i.e. GWT2180, OKV8004, JSQ1413), we will apply image processing techniques on those license plate files and pass them to the Tesseract OCR again. Applying the image processing techniques would increase the accuracy of the Tesseract Engine for the license plates of GWT2180, OKV8004, JSQ1413.
Code: Image Processing Techniques
Resize the image file by a factor of 2x in both the horizontal and vertical directions using cv2.resize
Converting to Gray-scale: Next, we convert our resized image file to gray scale to optimize the detection and reduce the amount of colors present in image drastically which will help in the detection of license plates easily.
Denoising the Image:
Gaussian Blur is a technique for denoising images. it makes the edges more clearer and smoother which in-turn makes the characters more readable.
Now, pass the transformed license plate file to the Tesseract OCR engine and see the predicted result.
'--oem 3 -l eng --psm 6 -c tessedit_char_whitelist = ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
Similarly, do this image processing for all other number plates that didn’t get 100% accuracy. Finally, the license plate detection model is ready.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.My Personal Notes arrow_drop_up
- Detect and Recognize Car License Plate from a video in real time
- Python | Reading contents of PDF using OCR (Optical Character Recognition)
- Text Detection and Extraction using OpenCV and OCR
- OCR of Handwritten digits | OpenCV
- OCR of English alphabets in Python OpenCV
- Reading Text from the Image using Tesseract
- Pafy - Checking CC License for each item of Playlist
- Python | OCR on All the Images present in a Folder Simultaneously
- OpenCV - Facial Landmarks and Face Detection using dlib and OpenCV
- Transition from OpenCV 2 to OpenCV 3.x
- Pattern Recognition | Basics and Design Principles
- Text Localization, Detection and Recognition using Pytesseract
- Speech Recognition in Python using Google Speech API
- Google Chrome Dino Bot using Image Recognition | Python
- Pattern Recognition | Introduction
- Python | Named Entity Recognition (NER) using spaCy
- ML | Implement Face recognition using k-NN with scikit-learn
- Python | Speech recognition on large audio files
- Applications of Pattern Recognition
- Python | Multiple Face Recognition using dlib
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.