-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathalgo.h
120 lines (53 loc) · 2.32 KB
/
algo.h
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
Version 1.0, 17.12.2015, Copyright University of Tübingen.
The Code is created based on the method from the paper:
"ElSe: Ellipse Selection for Robust Pupil Detection in Real-World Environments", W. Fuhl, T. C. Santini, T. C. Kübler, E. Kasneci
ETRA 2016 : Eye Tracking Research and Application 2016
The code and the algorithm are for non-comercial use only.
*/
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/core/core.hpp>
#include "find_best_edge.h"
#include "canny_impl.h"
#include "blob_gen.h"
#include "filter_edges.h"
namespace ELSE{
static cv::RotatedRect run(cv::Mat input_img, int validity_th=10){
float rz_fakk=float(input_img.cols)/384.0;
cv::Mat pic=cv::Mat::zeros(input_img.rows/rz_fakk, input_img.cols/rz_fakk, CV_8UC1);
cv::resize(input_img, pic,pic.size());
cv::normalize(pic, pic, 0, 255, cv::NORM_MINMAX, CV_8U);
double border=0.05;//0.1
double mean_dist=3;
int inner_color_range=0;
cv::RotatedRect ellipse;
cv::Point pos(0,0);
int start_x=floor(double(pic.cols)*border);
int start_y=floor(double(pic.rows)*border);
int end_x =pic.cols-start_x;
int end_y =pic.rows-start_y;
cv::Mat picpic = cv::Mat::zeros(end_y-start_y, end_x-start_x, CV_8U);
cv::Mat magni;
for(int i=0; i<picpic.cols; i++)
for(int j=0; j<picpic.rows; j++){
picpic.data[(picpic.cols*j)+i]=pic.data[(pic.cols*(start_y+j))+(start_x+i)];
}
cv::Mat detected_edges2 = canny_impl(&picpic,&magni);
cv::Mat detected_edges = cv::Mat::zeros(pic.rows, pic.cols, CV_8U);
for(int i=0; i<detected_edges2.cols; i++)
for(int j=0; j<detected_edges2.rows; j++){
detected_edges.data[(detected_edges.cols*(start_y+j))+(start_x+i)]=detected_edges2.data[(detected_edges2.cols*j)+i];
}
filter_edges(&detected_edges, start_x, end_x, start_y, end_y);
ellipse=find_best_edge(&pic, &detected_edges, &magni, start_x, end_x, start_y, end_y,mean_dist, inner_color_range,validity_th);
/*if(ellipse.center.x<=0 && ellipse.center.y<=0 || ellipse.center.x>=pic.cols || ellipse.center.y>=pic.rows){
ellipse=blob_finder(&pic,validity_th);
}*/
ellipse.size.height=ellipse.size.height*rz_fakk;
ellipse.size.width=ellipse.size.width*rz_fakk;
ellipse.center.x=ellipse.center.x*rz_fakk;
ellipse.center.y=ellipse.center.y*rz_fakk;
return ellipse;
}
}