Final Report (1) (AutoRecovered)

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 58

A PROJECT REPORT

ON

“Driver Drowsiness Detection”


Submitted in partial fulfilment of the
requirements for the degree of

BACHELOR OF COMPUTER APPLICATION


Prescribed By

Bengaluru City University

By

Jeevitha N S (R2018242)
Sinchana H R(R2018306)

VI Semester

KLE SOCIETY’s
S. NIJALINGAPPA COLLEGE
RAJAJINAGAR, BANGALORE-560010

Under the guidance of:

(Prof. Bharathi N)
Academic Year
2022-2023
BENGALURU CITY UNIVERSITY
KLE SOCIETY’s S. NIJALINGAPPA
COLLEGE BACHELOR OF COMPUTER
APPLICATION RAJAJINAGAR, BANGALORE-560010

CERTIFICATE
This is to certify that project work entitled “Driver Drowsiness
Detection” has been successfully carried out by Jeevitha N S
(R2018242) , Sinchana H R(R2018306) in partial fulfilment for the
award of VI semester BCA during the academic year 2022-23.

Signature of the Guide Signature of the Co-Ordinator


( Prof.Bharathi N) (Prof. Roopa H R)

Name of the Examiners: Signature with date


1.

2.
ACKNOWLEDGEMENT

I consider it is my privilege to express my sincere gratitude and respect to all those who
guided us in the completion of this project.

I thank my beloved Principal Dr.Arun Kumar Sonappanavar, for providing us with a


congenial environment to carry out our project.

I consider it is a privilege to place my deepest sense of gratitude and sincere thanks to our
beloved Co-Ordinator Prof. Roopa H R, for her sincere co-operation, guidance and
supervision during the course of this project work undertaken by us.

I’m thankful and wish to express my gratitude to my project guide Prof. Bharathi N, for her
kind co-operation and for providing valuable suggestions and constant encouragement for this
project.

I express my sincere thanks and gratitude to the guidance, timely advices, support, sincere co-
operation, suggestions, ideas and also constructive criticisms provided by all the teaching
staff of the Computer Science Department, KLE Society’s Nijalingappa College.

Jeevitha N S (R2018242)
Sinchana H R(R2018306)
ABSTRACT

Data science project as the data is collected in real-time. The data so collected is the eye
motion of the driver, and facial movements. These are then fed as information into the program
that is written using python.

This system already exists in multiple high-end cars and vehicles. Since the statistics majorly
reflect that most of our Indian cars do not feature this particular functionality, it gave me the
motive to develop such a system. We often see newspaper articles where accidents occurred as
drivers felt drowsy and hit the vehicle in front of them. This could have been avoided if their
vehicle were fitted with a technological feature called “The drowsiness Detection System” which
off-late is seen in higher-end vehicles. We have used Open Libraries such as (Open CV, Dlib,
Flask,Pyhton IDLE) is a open-source distribution of the python programming language for data
science that aims to simplify package management and deployment.
Contents

1. Introduction
2. System Analysis
3. Software Requirement Specification
3.1 Existing System
3.2 Proposed System
3.3 Requirement Specification
4. System Definition
a) System Design
b) System Architecture
5. Detailed Design
a. Flowchart
b. Data Flow Diagram
6. Implementation
7. Testing and Results
8. Screenshots
9. Conclusion
10. Future Enhancement
11. Bibliography
Driver Drowsiness Detection

Introduction

3 KLESNC /BCA/VI Sem/2022-2023 Page 1


Driver Drowsiness Detection

INTRODUCTION

Driver drowsiness detection system is a Data Science project that helps in identifying the
drowsiness of drivers at an early stage and avoids accidents and unforeseen circumstances.

We regard this as a data science project as the data is collected in real-time. The data so
collected is the eye motion of the driver, his body posture, and facial movements. These are then
fed as information into the program that is written using python. Open libraries such as Open CV
(Open Computer Vision), Dlib (For facial recognition), matplotlib are used to facilitate the
detection.

It is a car safety technology which helps prevent accidents caused by the driver getting
drowsy. Various studies have suggested that around 20% of all road accidents are fatigue-related,
up to 50% on certain roads.

This system already exists in multiple high-end cars and vehicles. Since the statistics
majorly reflect that most of our Indian cars do not feature this particular functionality, it gave me
the motive to develop such a system.

KLESNC /BCA/VI Sem/2022-2023 Page 2


Driver Drowsiness Detection

System Analysis

KLESNC /BCA/VI Sem/2022-2023 Page 3


Driver Drowsiness Detection

SYSTEM ANAYLSIS

System analysis is the most essential part of the development of any project. It is the way
of studying a system with an eye on solving its problems using computers. The system analyst has
to understand the functioning and concept of the system in detail before designing the appropriate
computer-based system. He has to carry out a customary approach that includes the following
basic steps:

 Requirement specification
 Preliminary investigation
 Feasibility study
 Detailed investigation
 Design and coding
 Testing
 Implementation

Data Science is the new trend and is the new technology which is in word of mouth in
everyday talks. Data Science is the Science of Analysing and getting information about what the
data talks about. To express in simple terms, it is the art of explaining what the data is talking
about. It makes human life easy by making us understand the insights of the data repository or
databases.

We often see newspaper articles where accidents occurred as drivers felt drowsy and hit the
vehicle in front of them. This could have been avoided if their vehicle were fitted with a
technological feature called “The drowsiness Detection System” which off-late is seen in higher-
end vehicles. These articles gave me the motive to develop a solution that could detect facial
movements and alert the driver as and when he felt sleepy.

KLESNC /BCA/VI Sem/2022-2023 Page 4


Driver Drowsiness Detection

It is just a small conceptual version that I would be developing and is at its pilot run as a
simulation using my computer. We have used Open Libraries such as (Open CV, Dlib, Python
IDLE. Python IDLE (Integrated Development and Learning Environment) is an interactive
development environment that comes bundled with the standard Python distribution. It serves as a
beginner-friendly and lightweight environment for writing, testing, and executing Python code.

KLESNC /BCA/VI Sem/2022-2023 Page 5


Driver Drowsiness Detection

Software
Requirement
Specification

KLESNC /BCA/VI Sem/2022-2023 Page 6


Driver Drowsiness Detection

SOFTWARE REQUIREMENT SPECIFICATION

Software Requirement Specification (SRS) is a fundamental document, which


forms the foundation of the software development process. SRS not only lists the
requirements of a system but also has a description of its major features.
A system requirement is one of the main steps involved in the development
process. It follows after a resource analysis phase that is the task to determine what a
particular software product does. The focus in this stage is one of the users of the
system and not the system solutions.
The result of the requirement specification document States the intention of
the software, properties and constraints of the desired system. SRS constitutes the
agreement between clients and developers regarding the contents of the software
product that is going to be developed. SRS should accurately and completely
represent the system requirements as it makes a huge contribution to the overall
project plan.

3.1 Existing System


There is no drowsiness detection system in most of our Indian vehicles. The
new Mahindra XUV700 is an exception for this as it features this technology in its
higher trim. Except for this vehicle, other vehicles in their higher versions get Lane
Assist systems and other such features. But most of the buyers tend to opt out of this
feature as the feature adds a big budget to the car's cost.

This is an attempt to develop a prototype for such a detection system for cars
that do not feature this technology.

KLESNC /BCA/VI Sem/2022-2023 Page 7


Driver Drowsiness Detection

3.2 Proposed System


Since this project is a pilot run, We would be implementing this as a
simulation on our laptop. This is an attempt to tell or inform the driver that he is
drowsy and he needs to be alert. It raises an alert when the facial movements
detected by the webcam of the computer generate a voice message to be alert. The
continues detection of eye- lid movement is being monitored using a threshold flag
variable which is responsible for activation of the system.

This system is developed using


 Python language.
 Open Libraries such as (Open CV, Dlib, Flask)
 Python IDLE

KLESNC /BCA/VI Sem/2022-2023 Page 8


Driver Drowsiness Detection

3.3 Requirement Specification

3.3.1 Hardware and Software requirements

Processor I3[RAM(8gb)]

Monitor[HardDisk-500gb]

Webcam

Python Python IDLE

Software

CMD Open CV Libraries

Python IDLe

KLESNC /BCA/VI Sem/2022-2023 Page 9


Driver Drowsiness Detection

3.3.2 About the technologies used

3.3.2.1 Python
Python has a simple syntax similar to the English language. Python has syntax
that allows developers to write programs with fewer lines than some other
programming languages. Python runs on an interpreter system, meaning that code
can be executed as soon as it is written. This means that prototyping can be very
quick. A Python module can be run directly — as above "python hello.py Bob" —
or it can be imported and used by some other module. When a Python file is run
directly, the special variable " name " is set to " main ".

3.3.2.2 Python IDLE

Python IDLE, short for Integrated Development and Learning Environment, is a user-
friendly and lightweight interactive development environment included with the
standard Python distribution. It serves as a helpful tool for both beginners and
experienced developers to write, test, and run Python code.
With its simple code editor, Python IDLE provides syntax highlighting, which aids in
writing and modifying Python scripts. The interactive shell is a standout feature,
allowing users to execute Python code line-by-line or in blocks. This feature is
particularly valuable for experimenting with code snippets and learning Python.

KLESNC /BCA/VI Sem/2022-2023 Page 10


Driver Drowsiness Detection

3.3.2.3 Flask Libraries

Flask, a popular Python web framework, offers a range of libraries and extensions
that enhance its functionality and streamline web application development. These
libraries provide various features, from form handling and database integration to
authentication and real-time communication. Let's explore some of the commonly
used Flask libraries:
One essential extension is Flask-WTF, which seamlessly integrates Flask with
WTForms. This combination simplifies for handling and validation, ensuring secure
and user-friendly data input in web applications.

3.3.2.4 OpenCV Libraries

OpenCV is a Computer Vision library with APIs that let you setup a pipeline
for your Computer Vision project. I/O Loading data from image files, videos,
capturing devices. Performing feature extraction. OpenCV contains a long list of
existing algorithms so you don't have to implement them yourself. Applying
machine learning algorithms for decision making, object recognition and detection.

KLESNC /BCA/VI Sem/2022-2023 Page 11


Driver Drowsiness Detection

System Definition

KLESNC /BCA/VI Sem/2022-2023 Page 12


Driver Drowsiness Detection

SYSTEM DESIGN
Software design is actually a multistep process that focuses on four distinct attributes of a
program:
 Data structure
 Software architecture
 Interface representations
 Procedural (algorithmic) detail

The design process translates requirements into a representation of the software that can
be assessed for quality before coding begins. System study provides an understanding of the
procedural details necessary for implementing the system recommended in the feasibility study.
Basically, it is all about the creation of a new system. This is a critical phase since it decides the
quality of the system and has a major impact on the testing and implementation phases. This
design document is a reference regarding the development of this project. This document gives all
the details of the modules and functions present in this project.
System design consists of three major steps:
 Drawings of the expanded system flowcharts to identify all the processing functions
required.
 The allocation of the equipment and software to be used.
 The identification of test requirements for the system.
While designing the system it passes through two different stages of development namely
Logical design and Physical design. The former reviews the present physical system, proposed
input and output specifications, makes edit security and control specifications and prepares a
logical walk- through. The latter maps out the details of the physical system, plans the system
implementation and specifies new hardware and software.

Structured design is a data flow-based methodology that partitions a program into a


hierarchy of modules organized in a top-down manner with details at the bottom. All the
unnecessary fields are to be avoided because it seriously affects the storage area of the system.

KLESNC /BCA/VI Sem/2022-2023 Page 13


Driver Drowsiness Detection

The fields in the database must be self-explanatory. User friendly and descriptive standard
screens are to be generated. For a particular mask, a generalized standard screen format is to be
made, as it will reduce avoidable errors during data entry. While menu design, it must be self-
explanatory, simple, brief, compact and attractive. Provision for necessary validation messages and
auto validation are to be made. The reports are generated as per need and accurately all the screens
including the menus are self-explanatory, standardized and simple.

Design Objectives and Principles

The correctness of the design of a system depends upon the level of precision of the
system built which satisfies the requirements of the system. The aim of the design phase is to
produce the best possible design within the limitations imposed by the requirements and the
facilities.

Some of the properties of the design are as follows:


a) Verifiability: Points out how easily the correctness of the design can be argued.
b) Traceability: All design elements must be traceable to the requirements.
c) Completeness: All the required components of the design must be specified completely.
d) Consistency: There should not be any inherent inconsistencies.
e) Efficiency: An efficient is one that consumes less processing time and requires less memory,
and so it must be satisfied.
f) Simplicity: It is the most important quality criteria for software systems. It would be a great
help for the analyst in future while repairing the system.

It is the process of defining the components, modules, interfaces, and data for
a system to satisfy specified requirements. System development is the process of
creating or altering systems, along with the processes, practices, models, and
methodologies used to develop them. The purpose of the System Design process is
to provide sufficient detailed data and information about the system and its system
elements to enable the implementation consistent with architectural entities as
defined in models and views of the system architecture.

KLESNC /BCA/VI Sem/2022-2023 Page 14


Driver Drowsiness Detection

Elements of a System

 Architecture - This is the conceptual model that defines the structure,


behaviour and more views of a system. We can use flowcharts to
represent and illustrate the architecture.

 Modules - This are components that handle one specific tasks in a system.
A combination of the modules make-up the system.

 Components - This provides a particular function or group of related


functions. They are made up of modules.

 Interfaces - This is the shared boundary across which the components of


a the system exchange information and relate.

 Data - This the management of the information and data flow.

SYSTEM ARCHITECTURE:
It is a conceptual model that describes the structure and behavior of multiple
components and subsystems like multiple software applications, network devices,
hardware, and even other machinery of a system. It is Architecture Description
Language (ADL) which helps to describe the entire system architecture. So, it is a
much broader topic. System architecture can be broadly categorized into centralized
and decentralized architectural an organization.
A software architecture is a set of principles that define the way software is
designed and developed. An architecture defines the structure of the software system
and how it is organized. It also describes the relationships between components, levels
of abstraction, and other aspects of the software system.

KLESNC /BCA/VI Sem/2022-2023 Page 15


Driver Drowsiness Detection

An architecture can be used to define the goals of a project, or it can be used


to guide the design and development of a new system. A software architecture is a
set of principles that define the way software is designed and developed. An
architecture defines the structure of the software system and how it is organized.

Drowsiness Detection System

Behavioral Approach

Eyes Face Head Yawing

KLESNC /BCA/VI Sem/2022-2023 Page 16


Driver Drowsiness Detection

Detailed Design

3 KLESNC /BCA/VI Sem/2022-2023 Page 17


Driver Drowsiness Detection

DATA-FLOW DIAGRAM

 DATA FLOW LEVEL- 0

Driver Alarm
Subject Drowsiness
Detection
System

 DATA FLOW LEVEL- 1

Find
Subject Landmark, Alert if drowsy
Calculate
threshold

KLESNC /BCA/VI Sem/2021-2022 Page 18


Driver Drowsiness Detection

KLESNC /BCA/VI Sem/2022-2023 Page 19


Driver Drowsiness Detection

Implementation

KLESNC /BCA/VI Sem/2022-2023 Page 20


Driver Drowsiness Detection

IMPLEMENTATION

from flask import Flask,render_template,redirect


import cv2
import numpy as np
import dlib
from imutils import face_utils
import time
import asyncio
from pygame import mixer

app = Flask(__name__)

mixer.init()
no_driver_sound = mixer.Sound('nodriver_audio.wav')
sleep_sound = mixer.Sound('sleep_sound.wav')
tired_sound = mixer.Sound('rest_audio.wav')

# Initializing the face detector and landmark detector


detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")

def compute(ptA, ptB):


dist = np.linalg.norm(ptA - ptB)
return dist

def blinked(a, b, c, d, e, f):


up = compute(b, d) + compute(c, e)
down = compute(a, f)
ratio = up/(2.0*down)

KLESNC /BCA/VI Sem/2022-2023 Page 21


Driver Drowsiness Detection

# Checking if it is blinked
if (ratio > 0.22):
return 'active'
else:
return 'sleep'

def mouth_aspect_ratio(mouth):
# compute the euclidean distances between the two sets of
# vertical mouth landmarks (x, y)-coordinates
A = compute(mouth[2], mouth[10]) # 51, 59
B = compute(mouth[4], mouth[8]) # 53, 57

# compute the euclidean distance between the horizontal


# mouth landmark (x, y)-coordinates
C = compute(mouth[0], mouth[6]) # 49, 55

# compute the mouth aspect ratio


mar = (A + B) / (2.0 * C)

# return the mouth aspect ratio


return mar

(mStart, mEnd) = (49, 68)

async def tired():


start = time.time()
rest_time_start=start
tired_sound.play()
a=0
while (time.time()-start < 9):
KLESNC /BCA/VI Sem/2022-2023 Page 22
Driver Drowsiness Detection

if(time.time()-rest_time_start>3):
tired_sound.play()
# cv2.imshow("USER",tired_img)
tired_sound.stop()
return

def detech():
# status marking for current state
sleep_sound_flag = 0
no_driver_sound_flag = 0
yawning = 0
no_yawn = 0
sleep = 0
active = 0
status = ""
color = (0, 0, 0)
no_driver=0
frame_color = (0, 255, 0)
# Initializing the camera and taking the instance
cap = cv2.VideoCapture(0)

# Give some time for camera to initialize(not required)


time.sleep(1)
start = time.time()
no_driver_time=time.time()
no_driver_sound_start = time.time()

while True:
_, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
face_frame = frame.copy()
faces = detector(gray, 0)
KLESNC /BCA/VI Sem/2022-2023 Page 23
Driver Drowsiness Detection

# detected face in faces array


if faces:
no_driver_sound_flag=0
no_driver_sound.stop()
no_driver=0
no_driver_time=time.time()
# sleep_sound.stop()
for face in faces:
x1 = face.left()
y1 = face.top()
x2 = face.right()
y2 = face.bottom()

cv2.rectangle(frame, (x1, y1), (x2, y2), frame_color, 2)


# cv2.rectangle(face_frame, (x1, y1), (x2, y2), (0, 255, 0), 2)

landmarks = predictor(gray, face)


landmarks = face_utils.shape_to_np(landmarks)

# The numbers are actually the landmarks which will show eye
left_blink = blinked(landmarks[36], landmarks[37],
landmarks[38], landmarks[41], landmarks[40],
landmarks[39])
right_blink = blinked(landmarks[42], landmarks[43],
landmarks[44], landmarks[47], landmarks[46],
landmarks[45])
mouth = landmarks[mStart:mEnd]
mouthMAR = mouth_aspect_ratio(mouth)
mar = mouthMAR

# Now judge what to do for the eye blinks

KLESNC /BCA/VI Sem/2022-2023 Page 24


Driver Drowsiness Detection

if (mar > 0.70):


sleep = 0
active = 0
yawning += 1
status = "Yawning"
color = (255, 0, 0)
frame_color = (255, 0, 0)
sleep_sound_flag = 0
sleep_sound.stop()

elif (left_blink == 'sleep' or right_blink == 'sleep'):


if (yawning > 20):
no_yawn += 1
sleep += 1
yawning = 0
active = 0
if (sleep > 5):
status = "Sleeping !"
color = (0, 0, 255)
frame_color = (0, 0, 255)
if sleep_sound_flag == 0:
sleep_sound.play()
sleep_sound_flag = 1
else:
if (yawning > 20):
no_yawn += 1
yawning = 0
sleep = 0
active += 1
status = "Awake"
color = (0, 255, 0)
frame_color = (0, 255, 0)
if active > 5:
KLESNC /BCA/VI Sem/2022-2023 Page 25
Driver Drowsiness Detection

sleep_sound_flag = 0
sleep_sound.stop()

cv2.putText(frame, status, (50, 50),


cv2.FONT_HERSHEY_SIMPLEX, 0.75, color, 2)

if (time.time()-start < 60 and no_yawn >= 3):


no_yawn = 0
# print("tired")
# asyncio.run(put_image(frame))
# time.sleep(2)
asyncio.run(tired())
elif time.time()-start > 60:
start = time.time()

for n in range(0, 68):


(x, y) = landmarks[n]
cv2.circle(face_frame, (x, y), 1, (255, 255, 255), -1)
else:
no_driver+=1
sleep_sound_flag = 0
sleep_sound.stop()
if(no_driver>10):
status="No Driver"
color=(0,0,0)
if time.time()-no_driver_time>5:
if(no_driver_sound_flag==0):
no_driver_sound.play()
no_driver_sound_start=time.time()
else:
if(time.time()-no_driver_sound_start>3):
no_driver_sound.play()
no_driver_sound_start=time.time()
KLESNC /BCA/VI Sem/2022-2023 Page 26
Driver Drowsiness Detection

no_driver_sound_flag=1

cv2.putText(frame, status, (50, 50),


cv2.FONT_HERSHEY_SIMPLEX, 0.75, color, 2)
cv2.imshow("DRIVER (Enter q to exit)", frame)
cv2.imshow("68_POINTS", face_frame)
if (cv2.waitKey(1) & 0xFF == ord('q')):
break
no_driver_sound.stop()
sleep_sound.stop()
tired_sound.stop()
cap.release()
cv2.destroyAllWindows()

@app.route("/open_camera")
def open():
detech()
print("open camera")
return redirect("/")

@app.route("/")
def home():
return render_template("index.html")

if __name__ == "__main__":
app.run(debug=True)

KLESNC /BCA/VI Sem/2022-2023 Page 27


Driver Drowsiness Detection

INDEX.HTML CODE
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DDD</title>
<link href="https://fonts.googleapis.com/css2?
family=Source+Sans+Pro:wght@300;400&display=swap" rel="stylesheet">
<link rel="stylesheet" href="/static/css/bootstrap.min.css">
<link rel="stylesheet" href="/static/css/slick.css" type="text/css" />
<link rel="stylesheet" href="/static/css/templatemo-style.css">
<link rel='stylesheet' href='https://use.fontawesome.com/releases/v5.2.0/css/all.css'>
<link rel='stylesheet'
href='https://use.fontawesome.com/releases/v5.2.0/css/fontawesome.css'><link
rel="stylesheet" href="./style.css">

</head>
<body>
<video autoplay muted loop id="bg-video">
<source src="/static/video/gfp-astro-timelapse.mp4" type="video/mp4">
</video>
<div class="page-container">
<div class="container-fluid">
<div class="row">
<div class="col-xs-12">
<div class="cd-slider-nav">
<nav class="navbar navbar-expand-lg" id="tm-nav">
<a class="navbar-brand" href="#">Driver Drowiness Detection</a>

KLESNC /BCA/VI Sem/2022-2023 Page 28


Driver Drowsiness Detection

<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-


target="#navbar-supported-content" aria-controls="navbarSupportedContent" aria-
expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbar-supported-content">
<ul class="navbar-nav mb-2 mb-lg-0">

<li class="nav-item selected">


<a class="nav-link" aria-current="page" href="#0" data-no="1">Home</a>
<div class="circle"></div>
</li>
<li class="nav-item">
<a class="nav-link" href="#0" data-no="3">About</a>
<div class="circle"></div>
</li>
<li class="nav-item">
<a class="nav-link" href="#0" data-no="4">Contact</a>
<div class="circle"></div>
</li>
<li class="nav-item">
<a class="nav-link" href="#0" data-no="5">Login</a>
<div class="circle"></div>
</li>
</ul>
</div>
</nav>
</div>
</div>
</div>
</div>
<div class="container-fluid tm-content-container">

KLESNC /BCA/VI Sem/2022-2023 Page 29


Driver Drowsiness Detection

<ul class="cd-hero-slider mb-0 py-5">


<li class="px-3" data-page-no="1">
<div class="page-width-1 page-left">
<div class="d-flex position-relative tm-border-top tm-border-bottom intro-
container">
<div class="intro-left tm-bg-dark">
<h2 class="mb-4">Welcome to DDD</h2>
<!-- <p class="mb-4">
commercial purpose. </p> -->
<p class="mb-0">
21 percent of all fatal accidents are due to drowsy driving, which is over 1 lakh
crashes, so use DDD.</p>
</div>
<div class="intro-right">
<img src="/static/img/driver_sleeping_img.jpg" alt="Image" class="img-fluid
intro-img-2">
</div>
<div class="circle intro-circle-1"></div>
<div class="circle intro-circle-2"></div>
<div class="circle intro-circle-3"></div>
<div class="circle intro-circle-4"></div>
</div>

<div class="text-center">
<!-- btn btn-primary tm-intro-btn tm-page-link -->
<a href="/open_camera" class="btn btn-primary tm-intro-btn">
Start Detection
</a>
</div>
</div>
</li>

KLESNC /BCA/VI Sem/2022-2023 Page 30


Driver Drowsiness Detection

<li data-page-no="3" class="px-3">


<div class="position-relative page-width-1 page-right tm-border-top tm-border-
bottom">
<div class="circle intro-circle-1"></div>
<div class="circle intro-circle-2"></div>
<div class="circle intro-circle-3"></div>
<div class="circle intro-circle-4"></div>
<div class="tm-bg-dark content-pad">
<h2 class="mb-4">About our company</h2>
<p class="mb-4">
A real-time drowsiness detection system for drivers, which alerts the driver if they
fall asleep due to fatigue while still driving.
</p>
<p>
The computer vision algorithm used for the implementation uses a trifold
approach to detect drowsiness, including
detection of faces, measurement of eye aspect ratio (to detect closure of eyes), and
measurement of mouth aspect ratio
(to detect yawning).

</p>
</div>
</div>
</li>

<li data-page-no="4">
<div class="mx-auto page-width-2">
<div class="row">
<div class="col-md-6 me-0 ms-auto">

KLESNC /BCA/VI Sem/2022-2023 Page 31


Driver Drowsiness Detection

<h2 class="mb-4">Contact Us</h2>


</div>
</div>
<div class="row">
<div class="col-md-6 tm-contact-left">
</div>
<div class="col-md-6 tm-contact-right">
<p class="mb-4">
<div>xyz</div>
<div>New Delhi - 45</div>
<div>India</div>
</p>
<div>
Email: <a href="mailto:FAR@company.com" class="tm-link-
white">info@company.com</a>
</div>
<div class="tm-mb-45">
Tel: <a href="tel:01100200340" class="tm-link-white">010-020-0340</a>
</div>
</div>
</div>
</div>
</li>
</div>
<div class="container-fluid">
<footer class="row mx-auto tm-footer">
<div class="col-md-6 px-0">
</div>
<div class="col-md-6 px-0 tm-footer-right">
Designed by FVR</a>
</div>
</footer>

KLESNC /BCA/VI Sem/2022-2023 Page 32


Driver Drowsiness Detection

</div>
</div>
<!-- Preloader, https://ihatetomatoes.net/create-custom-preloading-screen/ -->
<div id="loader-wrapper">
<div id="loader"></div>
<div class="loader-section section-left"></div>
<div class="loader-section section-right"></div>
</div>
<script src="/static/js/jquery-3.5.1.min.js"></script>
<script src="/static/js/bootstrap.min.js"></script>
<!-- <script src="/static/js/slick.js"></script> -->
<script src="/static/js/templatemo-script.js"></script>
</body>
</html>

KLESNC /BCA/VI Sem/2022-2023 Page 33


Driver Drowsiness Detection

Testing

KLESNC /BCA/VI Sem/2022-2023 Page 34


Driver Drowsiness Detection

INTRODUCTION TO TESTING
Software Testing is a critical element of software quality assurance and represents the
ultimate review of specification, design and coding, Testing presents an interesting anomaly for
the software engineer.

TESTING OBJECTIVE
 Testing is a process of executing a program with the intent of finding an error.
 A good test case is one that has a probability of finding an as yet undiscovered error.
 A successful test is one that uncovers an undiscovered error.

TESTING STRATEGIES
A Strategy for software testing integrates software test cases into a series of well planned
steps that result in the successful construction of software. Software testing is a broader topic for
what is referred to as Verification and Validation. Verification refers to the set of activities that
ensure that the software correctly implements a specific function. Validation refers he set of
activities that ensure that the software that has been built is traceable to customer’s requirements.

TEST CASE ANALYSIS


Unit Testing:

Unit testing focuses verification effort on the smallest unit of software design that is the
module. Using procedural design description as a guide, important control paths are tested to
uncover errors within the boundaries of the module. The unit test is normally white box testing
oriented and the step can be conducted in parallel for multiple modules.

Integration Testing:
Integration testing is a systematic technique for constructing the program structure, while
conducting test to uncover errors associated with the interface. The objective is to take unit tested
methods and build a program structure that has been dictated by design.

KLESNC /BCA/VI Sem/2022-2023 Page 35


Driver Drowsiness Detection

Top-down Integration:
Top down integrations is an incremental approach for construction of program structure.
Modules are integrated by moving downward through the control hierarchy, beginning with the
main control program. Modules subordinate to the main program are incorporated in the structure
either in the breath-first or depth-first manner.
Bottom-up Integration:
This method as the name suggests, begins construction and testing with atomic modules
i.e., modules at the lowest level. Because the modules are integrated in the bottom up manner the
processing required for the modules subordinate to a given level is always available and the need
for stubs is eliminated.
Validation Testing:
At the end of integration testing software is completely assembled as a package. Validation
testing is the next stage, which can be defined as successful when the software functions in the
manner reasonably expected by the customer. Reasonable expectations are those defined in the
software requirements specifications. Information contained in those sections form a basis for
validation testing approach.
System Testing:
System testing is actually a series of different tests whose primary purpose is to fully
exercise the computer-based system. Although each test has a different purpose, all work to verify
that all system elements have been properly integrated to perform allocated functions.
Security Testing:
Attempts to verify the protection mechanisms built into the sytem.
Performance Testing:
This method is designed to test runtime performance of software within the context of an
integrated system.

White-box and black-box testing


To meet Wikipedia's quality standards, this section may require cleanup. Please discuss this
issue on the talk page, and/or replace this tag with a more specific message.
White box and Black box testing are terms used to describe the point of view a test
engineer takes when designing test cases. Black box being an external view of the test object and
white box being an internal view. Software testing is partly intuitive, but largely systematic.
Good testing
KLESNC /BCA/VI Sem/2022-2023 Page 36
Driver Drowsiness Detection

involves much more than just running the program a few times to see whether it works. Thorough
analysis of the program under test, backed by a broad knowledge of testing techniques and tools
are prerequisites to systematic testing.
Software Testing is the process of executing software in a controlled manner; in order to
answer the question “Does this software behave as specified?” Software testing is used in
association with Verification and Validation. Verification is the checking of or testing of items,
including software, for conformance and consistency with an associated specification. Software
testing is just one kind of verification, which also uses techniques as reviews, inspections, walk-
through. Validation is the process of checking what has been specified is what the user actually
wanted.
 Validation: Are we doing the right job?

 Verification: Are we doing the job right?


In order to achieve consistency in the Testing style, it is imperative to have and follow a set
of testing principles. This enhances the efficiency of testing within SQA team members and thus
contributes to increased productivity. The purpose of this document is to provide overview of the
testing, plus the techniques.

Methodology
At SDEI, 3 levels of software testing is done at various SDLC phases
 Unit Testing: in which each unit (basic component) of the software is tested to verify that the
detailed design for the unit has been correctly implemented

 Integration testing: in which progressively larger groups of tested software components


corresponding to elements of the architectural design are integrated and tested until the software
works as a whole.

 System testing: in which the software is integrated to the overall product and tested to show
that all requirements are met. A further level of testing is also done, in accordance with
requirements:

Acceptance testing: upon which the acceptance of the complete software is based. The clients
often do this.

Regression testing: is used to refer the repetition of the earlier successful tests to ensure that

KLESNC /BCA/VI Sem/2022-2023 Page 37


Driver Drowsiness Detection

changes made in the software have not introduced new bugs/side effects.

KLESNC /BCA/VI Sem/2022-2023 Page 38


Driver Drowsiness Detection

In recent years the term grey box testing has come into common usage. The typical grey
box tester is permitted to set up or manipulate the testing environment, like seeding a database, and
can view the state of the product after his actions, like performing a SQL query on the database to
be certain of the values of columns. It is used almost exclusively of client-server testers or others
who use a database as a repository of information, but can also apply to a tester who has to
manipulate XML files (DTD or an actual XML file) or configuration files directly.
It can also be used of testers who know the internal workings or algorithm of the software
under test and can write tests specifically for the anticipated results. For example, testing a data
warehouse implementation involves loading the target database with information, and verifying
the correctness of data population and loading of data into the correct tables.

Test levels
o Unit testing tests the minimal software component and sub-component or modules by the
programmers.
o Integration testing exposes defects in the interfaces and interaction between integrated
components (modules).
o Functional testing tests the product according to programmable work.
o System testing tests an integrated system to verify/validate that it meets its requirements.
o Acceptance testing can be conducted by the client. It allows the end-user or customer or client
to decide whether or not to accept the product. Acceptance testing may be performed after the
testing and before the implementation phase. See also Development stage
o Alpha testing is simulated or actual operational testing by potential users/customers or an
independent test team at the developers' site. Alpha testing is often employed for off-the-shelf
software as a form of internal acceptance testing, before the software goes to beta testing.
o Beta testing comes after alpha testing. Versions of the software, known as beta versions, are
released to a limited audience outside of the company. The software is released to groups of
people so that further testing can ensure the product has few faults or bugs. Sometimes, beta
versions are made available to the open public to increase the feedback field to a maximal
number of future users.
It should be noted that although both Alpha and Beta are referred to as testing it is in fact
use emersion. The rigors that are applied are often unsystematic and many of the basic tenets of
testing

KLESNC /BCA/VI Sem/2022-2023 Page 39


Driver Drowsiness Detection

process are not used. The Alpha and Beta period provides insight into environmental and
utilization conditions that can impact the software.
After modifying software, either for a change in functionality or to fix defects, a regression
test re-runs previously passing tests on the modified software to ensure that the modifications
haven't unintentionally caused a regression of previous functionality. Regression testing can be
performed at any or all of the above test levels. These regression tests are often automated.

Test cases, suites, scripts and scenarios


A test case is a software testing document, which consists of event, action, input, output,
expected result and actual result. Clinically defined (IEEE 829-1998) a test case is an input and an
expected result. This can be as pragmatic as 'for condition x your derived result is y', whereas other
test cases described in more detail the input scenario and what results might be expected. It can
occasionally be a series of steps (but often steps are contained in a separate test procedure that can
be exercised against multiple test cases, as a matter of economy) but with one expected result or
expected outcome.
The optional fields are a test case ID, test step or order of execution number, related
requirement(s), depth, test category, author, and check boxes for whether the test is automatable
and has been automated. Larger test cases may also contain prerequisite states or steps, and
descriptions.
A test case should also contain a place for the actual result. These steps can be stored in a
word processor document, spreadsheet, database or other common repository. In a database
system, you may also be able to see past test results and who generated the results and the system
configuration used to generate those results. These past results would usually be stored in a
separate table.
The term test script is the combination of a test case, test procedure and test data. Initially
the term was derived from the by product of work created by automated regression test tools.
Today, test scripts can be manual, automated or a combination of both.
The most common term for a collection of test cases is a test suite. The test suite often also
contains more detailed instructions or goals for each collection of test cases. It definitely contains a
section where the tester identifies the system configuration used during testing. A group of test
cases may also contain prerequisite states or steps, and descriptions of the following tests.

KLESNC /BCA/VI Sem/2022-2023 Page 40


Driver Drowsiness Detection

A sample testing cycle


Although testing varies between organizations, there is a cycle to testing:
1. Requirements Analysis: Testing should begin in the requirements phase of the software
development life cycle. During the design phase, testers work with developers in determining what
aspects of a design are testable and under what parameter those tests work.
2. Test Planning: Test Strategy, Test Plan(s), Test Bed creation.

3. Test Development: Test Procedures, Test Scenarios, Test Cases, Test Scripts to use in testing
software.

4. Test Execution: Testers execute the software based on the plans and tests and report any errors
found to the development team.

5. Test Reporting: Once testing is completed, testers generate metrics and make final reports on
their test effort and whether or not the software tested is ready for release.

6. Retesting the Defects


Not all errors or defects reported must be fixed by a software development team. Some
may be caused by errors in configuring the test software to match the development or production
environment. Some defects can be handled by a workaround in the production environment.
Others might be deferred to future releases of the software, or the deficiency might be accepted by
the business user. There are yet other defects that may be rejected by the development team (of
course, with due reason) if they deem it inappropriate to be called a defect.

KLESNC /BCA/VI Sem/2022-2023 Page 41


Driver Drowsiness Detection

Test cases and Results

Test Cases:

Test Case No. Test Case Expected output

1 Webcam Access See the Face (Capture


Face)
Webcam Access No Face Detected

Error

2 Webcam Access with Posture Detected (Raise


Face Detected alarm if sleepy).

Webcam Access with Yawn Detected (Raise


Face Detected alarm if sleepy).

Webcam Access with Eye Closure Detected


Face Detected (Raise alarm if Closed)
If flag reach
End the Detection maximum.

KLESNC /BCA/VI Sem/2022-2023 Page 42


Driver Drowsiness Detection

Screenshots

KLESNC /BCA/VI Sem/2022-2023 Page 43


Driver Drowsiness Detection

SCREENSHOTS

KLESNC /BCA/VI Sem/2022-2023 Page 44


Driver Drowsiness Detection

KLESNC /BCA/VI Sem/2022-2023 Page 45


Driver Drowsiness Detection

OUTPUT:

Awake

Sleeping

KLESNC /BCA/VI Sem/2022-2023 Page 46


Driver Drowsiness Detection

Yawning

No Driver

KLESNC /BCA/VI Sem/2022-2023 Page 47


Driver Drowsiness Detection

Conclusion

KLESNC /BCA/VI Sem/2022-2023 Page 48


Driver Drowsiness Detection

CONCLUSION
 The drowsiness detection and correction system developed is capable of
detecting drowsiness in a rapid manner.

 The system which can differentiate normal eye blink and drowsiness which can
prevent the driver from entering the state of sleepiness while driving.

 When the eyes have been closed for about two seconds, the alarm beeps to
alert the driver and speed of the vehicle is reduced.

 Using drowsiness detection system, driver safety can be implemented in normal


cars also.

KLESNC /BCA/VI Sem/2022-2023 Page 49


Driver Drowsiness Detection

Future Enhancement

KLESNC /BCA/VI Sem/2022-2023 Page 50


Driver Drowsiness Detection

FUTURE ENHANCEMENT

 The future works may focus on the utilization of outer factors such as vehicle
states, sleeping hours, Weather Conditions, Mechanical data etc. for fatigue
measurement.
 Driver Drowsiness pose a major threat to highway safety, and the problem is
particularly severe for commercial motor vehicle operators.
 Monitoring the driver’s state of drowsiness and providing feedback on their
conditions.
 Twenty-four hours operations, high annual mileage, exposure to challenging
environmental conditions and demanding work schedules all contribute to this
serious safety issue.
 Currently, there is no adjustment in zoom or direction of the camera during
operation. Future work may be to automatically zoom is on the eyes once they
are localized.

KLESNC /BCA/VI Sem/2022-2023 Page 51


Driver Drowsiness Detection

Bibliography

KLESNC /BCA/VI Sem/2022-2023 Page 52


Driver Drowsiness Detection

BIBLIOGRAPY

 https://pyimagesearch.com/2017/05/08/drowsiness-detection-opencv/

 https://www.pantechsolutions.net/driver-drowsiness-detection-using-opencv-and-python

 https://data-flair.training/blogs/python-project-driver-drowsiness-detection-system/

 https://en.wikipedia.org/wiki/Driver_drowsiness_detection

KLESNC /BCA/VI Sem/2022-2023 Page 53

You might also like