Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 22

B.J.

B AUTONOMOUS COLLEGE
DEPARTMENT OF IMSc.ETC

IMPLIMENTATION OF DEEP LEARNING IN THE PROCESS OF


AUTOMATIC VEHICLE DETECTION SYSTEM

Submitted by :-
Gopinath Parida(201853031)
Dibyasmita Sahoo (201853011)
Monalisa Beura(201853033)
CONTENTS
1. Objective
2. Introduction
3. Hardware Software Requirement
4. Block Diagram
5. Working Model
6. Coding And Analysis
7. Advantages And Disadvantages
8. Future Scope
9. Conclusion
10. Reference
OBJECTIVE
Intelligent monitoring has emerged as the most crucial application in
recent years. Object detection is considered as a hotspot of computer
vision. As the bike riders in our country are increasing and the road
misshapes are also increasing day by day, due to which many
accidents occur which led to death and most of them are caused due
to not wearing helmets. So, our model detects the helmet of the rider.
If the two-wheeler rider does not wear the helmet, it detects the
number plate of the vehicle.
INTRODUCTION
Our world is developing on a very fast scale and it’s one of the reasons
that the Automobile industry in which motorcycle has always been the
predominant mode of transport. Since the rises of two wheelers have
increased so it led to accidents and injuries. Many riders generally do
not use helmets and that is one of the major reasons. So our main
motive behind helmet and number plate recognization and detection
was to first detect first if someone is wearing helmet or not, if he is
wearing it, n problem,but if not, it detect his number plate.
HARDWARE COMPONET

HDMI cod

720p usb cam


Hdmi to usb b
Respberry pi model 4
connector

5v Power
supply
Lcd display
SOFTWARE SPECIFICATIONS
 Anaconda

 Python

 Google colab
BLOCK DIAGRAM
WORKING MODEL

5v power supply
CODING
 import cv2
 import numpy as np
 import os
 import imutils
 from tensorflow.keras.models import load_model
 os.environ['TF_FORCE_GPU_ALLOW_GROWTH'] = 'true'

 net = cv2.dnn.readNet("yolov3-custom_7000.weights", "yolov3-custom.cfg")


 net.setPreferableBackend(cv2.dnn.DNN_BACKEND_CUDA)
 net.setPreferableTarget(cv2.dnn.DNN_TARGET_CUDA)
 model = load_model('helmet-nonhelmet_cnn.h5')
 print('model loaded!!!')
 cap = cv2.VideoCapture('video.mp4')
 COLORS = [(0,255,0),(0,0,255)]
 layer_names = net.getLayerNames()
 output_layers = [layer_names[i - 1] for i in net.getUnconnectedOutLayers()]
 fourcc = cv2.VideoWriter_fourcc(*"XVID")
 writer = cv2.VideoWriter('output.avi', fourcc, 5,(888,500))
 def helmet_or_nohelmet(helmet_roi):
 try:
 helmet_roi = cv2.resize(helmet_roi, (224, 224))
 helmet_roi = np.array(helmet_roi,dtype='float32')
 helmet_roi = helmet_roi.reshape(1, 224, 224, 3)
 helmet_roi = helmet_roi/255.0
 return int(model.predict(helmet_roi)[0][0])
 except:
 pass
 ret = True
 while ret:
 ret, img = cap.read()
 img = imutils.resize(img,height=500)
 # img = cv2.imread('test.png')
 height, width = img.shape[:2]
 blob = cv2.dnn.blobFromImage(img, 0.00392, (416, 416), (0, 0, 0), True, crop=False)
 net.setInput(blob)
 outs = net.forward(output_layers)
 confidences = []
 boxes = []
 classIds = []
 for out in outs:
 for detection in out:
 scores = detection[5:]
 class_id = np.argmax(scores)
 confidence = scores[class_id]
 if confidence > 0.3:
 center_x = int(detection[0] * width)
 center_y = int(detection[1] * height)
 w = int(detection[2] * width)
 h = int(detection[3] * height)
 x = int(center_x - w / 2)
 y = int(center_y - h / 2)
 boxes.append([x, y, w, h])
 confidences.append(float(confidence))
 classIds.append(class_id)
 indexes = cv2.dnn.NMSBoxes(boxes, confidences, 0.5, 0.4)
 for i in range(len(boxes)):
 if i in indexes:
 x,y,w,h = boxes[i]
 color = [int(c) for c in COLORS[classIds[i]]]
 # green --> bike
 # red --> number plate
 if classIds[i]==0: #bike
 helmet_roi = img[max(0,y):max(0,y)+max(0,h)//4,max(0,x):max(0,x)
+max(0,w)]
 else: #number plate
 x_h = x-60
 y_h = y-350
 w_h = w+100
 h_h = h+100
 cv2.rectangle(img, (x, y), (x + w, y + h), color, 7)
 # h_r = img[max(0,(y-330)):max(0,(y-330 + h+100)) , max(0,(x-80)):max(0,(x-80 +
w+130))]
 if y_h>0 and x_h>0:
 h_r = img[y_h:y_h+h_h , x_h:x_h +w_h]
 c = helmet_or_nohelmet(h_r)
 cv2.putText(img,['helmet','no-helmet'][c],(x,y-100),cv2.FONT_HERSHEY_SIMPLEX,2,
(0,255,0),2)
 cv2.rectangle(img, (x_h, y_h), (x_h + w_h, y_h + h_h),(255,0,0), 10)
 writer.write(img)
 cv2.imshow("Image", img)

 if cv2.waitKey(1) == 27:
 break
 writer.release()
 cap.release()
 cv2.waitKey(0)
Code explanation
 Line 1–8 — Importing required libraries.
 Line 10 — Allow TensorFlow to use GPU.
 Line 12 — Read the network weights from yolo files. These ‘yolo.weights’ is the file which we trained just to detect bikes and number
plates.
 Line 13–14 — If you want to use GPU, set the backend and target to CUDA.
 Line 17–18 — Load the CNN model we trained to detect helmets.
 Line 20 — VideoCapture object to read frames from the video feed.
 Line 21 — A color array which we will use later.
 Line 23–27 — This writer will help write our output frames to a video file using cv2.VideoWriter().
 Line 29–37 — This function will be provided with an image and the model will predict whether there is a helmet or not in the image.
 Line 39–40 — Get the output layers to take the output from them in further steps.
 Line 46–49 — Read the frames from the video file, resize them and get their height and width.
 Line 51 — Use cv2.dnn.blobFromImage() to create a blob from the image and to use this blob as input to our network.
 Line 53 — Set this blob as input to our network.
 Line 54 — Flow this blob through the network and get the outputs.
 Line 60–76 — Get the outputs from the network.
 Line 78 — Get the indexes of the boxes which we will not consider due to Non-Maximum Suppression.
 Line 80–99 — Draw a green box around bikes and a red box around number plates. Detect if there is a helmet or not and print that.
 Line 102–103 — Write the output images as a video.
 Line 105–106 — Break the code if someone hits the ESC key.
OUTPUT SNAPSHOT
ADVANTAGES
 Accuracy

 Speed
 Automation
 Scalability
 Flexibility
 Cost-effective
DISADVANTAGES

 Data availability
 Performance under different conditions
 False positives and negatives
 Computational complexity
 Ethical considerations
FUTURE SCOPE

 Add a tracking algorithm

 Add a lot of training data

 Work when there are multiple vehicles in the scene

 To directly extract the license number using an OCR (Optical Character Recognition )
CONCLUSION
In this paper, we introduce a real-time end-to-end helmet detection of motorcyclists
method based on YOLOv5 algorithm. This includes two stages of motorcycle
detection and helmet detection, and for each stage, we train a model, which are
YOLOv5-MD and YOLOv5-HD, to achieve a real-time effect while ensuring high
accuracy. In addition, our model size is still very advantageous, the first stage model
is only 20.6 MB, and the second stage model is only 14.8 MB. In our dataset, the
final end-to-end motorcycle helmet detection mAP reached 97.7%, F1-score reached
92.7, detection speed reached 63 FPS, achieved high accuracy and real-time effect.
In addition, our method can determine whether the motorcycle is overloaded by
calculating the number of helmets and No_helmets.
REFERENCE
1. Organisation mondiale de la santé: Global Status Report on Road Safety 2018, WHO (2018)

2. Ren, S., at el.: Faster R-CNN: towards real-time object detection with region proposal networks. arXiv:1506.01497 [cs],
(2016)

3. Redmon, J., et al.: You only look once: unified, real-time object detection. arXiv:1506.02640 [cs], (2016)

4. Lin, T.-Y., et al.: Focal loss for dense object detection. arXiv:1708.02002 (2018)

5. Sun, D., et al.: Visual cognition inspired vehicle re-identification via correlative sparse ranking with multi-view deep
features. In: Ren, J., et al. (Eds.): Advances in Brain Inspired Cognitive Systems Springer International Publishing, Xi’an,
China, (2018)

6. Bodla, N., et al.: Soft-NMS – Improving object detection with one line of code. arXiv:1704.04503 [cs], (2017).

7. Espinosa, J.E.: Detection of motorcycles in urban traffic using video analysis: A review. IEEE Trans. Intell. Transport. Syst.
1–16 (2020)

8. Silva, R., et al.: Automatic detection of motorcyclists without helmet. In: 2013 XXXIX Latin American Computing
Conference, Caracas, Venezuela, 7–11 Oct. 2013

9. Dahiya, K., et al.: Automatic detection of bike-riders without helmet using surveillance videos in real-time. In: 2016
International Joint Conference on Neural Networks (IJCNN)’ 2016 International Joint Conference on Neural Networks
(IJCNN), Vancouver, BC, Canada, 24–29 July 2016

10. 21. Padmini, V.L., et al.: Real time automatic detection of motorcyclists with and without a safety helmet. In: 2020
International Conference on Smart Electronics and Communication (ICOSEC), Trichy, India, 10–12 Sept. 2020

You might also like