This repository contains a solution for blinking detection with landmark detection on OpenCV and dlib. I uploaded a .rar file because the size of the Landmark module is nearly 100MB. The total size of the project is 150MB. The zipped version is 86MB.
Important Note: You should run it as adminastrator. Because communication between python and c # is provided by blinktext.txt file. And if you don't run as adminastrator, program cannot change text file and you will get error.
Important Note 2: If you want to work with python code without GUI you can just use BlinkDetection.py in python branch.
Python 3.7+
pip install -r requirements.txt
Run EyeBlinkDetectionApp.exe
There are two main parts in this project: Algorithm in python and GUI in C#
-
In the algorithm part used (shape_predictor_68_face_landmarks.dat) file for detecting face landmarks. Then I found dots that represent eyes. (Image 1: 36-41 for right and 42-47 for left eye).
-
When I detect where the eyes are, drew two lines longitudinally and laterally. Now I have open and close information for both eyes.
-
But I want to detect blink. But I wanted to detect blinking. Therefore, I have compared the two lines that I have obtained in very short intervals in a while loop and I have taken the ratio of these ratios.
-
If the final ratio is lower than the threshold which I set, our algorithm send a 'blinked' message to our C# GUI with blinktext.txt. You can check Image 2 for the ratio of ratios.
- When the user press the Start Detecting button C# runs python code(blinking_detectionD.py). It can take 10 seconds to start detecting. If the user doesn't blink for 25 seconds, a warning message appears in the lower right corner of the screen.
- Having trouble button deletes the contents of the blinktext1.txt file. blinktext1.txt file contains 'exit' information for while in python code. If any conflict happens and this text becomes 'exit' before the start, the user should press the Having Trouble button.