Driver Awakening System1
Driver Awakening System1
A PROJECT REPORT
Submitted by
U. SIVARAMAN 812419104065
degree of
BACHELOR OF ENGINEERING
in
JUNE 2022
DRIVER AWAKENING SYSTEM USING IOT
A PROJECT REPORT
Submitted by
U. SIVARAMAN 812419104065
degree of
BACHELOR OF ENGINEERING
in
JUNE 2022
i
ANNA UNIVERSITY : CHENNAI 600 025
BONAFIDE CERTIFICATE
Certified that this project report “DRIVER AWAKENING SYSTEM USING IOT” is
SIGNATURE SIGNATURE
ASSISTANT PROFESSOR
Engineering Engineering
ii
ACKNOWLEDGMENT
First of all we thank God for this shower of blessing and his divine help which
enables us to complete the project successfully.
iii
ABSTRACT
head pose and illumination condition. A new deep learning framework based
human intelligence in machines that are programmed to think like humans and
techniques, the driver’s face is located from a color video captured in a car.
Then, face detection is employed to locate the regions of the driver’s eyes,
which are used as the templates for eye tracking in subsequent frames. Finally,
the tracked eye’s images are used for drowsiness detection in order to generate
warning alarms. This system also contains an IOT device, which is used to
wake the driver up if he/she has drowsed. This concept of taking necessary
iv
TABLE OF CONTENTS
TITLE
CHAPTER NO PAGE NO.
ABSTRACT iv
LIST OF FIGURES ix
1 INTRODUCTION 1
2 LITERATURE SURVEY 6
2.1 IMPACT OF THE FACE ANGLE TO
TRAVELING TRAJECTORY DURING 6
THE RIDING STANDING-TYPE
PERSONAL MOBILITY DEVICE
2.2 USING REAL-LIFE ALERT-BASED 7
DATA TO ANALYSE DROWSINESS
AND DISTRACTION OF
COMMERCIAL DRIVERS
2.3 SMARTPHONES AS AN 8
INTEGRATED PLATFORM FOR
MONITORING DRIVER BEHAVIOR
2.4 DRIVER-IN-THE-LOOP FORWARD
COLLISION WARNING USING
MULTISAMPLE REINFORCEMENT 9
LEARNING
v
2.5 A NOVEL MODEL-BASED DRIVING 10
BEHAVIOR RECOGNITION SYSTEM
USING MOTION SENSORS.
2.6 DRIVER DROWSINESS
MONITORING SYSTEM USING
VISUAL BEHAVIOR AND MACHINE 11
LEARNING
2.7 ESTIMATION OF THE DRIVING
STYLE BASED ON THE USERS’
ACTIVITY AND ENVIRONMENT 13
INFLUENCE
3 SYSTEM ANALYSIS 15
3.1 EXISTING SYSTEM 15
3.1.1 Disadvantages 15
3.2 PROPOSED SYSTEM 16
3.2.1 Advantages 17
4 SYSTEM REQUIREMENTS 18
4.1 HARDWARE REQUIREMENTS 18
4.2 SOFTWARE REQUIREMENTS 18
5 SYSTEM DESIGN 19
5.1 SYSTEM ARCHITECTURE 19
5.2 DATA FLOW DIAGRAM 20
5.3 USE CASE DIAGRAM 22
vi
5.3.1 Class Diagram 24
5.3.2 Sequence Diagram 24
6 MODULE DESCRIPTION 26
6.1 LIST OF MODULES 26
6.1.1 Data Collection 26
6.1.2 Receive the Image Input 28
6.1.3 Detect face create ROI 29
6.1.4 Detect eyes from ROI and 31
create classifier
6.1.5 Categorize the state of the eye 33
7 CONCLUSION AND FUTURE 35
ENHANCEMENT
7.1 CONCLUSION 35
7.2 FUTURE ENHANCEMENT 36
APPENDICES 38
1. SAMPLE CODE 38
2. SCREENSHOT 47
REFERENCES 51
vii
LIST OF FIGURES
viii
CHAPTER 1
INTRODUCTION
Most of the road accidents are caused because of drowsiness and drunk
driving and also working environments, reduced sleep and time factor. Driver
drowsiness and fatigue drunk driving reduces the driver decision making
capability and perception level. These two situations affect the ability to
control the vehicle. There are some techniques which are used to detect
Drowsy Driver Detection system and a traffic detection system with external
these problems, we've incorporated driver alert system by watching each the
2
driver's eyes still as sensing still because the driver state of affairs based
important to recognise that as the number of vehicles using the roads rises, so
too does the threat of traffic accidents. Road accidents are very common in
nations with densely populated streets and roads. According to a poll by the
National Crime Records Bureau (NCRB), 0.13 million lives were lost in road
accidents in India alone in the year 2020. The leading cause of death
identified several risk factors for accidents, including speeding, drunk driving,
distracted driving, etc. The majority of traffic accidents are caused by drivers
who are irresponsible and who disregard traffic laws and safety precautions,
according to almost all of these criteria. Lack of sleep, night time driving, or
even both can cause drowsiness, which wears out the driver and takes their
attention away from the road. It is fairly typical for bus and truck drivers in
the transportation sector to nod off while operating the vehicle, especially in
3
circumstances necessitate that people are made aware of them in order to
prevent them and spare countless lives in the past. Technology is developing
quickly, and automation is making busy people's lives easier while also
mood of the driver must be created for real-time applications. This will
improve public safety and help decrease traffic accidents. In the field of
4
becomes a laborious process. The industry has created numerous strategies
based on various aspects because of how serious the issue is. The lack of
sleep, carelessness, or other factors that could divert the driver's focus from
driving could be to blame for their inattention. Alkinanietal used deep learning
Apart from detecting the drowsiness in drivers, this system also contains the
application of initiating alarm system and water spray for waking up the
by reacting as soon as the driver sleeps. Detecting the drowsiness alone is not
going to reduce the accidents occurred due to drowsiness, but reducing the
number of drivers sleeping does. Hence, this system will be very useful and
efficient in day-to-day life as it reduces the accidents and especially the threat
5
CHAPTER 2
LITERATURE SURVEY
MOBILITY DEVICE
DESCRIPTION:
has been a popular choice for recreational activities in the developed countries
such as in the USA and the countries in Europe. These devices are not
completely risk free and various accidents have been reported. Since that, the
research studies on the risk factors on riding PMD devices have not been
6
experiments that, the face direction is an important factor in risk assessment
running locus occurred in the direction opposite to the direction the subject
DRIVERS
DESCRIPTION:
distraction inasmuch as they drive for long periods of time and as a daily
7
monitored 70 professional drivers from different companies, was used to
time (sub-journey time), the journey time (a set of sub-journeys), the number
of breaks and the breaking duration time. Dummy variables were also
driving time, the number of distraction and drowsiness alerts increase too.
DESCRIPTION:
Nowadays, more than half of the world’s web traffic comes from mobile
8
combined with the connectivity and embedded sensing capability of
platform for monitoring driver behaviour in the context of ITS. This study
DESCRIPTION:
on the context of the vehicle and its surrounding vehicles leaving the human
9
(driver) context out of consideration. On the other side, and due to the
monitoring complex human context becomes feasible which paves the way to
moreover, varies across time for the same driver, the proposed Sentio
algorithm needs to take into account all these variabilities which are not
DESCRIPTION:
10
safety. Based on the theory of rigid body kinematics, we build a specific
physical model to reveal the data change rule during the vehicle moving
apply a Kalman filter for noise elimination and an adaptive time window for
data extraction. Based on the feature extraction guided by the built physical
accelerating, braking, and lane changing and turning with caution) and
11
2.6 DRIVER DROWSINESS MONITORING SYSTEM USING VISUAL
DESCRIPTION:
Drowsy driving is one of the major causes of road accidents and death.
area. Most of the conventional methods are either vehicle based, or behavioral
based or physiological based. Few methods are intrusive and distract the
driver, some require expensive sensors and data handling. Therefore, in this
study, a low cost, real time driver’s drowsiness detection system is developed
video and driver’s face is detected in each frame employing image processing
subsequently the eye aspect ratio, mouth opening ratio and nose length ratio
12
specificity of 100% has been achieved in Support Vector Machine based
classification.
AUTHOR: Mikhail Sysoev, Andrej Kos, Jože Guna, Matevž Pogačnik (2020)
DESCRIPTION:
New models and methods have been designed to predict the influence of
assessment of the driving style; (ii) the prediction of aggressive driving style
driving data from 10 drivers were collected for analysis in this study. The new
parameters used in the experiment are the car door opening and closing
data about the users’ activity. The driving style was predicted from the user’s
environment and activity data collected before driving. The prediction was
13
tested against the actual driving style, calculated from objective driving data.
The prediction has shown encouraging results, with precision values ranging
14
CHAPTER 3
SYSTEM ANALYSIS
utilized in order to extract the face and eyes in the given input. Eye joints
are used to find the state of eye. Based on joints Drowsiness is defined.
eye states tracking. Images are captured using a camera and used for
3.1.1. DISADVANTAGES
15
3.2 PROPOSED SYSTEM
In the proposed system, eye state is detected by cascade object detection
models. Once train the model, model will be stored for model deployment
package.
16
3.2.1 ADVANTAGES
17
CHAPTER 4
SOFTWARE REQUIREMENT
HARDWARE REQUIREMENTS:
• processor - Pentium – IV
• RAM - 4 GB (min)
• Hard Disk - 20 GB
SOFTWARE REQUIREMENTS:
18
CHAPTER 5
SYSTEM ANALYSIS
supports reasoning about the structures and behaviours of the system. System
them.
The input is given as a video, which is then converted into frames. These
frames are now forwarded for face detection. If face is not detected, the loop
continues. If face is detected, the region of interest is detected, from which eye
19
Figure 5.1 : System Architecture
to the system, various processing carried out on this data, and the output
2. The data flow diagram (DFD) is one of the most important modeling
20
the system process, the data used by the process, an external entity that
interacts with the system and the information flows in the system.
3. DFD shows how the information moves through the system and how it
depicts information flow and the transformations that are applied as data
DFD DIAGRAM
Level 0
21
Level 1
Eye State
detect
system in terms of actors, their goals (represented as use cases), and any
dependencies between those use cases. The main purpose of a use case
diagram is to show what system functions are performed for which actor.
22
Figure 5.4 : Use Case Diagram
23
5.3.1 Class Diagram
operations (or methods), and the relationships among the classes. It explains
interaction diagram that shows how processes operate with one another and in
are sometimes called event diagrams, event scenarios, and timing diagrams.
24
Figure 5.6: Sequence Diagram
25
CHAPTER 6
MODULE DESCRIPTION
6.1 LIST OF MODULES
1. Dataset collection.
The dataset used for this model is created using multiple photos of the
human eye with open and close states. To create the dataset, a script that
captures eyes from a camera and stores them in our local disk is written. They
are separated into their respective labels ‘Open’ or ‘Closed’. This process is
which were not necessary for building the model. In this case, this process is
26
done by using a cropping tool, in which the eyes alone are cropped and as the
next process, both the left eye and right eye are cropped independently.
27
The data comprises around 7000 images of people’s eyes under different
the pixel value ranges are taken into control using : img = img/255. After
training the model on our dataset, we have attached the final weights and
The input for our project is taken using the webcam. Webcam is
accessed, which records as videos and converts it into frames. The camera
actually runs in an infinite loop. Opencv generally has 24 frames per second
dependent on the camera the user uses. If the camera has the number of
frames per second higher than 24, then opencv will use 24fps. If the number
of frames is less than 24, then the camera’s frames per second is used.
parameter (0) indicates that the programmer must use the in-built or integrated
camera fitted in the system (if any). If the system must use the secondary or
28
VideoCapture method starts recording, read() method is used to convert it into
frames. These frames are stored as images and sent to the next process as
input.
This module receives the image as input. The objective of this module is
to detect face in the given image. If the face is not detected, this module skips
the further steps and processes the next frame or image. Before processing the
image for face detection, the image has to be converted into grayscale. Image
each frame is converted into grayscale before detecting the face. This
This method requires two parameters, the image or frame which has to be
converted and an integer value which specifies the color scheme to which the
stored for further processing. The next part of the process is the most
29
of determining whether the required property is present in the image and also
to focus only on that property. In this case, the function of the classifier is to
detect the face and focus the face alone for the further process.
ROI represents the region of interest, which means the part of the image
whose properties are used for classification. HAAR cascade classifier is used
for classification of images into their states, i.e., as opened or closed. This
state is used for initiating alarm systems and water spray. A cascade XML file
is used for classification. This xml file contains the required properties to be
which is present inside the cascade folder of the project is used for this
purpose.
this function for setting a classifier for face. This function accepts a
detect the region of interest(in this case, face). The classifier which has been
30
an array of detections with x,y coordinates, height and the width of the
The boundary box represents the part of the image which satisfies the
properties mentioned in the cascade xml file used for setting the classifier. At
this phase of the project, each frame which has faces in it are filtered and
The next phase of this project is to classify the left and right eye from
the faces that are classified in the previous phase. Similar process that is used
for the classification of face from a frame is used in this phase to classify the
eyes from the face. The same procedure to detect faces is used to detect eyes.
Separate classifier xml files are used for left and right eyes. Separate
classifiers are set for left eye and right eye namely, Leye and Reye.
classifier for the left eye. Similarly, a variable Reye is declared and assigned
31
cascade xml file, haarcascade_righteye_2split.xml as argument. This Reye
Then with this classifier, we detect the region of interest(in this case,
face). The classifier which has been set into a variable lefteye and righteye.
the grayscale image as argument and returns an array of detections with x,y
coordinates, height and the width of the boundary box of the object. The
boundary box represents the part of the image which satisfies the properties
mentioned in the cascade xml file used for setting the classifier. At this phase
32
of the project, the classifier function filters the left eye and right eye and saves
This project uses HAAR cascade classifier to classify whether the eyes
in the given image are open or closed. A Video is processed into several steps
including, converting into frames, convert them into grayscale, detect the
region of interest, detect left eye and right eye respectively etc., then finally
the frame with boundary boxes for the eyes are received as input for this
phase. In the first phase the machine has been trained using images which
undergoes resizing into 24*24 pixels. Thus, the image which is given as input
for classification will also be resized into same 24*24 pixels in order to
In real time, the images that are taken as input from a vehicle may
33
prediction begins. If the output of the prediction is 0, then the eye is open. If
the output of the prediction is 1, then the eye is closed. These open and closed
states are taken into action by accounting both the right and left eyes.
Based on the states of the eyes, the alarm system and water spray are
triggered. As a product, the camera, alarm system and water spray will be
integrated with raspberry pi, which acts as a mini computer. Due to its wired
connection, the reaction time will be fast. The cut-off time has been set to 5
seconds, which means, if the driver closes his/her eyes for more than 5
seconds, then the alarm system and water spray are initiated. This value is
34
CHAPTER 7
7.1 CONCLUSION
complexity and high accuracy. According to the report 2020 based on the road
Territories.
accuracy along with low operation time. For further research, we will create
our own drowsiness recognition dataset and validate the proposed method. In
35
7.2 FUTURE ENHANCEMENT
automatically in day-to-day lifestyle. This would help to learn new trends like
few people yarn while they feel sleepy, few people even sleep as eyes
Trends like this will change from person to person and cannot be trained in
machines. Thus, implementing deep learning would help the system to learns
these trends and make this project more efficient and accurate.
Integrating our project with this kind of ongoing technologies would make it
easier to safely park the vehicle roadside and make the driver rest for few
his/her drivers work, how often he/she sleeps, risk level etc., through which
36
the can determine the driver’s work and take necessary actions. A monitoring
system will make the drivers to be active at it risks their life as well as their
job.
37
APPENDIX:1
SAMPLE CODE
driver_drowsiness.py:
import cv2
import os
import tensorflow as tf
import numpy as np
import time
path = os.getcwd()
mixer.init()
sound = mixer.Sound('audio.mp3')
## cascating files
face = cv2.CascadeClassifier('cascade\haarcascade_frontalface_alt.xml')
leye = cv2.CascadeClassifier('cascade\haarcascade_lefteye_2splits.xml')
reye = cv2.CascadeClassifier('cascade\haarcascade_righteye_2splits.xml')
38
## number of class
lbl=['Close','Open']
## load model
model = tf.keras.models.load_model('models/drowsiness_model.h5')
cap = cv2.VideoCapture(0)
font = cv2.FONT_HERSHEY_COMPLEX_SMALL
count=0
score=0
thicc=2
rpred=[99]
lpred=[99]
while(True):
height,width = frame.shape[:2]
39
faces =
face.detectMultiScale(gray,minNeighbors=5,scaleFactor=1.1,minSize=(25,25)
)
left_eye = leye.detectMultiScale(gray)
right_eye = reye.detectMultiScale(gray)
r_eye=frame[y:y+h,x:x+w]
count=count+1
r_eye = cv2.cvtColor(r_eye,cv2.COLOR_BGR2GRAY)
r_eye = cv2.resize(r_eye,(24,24))
r_eye= r_eye/255
r_eye= r_eye.reshape(24,24,-1)
r_eye = np.expand_dims(r_eye,axis=0)
rpred_ = model.predict(r_eye)
lpred = np.argmax(rpred_,axis=1)
40
#print(lpred)
if(rpred[0]==1):
lbl='Open'
if(rpred[0]==0):
lbl='Closed'
break
l_eye=frame[y:y+h,x:x+w]
count=count+1
l_eye = cv2.cvtColor(l_eye,cv2.COLOR_BGR2GRAY)
l_eye = cv2.resize(l_eye,(24,24))
l_eye= l_eye/255
l_eye=l_eye.reshape(24,24,-1)
l_eye = np.expand_dims(l_eye,axis=0)
lpred_ = model.predict(l_eye)
lpred = np.argmax(lpred_,axis=1)
if(lpred[0]==1):
lbl='Open'
41
if(lpred[0]==0):
lbl='Closed'
break
if(rpred[0]==0 or lpred[0]==0):
print('sleep')
# send()
score=score+1
cv2.putText(frame,"Closed",(10,height-20), font,
1,(255,255,255),1,cv2.LINE_AA)
if(rpred[0]==1 or lpred[0]==1):
#score=score-3
score=0
cv2.putText(frame,"Open",(10,height-20), font,
1,(255,255,255),1,cv2.LINE_AA)
print('No sleep')
#ser.write(b'0')
time.sleep(2)
print('-------------')
#print('0 Send')
42
print('-------------')
if(score<0):
score=0
cv2.putText(frame,'Score:'+str(score),(100,height-20), font,
1,(255,255,255),1,cv2.LINE_AA)
if(score>6):
cv2.imwrite(os.path.join(path,'image.jpg'),frame)
cv2.imwrite('image.jpg', frame)
#report_send_mail('image.jpg')
#ser.write(b'1')
time.sleep(2)
print('-------------')
#print('1 Send')
print('-------------')
try:
sound.play()
led_on_off()
43
except:
pass
if(thicc<16):
thicc= thicc+2
else:
thicc=thicc-2
if(thicc<2):
thicc=2
cv2.rectangle(frame,(0,0),(width,height),(0,0,255),thicc)
# to plot on screen
cv2.imshow('frame',frame)
break
## release image
cap.release()
cv2.destroyAllWindows()
44
Send_data.py:
import serial
import time
def led_on_off():
time.sleep(0.1)
ser.write(b'H')
Main.ino:
#include <Servo.h>
int angle=0;
int servoPin = 9;
Servo servo;
void setup() {
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
servo.attach(servoPin);
}
45
void loop() {
if(Serial.available() > 0){
String msg=Serial.readString();
// while(true){
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the
voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the
voltage LOW
delay(1000);
for(angle = 0; angle < 180; angle++) {
servo.write(angle);
delay(15);
}
for(angle = 180; angle > 0; angle--) {
servo.write(angle);
delay(15);
}
}
}
46
APPENDIX:2
SCREENSHOTS
47
Figure A.2.2 : Close State
48
Figure A.2.3 : Water Spray
49
Figure A.2.4 : Arduino kit
50
REFERENCES:
51
6. J. Kim et al., “Impact of the face angle to traveling trajectory during the
riding standing-type personal mobility device,” in Proc. Web Conf.
(MATEC), vol. 161, Apr. 2018, Art. no. 003001.
7. Lashkov, A. Smirnov, A. Kashevnik, and V. Parfenov, “Ontologybased
approach and implementation of ADAS system for mobile device use
while driving,” in Proc. 6th Int. Conf. Knowl. Eng. Semantic Web, Sep.
2015, pp. 117–131.
8. L. Moreira-Matias and H. Farah, “On developing a driver identification
methodology using in-vehicle data recorders,” IEEE Trans. Intell.
Transp. Syst., vol. 18, no. 9, pp. 2387–2396, Sep. 2017.
9. S. Sivaraman and M. M. Trivedi, “Looking at vehicles on the road: A
survey of vision-based vehicle detection, tracking, and behavior
analysis,” IEEE Trans. Intell. Transp. Syst., vol. 14, no. 4, pp. 1773–
1795, Dec. 2013.
10. A. Smirnov, A. Kashevnik, I. Lashkov, N. Hashimoto, and A. Boyali,
“Smartphone-based two-wheeled self-balancing vehicles rider assistant,”
in Proc. 17th IEEE Conf. Open Innov. Assoc. (FRUCT), Apr. 2015, pp.
201–209.
52