Detecting Indian number plates easily using Python!

Prathmesh Patil
Analytics Vidhya
Published in
4 min readNov 10, 2021

When it comes to projects based on object detection, detecting number plates is the most interesting and at the same time challenging as well.

I am saying ‘challenging’ because detecting the number plates by annotating the images and then sending them for training object detection algorithms like Faster RCNN, SDD or YOLO is relatively easy. But when it comes to extracting or getting the text from the detected plates accurately is tricky!.

There are various reasons for it such as lighting conditions, quality of the image, distortion, broken number plate, distance of the plate inside the image, etc these are some of the factors which makes it challenging and yet fun to work on!
This is why in this blog I will quickly take you through my simple library which will help in detecting and optionally extracting the number plates with just a few lines of code!

Contents

  1. Introduction to INPR
  2. Installing INPR
  3. Importing the libraries
  4. Getting the images
  5. Detecting the plates
  6. Getting the number plate
  7. Conclusion

Introduction to INPR

INPR is a simple to use deep learning based library for python which can be used for detecting the Indian number plates and optionally extracting the detected number plate as well.
This is a completely open sourced library published by me as a contribution to the open-source community. I always wanted to contribute towards open source in some ways so I decided to create and publish this library, so let's get started!

Installing INPR and other dependencies

Installing INPR is as simple as running the below commands in your cmd/terminal, INPR requires other dependencies like torch, detectron2 and fvcore.

1. installing INPR and its dependencies

Importing the libraries

Once installation of all the libraries is completed then we will import them in order to use it.

2. importing the libraries

Getting the images

Okay now everything is ready let’s use the library!…but hold on we need images so that we can use them for detecting. For getting the images use this simple command which will pull the image from my GitHub repo. But make sure you are in the same working directory. I have also provided some other images as well so you can also use those or use your own image.

3. getting the images

Once we get the images let’s visualize one of them using them.

4. visualizing the image
4.1 sample image

Detecting the plates

Till now we have collected some images and visualized one of them, now it's time to pass the same image for detecting the plates. The below code snippet does the same.

5. detecting the number plate

Once the above code is executed we can see the detected image simply by using the below code.

5.1 checking the detected number plate
5.2 detected number plate

As you can see from the above image the number plate has been detected! you can also observe that the resolution of the image also drops because internally the detection algorithm reduces the image size to reduce the computation complexity.

Getting the number plate

Optionally you can also try to get the detected number plate using the below code.

6. getting the number plate

If the OCR’s is able to fetch the text then you will get the number plate. Also as of now getting the number plate is limited to some images as there are various factors affecting it like lighting, image quality, unknown text on the plate or different language used, distance, distortion or blur, etc. That is why I call this part a tricky one.
But still, you can always give it a try! at the same time I am trying to improve it from my side as well so stay tuned!.

Conclusion

To conclude this is how you can easily detect and extract the Indian number plates with just a few lines of code. My main aim was just to make this task easier by making a package so that others can also use it within python itself.
Moreover, I am still working on it but if you feel like contributing then feel free to reach out through my email, LinkedIn or you can also raise an issue on GitHub as well and here are my GitHub and PyPI.

GitHub:- https://github.com/patrickn699/INPR
PyPI:- https://pypi.org/project/INPR/
YouTube:- https://youtu.be/CjkuUnPK3aI

You can also try it on Google Colab!

I hope you liked this quick tutorial on INPR, also share this blog with your friends, star my GitHub repo and do connect with me. Thanks for reading!

--

--

Prathmesh Patil
Analytics Vidhya

ML enthusiast, Data Science, Python developer, Google Cloud & Serverless. LinkedIn: https://www.linkedin.com/in/prathmesh