-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
372 lines (348 loc) · 10.8 KB
/
Copy pathindex.html
File metadata and controls
372 lines (348 loc) · 10.8 KB
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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Eye Gaze Data Collection by PHAS Group 11</title>
<script src="https://cdn.jsdelivr.net/npm/piexifjs"></script>
<style>
body {
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-start;
font-family: 'Roboto', sans-serif;
background-color: #f4f7fa;
color: #333;
margin: 0;
padding: 20px;
height: 100vh;
overflow-y: auto;
}
h1 {
color: #4a90e2;
font-size: 28px;
margin-bottom: 15px;
text-align: center;
line-height: 1.4;
}
h1 .phas-group {
display: block;
font-size: 22px;
color: #4a90e2;
font-weight: bold;
}
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
text-align: center;
max-width: 800px;
width: 100%;
}
#videoContainer {
position: relative;
border: 3px solid #4a90e2;
border-radius: 12px;
overflow: hidden;
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
margin-bottom: 30px;
display: flex;
justify-content: center;
width: 100%;
max-width: 650px;
height: auto;
}
/* Mirror the video for a selfie view */
#video {
display: block;
border-radius: 12px;
width: 100%;
height: auto;
transform: scaleX(-1);
}
.dropdown,
.lighting-dropdown,
.circle-checkbox {
width: 100%;
max-width: 350px;
text-align: center;
margin: 15px 0;
}
label {
font-size: 18px;
margin-bottom: 12px;
display: block;
font-weight: bold;
color: #333;
}
.dropdown select,
.lighting-dropdown select {
padding: 14px 20px;
font-size: 18px;
border: 2px solid #4a90e2;
border-radius: 10px;
background-color: #ffffff;
cursor: pointer;
width: 100%;
transition: all 0.3s ease-in-out;
}
.dropdown select:hover,
.lighting-dropdown select:hover {
border-color: #357ABD;
}
.circle-checkbox {
display: flex;
align-items: center;
justify-content: flex-start;
margin-top: 15px;
cursor: pointer;
}
.circle-checkbox input {
appearance: none;
width: 22px;
height: 22px;
border-radius: 50%;
background-color: #ccc;
margin-right: 12px;
border: 2px solid #fff;
cursor: pointer;
}
.circle-checkbox input:checked {
background-color: #28a745;
}
.status {
font-size: 20px;
color: #357ABD;
font-weight: bold;
margin-top: 15px;
display: block;
visibility: visible;
}
.button-container {
margin-top: 15px;
display: flex;
justify-content: center;
width: 100%;
max-width: 350px;
}
button {
padding: 14px 22px;
font-size: 18px;
color: #fff;
background-color: #4a90e2;
border: none;
border-radius: 10px;
cursor: pointer;
transition: background-color 0.3s;
width: 100%;
}
button:hover {
background-color: #357ABD;
}
#stopBtn {
background-color: #ff3b3b;
}
#stopBtn:hover {
background-color: #ff1a1a;
}
.guidelines {
margin-top: 30px;
text-align: left;
color: #555;
max-width: 700px;
font-size: 16px;
}
.guidelines ul {
padding-left: 20px;
}
.guidelines li {
margin-bottom: 12px;
}
.circle-checkbox label {
margin-left: 12px;
font-weight: normal;
font-size: 18px;
}
.footer {
margin-top: auto;
text-align: center;
font-size: 14px;
color: #fffefe;
padding: 10px;
width: 100%;
background-color: #4a90e2;
border: 1px solid #ccc;
border-radius: 10px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
</style>
</head>
<body>
<div class="content">
<h1>
Eye Gaze Data Collection
<span class="phas-group">by PHAS Group 11</span>
</h1>
<!-- Start Camera Button -->
<div class="button-container" style="max-width: 350px;">
<button id="startCameraBtn" onclick="startCamera()">Start Camera</button>
</div>
<p>Select a label and start data collection.</p>
<div id="videoContainer">
<video id="video" width="100%" height="auto" playsinline></video>
</div>
<div class="dropdown">
<label for="labelSelect">Choose Label:</label>
<select id="labelSelect">
<option value="Center">Center</option>
<option value="Left">Left</option>
<option value="Right">Right</option>
<option value="Blink">Blink</option>
<option value="Stop">Stop</option>
</select>
</div>
<div class="button-container">
<button id="startStopBtn" onclick="startStopCapture()">Start Data Collection</button>
</div>
<div class="lighting-dropdown">
<label for="lightingSelect">Lighting Condition:</label>
<select id="lightingSelect">
<option value="Good">Good</option>
<option value="Poor">Poor</option>
<option value="Sunlight">Sunlight</option>
</select>
</div>
<div class="dropdown">
<label for="glassesSelect">Wearing Glasses:</label>
<select id="glassesSelect">
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
</div>
<div class="status" id="status">Status: Idle</div>
<div class="guidelines">
<h3>Guidelines for Data Collection:</h3>
<ul>
<li>Ensure proper lighting to avoid glare and shadows on the face.</li>
<li>Position your face such that it is fully visible to the camera.</li>
<li>For glasses-wearing users, clean the lenses to minimize reflections.</li>
<li>Hold each gaze direction (Center, Left, Right) steadily for 3-5 seconds.</li>
<li>Ensure the entire eye region is visible during gaze capture.</li>
<li>For "Blink" data, blink naturally and avoid rapid eye movements.</li>
<li>Repeat the data collection process for multiple sessions to ensure diversity in data.</li>
</ul>
</div>
</div>
<!-- Footer -->
<div class="footer">
<span>Copyright © 2025 PHAS Group 11</span>
</div>
<script>
const video = document.getElementById('video');
const startCameraBtn = document.getElementById('startCameraBtn');
const startStopBtn = document.getElementById('startStopBtn');
const statusDisplay = document.getElementById('status');
const labelSelect = document.getElementById('labelSelect');
const lightingSelect = document.getElementById('lightingSelect');
const glassesSelect = document.getElementById('glassesSelect');
let stream = null;
let collecting = false;
let interval;
let currentLabel = "Center";
let lightingCondition = "Good";
let wearingGlasses = "No";
// Update selected label and metadata when changed
labelSelect.addEventListener('change', function () {
currentLabel = labelSelect.value;
});
lightingSelect.addEventListener('change', function () {
lightingCondition = lightingSelect.value;
});
glassesSelect.addEventListener('change', function () {
wearingGlasses = glassesSelect.value;
});
// Start the camera only after user interaction
function startCamera() {
if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
navigator.mediaDevices.getUserMedia({ video: true })
.then((mediaStream) => {
stream = mediaStream;
video.srcObject = stream;
video.play();
// Disable the start camera button after successful start
startCameraBtn.disabled = true;
startCameraBtn.textContent = "Camera Started";
})
.catch((error) => {
console.error("Error accessing camera: ", error);
alert("Unable to access the camera. Please check camera permissions.");
});
} else {
alert("getUserMedia is not supported in this browser.");
}
}
function startStopCapture() {
if (!stream) {
alert("Please start the camera first.");
return;
}
if (collecting) {
collecting = false;
statusDisplay.textContent = "Status: Idle";
statusDisplay.style.color = "#357ABD"; // Blue for idle state
clearInterval(interval);
startStopBtn.textContent = "Start Data Collection";
startStopBtn.style.backgroundColor = "#4a90e2";
} else {
collecting = true;
statusDisplay.textContent = "Status: Collecting...";
statusDisplay.style.color = "#28a745"; // Green when collecting
interval = setInterval(captureImage, 2000);
startStopBtn.textContent = "Stop Data Collection";
startStopBtn.style.backgroundColor = "#ff3b3b";
}
}
function captureImage() {
const timestamp = Date.now();
const canvas = document.createElement('canvas');
canvas.width = video.videoWidth;
canvas.height = video.videoHeight;
const ctx = canvas.getContext('2d');
// Mirror the image when capturing by translating and scaling the context
ctx.translate(canvas.width, 0);
ctx.scale(-1, 1);
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
const imageDataUrl = canvas.toDataURL('image/jpeg');
addMetadataAndDownload(imageDataUrl, timestamp);
}
function addMetadataAndDownload(dataUrl, timestamp) {
const metadata = {
label: currentLabel,
timestamp: timestamp,
lighting: lightingCondition,
glasses: wearingGlasses
};
// Embed lighting condition and glasses status in the EXIF data
const exifData = {
'0th': {
[piexif.ImageIFD.Make]: `Lighting: ${lightingCondition}, Glasses: ${wearingGlasses}`,
[piexif.ImageIFD.Model]: "EyeGazeModel2025"
},
'Exif': {
[piexif.ExifIFD.DateTimeOriginal]: new Date(timestamp).toISOString()
},
'UserComment': JSON.stringify(metadata)
};
const exifBytes = piexif.dump(exifData);
const newDataUrl = piexif.insert(exifBytes, dataUrl);
const a = document.createElement('a');
const filename = `${currentLabel}_${timestamp}.jpg`;
a.href = newDataUrl;
a.download = filename;
a.click();
}
</script>
</body>
</html>