IoT Report
IoT Report
Mukund PG – CB.EN.U4CCE20034
----------------------------------------------------------------
INTRODUCTION:
Humanity has always placed a high priority on security. Today, to help people feel comfortable,
video surveillance cameras are installed in public places like schools, hospitals, and other
buildings. According to an HIS survey, there were an estimated 245 million installed and
operational security cameras in 2014, or one security camera for every 30 persons on the earth.
These cameras can be made smarter by teaching them to process data from the video feed
thanks to technological advancements, particularly in image processing and machine learning.
Vehicle-related security and safety issues are growing in importance as more automobiles are
present on the roadways in our metropolitan centres. Since there are so many vehicles on the
road, it is practically difficult to personally check and verify each one. In order to identify
unregistered and suspect automobiles, some sort of automated technology is required for
vehicle number plate identification. Using a Raspberry Pi for vehicle number plate recognition
can be an excellent answer to these issues.
DESCRIPTION:
In fields including toll collecting, parking management, traffic policing, and crime
investigation, automatic vehicle number plate detection is crucial. A vehicle number plate
recognition project based on the Raspberry Pi is suggested for the effective identification and
detection of cars. The project includes a Raspberry Pi 4, Pi camera, and LCD 16x2 display.
HARDWARE COMPONENTS:
CIRCUIT DIAGRAM:
STEPS INVOLVED:
The initial stage is to identify the vehicle's licence plate. In order to locate the number
plate, we will use OpenCV's contour feature to detect for rectangular objects. If we are
aware of the exact dimensions, colour, and general location of the number plate, the
accuracy can be increased. Typically, the location of the camera and the kind of licence
plate used in that nation are utilised to train the detection algorithm. If there isn't even a
car in the photograph, things grow more difficult; in this instance, we'll take an extra step
to find the automobile and then the licence plate.
2. Character Segmentation:
Once the licence plate has been located, we must clip it out and save the image as a new
one. Again, OpenCV makes this simple to accomplish.
3. Character Recognition:
The newly acquired image from the previous phase is almost certainly written with some
characters (numbers or alphabets). OCR (Optical Character Recognition) can be used on
it to find the number. Using a Raspberry Pi, we previously discussed optical character
recognition (OCR).
ALGORITHM:
FLOWCHART:
WORKING:
The detection of the licence plate is the first stage in this Raspberry Pi licence plate reader.
Take a look at a sample photograph of an automobile and begin by locating the licence plate
on it. Then, the same image will be used for both character segmentation and character
recognition. The whole code is supplied at the bottom of this page.
When resizing, ensure that the licence plate is still visible in the frame to avoid any issues with
higher resolution photographs. In every stage of picture processing, grey scaling is used. As
we are no longer dealing with the colour details when processing an image, other subsequent
processes move more quickly. After completing this stage, the image would resemble this.
Each image will contain both helpful and useless information; in this case, only the licence
plate is useful for our software; the other information is largely irrelevant. Noise is the term for
this unimportant information. A bilateral filter (Blurring) will typically eliminate the
extraneous elements from an image.
To blur out more background information, you can increase the sigma colour and sigma space
from 17 to higher numbers. Just be careful not to blur the useful area. The final image is
displayed below; as you can see, it has background details (a tree and a building) that are blurry.
By doing this, we may prevent the programme from focusing on these areas in the future.
3) Edge detection using Canny
The next step is interesting where we perform edge detection. There are many ways to do it,
the most easy and popular way is to use the canny edge method from OpenCV.
4) Now we can start looking for contours on our image, we have already learned about
how to find contour using OpenCV, The counters are then detected, sorted from large
to tiny, and the first 10 results are solely taken into consideration. The value 0.018 is an
experimental value; you can play around it to check which works best for you.
Once we have found the right contour, we save it in a variable called (screenCnt) and
then draw a rectangle box around it to make sure we have detected the license plate
correctly.
5) So we can proceed with masking the entire picture except for the place where the
number plate is.
The next step in Raspberry Pi Number Plate Recognition is to segment the license plate out of
the image by cropping it and saving it as a new image. We can then use this image to detect
the character in it. The code to crop ROI (Region of interest) image form the main image is
shown below
The resulting image is shown below. Normally added to cropping the image, we can also gray
it and edge it if required. This is done to improve the character recognition in next step.
However I found that it works fine even with the original image.
Step 3: Character Recognition
The Final step in this Raspberry Pi Number Plate Recognition is to actually read the number
plate information from the segmented image. We will use the pytesseract package to read
characters from image, just like we did in previous tutorial. The code for the same is given
below.
SOURCE CODE:
import cv2
import imutils
import numpy as np
import pytesseract
from PIL import Image
from picamera import PiCamera
import time
import smtplib
import pandas as pd
from time import sleep
import RPi.GPIO as GPIO
import board
import digitalio
import random
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
def similar(plate_text,word):
a=SequenceMatcher(None,plate_text,word)
return a.ratio()
p.start_preview()
time.sleep(4)
p.capture('4.jpg')
p.stop_preview()
img = cv2.imread('4.jpg',cv2.IMREAD_COLOR)
img = cv2.resize(img, (620,480) )
if screenCnt is None:
detected = 0
print("No contour detected")
else:
detected = 1
if detected == 1:
cv2.drawContours(img, [screenCnt], -1, (0, 255, 0), 3)
# Now crop
(x, y) = np.where(mask == 255)
(topx, topy) = (np.min(x), np.min(y))
(bottomx, bottomy) = (np.max(x), np.max(y))
Cropped = gray[topx:bottomx+1, topy:bottomy+1]
cv2.imshow('cropped',Cropped)
im1=cv2.imwrite('Cropped.png',Cropped)
#Read the number plate6
#text = pytesseract.image_to_string(Cropped, config='--psm 9')
text=pytesseract.image_to_string(Image.open('Cropped.png'),lang='eng',
config='--oem 3 --psm 11 ')
plate_text=[]
for i in text:
if i.isalnum():
plate_text.append(i)
plate_text="".join(plate_text)
cv2.imshow('image',img)
print("Detected Number is:",plate_text)
plate_text=str(plate_text)
cv2.waitKey(0)
cv2.destroyAllWindows()
num=""
ob=pd.read_csv('/home/pi/Desktop/data.csv')
for i in ob['Number']:
if similar(plate_text,i)>0.5:
print("Vehicle Registration Number Detected")
num=i
print(i)
msg = "Reg No:" + str(num)
t=ob.loc[ob['Number']==i,'emailid'].values[0]
lcd.message= msg
send_msg(t, num)
sleep(30)
lcd.clear()
if num=="":
msg="Not Regd"
lcd.message= msg
OUTPUT:
Fig: Printing the Regd. No on LCD
CONCLUSION:
The project is mainly based on license plate detection and recognition method. Firstly, the
license plate is processed for obtaining a better image and removing noise. We used Python
libraries including OpenCV and Tesseract OCR for License Plate Recognition. Horizontal and
vertical projection, Optical character recognition, Convolutional network methods are used for
character segmentation and character recognition.
THANK YOU