-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
420 lines (362 loc) · 31.5 KB
/
index.html
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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
<!DOCTYPE html>
<!-- saved from url=(0068)http://auduno.github.io/clmtrackr/examples/clm_emotiondetection.html -->
<html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Face tracker</title>
<meta charset="utf-8">
<link href="assets/bootstrap.min.css" rel="stylesheet" type="text/css">
<style>
@import url(https://fonts.googleapis.com/css?family=Lato:300italic,700italic,300,700);
body {
font-family: 'Lato';
/*background-color: #f0f0f0;*/
background-color: #000;
margin: 0px auto;
max-width: 1150px;
}
#overlay {
position: absolute;
top: 0px;
left: 0px;
-o-transform : scaleX(-1);
-webkit-transform : scaleX(-1);
transform : scaleX(-1);
-ms-filter : fliph; /*IE*/
filter : fliph; /*IE*/
width : 600px;
height : 450px;
}
#videoel {
-o-transform : scaleX(-1);
-webkit-transform : scaleX(-1);
transform : scaleX(-1);
-ms-filter : fliph; /*IE*/
filter : fliph; /*IE*/
width : 600px;
height : 450px;
}
#container {
position : relative;
width : 370px;
/*margin : 0px auto;*/
}
#content {
margin-top : 50px;
margin-left : auto;
margin-right : auto;
max-width: 600px;
}
#sketch, #filter {
display: none;
}
h2 {
font-weight : 400;
}
.btn {
font-family: 'Lato';
font-size: 16px;
}
#controls {
text-align : center;
}
#emotion_container {
width: 600px;
}
#emotion_icons {
height: 50px;
padding-left: 40px;
}
.emotion_icon {
width : 40px;
height : 40px;
margin-top: 5px;
/*margin-left : 13px;*/
margin-left : 35px;
}
#emotion_chart, #emotion_icons {
margin: 0 auto;
width : 400px;
}
#icon1, #icon2, #icon3, #icon4, #icon5, #icon6 {
visibility : hidden;
}
/* d3 */
.bar {
fill : steelblue;
fill-opacity : .9;
}
</style>
</head>
<body data-pinterest-extension-installed="cr1.3.1">
<script src="assets/utils.js"></script>
<script src="assets/clmtrackr.js"></script>
<script src="assets/model_pca_20_svm_emotionDetection.js"></script>
<script src="assets/Stats.js"></script>
<script src="assets/d3.min.js"></script>
<script src="assets/emotion_classifier.js"></script>
<script src="assets/emotionmodel.js"></script>
<script src='https://cdn.firebase.com/js/client/1.0.11/firebase.js'></script>
<div id="content">
<div id="container">
<video id="videoel" width="400" height="300" preload="auto" loop="" src="">
</video>
<canvas id="overlay" width="400" height="300"></canvas>
<div style="cursor: pointer; width: 80px; opacity: 0.9; z-index: 10001; position: absolute; top: 0px;"><div style="text-align: left; line-height: 1.2em; background-color: rgb(8, 8, 24); padding: 0px 0px 3px 3px;"><div style="font-family: Helvetica, Arial, sans-serif; font-size: 9px; color: rgb(0, 255, 255); font-weight: bold;">FPS</div><div style="position: relative; width: 74px; height: 30px; background-color: rgb(0, 255, 255);"><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span><span style="width: 1px; height: 30px; float: left; background-color: rgb(16, 16, 48);"></span></div></div><div style="text-align: left; line-height: 1.2em; background-color: rgb(8, 24, 8); padding: 0px 0px 3px 3px; display: none;"><div style="font-family: Helvetica, Arial, sans-serif; font-size: 9px; color: rgb(0, 255, 0); font-weight: bold;">MS</div><div style="position: relative; width: 74px; height: 30px; background-color: rgb(0, 255, 0);"><span style="width: 1px; height: 6.86046656453982px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 17.949876696802676px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 9.139851378276944px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 4.916088134050369px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 11.22931214980781px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 17.84369926666841px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 19.744093576446176px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 3.5225125565193594px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 21.991657270118594px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 0.28319732286036015px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 15.526293588336557px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 26.137069487012923px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 4.494197317399085px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 13.70043083326891px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 28.82577604847029px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 19.959718950558454px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 16.365701977629215px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 12.511858998332173px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 28.969159636180848px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 6.148840240202844px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 12.937114310916513px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 26.941470389720052px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 0.5776240839622915px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 25.41857256554067px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 7.72257573204115px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 29.839038499630988px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 27.7731153764762px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 23.978352905251086px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 9.910454470664263px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 14.413235331885517px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 4.197829097975045px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 28.46090403618291px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 10.63175791874528px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 28.454613655339926px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 23.68435667362064px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 9.952766743954271px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 12.250116379000247px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 12.564081370364875px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 21.399414902552962px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 8.86221859138459px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 28.495464166626334px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 17.650587474927306px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 4.648391869850457px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 10.243412428535521px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 8.536452047992498px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 18.072374851908535px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 22.98635516082868px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 0.8667350979521871px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 0.8161302725784481px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 26.165081241633743px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 0.6401708861812949px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 1.167864901944995px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 8.568281934130937px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 22.707279827445745px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 25.740468360017985px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 14.28803548682481px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 26.679527345113456px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 16.336797375697643px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 27.408302791882306px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 13.53536487556994px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 15.552429989911616px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 26.620932058431208px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 26.005663645919412px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 6.914105422329158px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 17.915287502110004px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 3.4364497242495418px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 8.91495808493346px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 3.7939785816706717px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 29.24873276380822px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 6.194654807914048px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 9.4862584839575px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 3.7284077634103596px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 24.88894209265709px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 20.62520609702915px; float: left; background-color: rgb(16, 48, 16);"></span></div></div></div></div>
<canvas id="sketch" width="400" height="300"></canvas>
<div id="emotion_container" style="display:none;">
<div id="emotion_icons">
<img class="emotion_icon" id="icon1" src="assets/icon_angry.png">
<img class="emotion_icon" id="icon2" src="assets/icon_sad.png">
<img class="emotion_icon" id="icon3" src="assets/icon_surprised.png">
<img class="emotion_icon" id="icon4" src="assets/icon_happy.png">
</div>
<div id="emotion_chart"><svg width="400" height="100"><rect x="40" y="70" height="0" width="30" fill="#2d578b"></rect><rect x="125" y="70" height="0" width="30" fill="#2d578b"></rect><rect x="210" y="70" height="0" width="30" fill="#2d578b"></rect><rect x="295" y="70" height="0" width="30" fill="#2d578b"></rect><text x="70" y="70" dx="-15" dy="1.2em" text-anchor="middle" fill="white" class="labels">0</text><text x="155" y="70" dx="-15" dy="1.2em" text-anchor="middle" fill="white" class="labels">0</text><text x="240" y="70" dx="-15" dy="1.2em" text-anchor="middle" fill="white" class="labels">0</text><text x="325" y="70" dx="-15" dy="1.2em" text-anchor="middle" fill="white" class="labels">0</text><text x="70" y="70" dx="-15" text-anchor="middle" style="font-size: 12" transform="translate(0, 18)" class="yAxis">angry</text><text x="155" y="70" dx="-15" text-anchor="middle" style="font-size: 12" transform="translate(0, 18)" class="yAxis">sad</text><text x="240" y="70" dx="-15" text-anchor="middle" style="font-size: 12" transform="translate(0, 18)" class="yAxis">surprised</text><text x="325" y="70" dx="-15" text-anchor="middle" style="font-size: 12" transform="translate(0, 18)" class="yAxis">happy</text></svg></div>
</div>
<div id="controls">
<input class="btn" type="button" value="Start" onclick="startVideo()" id="startbutton">
<input class="btn" type="button" value="Stop tracking" onclick="stopTracking()" id="startbutton">
</div>
<script>
var vid = document.getElementById('videoel');
var overlay = document.getElementById('overlay');
var overlayCC = overlay.getContext('2d');
//var fullname = prompt('Hello astronaut what is your name?', 'Astronaut #1');
var fullname = null;
if (!fullname) {
fullname = 'Astronaut #' + Math.floor((Math.random()*100)+1);
}
console.log(fullname);
/********** check and set up video/webcam **********/
function enablestart() {
var startbutton = document.getElementById('startbutton');
startbutton.value = "Start";
startbutton.disabled = null;
}
/*var insertAltVideo = function(video) {
if (supports_video()) {
if (supports_ogg_theora_video()) {
video.src = "../media/cap12_edit.ogv";
} else if (supports_h264_baseline_video()) {
video.src = "../media/cap12_edit.mp4";
} else {
return false;
}
//video.play();
return true;
} else return false;
}*/
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
window.URL = window.URL || window.webkitURL || window.msURL || window.mozURL;
// check for camerasupport
if (navigator.getUserMedia) {
// set up stream
var videoSelector = {video : true};
if (window.navigator.appVersion.match(/Chrome\/(.*?) /)) {
var chromeVersion = parseInt(window.navigator.appVersion.match(/Chrome\/(\d+)\./)[1], 10);
if (chromeVersion < 20) {
videoSelector = "video";
}
};
navigator.getUserMedia(videoSelector, function( stream ) {
if (vid.mozCaptureStream) {
vid.mozSrcObject = stream;
} else {
vid.src = (window.URL && window.URL.createObjectURL(stream)) || stream;
}
vid.play();
}, function() {
//insertAltVideo(vid);
alert("There was some problem trying to fetch video from your webcam. If you have a webcam, please make sure to accept when the browser asks for access to your webcam.");
});
} else {
//insertAltVideo(vid);
alert("This demo depends on getUserMedia, which your browser does not seem to support. :(");
}
vid.addEventListener('canplay', enablestart, false);
/*********** setup of emotion detection *************/
var isPaused = false;
var ctrack = new clm.tracker({useWebGL : true});
ctrack.init(pModel);
function startVideo() {
// start video
vid.play();
// start tracking
ctrack.start(vid);
// start loop to draw face
drawLoop();
// connect astronaut
connectAstronaut();
}
function stopTracking() {
vid.pause();
ctrack.stop(vid);
isPaused = true;
}
function drawLoop() {
requestAnimFrame(drawLoop);
overlayCC.clearRect(0, 0, 400, 300);
//psrElement.innerHTML = "score :" + ctrack.getScore().toFixed(4);
if (ctrack.getCurrentPosition()) {
ctrack.draw(overlay);
}
var cp = ctrack.getCurrentParameters();
var er = ec.meanPredict(cp);
if (er) {
updateData(er);
for (var i = 0;i < er.length;i++) {
if (er[i].value > 0.4) {
document.getElementById('icon'+(i+1)).style.visibility = 'visible';
} else {
document.getElementById('icon'+(i+1)).style.visibility = 'hidden';
}
}
}
}
var ec = new emotionClassifier();
ec.init(emotionModel);
var emotionData = ec.getBlank();
/************ d3 code for barchart *****************/
var margin = {top : 20, right : 20, bottom : 10, left : 40},
width = 400 - margin.left - margin.right,
height = 100 - margin.top - margin.bottom;
var barWidth = 30;
var formatPercent = d3.format(".0%");
var x = d3.scale.linear()
.domain([0, ec.getEmotions().length]).range([margin.left, width+margin.left]);
var y = d3.scale.linear()
.domain([0,1]).range([0, height]);
var svg = d3.select("#emotion_chart").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
svg.selectAll("rect").
data(emotionData).
enter().
append("svg:rect").
attr("x", function(datum, index) { return x(index); }).
attr("y", function(datum) { return height - y(datum.value); }).
attr("height", function(datum) { return y(datum.value); }).
attr("width", barWidth).
attr("fill", "#2d578b");
svg.selectAll("text.labels").
data(emotionData).
enter().
append("svg:text").
attr("x", function(datum, index) { return x(index) + barWidth; }).
attr("y", function(datum) { return height - y(datum.value); }).
attr("dx", -barWidth/2).
attr("dy", "1.2em").
attr("text-anchor", "middle").
text(function(datum) { return datum.value;}).
attr("fill", "white").
attr("class", "labels");
svg.selectAll("text.yAxis").
data(emotionData).
enter().append("svg:text").
attr("x", function(datum, index) { return x(index) + barWidth; }).
attr("y", height).
attr("dx", -barWidth/2).
attr("text-anchor", "middle").
attr("style", "font-size: 12").
text(function(datum) { return datum.emotion;}).
attr("transform", "translate(0, 18)").
attr("class", "yAxis");
function updateData(data) {
if (!isPaused) {
setAstronautData(data);
}
// update
var rects = svg.selectAll("rect")
.data(data)
.attr("y", function(datum) { return height - y(datum.value); })
.attr("height", function(datum) { return y(datum.value); });
var texts = svg.selectAll("text.labels")
.data(data)
.attr("y", function(datum) { return height - y(datum.value); })
.text(function(datum) { return datum.value.toFixed(1);});
// enter
rects.enter().append("svg:rect");
texts.enter().append("svg:text");
// exit
rects.exit().remove();
texts.exit().remove();
}
/******** stats ********/
stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.top = '0px';
document.getElementById('container').appendChild( stats.domElement );
/********** connects to firebase and send data **********/
var astronauts = new Firebase('https://y1dzhuuj.firebaseio.com/astronauts');
var astronaut = null;
var astronautCurrentData = {};
/**
* Connect Astronaut
*
* @return {Void}
*/
function connectAstronaut() {
// Add the new astronaut
astronaut = astronauts.push(
{
name: fullname,
current: {
angry: 0,
sad: 0,
surprised: 0,
happy: 0
},
createdAt: Firebase.ServerValue.TIMESTAMP
}
);
// Set presence
var astronautKey = astronaut.name();
var connection = new Firebase('https://y1dzhuuj.firebaseio.com/connections/' + astronautKey);
var connected = new Firebase('https://y1dzhuuj.firebaseio.com//.info/connected');
connected.on('value', function(snap) {
if (snap.val() === true) {
// We're connected (or reconnected)! Do anything here that should happen only if online (or on reconnect)
// Add this device to my connections list
// this value could contain info about the device or a timestamp too
connection.set({ timestamp: Firebase.ServerValue.TIMESTAMP});
// When I disconnect, remove this device
connection.onDisconnect().remove();
// When I disconnect, update the last time I was seen online
//lastOnlineRef.onDisconnect().set(Firebase.ServerValue.TIMESTAMP);
}
});
// Set timer to update astronaut status every 1 sec
setInterval(sendAstronautData, 2000);
}
/**
* Set Astronaut Data
*
* @param {Object} data Current emotional status
*/
function setAstronautData(data) {
astronautCurrentData = {
timestamp: Firebase.ServerValue.TIMESTAMP,
angry: data[0].value,
sad: data[1].value,
surprised: data[2].value,
happy: data[3].value
}
};
/**
* Save Astronaut data
*
* @return {Void}
*/
function sendAstronautData() {
astronaut.child('history').push(astronautCurrentData);
astronaut.child('current').update(astronautCurrentData);
}
// update stats on every iteration
document.addEventListener(
'clmtrackrIteration',
function(event) {
stats.update();
},
false
);
</script>
</div><canvas width="11px" height="781px" id="renderCanvas" style="display:none;"></canvas>
<span style="height: 20px; width: 40px; min-height: 20px; min-width: 40px; position: absolute; opacity: 0.85; z-index: 8675309; display: none; cursor: pointer; background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAUCAYAAAD/Rn+7AAADU0lEQVR42s2WXUhTYRjHz0VEVPRFUGmtVEaFUZFhHxBhsotCU5JwBWEf1EWEEVHQx4UfFWYkFa2biPJiXbUta33OXFtuUXMzJ4bK3Nqay7m5NeZq6h/tPQ+xU20zugjOxR/+7/O8539+5znnwMtNTExwJtMb3L/fiLv3botCSmUjeCaejTOb39AiFothfHxcFIrHY8RksZjBsckJcOIRMfFsHD/SsbExUYpnI8DR0dGUGjSb0byhEJp5Uqg5CTSzc2CQleJbMEj9/ywBcGRkJEk9DQqouEVQT1sK444yWI9UonmTjGqauVLEIlHa9x8lAMbj8SSpp0rwKGMVvg8P46vbg0C7na8z8JsMcgHe7jlEa+edRhiLy8n/TUMfu6EvLElk+U0WtGwrTrdfAGQf5J8iiK4LVzDU28t8JtMSocf8E+l68myaNFXm/6rXslLK7ay5TOunuRvZWpJuvwAYjUaTpOIWoquuAZ219RTaxKYp9BbjycoN5FvL9qH9TBX5rvoGdJythvXYSTxdtRnWylO/ZdqrLsGwszzhWQ593z2KlAwCYCQSSZJ6ehZ0W7bD9VBLgN0NCqr3qR7R2rBrL3pu3Sb/7nDlz2uy6cG0OXk0GTbZXzNp8trsPAQdTj6frlWzN2DcXZGKQQAMh8NJ6rpyHe+PnkCr/CAFdZyvpfpjuvkifLF9wIt1Wwlo0OHie1RvWrKa93RjzfzliTzPKz3ltB0/Tevmwp14wGUgHAzSOoUEwFAolFaaBSuhnslPRkJexUJtZ6v5HtUeLswl33n1BgEY5fvhs9sJ3FAiT+QYyyvoAQJuD0KBAFRTJNAuz5/s3gJgMBhMJwrVFRThM5tY5zUF/A4X1f2fvQTRLCuBreoim0YmAbqNJryvPEXeeq46kaNdkQ/1HCncbJKPs9ZSv2VHGfWsZ2hfkhKAfr8/pdxWKx4wwD69PmVfNSOL+lr2w+gYqHpWDtXt1xQ8AMlWU0e1lqLd/APRHoP8AJqWrQG9gYxcPMsvSJUvAA4MDKTUJ7MZLaVy8v+qT21tcDx/OemePr0RTkNrur4A6PP5xCgBsL+/X4wiQDpuuVxOeL1eMYmYeDY6sOp0z+B0OuHxeEQhxkJMFosJiSO/UinOI/8Pc+l7KKArAT8AAAAASUVORK5CYII=);"></span></body></html>