forked from lsobieszek/Eye_Tracking_Project
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CalibrationPanel.java
349 lines (270 loc) · 10.5 KB
/
CalibrationPanel.java
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package EyeTracking;
import com.googlecode.javacv.cpp.opencv_core;
import com.googlecode.javacv.cpp.opencv_core.CvPoint;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsEnvironment;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.geom.Ellipse2D;
import javax.swing.JPanel;
import javax.swing.Timer;
import sun.security.util.Length;
/**
*
* @author XXX
*/
public class CalibrationPanel extends javax.swing.JPanel implements ActionListener {
Timer tm = new Timer(60, this);
double scrW;
double scrH;
CvPoint centerCenter;
CvPoint centerTop;
CvPoint centerBottom;
CvPoint leftCenter;
CvPoint leftTop;
CvPoint leftBottom;
CvPoint rightCenter;
CvPoint rightTop;
CvPoint rightBottom;
CvPoint centerTop25;
CvPoint centerBottom45;
CvPoint leftCenter25;
CvPoint rightCenter45;
int y;// = 20 + 40 + (int) (scrW / 5);
int x;//=(int)( scrH / 2);
CvPoint[] calibCord = new CvPoint[10];
int counter = -1;
int textCounter = -1;
boolean CALIB_START = false;
boolean POINT_READY = false;
boolean AUTO = false;
public void setAUTO(boolean AUTO) {
this.AUTO = AUTO;
}
public boolean isPOINT_READY() {
return POINT_READY;
}
public boolean isCALIB_START() {
return CALIB_START;
}
public void setCalibCord(CvPoint[] calibCord) {
this.calibCord = calibCord;
}
private int size = 40;
public int getCounter() {
return counter;
}
public int setDefaultSize() {
return size = 50;
}
public CvPoint getCenterTop25() {
return centerTop25;
}
public void setCenterTop25(CvPoint centerTop25) {
this.centerTop25 = centerTop25;
}
public CvPoint getCenterBottom45() {
return centerBottom45;
}
public void setCenterBottom45(CvPoint centerBottom45) {
this.centerBottom45 = centerBottom45;
}
public CvPoint getLeftCenter25() {
return leftCenter25;
}
public void setLeftCenter25(CvPoint leftCenter25) {
this.leftCenter25 = leftCenter25;
}
public CvPoint getRightCenter45() {
return rightCenter45;
}
public void setRightCenter45(CvPoint rightCenter45) {
this.rightCenter45 = rightCenter45;
}
public CvPoint getCenterCenter() {
return centerCenter;
}
public CvPoint getCenterTop() {
return centerTop;
}
public CvPoint getCenterBottom() {
return centerBottom;
}
public CvPoint getLeftCenter() {
return leftCenter;
}
public CvPoint getLeftTop() {
return leftTop;
}
public CvPoint getLeftBottom() {
return leftBottom;
}
public CvPoint getRightCenter() {
return rightCenter;
}
public CvPoint getRightTop() {
return rightTop;
}
public CvPoint getRightBottom() {
return rightBottom;
}
public double getScrW() {
return scrW;
}
public void setScrW(double scrW) {
this.scrW = scrW;
}
public double getScrH() {
return scrH;
}
public void setScrH(double scrH) {
this.scrH = scrH;
}
/**
* Creates new form CalibrationPanel
*/
public CalibrationPanel() {
initComponents();
Toolkit screenSize = Toolkit.getDefaultToolkit();
Dimension scrSize = screenSize.getScreenSize();
double width = scrSize.getWidth();
double height = scrSize.getHeight();
setScrH(height);
setScrW(width);
System.out.println("Calibration panel dimension " + scrSize);
/// setSize(scrSize);
// setSize(500, 500);
setVisible(true);
x = 20;
y = (int) (scrH / 2);
tm.start();
}
private Ellipse2D getEllipseFromCenter(double x, double y, double width, double height) {
double newX = x - width / 2.0;
double newY = y - height / 2.0;
Ellipse2D ellipse = new Ellipse2D.Double(newX, newY, width, height);
return ellipse;
}
public void paint(Graphics g) {
textCounter++;
Graphics2D g2 = (Graphics2D) g;
super.paintComponent(g2);
int fontSize = 46;
Font font = new Font("Serif", Font.PLAIN, fontSize);
g2.setFont(font);
if (textCounter > 0 && textCounter < 40 && AUTO == true) {
g2.drawString("calibration will start at: ", (int) scrW / 2 - 200, (int) scrH / 2 + fontSize / 3);
} else if (textCounter > 40 && textCounter < 60 && AUTO == true) {
g2.drawString("5", (int) scrW / 2 + 30, (int) scrH / 2 + fontSize / 3);
} else if (textCounter > 60 && textCounter < 80 && AUTO == true) {
g2.drawString("4", (int) scrW / 2 + 30, (int) scrH / 2 + fontSize / 3);
} else if (textCounter > 80 && textCounter < 100 && AUTO == true) {
g2.drawString("3", 20 + 40 + (int) (scrW / 5) + 30, (int) scrH / 2 + fontSize / 3);
} else if (textCounter > 100 && textCounter < 120 && AUTO == true) {
g2.drawString("2", 40, (int) scrH / 2 + fontSize / 3);
} else if (textCounter > 120 && textCounter < 140 && AUTO == true) {
g2.drawString("1", 40, (int) scrH / 2 + fontSize / 3);
} else if (textCounter > 140 && textCounter < 160 && AUTO == true) {
CALIB_START = true;
}
size--;
// System.out.println("Size ############## " + size);
if (size < 2 && counter < calibCord.length + 1 && CALIB_START == true) {
counter++;
if (counter < calibCord.length) {
setDefaultSize();
x = calibCord[counter].x();
y = calibCord[counter].y();
}
}
if (size < 20) {
POINT_READY = true;
} else {
POINT_READY = false;
}
if (counter > 10) {
g2.drawString("calibration compleated: ", (int) scrW / 2 - 200, (int) scrH / 2 + fontSize / 3);
tm.stop();
}
g2.setColor(Color.red);
g2.fill(getEllipseFromCenter(x, y, size, size));
g2.setColor(Color.black);
g2.draw(getEllipseFromCenter(x, y, size, size));/// Srodek środek
g2.draw(getEllipseFromCenter(scrW / 2, scrH / 2, 10, 10));/// Srodek środek
g2.draw(getEllipseFromCenter(scrW / 2, scrH / 2, 4, 4));
centerCenter = opencv_core.cvPoint((int) scrW / 2, (int) scrH / 2);
g2.draw(getEllipseFromCenter(scrW / 2, 40 + (scrH / 5), 10, 10));/// Srodek góra 2/5
g2.draw(getEllipseFromCenter(scrW / 2, 40 + (scrH / 5), 4, 4));
centerTop25 = opencv_core.cvPoint((int) scrW / 2, 40 + (int) (scrH / 5));
g2.draw(getEllipseFromCenter(scrW / 2, 20, 10, 10));/// Srodek góra
g2.draw(getEllipseFromCenter(scrW / 2, 20, 4, 4));
centerTop = opencv_core.cvPoint((int) scrW / 2, 20);
g2.draw(getEllipseFromCenter(scrW / 2, scrH - 40 - (scrH / 5), 10, 10));/// Srodek dół 4/5
g2.draw(getEllipseFromCenter(scrW / 2, scrH - 40 - (scrH / 5), 4, 4));
centerBottom45 = opencv_core.cvPoint((int) scrW / 2, (int) scrH - 40 - (int) (scrH / 5));
g2.draw(getEllipseFromCenter(scrW / 2, scrH - 20, 10, 10));/// Srodek dół
g2.draw(getEllipseFromCenter(scrW / 2, scrH - 20, 4, 4));
centerBottom = opencv_core.cvPoint((int) scrW / 2, (int) scrH - 20);
g2.draw(getEllipseFromCenter(20 + 40 + (scrW / 5), scrH / 2, 10, 10));/// Lewo środek 2/5
g2.draw(getEllipseFromCenter(20 + 40 + (scrW / 5), scrH / 2, 4, 4));
leftCenter25 = opencv_core.cvPoint(20 + 40 + (int) (scrW / 5), (int) scrH / 2);
g2.draw(getEllipseFromCenter(20, scrH / 2, 10, 10));/// Lewo środek
g2.draw(getEllipseFromCenter(20, scrH / 2, 4, 4));
leftCenter = opencv_core.cvPoint(20, (int) scrH / 2);
g2.draw(getEllipseFromCenter(20, 20, 10, 10));/// Lewo góra
g2.draw(getEllipseFromCenter(20, 20, 4, 4));
leftTop = opencv_core.cvPoint(20, 20);
g2.draw(getEllipseFromCenter(20, scrH - 20, 10, 10));/// Lewo dół
g2.draw(getEllipseFromCenter(20, scrH - 20, 4, 4));
leftBottom = opencv_core.cvPoint(20, (int) scrH - 20);
g2.draw(getEllipseFromCenter(scrW - 20, scrH / 2, 10, 10));/// Prawo środek
g2.draw(getEllipseFromCenter(scrW - 20, scrH / 2, 4, 4));
rightCenter = opencv_core.cvPoint((int) scrW - 20, (int) scrH / 2);
g2.draw(getEllipseFromCenter(scrW - 20 - 40 - (scrW / 5), scrH / 2, 10, 10));/// Prawo środek 4/5
g2.draw(getEllipseFromCenter(scrW - 20 - 40 - (scrW / 5), scrH / 2, 4, 4));
rightCenter45 = opencv_core.cvPoint((int) scrW - 20 - 40 - (int) (scrW / 5), (int) scrH / 2);
g2.draw(getEllipseFromCenter(scrW - 20, 20, 10, 10));/// Prawo góra
g2.draw(getEllipseFromCenter(scrW - 20, 20, 4, 4));
rightTop = opencv_core.cvPoint((int) scrW - 20, 20);
g2.draw(getEllipseFromCenter(scrW - 20, scrH - 20, 10, 10));/// Prawo dół
g2.draw(getEllipseFromCenter(scrW - 20, scrH - 20, 4, 4));
rightBottom = opencv_core.cvPoint((int) scrW - 20, (int) scrH - 20);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
@Override
public void actionPerformed(ActionEvent e) {
repaint();
}
}