Deep Learning CNN Model to Auto-Detect Vehicle’s Number Plate Using Python and Flask API

Prerequisite: →

  1. Python and Deep Learning Libraries Installed OR (You can use Google Colab)
  2. Flask Installed
  3. Video or Image in which we want to detect the car’s plate and retrieve info
  4. Basic knowledge of Image Processing
  5. RTO’s API Key (You can use this API by visiting and creating an account on it)

Code Part-1

(Vehicle’s Number Plate Detection)

  1. First of all, the important libraries are imported like NumPy, cv2, and matplotlib.
  2. Then the CascadeClassifier is used for detecting the vehicle’s number plate region. Cascading classifiers are used to detect a particular feature or a region inside an image. The feature here is the Number Plate of a Vehicle.
  3. Cascading classifiers are trained with several hundred “positive” sample views of a particular object and arbitrary “negative” images of the same size. After the classifier is trained it can be applied to a region of an image and detect the object.
  4. Then there is a function called plate_detect() to detect the vehicle’s number plate and mark it with a green rectangle on it then crop that image’s plate region and return it to another function.
  5. This function will be called from another function called display_img().

Code Part-2

(Displaying the Image)

  1. The above code is used to display the image.
  2. There is a function called display_img() which will take an image as a parameter and convert it from BGR color code to RGB Color code then will display it on screen using matplotlib.
  3. Then we will read an image called car.jpg and call the function plate_detect() and then display the car image and the cropped plate image.

Code Part-3

(Preprocessing Image)

Code Part-4

( Segmentation of Image’s Characters)

Code Part-5

(Image Augmentation and Calculate Accuracy)

Code Part-6

(Creating and Training the Model)

Code Part-7

Code Part-8

(Getting Vehicle’s Owner Information)

Flask Web App

Code for Getting Vehicle’s Owner Info (

Now this is the main file for Flask

  1. Get the HTML file index.html and render it.
  2. Check for the extension of the file that is uploaded (to check for image or mp4 files)
  3. At last, it will get the carDetails.html file which uses the jinja2 template, and Pass the vehicle information to it.

Index.html code

CarDetails.html code

CarDetails.html output

ARTH-School of technology, BCA graduate

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Code/papeReview: ELMo

Short Introduction about Machine Learning

Ranking features based on the predictive power/importance of the class labels

Dask and TensorFlow in Production at GrubHub

Papers to Read on using Long Short Term Memory(LSTM) architecture in forecasting

Breast Cancer Detection using Machine Learning

Neural Network in Excel

The practical guide for Object Detection with YOLOv5 algorithm

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Vinodha kumara

Vinodha kumara

ARTH-School of technology, BCA graduate

More from Medium

Read & write multiple images from a directory in Python (skimage, opencv)


How to Extract any Object in your Scene using deeplabv3-xception65-ade20k TensorFlow light model on…

Computer vision applications: Image as visual data