Xpolakm5 Computer Vision Eye Blink Detection
Xpolakm5 Computer Vision Eye Blink Detection
Xpolakm5 Computer Vision Eye Blink Detection
This application detect eye blinking by calculating optical flow in area of eyes inside stabilized picture
of head. When the user have closed eyes for more than 5 seconds, the application starts to beep to
wake him up. This can be used inside vehicles to prevent driver sleeping behind the steering wheel.
For eye blinking detection is used generic webcam on computer.
First approach
The first approach to this problem was to detect face by using HAAR Cascade Classifier
(haarcascade_frontalface_alt2 ). Then the program would take eyes position (static, defined by
approximate position where the eyes should be or dynamic also by using HAAR Cascade).
This approach was not working well (or at all) because Optical Flow (calculated by Farenback algorithm)
was not stable. The Cascade Classifier was looking for face on every new frame and it was still changing
its size and position the image was shaky.
Second approach
When I wanted to stabilize the image, I wanted to found darkest area of the eye image, and the other
similar (dark) pixels to redraw as absolutely black (0h). Later I wanted to show just these black pixels
and see just the one black circle. But this method is really unstable when there is not a good lightning
and there are darker shadows than the actual eye.
void detectBlink(Mat &matEyePrevious, Mat &matEyeCurrent, String eye, bool &eyeOpen, int
&blinkNumber, clock_t &closeTime) {
Mat leftFlow, leftCflow;
calcOpticalFlowFarneback(matEyePrevious, matEyeCurrent, leftFlow, 0.5, 3, 15, 3, 5, 1.2, 0);
cvtColor(matEyePrevious, leftCflow, CV_GRAY2BGR);
int movementX, movementY;
calcFlowEyes(leftFlow, leftCflow, 1, movementX, movementY);
if (movementY == 0) {
return;
}
if (movementY > 0 && eyeOpen) {
closeTime = clock();
eyeOpen = false;
blinkNumber = blinkNumber + 1;
}
else if (movementY < 0 && !eyeOpen){
eyeOpen = true;
}
Image 3. Top left and right eye on current frame, bottom previous frame
Now, when the variables for eyes (if each eye is opened or closed) are set, we can show it on the Result
window.
https://youtu.be/v0UNbB_vyrM