Recognizing Characters on the Number Plate of a Car using Python and Fetching Owner's details.

Kothapally Gnana praneeth
3 min readJul 5, 2021

In this story, I will cover

=>How to recognize the number plate of a vehicle.

=>Recognising characters

=>Fetching and displaying owner's details in Web Portal.

Note: My code not able to recognize all number plates. I will upload one more story on this with 100% result.

Source code of this story available on GitHub.

First, install all the required libraries using the pip command. we need OpenCV,easyocr,requests,xmltodict etc.,

Using Haarcascade (haarcascade_russian_plate_number.xml) number plate recognization model, the number plate of a vehicle in an image or video is recognized.

Once the number plate gets recognized need to detect the vehicle number in the number plate. For this, we are using “EasyOCR” as OCR(Optical Character Recognition) . Optical character recognition or OCR refers to a set of computer vision problems requiring us to convert images of digital or hand-written text images to machine-readable text in a form your computer can process, store, and edit as a text file as a part of a data entry and manipulation software.

  • The EasyOCR package can be installed with single pip command.
  • The dependencies on the EasyOCR package are minimal, making it easy to configure your OCR development environment.
  • Once EasyOCR is installed, only one import statement is required to import the package into your project.
  • From there, all you need is two lines of code to perform OCR — one to initialize the Reader class and then another to OCR the image via the read text function.

By using for loops and conditional statements we can easily eliminate unwanted elements like space, comma, special symbols in the detected vehicle number.

Now by using any API we need to fetch vehicle owner details. Here I’m using Regcheck API(http://www.regcheck.org.uk). The RegCheck API is a SOAP-based ASP.NET ASMX web service that permits the lookup of vehicle details across many countries, including the UK, Ireland, Finland, Netherlands, Norway, Sweden, Portugal, Italy, France, Spain, Australia, the USA, and others.

This API returns details in an XML format we need to convert it into the string format.

converting XML to JSON:

To handle the JSON file format, Python provides a module named json.

=>install xmltodict module using pip or any other python package manager.

=>import json module using the keyword import.

=> Convert the xml_data into a dictionary and store it in a variable
JSON objects are surrounded by curly braces { }. They are written in key and value pairs.
json.loads() takes in a string and returns a json object.
json.dumps() takes in a json object and returns a string.
We use xml_data as the input string and generate python object, so we use json.dumps().

Here, json_data is the variable used to store the generated object.

Using HTML, CSS and js create a web portal for displaying owner's information.

--

--