System Design To Drowsiness Warning For Driver Using Python, Dlib, and OpenCV
System Design To Drowsiness Warning For Driver Using Python, Dlib, and OpenCV
Tran Thi Hien12*, Qiaokang Liang2, and Nguyen Thi Dieu Linh3
1
Nam Dinh University of Technology Education, Vietnam
2
Hunan University, Changsha 410082, China
3
Hanoi University of Industry, Vietnam
*
[email protected]
Abstract. A large number of road accidents today are related to the
drowsiness of the driver of a vehicle due to many causes such as fatigue,
drunkenness. However, detecting driver drowsiness and warning is com-
pletely possible. In this paper, the authors propose a design pattern for
driver drowsiness warning systems using Python, Dlib and OpenCV. Ex-
perimental results show that the system works in many different environ-
mental conditions, meeting the requirements such as: Flexibility and con-
venience, high accuracy, processing time and warning fast enough for a
real time request application.
Keywords: Drowsiness warning, OpenCV, Eyes closeness detection
1 Introduction
Most of the methods proposed for imagebased drowsiness detection use symptoms
related to the level of the driver’s drowsiness. Detecting eyes that are closed or open is
used in many methods. Dasgupta [1] used the amount of eyelid closure as a cue for
drowsiness. Te presence of the iris in the image indicates that the eye is open. Detection
of the iris in an eye image using the circular Hough transform is used in [2] to classify
the eye as being open or closed. Other methods include template matching [3, 4], use
of local image features [5, 6], and using a Hidden Markov Model [7]. Head pose esti-
mation is used by Teyeb [8], where the level of driver alertness is measured by the head
being inclined to a certain degree and for a specifc time period. A threshold placed on
the changing rate of the mouth contour to detect yawning is used by Alioua [9] to detect
drowsiness of the driver. However, expert knowledge can be instrumental for accurate
and timely detection of drowsiness. Such knowledge is implemented by Rezaei and
Klette [10] using a fuzzy control fusion system.
In addition to these techniques, specialized machine learning-based methods have
been proposed with the recent emergence of deep learning. Park [11] proposed a deep
architecture, referred to as deep drowsiness detection. It is reliable for the exclusion of
backgrounds and environment variations and achieved 73.06% accuracy. Weng [12]
introduced a novel hierarchical temporal deep belief network for drowsiness detection.
Teir work highlights the detection of head positions and faces to detect drowsiness.
Huynh [13] used a three-dimensional convolutional neural network to extract features
2
2 Design system
The requirement for the system is to monitor and detect the driver's sleepiness during
driving with high accuracy, real-time response, and compact.
The system is built with four main parts: Hardware, operating system, algorithms and
display functions of the system.
a) System hardware structure
- The screen displays the results of the system: It is necessary to select a monitor
with HDMI port to connect to the Raspberry.
- Speaker: alarms when the system detects the driver's sleepy state.
- Mouse and keyboard: Help the driver to control the system.
b) Ubuntu operating system
The Ubuntu operating system is small in size, suitable for devices with limited
memory of the Raspberry Pi 4, as well as possessing a huge application store. In addi-
tion, it also has the advantages of: Hardware requirements are not too high, high secu-
rity, diverse and free application store, high compatibility, built-in necessary tools, and
community massive support.
c) Drowsiness detection algorithm
In the study, the authors built algorithms based on the Python programming language
to help identify and detect driver drowsiness. The main tools used include:
- Dlib open source library: The algorithm that Dlib uses to extract image properties
is HOG (Histogram of Oriented Gradients) and SVM (Support Vector Machine).
- Facial Landmark Recognition Algorithm:
The mission of Facial Landmark is to locate the face in the photo and identify the
points that make up the structure of the face. To perform these two tasks, the facial
landmark recognition algorithm will determine 68 main points according to the coordi-
nates (x, y) that make up the human face. Thereby distinguishing: mouth, right eye-
brow, left eyebrow, right eye, left eye, nose, jaw.
The distance between two points A and B is calculated according to the Pythagorean
formula used by scipy library to calculate the eucliden distance between the landmarks
on the face.
d) Display function of the system
This function displays the results of the OpenCV computer vision image processing
on an open source basis...
p2 p6 p3 p5
EAR
2 p1 p4
The results of the EAR calculation give us an approximate value that remains con-
stant at the time of the eye opening but will rapidly decrease to 0 when the eye closing.
5
Fig.4. Eye-frame rate values graph when eyes are closed and open
Looking at the figure above, this is the timed eye-frame rate for a video clip. The
eye-frame rate here fluctuated around 0.25 then quickly dropped to 0 then increased
again. That showed a blink of an eye had just taken place.
The mouth will be denoted by 12 distinct points.
Look at the picture below, this is the oral frame rate over time for a video clip. The
oral frame rate here hovers around a 0.3 value when in the normal state then quickly
rises to more than 1 and then decreases. This shows that the state of the mouth has
changed from normal to open. So we can determine the driver's yawning state.
6
Fig.6. Mouth frame rate variation chart when close and open
Set threshold standards, to check driver drowsiness: EAR allowed value: 0.25. MAR
allowed values: 0.7.
- Warning: During driving, if the ratio of the eyes and mouth do not meet the above
two rates. The system will set a timer to provide safety warnings if the ratio of the eyes
and mouth.
a) Experiment
In order to evaluate our proposed method, we used image datasets that are incremen-
tally difficult. We outlined the accuracy of face detection, eye detection, mouth detec-
tion and then classification of the eyes as open or closed, yawn mouth or not . The
detection results of both the open/closed eyes and yawn mouth are shown in Figure 7
to figure 11.
MAR: 0.35 EAR: 0.38 MAR: 0.33 EAR: 0.33
counterMieng: 0.00 counterMat: 0.00 counterMieng: 00.00 counterMat: 00.00 MAR: 0.33 EAR: 0.35 EAR: 0.29
MAR: 0.32
NguGat: 0.00 NguGat: 1.00 counterMieng: 0.00 counterMat: 00.00 counterMat: 00.00
counterMieng: 0.00
NguGat: 0.00 NguGat: 2.00
Fig.7. Front face state, not wearing and wearing glasses, sufficient and underexposed
CANH BAO NGU GAT EAR: 0.14 CANH BAO NGU GAT! EAR: 0.18
CANH BAO NGU GAT! EAR: 0.16 CANH BAO NGU GAT! EAR: 0.15
MAR: 0.12 counterMat: 25.00 MAR: 0.34 counterMat: 29.00
MAR: 0.34 counterMat: 102.00 MAR: 0.36 counterMat: 5.00
counterMieng: 0.00 NguGat: 1.00 counterMieng: 00.00 NguGat: 2.00
counterMieng: 0.00 NguGat: 1.00 counterMieng: 0.00 NguGat: 3.00
Fig.8. Eyes closed for more than 1.5 seconds, not wearing and wearing glasses, suffi-
cient and underexposed
7
CANH BAO NGAP! EAR: 0.35 CANH BAO NGAP! EAR: 0.38 CANH BAO NGAP! EAR: 0.25
MAR: 1.31 counterMat: 0.00 MAR: 1.07 counterMat: 00.00 CANH BAO NGAP! EAR: 0.41
MAR: 0.92 counterMat: 2.00
counterMieng: 79.00 NguGat: 0.00 counterMieng: 29.00 NguGat: 1.00 MAR: 0.81 counterMat: 00.00
counterMieng: 45.00 NguGat: 1.00
counterMieng: 28.00 NguGat: 3.00
Fig.4. The state of yawn mouth more than 1.5 seconds, not wearing and wearing
glasses, sufficient and underexposed
MAR: 0.47 EAR: 0.41 MAR: 0.06 EAR: 0.4 MAR: 0.51 EAR: 0.43 MAR: 0.40 EAR: 0.28
counterMieng: 0.00 counterMat: 0.00 counterMieng: 0.00 counterMat: 0.00 counterMieng: 0.00 counterMat: 0.00 counterMieng: 0.00 counterMat: 0.00
NguGat: 0.00 NguGat: 0.00 NguGat: 0.00 NguGat: 3.00
Fig.9. The face is tilted at an angle of 300, not wearing and wearing glasses, sufficient
and underexposed
CANH BAO NGU GAT! EAR: 0.21 CANH BAO NGAP! EAR: 0.30 CANH BAO NGAP! EAR: 0.43 CANH BAO NGAP! EAR: 0.30
MAR: 0.32 counterMat: 103.00 MAR: 1.21 counterMat: 0.00 MAR: 1.10 counterMat: 0.00 MAR: 1.19 counterMat: 0.00
counterMieng: 0.00 NguGat: 2.00 counterMieng: 64.00 NguGat: 0.00 counterMieng: 25.00 NguGat: 2.00 counterMieng: 65.00 NguGat: 0.00
Fig.10. Eyes closed or yawning , the face is tilted at an angle of 300, not wearing and
wearing glasses, sufficient and underexposed
Fig.11. State head down overslept or head up overslept make the system not recog-
nize
b) Evaluate the results
The proposed method was evaluated with a real-time video of someone driving a car.
The video was recorded in the day time with variations in illumination due to differ-
ences in the direction of sunlight. The main purpose of the proposed algorithm is to
classify eyes in the detected face and eye images.
- When the driver sitting right posture, the system's exact identification rate is as
follows: Face is 97.5%; the eye is 88%; Mouth is 91%. So the system meets the require-
ments set out.
8
- When the driver sitting the face is tilted at an angle of 300, the system's exact
identification rate is as follows: Face is 97.5%; the eye is 65%; Mouth is 88%. Results
are affected by ghosting that occurs when the driver wears glasses. However, the system
basically meets the requirements set out.
The above results show the feasibility of the proposed method for driver drowsiness
detection. It should be noted, however, that these results were achieved during the day
time. For night time, our proposed method can be used on top of face and eye detection
algorithms that work during night time.
5 Conclusion
By combining the hardware is the Raspberry Pi 4 processor, the Dlib algorithms with
the display function of OpenCV, we conduct design drowsiness warning system for
drivers. Experimental results above the image of the driver under light conditions, tilt
angle, wear different glasses. Synthesize and compare with the initial requirements of
the system, shows: The system works in many different environmental conditions, meet
the requirements set out such as: Flexible, onvenient, high precision, processing time
and alarms are fast enough for a real time request application.
References
1. A. Dasgupta, A. George, S. L. Happy, A. Routray: A visionbased system for monitoring the
loss of attention in automotive drivers. IEEE Transactions on Intelligent Transportation Sys-
tems, vol. 14, no. 4, pp. 1825–1838, (2013).
2. N. Alioua, A. Amine, M. Rziza, D. Aboutajdine: Eye state analysis using iris detection based
on Circular Hough Transform. Proceedings of the 2011 International Conference on Multi-
media Computing and Systems, ICMCS’11, IEEE, pp. 1–5, (2011).
3. X. Liu, X. Tan, S. Chen: Eyes closeness detection using appearance based methods. Pro-
ceedings of the International Conference on Intelligent Information Processing, vol. 385, pp.
398–408, Springer, (2012).
4. G. Fa-deng, H. Min-xian: Study on the detection of locomotive driver fatigue based on im-
age. Proceedings of the 2010 2nd International Conference on Computer Engineering and
Technology, pp. V7-612–V7-615, Chengdu, China, (2010).
5. L. Zhou, H. Wang: Open/closed eye recognition by local binary increasing intensity patterns.
Proceedings of the 2011 IEEE 5th International Conference on Robotics, Automation and
Mechatronics, RAM 2011, IEEE, pp. 7–11, China, (2011).
6. M. Tafreshi, A. M. Fotouhi: A fast and accurate algorithm for eye opening or closing detec-
tion based on local maximum vertical derivative pattern. Turkish Journal of Electrical Engi-
neering & Computer Sciences, vol. 24, no. 6, pp. 5124–5134, (2016).
7. H. Qin, J. Liu, T. Hong: An eye state identifcation method based on the embedded hidden
Markov model. Proceedings of the 2012 IEEE International Conference on Vehicular Elec-
tronics and Safety, ICVES 2012, IEEE, pp. 255–260, Turkey, (2012).
8. I. Teyeb, O. Jemai, M. Zaied, C. B. Amar: A drowsy driver detection system based on a new
method of head posture estimation. Proceedings of the International Conference on Intelli-
gent Data Engineering and Automated Learning, pp. 362–369, Springer, (2014).
9