In our fast-paced lives, where cars have become an integral part of daily routines, the risk of accidents due to human errors, especially drowsy driving, has become a growing concern. Recognizing the potential dangers, the automotive industry has turned to advanced technologies for safety solutions. In this blog post, we explore PERCLOS (PERcentage of eye CLOSure), a gold standard in driver drowsiness detection, providing insights into its calculation and a simplified implementation.
PERCLOS is a pivotal metric for measuring drowsiness, widely adopted in various industries. This metric quantifies the extent of eye closure over a specific time period, leveraging the fact that eyelid drooping or closure is a common symptom of drowsiness.
The calculation involves:
1. Utilizing an eye-tracking system or camera-based monitoring system to capture continuous images or videos of the driver's face. In earlier implementations, algorithms like Viola-Jones were used to detect the driver’s face, while more recent implementations use DeepLearning models for this purpose.
2. Analyzing each frame to identify the state of the driver's eyes using facial landmark detection or other computer vision techniques.
3. Choosing a specific time interval for calculation (commonly a few seconds to a minute).
4. Counting instances of eye closure within the defined time window. There are many definitions for eye closure, a general approach is to consider the eye close when the eyelid covers about 80% of the eye.
5. Calculate PERCLOS using the formula:
For example, if there are 20 instances of eye closure within a 60-second interval with a total of 600 frames, the PERCLOS would be (20 / 600) * 100 = 3.33%.
A higher PERCLOS percentage indicates a greater proportion of time spent with closed or partially closed eyes, suggesting increased drowsiness. Typically, it is required to define a threshold above which it is considered that the driver is experiencing drowsiness, some typical values are 20% or 40%.
Working with PERCLOS
A better way to understand how PERCLOS works for detecting drowsiness is to implement it. We are going to go over a simplified implementation of PERCLOS just as a toy example that will be enough to demonstrate the advantages and disadvantages of PERCLOS.
In order to implement our example, we are going to use MediaPipe, a Google’s Open Source framework with out-of-the-box implementations of computer vision and machine learning functions. Here is the list of requirements for a Conda environment (not a fan of Conda? Try PyEnv instead! 🙂 ) :
conda create --name perclos
conda activate perclos
conda install -c conda-forge mediapipe matplotlib opencv numpy
Okay! We are ready to start!
In order to perform the landmark detection in the face of our test subjects, we are going to use the FaseMesh class from MediaPipe. The result of performing the face landmark detection extracts a predefined set of points from the image for a total of 478 landmarks. Figure 1 shows the canonical model used by MediaPipe.
Figure 1. Canonical Face Model used by MediaPipe. (Original URL here)
Fortunately, MediaPipe Face Landmark Detection task already absorbs most of the job for us, taking care of detecting the face in the image and then, detecting the corresponding landmarks. A sample result is shown in Figure 2.
Figure 2. Sample image of face landmark detection using MediaPipe.
Now that we have a way to get the landmarks from any image, we can formulate our simplified drowsiness detection algorithm:
Get landmarks from input video using MediaPipe
Pick top and bottom eye landmarks to measure the closure of the eye. In our case we picked landmarks (145, 159) and (374, 386) for right and left eye accordingly.
Instead of calculating a percentage for the eye closure we just set a very low threshold for the distance between the landmarks to consider the eyes closed. In our case we set it to 0.009 after a few experiments.
We use the frames as our own time counter, so we determine how many frames present eyes closed within a specific time interval, expressed in a total number of frames analyzed.
We use the previous count to calculate the PERCLOS and determine whether the subject is likely experiencing micro sleeps and thus, falling asleep.
The following code runs the drowsiness detection using the above algorithm:
The following video shows a sample output of the algorithm, note how it detects when the subject is presenting micro sleeps i.e. his eyes are closed for a longer time.
Advantages and Limitations
While PERCLOS serves as a straightforward and effective solution for drowsiness detection, it has its limitations. The method is highly sensitive to occlusions, requiring a consistently clear view of the eyes. Moreover, PERCLOS is most effective at advanced stages of sleepiness, making early-stage detection challenging where no evident symptoms of drowsiness occur.
Despite its limitations, PERCLOS remains a widely used tool for drowsiness detection, thanks to its simplicity and effectiveness. In future blogs, we will delve into the challenges of detecting pre-drowsy states based on microexpressions and using advanced technologies like transformers. Stay tuned for more!
The RidgeRun.ai Team!