Various studies show that around 20% of all road accidents are fatigue-related, up to 50% on certain conditions. One of the ways to reduce this percentage is to use Driver drowsiness detection technology. In this code I introduce an implementation of Driver drowsiness detection via eye monitoring being it closed or opened.
Dlib is a C++ toolkit for machine learning, it also provides a python API to use it in your python apps. One of its best features is a great documentation for C++ and Python API. It is used in the code to detect faces and get facial landmarks coordinates especially the 12 points which define the two eyes left and right (Fig 1). After getting the 12 points of left and right eye, we compute Eye aspect ratio (Fig 2) to estimate the level of the eye opening. Open eyes have high values (>0.2) of EAR while the closed eye it is getting close to zero.
Python code: Simple app to detect the status of eye being it closed or opened (Source code here with two test images).
python sleep_detection.py /path/to/shape_predictor_68_face_landmarks.dat test1.jpg
To Compile c++ app, clone dlib from github and execute the following commands in your terminal.
$git clone https://github.com/davisking/dlib.git $cd dlib $mkdir sleep_detection $cd sleep_detection/Then paste two files (sleep_detetction.cpp and CMakeLists.txt) from my repository here to sleep_detection folder and then create build folder and compile the app via these commands.
$mkdir build $cd build $cmake .. $cmake --build . --config ReleaseRun the following command to run the app.
Real-Time Eye Blink Detection using Facial Landmarks by Tereza Soukupova and Jan Cech https://vision.fe.uni-lj.si/cvw.../proceedings/papers/05.pdf