forked from hitsuji71gth/VirtualAfroHair
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
194 lines (169 loc) · 5.44 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
<!doctype html>
<html lang="en">
<head>
<title>HairStyle Checker</title>
<meta charset="utf-8">
<link href="./styles/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;
}
#sketch {
display: none;
}
#filter {
display: none;
}
h2 {
font-weight : 400;
}
.nogum {
display : none;
}
.btn {
font-family: 'Lato';
font-size: 16px;
}
.hide {
display : none;
}
.nohide {
display : block;
}
</style>
</head>
<body>
<script src="./js/jquery-2.0.3.min.js"></script>
<script src="./js/clmtrackr.min.js"></script>
<script src="./js/model_pca_20_svm.js"></script>
<div id="content">
<h2>Hairstyle Checker</h2>
<div id="container">
<video id="videoel" width="640" height="480" preload="auto" loop>
<!--<video id="videoel" width="320" height="240" preload="auto">-->
<!--<source src="./media/franck.ogv" type="video/ogg"/>-->
</video>
<canvas id="overlay" width="640" height="480"></canvas>
</div>
<input class="btn" type="button" value="wait, loading video" disabled="disabled" onclick="startVideo()" id="startbutton"></input>
<div id="mouse"></div>
<div id="faceposition">
<ul id="positionlist"></ul>
</div>
<script>
var vid = document.getElementById('videoel');
var overlay = document.getElementById('overlay');
var overlayCC = overlay.getContext('2d');
// overlay.onmousemove = function(e) {
// var rect = e.target.getBoundingClientRect();
// $("div#mouse").text((640 - e.clientX + rect.left) + ", " + (e.clientY - rect.top));
// }
var ctrack = new clm.tracker({useWebGL : true});
ctrack.init(pModel);
function enablestart() {
var startbutton = document.getElementById('startbutton');
startbutton.value = "start";
startbutton.disabled = null;
}
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() {
alert("There was some problem trying to fetch video from your webcam, using a fallback video instead.");
});
} else {
alert("Your browser does not seem to support getUserMedia, using a fallback video instead.");
}
vid.addEventListener('canplay', enablestart, false);
function startVideo() {
// start video
vid.play();
// start tracking
ctrack.start(vid);
// start loop to draw face
drawLoop();
}
var img = new Image();
img.src = "img/Image004.png";
img.onload = function() {
};
window.requestAnimFrame = window.requestAnimFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.msRequestAnimationFrame;
function drawLoop() {
window.requestAnimFrame(drawLoop);
overlayCC.clearRect(0, 0, 640, 480);
var positions = ctrack.getCurrentPosition();
if (positions) {
var x_pos19 = positions[19][0];
var y_pos19 = positions[19][1];
var x_pos15 = positions[15][0];
var expansion = (x_pos15 - x_pos19) / 140;
var x_img = x_pos19 - 140 * expansion;
var y_img = y_pos19 - 300 * expansion;
var length_img = 450 * expansion;
overlayCC.drawImage(img, x_img, y_img, length_img, length_img);
// ctrack.draw(overlay);
// overlayCC.beginPath();
// overlayCC.moveTo(positions[0][0], positions[0][1]);
// overlayCC.lineTo(positions[0][0], positions[20][1] - 30);
// overlayCC.lineTo(positions[14][0], positions[16][1] - 30);
// overlayCC.lineTo(positions[14][0], positions[14][1]);
// overlayCC.closePath();
// overlayCC.stroke();
$("ul#positionlist").empty();
for(var i=0; i<positions.length; i++) {
$("ul#positionlist").append("<li>position[" + i + "] = {" + positions[i][0] + ", " + positions[i][1] + "}</li>");
}
}
}
</script>
</div>
</body>
</html>