# Research on a Real-Time Driver Fatigue Detection Algorithm Based on Facial Video Sequences
## 2 Approach
### Driver Fatigue Recognition Features
#### 2.3.3 The Flow Chart of Online Monitoring  
As mentioned previously, driver fatigue is a process of dynamic change. In this paper, we have proposed a comprehensive identifier to judge the driver fatigue state. Compared with the traditional single fatigue index, the identifier has the characteristics of high identification accuracy and good reliability in driver fatigue identification. The flow chart of the on-line monitoring system for driver fatigue status is as follows:  
1. The camera collects video input, detects each frame of image, and filters out the image containing face. 2. ROI (region of interest) of eyes and mouth of face image are extracted. 3. Based on the extracted ROI, EAR and MAR are calculated for the eye and mouth regions, respectively, to obtain the values of EAR and MAR. According to the obtained EAR value, PERCLOS is calculated, and the obtained EAR, PERCLOS, and MAR values are applied to K-nearest neighbor (KNN), respectively. 4. Through experiments, the threshold of EAR is set to 0.2 and the threshold of PERCLOS is set to 0.8 according to the p80 criterion. 5. When the Mar value is greater than 0.6, the driver is considered to start yawning, and the Mar threshold is set to 0.6. 6. Set the weight values of EAR and PERCLOS to 0.2 and 0.8, respectively, and the Mar value is the auxiliary value, and its weight value is 0.1. 7. Through experimental calculation, it is reasonable that the M threshold is 0.605. In this part, \(N\) is recorded as the number of times M \(>\) 0.605 (i.e., the cumulative length of driver's eyes closed within a certain period of time). 8. According to the experimental results, when 10 \(<N<\) = 20, mild fatigue; 20 \(<N<\) 50, moderate fatigue; \(N\geq\) 50, severe fatigue. In Figure 6, M is a newly proposed comprehensive index to judge the driver's fatigue degree. The specific acquisition method is to add the calculated EAR, PERCLOS, and MAR values according to their respective weight proportion to obtain M. The number of frames when M \(>\) 0.605 in a certain time is recorded as \(N\). In the detection algorithm, the detection cycle is set to 90 frames, that is, the fatigue degree is determined according to the number of frames \(N\) with M greater than 0.605 in the detection cycle. When 10 \(<N\leq\) 20, it is marked as mild fatigue; when 20 \(<N<\) 50, moderate fatigue; and when \(N\geq\) 50, severe fatigue. A KNN classifier is trained with the input data. KNN algorithm is a widely used and practical classifier model in the field of data classification and processing [28]. For the existing sample data set, the distance between the measured sample data reference point and other arbitrary data points is calculated in the form of the K classification threshold, so as to realize the classification and recognition of any given sample data points. Figure 6: Online detection of driver fatigue. Firstly, in the KNN classifier model, the calculated distance between data set \(D(x_{i},y_{i})\) and the sample reference point with the set threshold \(K\) is often used as the reference index of the tested data, which can effectively solve the matching optimization problem between the sample points \((x,y)\). Then, the Euclidean distance \(D(x,y)\) is selected as the measurement criterion of the sample data tested. \[D(x,y)=\sqrt{(x_{1}-y_{1})^{2}+(x_{2}-y_{2})^{2}+\ldots+(x_{n}-y_{n})^{2}}= \sqrt{\sum_{i=1}^{n}(x_{i}-y_{i})^{2}} \tag{5}\]  
Then there is the selection of the \(K\) value. In the KNN algorithm, the accuracy of calculation results largely depends on the selection of the \(K\) value. Therefore, if the selection of the \(K\) value in the dataset classifier is too large or too small, it will produce a deviation in the data classification results, which is not conducive to the final fitting effect of the classification model. However, for different data sets, there is no fixed empirical value (usually set to 5 by default). Generally, a smaller value can be selected according to the distribution of sample data parameter sets.