-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFace tracker.html
252 lines (219 loc) · 22.7 KB
/
Face tracker.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
<!DOCTYPE html>
<!-- saved from url=(0056)https://www.auduno.com/clmtrackr/examples/clm_video.html -->
<html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Face tracker</title>
<link href="./Face tracker_files/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;
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*/
}
#videoel {
-o-transform : scaleX(-1);
-webkit-transform : scaleX(-1);
transform : scaleX(-1);
-ms-filter : fliph; /*IE*/
filter : fliph; /*IE*/
}
#container {
position : relative;
width : 370px;
/*margin : 0px auto;*/
}
#content {
margin-top : 70px;
margin-left : 100px;
margin-right : 100px;
max-width: 950px;
}
h2 {
font-weight : 400;
}
.nogum {
display : none;
}
.btn {
font-family: 'Lato';
font-size: 16px;
}
.hide {
display : none;
}
.nohide {
display : block;
}
</style>
<script type="text/javascript" async="" src="./Face tracker_files/ga.js"></script><script>
// getUserMedia only works over https in Chrome 47+, so we redirect to https. Also notify user if running from file.
if (window.location.protocol == "file:") {
} else if (window.location.hostname !== "localhost" && window.location.protocol !== "https:"){
window.location.protocol = "https";
}
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-32642923-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body>
<script src="./Face tracker_files/utils.js"></script>
<script src="./Face tracker_files/clmtrackr.js"></script>
<script src="./Face tracker_files/Stats.js"></script>
<div id="content">
<h2>Facetracking example</h2>
<div id="container">
<video id="videoel" width="400" height="300" preload="auto" loop="" playsinline="" autoplay="">
</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: 13.7919px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 1.13488px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 27.5854px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 26.9044px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 14.8892px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 24.7321px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 10.5535px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 10.7786px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 26.8004px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 3.17288px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 22.5382px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 20.8977px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 28.3471px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 16.2001px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 9.96774px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 12.6839px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 12.4333px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 26.0937px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 17.9997px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 14.3914px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 27.3699px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 2.6687px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 0.0579274px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 6.02638px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 15.865px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 0.523029px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 26.5575px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 24.7838px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 7.25871px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 26.9394px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 25.0363px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 11.6058px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 4.38884px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 20.1697px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 23.2738px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 17.6213px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 0.43069px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 1.59218px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 0.366826px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 28.5021px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 23.7501px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 12.9396px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 16.08px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 12.2757px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 0.300801px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 1.64547px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 28.8626px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 18.5795px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 14.3344px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 24.0759px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 22.7857px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 1.47025px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 24.3188px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 21.5294px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 16.4438px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 13.7352px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 13.6628px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 15.8149px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 0.775532px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 28.1739px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 12.0623px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 10.0906px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 0.48676px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 13.5041px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 2.26149px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 26.7871px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 17.015px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 28.6888px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 11.5496px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 26.3176px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 27.3139px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 17.6083px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 15.5824px; float: left; background-color: rgb(16, 48, 16);"></span><span style="width: 1px; height: 17.3497px; float: left; background-color: rgb(16, 48, 16);"></span></div></div></div></div>
<br>
<input class="btn" type="button" value="start" onclick="startVideo()" id="startbutton">
<div id="text">
<p>This is an example of face tracking using the javascript library <a href="https://github.com/auduno/clmtrackr"><em>clmtrackr</em></a>. The fitting method is generally called "Non-rigid/deformable face tracking/alignment using constrained local models".</p>
<p>Note that this example works best in Google Chrome, with a computer that supports WebGL and floating point textures. It should however work in any modern browser.</p>
<div id="gum" class="gum">
<p>To try it out:
</p><ol>
<li>allow the page to use your webcamera</li>
<li>make sure that your face is clearly visible in the video, and click start</li>
<li>see the model fitted to your face</li>
<ol>
<p></p>
</ol></ol></div>
<div id="nogum" class="nogum">
<p>
There was some problem trying to capture your webcamera, please check that your browser supports WebRTC. Using a fallback video instead. To try it out:
</p><ol>
<li>click start</li>
<li>see the model fitted to the face</li>
</ol>
<p></p>
</div>
</div>
<a href="https://github.com/auduno/clmtrackr"><img style="position: absolute; top: 0; left: 0; border: 0;" src="./Face tracker_files/forkme_left_green_007200.png" alt="Fork me on GitHub"></a>
<script>
var vid = document.getElementById('videoel');
var vid_width = vid.width;
var vid_height = vid.height;
var overlay = document.getElementById('overlay');
var overlayCC = overlay.getContext('2d');
/*********** Setup of video/webcam and checking for webGL support *********/
function enablestart() {
var startbutton = document.getElementById('startbutton');
startbutton.value = "start";
startbutton.disabled = null;
}
var insertAltVideo = function(video) {
// insert alternate video if getUserMedia not available
if (supports_video()) {
if (supports_webm_video()) {
video.src = "./media/cap12_edit.webm";
} else if (supports_h264_baseline_video()) {
video.src = "./media/cap12_edit.mp4";
} else {
return false;
}
return true;
} else return false;
}
function adjustVideoProportions() {
// resize overlay and video if proportions of video are not 4:3
// keep same height, just change width
var proportion = vid.videoWidth/vid.videoHeight;
vid_width = Math.round(vid_height * proportion);
vid.width = vid_width;
overlay.width = vid_width;
}
function gumSuccess( stream ) {
// add camera stream if getUserMedia succeeded
if ("srcObject" in vid) {
vid.srcObject = stream;
} else {
vid.src = (window.URL && window.URL.createObjectURL(stream));
}
vid.onloadedmetadata = function() {
adjustVideoProportions();
vid.play();
}
vid.onresize = function() {
adjustVideoProportions();
if (trackingStarted) {
ctrack.stop();
ctrack.reset();
ctrack.start(vid);
}
}
}
function gumFail() {
// fall back to video if getUserMedia failed
insertAltVideo(vid);
document.getElementById('gum').className = "hide";
document.getElementById('nogum').className = "nohide";
alert("There was some problem trying to fetch video from your webcam, using a fallback video instead.");
}
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
window.URL = window.URL || window.webkitURL || window.msURL || window.mozURL;
// set up video
if (navigator.mediaDevices) {
navigator.mediaDevices.getUserMedia({video : true}).then(gumSuccess).catch(gumFail);
} else if (navigator.getUserMedia) {
navigator.getUserMedia({video : true}, gumSuccess, gumFail);
} else {
insertAltVideo(vid);
document.getElementById('gum').className = "hide";
document.getElementById('nogum').className = "nohide";
alert("Your browser does not seem to support getUserMedia, using a fallback video instead.");
}
vid.addEventListener('canplay', enablestart, false);
/*********** Code for face tracking *********/
var ctrack = new clm.tracker();
ctrack.init();
var trackingStarted = false;
function startVideo() {
// start video
vid.play();
// start tracking
ctrack.start(vid);
trackingStarted = true;
// start loop to draw face
drawLoop();
}
function drawLoop() {
requestAnimFrame(drawLoop);
overlayCC.clearRect(0, 0, vid_width, vid_height);
//psrElement.innerHTML = "score :" + ctrack.getScore().toFixed(4);
if (ctrack.getCurrentPosition()) {
ctrack.draw(overlay);
}
}
/*********** Code for stats **********/
stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.top = '0px';
document.getElementById('container').appendChild( stats.domElement );
// update stats on every iteration
document.addEventListener('clmtrackrIteration', function(event) {
stats.update();
}, false);
</script>
</div>
</body><div></div></html>