-
Notifications
You must be signed in to change notification settings - Fork 148
/
Copy pathminimalWebcam.html
79 lines (55 loc) · 1.93 KB
/
minimalWebcam.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Beyond Reality Face - BRFv4 - HTML5/Javascript - minimal webcam example</title>
<style>
html, body { width: 100%; height: 100%; background-color: #ffffff; margin: 0; padding: 0; overflow: hidden; }
</style>
</head>
<body>
<video id="_webcam" style="display: none;" playsinline></video>
<canvas id="_imageData"></canvas>
<script src="js/utils/BRFv4Stats.js"></script>
<script src="js/BRFv4DemoMinimalWebcam.js"></script>
<script>
// BRFv4DemoMinimal.js defines: var handleTrackingResults = function(brfv4, faces, imageDataCtx)
// Here we overwrite it. The initialization code for BRFv4 should always be similar,
// that's why we put it into its own file.
handleTrackingResults = function(
brfv4, // namespace
faces, // tracked faces
imageDataCtx // canvas context to draw into
) {
for(var i = 0; i < faces.length; i++) {
var face = faces[i];
if(face.state === brfv4.BRFState.FACE_TRACKING_START ||
face.state === brfv4.BRFState.FACE_TRACKING) {
imageDataCtx.strokeStyle = "#00a0ff";
for(var k = 0; k < face.vertices.length; k += 2) {
imageDataCtx.beginPath();
imageDataCtx.arc(face.vertices[k], face.vertices[k + 1], 2, 0, 2 * Math.PI);
imageDataCtx.stroke();
}
}
}
};
onResize = function () {
// fill whole browser
var imageData = document.getElementById("_imageData");
var ww = window.innerWidth;
var wh = window.innerHeight;
var s = wh / imageData.height;
if(imageData.width * s < ww) {
s = ww / imageData.width;
}
var iw = imageData.width * s;
var ih = imageData.height * s;
var ix = (ww - iw) * 0.5;
var iy = (wh - ih) * 0.5;
imageData.style.transformOrigin = "0% 0%";
imageData.style.transform = "matrix("+s+", 0, 0, "+s+", "+ix+", "+iy+")";
};
</script>
</body>
</html>