# fatigue-detector
This is an OpenCV-based fatigue detection program.
![](https://github.com/lizhunan/asset/blob/main/fatigue-detector/pre.gif?raw=true)
<p align="lift">
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-4caf50.svg" alt="License"></a>
</a>
</p>
## Requirement
The code has used as few complex third-party libraries as possible, and tried to reduce the complexity of setting up the environment. However, there are still some required libraries that need to be imported:
- opencv-python 4.7.0.72
- dlib 19.24.2
- numpy 1.21.6
As a real-time face-swapping program, some necessary hardware is required, and the author's test environment is shown in the following table:
|CPU|GPU|Memory|OS|Camera|
|---|---|---|---|---|
|Intel(R) Core(TM) i7-1065G CPU @ 1.30GHz|Intel(R) Iris(R) Plus Graphics(Inessential)|16G|Windows 11|build-in(Essential)|
## How to Use
1. Clone the code from Github.
2. Download the [shape_predictor_68_face_landmarks.dat](http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2) which is a model file provided by dlib for face detection with 68 face landmarks.
3. Move the model file to the `./model`.
4. Run: `python run.py`
parameters:
- `--ear`: The mean aspect ratio for eyes. The ratio means that the eyes tend to be closed. The default value is 0.2.
- `--mar`: The mouth aspect ratio. The larger the ratio, the more inclined to open the mouth. The default value is 0.6.
- `--max_blinks`: The maximum number of blinks refers to the number of consecutive blinks in a certain period of time, and if the threshold is exceeded, it represents fatigue.
- `--max_yawning`: The maximum number of yawns refers to the number of yawns in a certain period of time, and if the threshold is exceeded, it represents fatigue.
## Principle
Because when people are tired, they will probably have two states:
- Blink: normal people's eyes blink about 10-15 times per minute, and each blink is about 0.2-0.4 seconds. If you are tired, the blink frequency will increase and the speed will slow down.
- Yawning: This is when the mouth grows large and stays in a certain state.
Therefore, whether a person is tired can be detected from the degree of opening and closing of the eyes, the blink rate, and the degree of opening and closing of the mouth to determine whether a person is tired.
### Method
1. Location of eyes and mouth.
2. Calculate the aspect ratio for eyes and mouth separately.
3. Estimate the fatigue state according to aspect ratio.
### EAR (eye aspect ratio)
In *[Real-Time Eye Blink Detection using Facial Landmarks](https://vision.fe.uni-lj.si/cvww2016/proceedings/papers/05.pdf)*, EAR is proposed.
In brief, when a person blinks, the distance of landmarks in eyes will be changed. So, the distance can be used to detect if an eye blinks.
![](https://github.com/lizhunan/asset/blob/main/fatigue-detector/ear.png?raw=true)
The EAR can be defined:
$$
EAR=\frac{\Vert p_2 - p_6 \Vert + \Vert p_3 - p_5 \Vert}{2\Vert p_1 - p_4 \Vert}
$$
The function is
``` python
def eye_aspect_ratio(eye):
A = np.linalg.norm(eye[1] - eye[5])
B = np.linalg.norm(eye[2] - eye[4])
C = np.linalg.norm(eye[0] - eye[3])
return (A + B) /(2.0 * C)
```
### MAR (mouth aspect ratio)
Similarly, the MAR can be calculated as well. the MAR can be calculated:
```python
def mouth_aspect_ratio(mouth):
A = np.linalg.norm(mouth[2] - mouth[10])
B = np.linalg.norm(mouth[4] - mouth[8])
C = np.linalg.norm(mouth[0] - mouth[6])
return (A + B) / (2.0 * C)
```
## License and Citations
The source code is published under MIT license, see [license file](./LICENSE) for details.
没有合适的资源?快使用搜索试试~ 我知道了~
基于OpenCV的疲劳检测
共6个文件
py:2个
gitignore:1个
gitkeep:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 133 浏览量
2024-10-22
19:50:56
上传
评论 1
收藏 6KB ZIP 举报
温馨提示
因为当人们疲惫时,他们可能会有两种状态: 眨眼:正常人的眼睛每分钟眨眼大约10-15次,每次眨眼大约是0.2-0.4秒。如果您累了,闪烁频率会增加,速度会减慢。 打哈欠:这是嘴巴变大并保持一定状态的时候。 因此,可以从眼睛的开闭程度、眨眼频率、嘴巴的开闭程度来判断一个人是否累。 方法 眼睛和嘴巴的位置。 分别计算眼睛和嘴巴的纵横比。 根据纵横比估计疲劳状态。
资源推荐
资源详情
资源评论
收起资源包目录
fatigue-detector-main.zip (6个子文件)
fatigue-detector-main
main.py 3KB
LICENSE 1KB
run.py 816B
model
.gitkeep 0B
.gitignore 3KB
README.md 4KB
共 6 条
- 1
资源评论
hakesashou
- 粉丝: 6734
- 资源: 1676
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功