forked from tiendan/OpenGazer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlinkDetector.cpp
More file actions
executable file
·34 lines (26 loc) · 926 Bytes
/
Copy pathBlinkDetector.cpp
File metadata and controls
executable file
·34 lines (26 loc) · 926 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <opencv2/imgproc/imgproc.hpp>
#include "BlinkDetector.h"
#include "EyeExtractor.h"
BlinkDetector::BlinkDetector():
_averageEye(new cv::Mat(EyeExtractor::eyeSize, CV_32FC1)),
//_accumulator(0.1, 1000.0),
//_states(constructStates()),
_initialized(false),
isBlinking(false)
{
}
void BlinkDetector::update(const cv::Mat &eyeFloat) {
if (!_initialized) {
eyeFloat.copyTo(*_averageEye.get());
_initialized = true;
}
double distance = cv::norm(eyeFloat, *_averageEye, CV_L2);
double norm = cv::norm(*_averageEye, CV_L2);
// Normalize distance by the norm of the previous eye image
distance = distance / norm;
isBlinking = (distance > 0.18);
//std::cout << "Distance is " << distance << std::endl;
eyeFloat.copyTo(*_averageEye.get());
//cv::accumulateWeighted(*eyeFloat, *_averageEye, 0.05); //TODO Maybe use running average of eye image
}