"Real Time Driver Behavior Detection": A Project Report On
"Real Time Driver Behavior Detection": A Project Report On
on
“Real Time Driver Behavior Detection”
Submitted for Partial Fulfillment of award of
Bachelor of Technology
in
Computer Science and Engineering
by
Mayank Jain (1806410903)
Madhav Jaiswal (1706410067)
Md. Arif Khan (1706410071)
Sumit Kahar (1706410107)
Yash Kumar Singh (1706410124)
The work presented in my dissertation titled “Real Time Driver Behavior Detection”
submitted to the Department of Computer Science Engineering, Hindustan College
of Science and Technology, Mathura, for the award of Bachelor of Technology, is
my original work. I have neither plagiarized nor submitted the same work for award
of any other degree. In case this undertaking is found incorrect, I accept that my
degree may be withdrawn.
July, 2021
HCST, Farah, Mathura
CERTIFICATE
Certified that the work contained in the dissertation entitled “Real Time Driver
Behavior Detection”, by
Mayank Jain (1806410903)
Madhav Jaiswal (1706410067)
Md. Arif Khan (1706410071)
Sumit Kahar (1706410107)
Yash Kumar Singh (1706410124)
for the award of Bachelor of Technology from DR. A.P.J. ABDUL KALAM
TECHNICAL UNIVERSITY has been carried out under my supervision and this
work has not been submitted elsewhere for a degree.
(Sachin Shrivastava)
Finally, We would like to express my sincere and deep gratitude to Mr. Munish
Khanna (HOD) and Kapil Shrivastava (Project Coordinator) for their support and
guidance.
Date:
INDEX
1. Introduction of project....................................................................... 6
7. Input Screen......................................................................................20-28
9. Testing .............................................................................................. 32
Drowsiness detection is a safety technology that can prevent accidents that are caused by drivers
who fell asleep while driving. The objective of this project is to build a drowsiness detection
system that will detect that a person's eyes are closed for a few seconds. Driver drowsiness
detection is a car safety technology which prevents accidents when the driver is getting drowsy.
Various studies have suggested that around 20% of all road accidents are fatigue-related, up to
50% on certain roads. Driver fatigue is a significant factor in a large number of vehicle accidents.
Recent statistics estimate that annually 1,200 deaths and 76,000 injuries can be attributed to
fatigue related crashes.
The development of technologies for detecting or preventing drowsiness at the wheel is a major
challenge in the field of accident avoidance systems. Because of the hazard that drowsiness
presents on the road, methods need to be developed for counteracting its affects. Driver
inattention might be the result of a lack of alertness when driving due to driver drowsiness and
distraction.
Driver distraction occurs when an object or event draws a person’s attention away from the
driving task. Unlike driver distraction, driver drowsiness involves no triggering event but,
instead, is characterized by a progressive withdrawal of attention from the road and traffic
demands. Both driver drowsiness and distraction, however, might have the same effects, i.e.,
decreased driving performance, longer reaction time, and an increased risk of crash
involvement.
Based on Acquisition of video from the camera that is in front of driver perform real-time
processing of an incoming video stream in order to infer the driver’s level of fatigue if the
drowsiness is Estimated then it will give the alert by sensing the eyes.
2.) Problem Definition
Today drowsy driving is a serious problem that leads to thousands of accidents each year. Motor
vehicle collisions lead to significant death and disability as well as significant financial cost to
both security and individual due to the driver impairments. Drowsiness is one of the factors for
collisions. In India, no monitoring device is used to measure the drowsiness of driver. Some
kind of systems like driver fatigue monitor, real time vision based on driver state monitoring
system, seeing driver assisting system, user center drowsiness driver detection and working
system are implemented in foreign countries. All the systems focus either changes in eye
movement, physiological measures or driver performance measure. Due to illumination
variation, the traditional systems have some defects.
As the name implies, a feasibility analysis is used to determine the viability of an idea, such as
ensuring a project is legally and technically feasible as well as economically justifiable. In
simple terms, a feasibility study involves taking a judgment call on whether a project is doable.
The two criteria to judge feasibility are cost required and value to be delivered. A well-designed
study should offer a historical background of the business or project, a description of the product
or service, accounting statements, details of operations and management, marketing research
and policies, financial data, legal requirements and tax obligations. Generally, such studies
precede technical development and project implementation.
A feasibility study evaluates the project's potential for success; therefore, perceived objectivity is
an important factor in the credibility of the study for potential investors and lending institutions.
Technical Feasibility
Economic Feasibility
Economic Feasibility helps organizations assess the project's viability, cost, and benefits associated
with the projects before financial resources are allocated. It also serves as an independent project
assessment, and enhances project credibility, as a result. It helps decision-makers determine the
positive economic benefits to the organization that the proposed system will provide, and helps
quantify them. This assessment typically involves a cost/ benefits analysis of the project.
Operational Feasibility
Operational Feasibility involves undertaking a study to analyze and determine whether your
business needs can be fulfilled by using the proposed solution. It also measures how well the
proposed system solves problems and takes advantage of the opportunities identified during
scope definition. Operational feasibility studies also analyze how the project plan satisfies the
requirements identified in the requirements analysis phase of system development. To ensure
success, desired operational outcomes must inform and guide design and development. These
include such design-dependent parameters such as reliability, maintainability, supportability,
usability, disposability, sustainability, affordability, and others.
Scheduling Feasibility
Scheduling Feasibility is the most important for project success. A project will fail if not
completed on time. In scheduling feasibility, we estimate how much time the system will take to
complete.
Legal Feasibility
Legal Feasibility investigates if the proposed system conflicts with legal requirements like data
protection acts or social media laws.
4.) Scope of the Proposed System
The main idea behind this project is to develop a nonintrusive system which can detect fatigue of
any human and can issue a timely warning. Drivers who do not take regular breaks when driving
long distances run a high risk of becoming drowsy a state which they often fail to recognize early
enough. According to the expert’s studies show that around one quarter of all serious motorway
accidents are attributable to sleepy drivers in need of a rest, meaning that drowsiness causes more
road accidents than drink-driving. This system will monitor the driver eyes using a camera and
by developing an algorithm we can detect symptoms of driver fatigue early enough to avoid the
person from sleeping. So, this project will be helpful in detecting driver fatigue in advance and
will give warning output in form of alarm and popups.
5.) System Requirements
Computer software needs certain hardware components or other software resources to be present
on a computer. These prerequisites are known as system requirements.
The section of hardware requirements is an important task related to the software development
insufficient random access memory may affect adversely on the speed and efficiency of the
entire system. The process should be powerful to handle the entire operations. The hard disk
should have sufficient capacity to store the file and application.
Network Connectivity
A major element in building a system is the section of compatible software since the software in
the market is experiencing in geometric progression. Selected software should be acceptable by
the firm and one user as well as it should be feasible for the system. This document gives a
detailed description of the software requirement specification. The study of requirement
specification is focused specially on the functioning of the system. It allows the developer or
analyst to understand the system, function to be carried out the performance level to be obtained
and corresponding interfaces to be established.
GUI Tkinter: Tkinter commonly comes bundled with Python, using Tk and is Python's
standard GUI framework. It is famous for its simplicity and graphical user interface. It is open-
source and available under the Python License.
CNN: A Convolutional Neural Network is a special type of deep neural network which
performs extremely well for image classification purposes. A CNN basically consists of an
input layer, an output layer and a hidden layer which can have multiple numbers of layers. A
convolution operation is performed on these layers using a filter that performs 2D matrix
multiplication on the layer and filter.
OpenCV: OpenCV is a huge open-source library for computer vision, machine learning, and
image processing. OpenCV supports a wide variety of programming languages like Python,
C++, Java, etc. It can process images and videos to identify objects, faces, or even the
handwriting of a human. When it is integrated with various libraries, such as Numpy which is a
highly optimized library for numerical operations, then the number of weapons increases in
your Arsenal i.e whatever operations one can do in Numpy can be combined with OpenCV.
Tensor Flow: An end-to-end open source python platform for everyone. Tensor Flow is a
python library for fast numerical computing created and released by Google. It is a foundation
library that can be used to create Deep Learning models directly or by using wrapper libraries
that simplify the process built on top of Tensor Flow.
Keras: Keras is a minimalist python library for deep learning that can run on top of Theano
or Tensor Flow. It was developed to make implementing deep learning models as fast and
easy as possible for research and development.
Pygame: Pygame is a python wrapper module for the SDL (Simple Direct Media Layer)
multimedia library. It contains python functions and classes that will allow you to use SDL’s
support for playing cdroms, audio and video output, and keyboard, mouse and joystick
input.
6.) System Logical Design
Systems design is the process of defining the architecture, modules, interfaces, and data for a
system to satisfy specified requirements. Systems design could be seen as the application of
systems theory to product development.
Data flow diagram graphically representing the functions, or processes, which capture,
manipulate, store, and distribute data between a system and its environment and
between components of a system. The visual representation makes it a good
communication tool between user and system designer. Structures of DFD allow
starting from a broad overview and expand it to a hierarchy of detailed diagrams.
Data flow diagrams (DFDs) reveal relationships among and between the various
components in a program or system. DFDs are an important technique for modeling a
system’s high-level detail by showing how input data is transformed to output results
through a sequence of functional transformations. DFDs consist of four major
components: entities, processes, data stores, and data flows. The symbols used to
depict how these components interact in a system are simple and easy to understand;
however, there are several DFD models to work from, each having its own semiology.
DFD (level-0)
DFD (level-1)
DFD (level-2)
DFD (level-0)
DFD (level-1)
Entity Relationship Diagrams are a major data modeling tool and will help organize the data in
your project into entities and define the relationships between the entities. This process has
proved to enable the analyst to produce a good database structure so that the data can be stored
and retrieved in a most efficient manner. By using a graphical format it may help
communication about the design between the designer and the user and the designer and the
people who will implement it.
Fig.4. ER Diagram
6.3.) Use Case Diagram
8.1.)
8.2.)
8.3.)
9.) Testing
The different types of methodologies have been developed to find out drowsiness.
This technique is an intrusive method wherein electrodes are used to obtain pulse rate, heart rate
and brain activity information. ECG is used to calculate the variations in heart rate and detect
different conditions for drowsiness. The correlation between different signals such as ecg
(electrocardiogram), EEG (electroencephalogram), and EMG (electromyogram) are made and
then the output is generated whether the person is drowsy or not.
In this technique eye blinking frequency, head pose, etc. of a person is monitored through a camera
and the person is alerted if any of these drowsiness symptoms are detected.
9.3) Technology
The different types of technologies have been used to find out drowsiness.
9.3.1) Python
Python is an open source, high-level programming language. Python is a powerful language that
we can use to create games, write GUIs, and develop web applications. Python is a high-level,
interpreted, interactive and object-oriented scripting language. Python is designed to be highly
readable. It uses English keywords frequently where as other languages use punctuation, and it
has fewer syntactical constructions than other languages.
Python is an easy to learn, powerful programming language. It has efficient high- level data
structures and a simple but effective approach to object-oriented programming. Python’s elegant
syntax and dynamic typing, together with its interpreted nature, make it an ideal language for
scripting and rapid application development in many areas on most platforms. The Python
interpreter and the extensive standard library are freely available in source or binary form for all
major platforms.
Python is a great language for the beginner-level programmers and supports the development of a
wide range of applications from simple text processing to www browsers to games.
Features of Python:-
Easy to learn: Python has few keywords, simple structure, and a clearly defined syntax.
This allows us to pick up the language quickly.
Easy to read: Python code is more clearly defined and visible to the eyes.
A broad standard library: Python's bulk of the library is very portable and cross platform
compatible on UNIX, Windows, and Macintosh.
Interactive Mode: Python has support for an interactive mode which allows interactive
testing and debugging.
Portable: Python can run on a wide variety of hardware platforms and has the same interface
on all platforms.
GUI Programming: Python supports GUI applications that can be created and ported to
many system calls, libraries and windows systems, such as Windows MFC, Macintosh, and
the X Window system of Unix.
Scalable: Python provides a better structure and support for large programs than shell
scripting.
Machine learning is the kind of programming which gives computers the capability
to automatically learn from data without being explicitly programmed. This means
in other words that these programs change their behavior by learning from data.
Python is clearly one of the best languages for machine learning.
Python does contain special libraries for machine learning namely scipy, pandas and
numpy which great for linear algebra and getting to know kernel methods of
machine learning. The language is great to use when working with machine learning
algorithms and has easy syntax relatively.
10.) Coding
def hel():
help(cv2)
def Contri():
tkinter.messagebox.showinfo("Contributors","\n1 Made By Mayank,Madhav,Yash,Arif,Sumit \n")
def anotherWin():
tkinter.messagebox.showinfo("About",'Driver Cam version v1.0\n Made Using\n-OpenCV\n-Numpy\n-
Tkinter\n In Python 3')
menu = Menu(root)
root.config(menu=menu)
subm2 = Menu(menu)
menu.add_cascade(label="About",menu=subm2)
subm2.add_command(label="Driver Cam",command=anotherWin)
subm2.add_command(label="Contributors",command=Contri)
def exitt():
exit()
def web():
capture =cv2.VideoCapture(0)
while True:
ret,frame=capture.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF ==ord('q'):
break
capture.release()
cv2.destroyAllWindows()
def webrec():
capture =cv2.VideoCapture(0)
fourcc=cv2.VideoWriter_fourcc(*'XVID')
op=cv2.VideoWriter('Sample1.avi',fourcc,11.0,(640,480))
while True:
ret,frame=capture.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow('frame',frame)
op.write(frame)
if cv2.waitKey(1) & 0xFF ==ord('q'):
break
op.release()
capture.release()
cv2.destroyAllWindows()
def webdet():
capture =cv2.VideoCapture(0)
face_cascade = cv2.CascadeClassifier('lbpcascade_frontalface.xml')
eye_glass = cv2.CascadeClassifier('haarcascade_eye_tree_eyeglasses.xml')
while True:
ret, frame = capture.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray)
eye_g = eye_glass.detectMultiScale(roi_gray)
for (ex,ey,ew,eh) in eye_g:
cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(0,255,0),2)
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xff == ord('q'):
break
capture.release()
cv2.destroyAllWindows()
def webdetRec():
capture =cv2.VideoCapture(0)
face_cascade = cv2.CascadeClassifier('lbpcascade_frontalface.xml')
eye_glass = cv2.CascadeClassifier('haarcascade_eye_tree_eyeglasses.xml')
fourcc=cv2.VideoWriter_fourcc(*'XVID')
op=cv2.VideoWriter('Sample2.avi',fourcc,9.0,(640,480))
while True:
ret, frame = capture.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray)
eye_g = eye_glass.detectMultiScale(roi_gray)
for (ex,ey,ew,eh) in eye_g:
cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(0,255,0),2)
op.write(frame)
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xff == ord('q'):
break
op.release()
capture.release()
cv2.destroyAllWindows()
def alert():
mixer.init()
alert=mixer.Sound('beep-07.wav')
alert.play()
time.sleep(0.1)
alert.play()
def blink():
capture =cv2.VideoCapture(0)
face_cascade = cv2.CascadeClassifier('lbpcascade_frontalface.xml')
eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')
blink_cascade = cv2.CascadeClassifier('CustomBlinkCascade.xml')
while True:
ret, frame = capture.read()
gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray)
eyes = eye_cascade.detectMultiScale(roi_gray)
for(ex,ey,ew,eh) in eyes:
cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(0,255,0),2)
blink = blink_cascade.detectMultiScale(roi_gray)
for(eyx,eyy,eyw,eyh) in blink:
cv2.rectangle(roi_color,(eyx,eyy),(eyx+eyw,eyy+eyh),(255,255,0),2)
alert()
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF ==ord('q'):
break
capture.release()
cv2.destroyAllWindows()
but1=Button(frame,padx=5,pady=5,width=39,bg='white',fg='black',relief=GROOVE,command=web,text
='Open Cam',font=('helvetica 15 bold'))
but1.place(x=5,y=104)
but2=Button(frame,padx=5,pady=5,width=39,bg='white',fg='black',relief=GROOVE,command=webrec,t
ext='Open Cam & Record',font=('helvetica 15 bold'))
but2.place(x=5,y=176)
but3=Button(frame,padx=5,pady=5,width=39,bg='white',fg='black',relief=GROOVE,command=webdet,t
ext='Open Cam & Detect',font=('helvetica 15 bold'))
but3.place(x=5,y=250)
but4=Button(frame,padx=5,pady=5,width=39,bg='white',fg='black',relief=GROOVE,command=webdetR
ec,text='Detect & Record',font=('helvetica 15 bold'))
but4.place(x=5,y=322)
but5=Button(frame,padx=5,pady=5,width=39,bg='white',fg='black',relief=GROOVE,command=blink,tex
t='Detect Eye Blink & Record With Sound',font=('helvetica 15 bold'))
but5.place(x=5,y=400)
but5=Button(frame,padx=5,pady=5,width=5,bg='white',fg='black',relief=GROOVE,text='EXIT',comman
d=exitt,font=('helvetica 15 bold'))
but5.place(x=210,y=478)
root.mainloop()
11.) Conclusion
The real time system has been successfully created to detect the face and hence the eyes and
mouth of the driver to check whether he is blinking or yawning to acquire information about his
level of alertness. The system has been tried and tested in different lighting conditions and with
different people with varied facial characteristics. It has been experimentally found that absolute
accuracy is achieved when the lighting conditions are bright and favorable. The biggest drawback
experienced till now is the presence of beard or sunglasses or spectacles on the driver’s face. This
interferes with the detection of eyes and mouth and may lead to false triggering. This system is
real time and checks the state of the driver all through the journey.
12.) Limitations
Use of spectacles
In case the user uses spectacle then it is difficult to detect the state of the eye. As it hugely
depends on light hence reflection of spectacles may give the output for a closed eye as
opened eye. Hence for this purpose the closeness of eye to the camera is required to avoid
light.
If multiple face arises in the window then the camera may detect more number of
faces undesired output may appear. Because of different condition of different faces.
So, we need to make sure that only the driver face come within the range of the
camera. Also, the speed of detection reduces because of operation on multiple faces.
The system has been tried and tested in different lighting conditions and with different
people with varied facial characteristics. It has been experimentally found that absolute
accuracy is achieved when the lighting conditions are bright and favourable.
13.) Future Scope
The future scope for this project includes increasing the speed of operation
of the system and hence increases the accuracy rate. Further, this concept
can be extended to provide an inexpensive solution for commercial vehicles.
The difficulties faced due to bad lighting that may occur while driving during night time
is a potent problem that needs to be taken care of.
Bearded men and people wearing spectacles too should be able to use this system
accurately. This is drawback that needs to be mended as future scope.
Another area for further work would include involving the dynamics and working
of the vehicle when the buzzer is set off. This, if used with extreme discretion, can
help further reduce road accidents. The speed of the vehicle can be reduced or a
remote terminal can be warned about fatigue detected in the driver.
14.) Bibliography
Real-Time Driver Drowsiness Detection System Using Eye Aspect Ratio and Eye Closure
Ratio. (https://ieeexplore.ieee.org/document/9251035)
https://realpython.com/face-recognition-with-python/
https://docs.opencv.org /3.4/d7/d8b/tutorial_py_face_detection.html
https://www.learnopencv.com/training-better-haar-lbp-cascade-eye-detector- opencv/
https://docs.opencv.org/master/d9/df8/tutorial_root.ht
https://docs.opencv.org/master/d9/df8/tutorial_root.ht
https://docs.opencv.org/master/d9/df8/tutorial_root.ht