-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
152 lines (125 loc) · 4.58 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
<!DOCTYPE HTML>
<!--
Identity by HTML5 UP
html5up.net | @ajlkn
Free for personal and commercial use under the CCA 3.0 license (html5up.net/license)
-->
<html>
<head>
<title>Posturewatch</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<link rel="stylesheet" href="assets/css/main.css" />
<noscript><link rel="stylesheet" href="assets/css/noscript.css" /></noscript>
</head>
<body class="is-preload">
<!-- Wrapper -->
<div id="wrapper">
<!-- Main -->
<section id="main">
<header>
<span class="avatar">
<video id="_webcam" style="display: none;" playsinline></video>
<canvas id="_imageData"></canvas>
</span>
<h1 id="status">Status</h1>
<p id="status-sub">Status details</p>
</header>
<footer id="controls">
<ul class="icons">
<li><a href="#" onclick="calibrate()" class="fa-crosshairs">Recalibrate</a></li>
</ul>
</footer>
<div class="mini">
<h2>Hello!</h2>
This is a quick thing I whipped up to sit straight at work.<br/>
The source code is available on
<a href="https://github.com/rpolyano/posturewatch">GitHub</a>.<br/>
<br/>
<br/>
<h2>Privacy</h2>
This application is entirely client side. That means it runs<br/>
in your browser. Nothing is stored because there is no server<br/>
and no database. Javascript is required though.
</div>
</section>
<!-- Footer -->
<footer id="footer">
<ul class="copyright">
<li>© Roman Polyanovsky</li><li>Design: <a href="http://html5up.net">HTML5 UP</a></li>
</ul>
</footer>
</div>
<!-- Scripts -->
<script>
if ('addEventListener' in window) {
window.addEventListener('load', function() { document.body.className = document.body.className.replace(/\bis-preload\b/, ''); });
document.body.className += (navigator.userAgent.match(/(MSIE|rv:11\.0)/) ? ' is-ie' : '');
}
</script>
<script src="js/utils/BRFv4Stats.js"></script>
<script src="js/Tone.min.js"></script>
<script src="js/BRFv4DemoMinimalWebcam.js"></script>
<script src="js/Posture.js"></script>
<script>
var tiltSpan = document.getElementById('_tilt');
var noseTipSpan = document.getElementById('_noseTipY');
var postureStateSpan = document.getElementById('_postureState');
var statusSpan = document.getElementById('status');
var statusSubSpan = document.getElementById('status-sub');
var postureY = 0;
var chinY = 0;
function drawOverlay(ctx) {
ctx.fillStyle = 'rgba(50, 50, 255, 0.5)';
ctx.fillRect(0, postureY - 2, ctx.canvas.clientWidth, 4);
//ctx.fillStyle = 'rgba(50, 255, 50, 0.5)';
//ctx.fillRect(0, goodPostureY, ctx.canvas.clientWidth, badPostureY);
ctx.fillStyle = 'rgba(255, 0, 0, 0.5)';
ctx.fillRect(0, badPostureY, ctx.canvas.clientWidth, ctx.canvas.clientHeight - badPostureY);
}
// 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) {
if (k == 60) {
imageDataCtx.beginPath();
imageDataCtx.arc(face.vertices[k], face.vertices[k + 1], 2, 0, 2 * Math.PI);
imageDataCtx.stroke();
}
}
}
}
postureY = face.vertices[61];
chinY = face.vertices[133]
tick()
drawOverlay(imageDataCtx);
};
onResize = function () {
// fill whole browser
var imageData = document.getElementById("_imageData");
var ww = 640;
var wh = 480;
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>