CAR NUMBER PLATE DETECTION
Task Description 📄
👉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)
Step: 1 Create a model that will detect a car in a live stream or video and recognize characters on number plate of the car.
STEP:1: capturing the car
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
while(cap.isOpened()):
ret, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow(‘frame’,gray)
if cv2.waitKey(10) == 76:
break
cap.release()
cv2.destroyAllWindows()
STEP:2: Filtering and contouring the image
import imutils
import easyocr
bfilter = cv2.bilateralFilter(gray, 11, 23, 23)
edge = cv2.Canny(bfilter, 30, 210)
keypoints = cv2.findContours(edge.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
contours = imutils.grab_contours(keypoints)
contours = sorted(contours, key=cv2.contourArea, reverse=True)[:10]
loc = None
for contour in contours:
approx = cv2.approxPolyDP(contour, 10, True)
if len(approx) == 4:
loc = approx
break
mask = np.zeros(gray.shape, np.uint8)
nimg = cv2.drawContours(mask, [loc], 0,255, -1)
nimg = cv2.bitwise_and(frame, frame, mask=mask)
(x,y) = np.where(mask==255)
(x1, y1) = (np.min(x), np.min(y))
(x2, y2) = (np.max(x), np.max(y))
c_image = gray[x1:x2+1, y1:y2+1]
reader = easyocr.Reader([‘en’])
result = reader.readtext(c_image)
STEP:3: Showing the detected number plate
from matplotlib import pyplot as plt
text = result[0][-5]
font = cv2.FONT_HERSHEY_SIMPLEX
res = cv2.putText(frame, text=text, org=(approx[0][0][0], approx[1][0][1]+60), fontFace=font, fontScale=1, color=(0,255,0), thickness=2, lineType=cv2.LINE_AA)
res = cv2.rectangle(frame, tuple(approx[0][0]), tuple(approx[2][0]), (0,255,0),3)
plt.imshow(cv2.cvtColor(res, cv2.COLOR_BGR2RGB))
STEP:4: Display plate No
print(text)
Step:2 Secondly , it will use the characters and fetch the owners information using RTO API’s .
It will help to fetch data of car owner using car number plate. I have taken only 3 car’s data we can take more data.
#!/usr/bin/python3
import cgi
import os
import subprocess as sp
print("content-type: text/html")
print()
f=cgi.FieldStorage()
cmd = f.getvalue("x")
if cmd == "256 D 259":
print('''<pre>
Car Number: 256 D 259
Car Model: BMW
Registration Name: Amith
Registration Date: 11/1/2010
Fuel Type: CNG
Location: Delhi, India
Vehicle Class: SUV
Insurance Upto: 19/12/2022
</pre>''')
elif cmd == "B 2228HM":
print('''<pre>
Car Number: B 2228HM
Car Model: BMW
Registration Name: Ram
Registration Date: 17/1/2013
Fuel Type: CNG
Location: Amritsar, India
Vehicle Class: SUV
Insurance Upto: 19/12/2026
</pre>''')
elif cmd == "TTL D4FTY":
print('''<pre>
Car Number: TTL D4FTY
Car Model: BMW
Registration Name: Suman
Registration Date: 17/1/2012
Fuel Type: CNG
Location: TamilNadu, India
Vehicle Class: SUV
Insurance Upto: 19/12/2022
</pre>''')elif cmd == "UP15CU8383":
print('''<pre>
Car Number: GD70 EEO
Car Model: BREZZA VDI AMT
Registration Name: Shani Deshwal
Registration Date: 29/11/2018
Fuel Type: DIESEL
Location: Uttar predesh, India
Vehicle Class: Motor car
Insurance Upto: 27/10/2019
</pre>''')
Step:3 Create a Web portal where all this information will be displayed (using html,css,and js)
This is web Gui that shows tha car details and owner name.
car.html
<!DOCTYPE html>
<html lang=”en”>
<meta charset=”utf-8">
<title>Car GUI</title>
<body>
<script src=’car.js’ ></script>
<h1 style = “font-size: 50px; text-shadow: 2px 2px 2px rgba(22,20,19,0.4); color: #e0c7c5; text-align: center;”> WELCOME </h1>
<style>
body{
background-image: url(‘index.jpg’);
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
}
</style>
<b><h2 style=”color:#e0c7c5;
text-align:center;
-webkit-text-stroke:1px darkblue;
font-size:250%;”>
<br/>
<br/>
Enter the car number : <input id = “in1” />
</h2></b>
<br/>
<pre>
<div style = “color: white; text-align:center;
font-family:verdana;
font-size:200%;
background-image: linear-gradient(to left, rgba(255,0,0,0.14), rgba(255,0,0,0.75));
}” id =”d1"> Here is the output </div>
<button style = “width: 170px;
display: block;
margin-left: auto;
margin-right: auto;
color: #591BC5;
font-size: 17px;
border:1px solid #EFEEF5;
font-weight: 500;
background: #EFEEF5;
border-radius: 20px;
padding: 10px;
cursor:pointer;
transition: .3s;” onclick=”lw()”>SUBMIT</button>
</pre>
</body>
</html>
car.js
function lw()
{
var i = document.getElementById(“in1”).value
var xhr = new XMLHttpRequest();
xhr.open(“GET”, “http://192.168.43.226/cgi-bin/car.py?x=" + i, true);
xhr.send();
xhr.onload= function() {
var i = document.getElementById(“in1”).value
var output = xhr.responseText;
document.getElementById(“d1”).innerHTML = output;
}
}
Thanks for reading me…