dharshan r
4 min readAug 22, 2021

--

Task 08 đź’»

Team Task

Object Recognition using CNN model

Task Description đź“„

đź“Ś In this task :
👉Create a model that will detect a car in a live stream or video and recognize characters on number plate of the car .
👉Secondly , it will use the characters and fetch the owners information using RTO API’s .
👉Create a Web portal where all this information will be displayed (using html,css,and js

Object Recognition using CNN model

In this article, I am going to show you how you can create CNN Model or Deep Learning Model for Vehicle’s Number Plate Detection System that will get the owner’s information using Python and Flask API.

  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)

The following tasks will be performed in the above code:

  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)

The following tasks will be performed in the above code:

  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)

(Getting Vehicle’s Owner Information)

Flask Web App

Now we will convert the above Deep Learning code into a Flask WebApp.

Code for Getting Vehicle’s Owner Info (prediction.py)

Now this is the main app.py file for Flask

The functionality of this code is to:

  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

This is a simple HTML file with a background image with some heading and a submit button where you can submit your image or video to test the model.

CarDetails.html output

Thanks for Reading !!

Keep Learning !! Keep Sharing !!

--

--