A very simple demo code for eye blink detection with dlib libray with python, Note this project is basically dependent on the library dlib. The methods used in the demo code is introduced in Paper. This code is based on the blogEye blink detection with OpenCV, Python, and dlib. Here is the Chinese translationOpenCV/Python/dlib眨眼检测.
- win10
- python 3.5.4
- opencv 3.3.1
- imutils 0.4.6
- dlib 18.18
- Anaconda3
conda intall dlib
conda install opencv3
pip install imutils
open the terminal
python detect_blinks.py
The default args open the camera and detect the eye blink in the video
python detect_blinks.py -h
optional arguments:
-h, --help show this help message and exit
-p SHAPE_PREDICTOR, --shape-predictor SHAPE_PREDICTOR
path to facial landmark predictor
-v VIDEO, --video VIDEO
path to input video file
-t THRESHOLD, --threshold THRESHOLD
threshold to determine closed eyes
-f FRAMES, --frames FRAMES
the number of consecutive frames the eye must be below
the threshold
You can see more information about the args, parse a larger threshold means an eye can be more easily considered as closed, vice versa.parse a larger frames means only if the closed eyes last for more frames, can it be considered as a closed eye.You can aslo parse a video file by parsing video args. the shape-predictor args indicate the trained model path which is provided in the demo