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 http://www.regcheck.org.uk/ 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 (prediction.py)

Now this is the main app.py 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

MLOPS Training by Vimal Daga sir

Decoding Sentence Encoders 🔐

Machine learning papers

Machine Learning Classification Models (Part I)

How to Accelerate Your Python Deep Learning with Cloud GPU?

Neural Challenge #2: Basic Challenge

Writing a Neural Machine Translation Model: Seq2Seq model with Attention.

An Introduction to Machine Learning — The basics to get you started

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

UNMANNED AIR VEHICLES(UAV) DETECTION with YOLOv3 -Anıl ÖZEN

How to use facial landmarks obtained from dlib

Drowsiness Detection using OpenCV

HOW TO DETECT SHAPES USING CV2- WITH SOURCE CODE — EASY PROJECT