-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
459 lines (432 loc) · 16.8 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
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
<!DOCTYPE html>
<html lang="en" style="scroll-behavior: smooth">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Pose-Bot | Correct it!</title>
<!-- <link rel="stylesheet" href="styles.css" /> -->
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2"
crossorigin="anonymous"
/>
<script
src="https://code.jquery.com/jquery-3.5.1.slim.min.js"
integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj"
crossorigin="anonymous"
></script>
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"
integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN"
crossorigin="anonymous"
></script>
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"
integrity="sha384-w1Q4orYjBQndcko6MimVbzY0tgp4pWB4lZ7lr30WKz0vr/aWKhXdBNmNb5D92v7s"
crossorigin="anonymous"
></script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/[email protected]/dist/tf.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@teachablemachine/[email protected]/dist/teachablemachine-pose.min.js"></script>
<script type="text/javascript">
// More API functions here:
// https://github.com/googlecreativelab/teachablemachine-community/tree/master/libraries/pose
console.log = () => {};
// the link to your model provided by Teachable Machine export panel
const URL = "./TestFolder/TestTeachableModel/my_model/";
let model, webcam, ctx, labelContainer, maxPredictions;
let group = [];
let toggle = false;
async function init() {
toggle = true;
const modelURL = URL + "model.json";
const metadataURL = URL + "metadata.json";
// load the model and metadata
// Refer to tmImage.loadFromFiles() in the API to support files from a file picker
// Note: the pose library adds a tmPose object to your window (window.tmPose)
model = await tmPose.load(modelURL, metadataURL);
// you need to create File objects, like with file input elements (<input type="file" ...>)
// const uploadModel = document.getElementById('upload-model');
// const uploadWeights = document.getElementById('upload-weights');
// const uploadMetadata = document.getElementById('upload-metadata');
// model = await tmPose.loadFromFiles(uploadModel.files[0], uploadWeights.files[0], uploadMetadata.files[0])
maxPredictions = model.getTotalClasses();
// Convenience function to setup a webcam
let mql = window.matchMedia("(max-width: 570px)");
const size = !mql ? window.innerWidth * 0.6 : window.innerHeight * 0.48;
const flip = true; // whether to flip the webcam
webcam = new tmPose.Webcam(size, size, flip); // width, height, flip
await webcam.setup(); // request access to the webcam
await webcam.play();
window.requestAnimationFrame(loop);
// append/get elements to the DOM
const canvas = document.getElementById("canvas");
canvas.width = !mql
? window.innerWidth * 0.5
: window.innerHeight * 0.45;
canvas.height = !mql
? window.innerWidth * 0.5
: window.innerHeight * 0.45;
ctx = canvas.getContext("2d");
labelContainer = document.getElementById("label-container");
for (let i = 0; i < maxPredictions; i++) {
// and class labels
labelContainer.appendChild(document.createElement("div"));
}
}
async function loop(timestamp) {
console.log(timestamp);
webcam.update(); // update the webcam frame
await predict();
if (toggle) {
window.requestAnimationFrame(loop);
}
}
async function predict() {
// Prediction #1: run input through posenet
// estimatePose can take in an image, video or canvas html element
const { pose, posenetOutput } = await model.estimatePose(webcam.canvas);
// Prediction 2: run input through teachable machine classification model
const prediction = await model.predict(posenetOutput);
// console.log(group)
if (group.length < 100) {
group.push(prediction);
} else {
group.shift();
group.push(prediction);
}
checkPosture(group);
// console.log(group)
for (let i = 0; i < maxPredictions; i++) {
const classPrediction =
prediction[i].className +
": " +
prediction[i].probability.toFixed(2);
// labelContainer.childNodes[i].innerHTML = classPrediction;
}
// finally draw the poses
drawPose(pose);
}
function notifyMe(message) {
// Let's check if the browser supports notifications
const startover = function () {
// console.log('NOTIFICATION CLICKed')
toggle = true;
// console.log(toggle)
window.requestAnimationFrame(loop);
group = [];
};
if (!("Notification" in window)) {
alert("This browser does not support desktop notification");
}
// Let's check whether notification permissions have already been granted
else if (Notification.permission === "granted") {
// If it's okay let's create a notification
var title = "Posture";
var icon =
"https://homepages.cae.wisc.edu/~ece533/images/airplane.png";
var body =
message + ". Please sit in correctly and click this notification";
var tag = "pose-bot";
var notification = new Notification(title, { body, icon, tag });
}
// Otherwise, we need to ask the user for permission
else if (Notification.permission !== "denied") {
Notification.requestPermission().then(function (permission) {
// If the user accepts, let's create a notification
if (permission === "granted") {
var notification = new Notification(title, { body, icon, tag });
}
});
}
notification.onclick = startover;
notification.onclose = startover;
// At last, if the user has denied notifications, and you
// want to be respectful there is no need to bother them any more.
}
function checkPosture(posturegroup) {
//group
console.log(group);
goodposture = (
posturegroup.reduce((sum, data) => {
return sum + data[0].probability;
}, 0) / 100
).toFixed(3);
badposture = (
posturegroup.reduce((sum, data) => {
return sum + data[1].probability;
}, 0) / 100
).toFixed(3);
nearscreen = (
posturegroup.reduce((sum, data) => {
return sum + data[2].probability;
}, 0) / 100
).toFixed(3);
// console.log('good: ',goodposture,' bad: ', badposture)
// document.getElementById('good').innerHTML = 'Good: ' + goodposture
// document.getElementById('bad').innerHTML = 'Bad: ' + badposture
console.log({ goodposture, badposture, nearscreen });
if (badposture >= 0.9) {
// console.log('bad posture')
toggle = false;
group = [];
notifyMe("Correct your posture");
}
if (nearscreen >= 0.9) {
// console.log('bad posture')
toggle = false;
group = [];
notifyMe("get away from screen");
}
}
function drawPose(pose) {
if (webcam.canvas) {
ctx.drawImage(webcam.canvas, 0, 0);
// draw the keypoints and skeleton
if (pose) {
const minPartConfidence = 0.5;
tmPose.drawKeypoints(pose.keypoints, minPartConfidence, ctx);
tmPose.drawSkeleton(pose.keypoints, minPartConfidence, ctx);
}
}
}
</script>
</head>
<style>
* {
/* border: 1px dotted green; */
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
main > img {
height: 300px;
}
/* width */
::-webkit-scrollbar {
width: 10px;
}
/* Track */
::-webkit-scrollbar-track {
background: #f1f1f1;
}
/* Handle */
::-webkit-scrollbar-thumb {
background: #3ba2c2;
}
/* Handle on hover */
::-webkit-scrollbar-thumb:hover {
background: #286274;
}
.btn-primary {
background-color: #3b5fc2;
}
.btn-primary:hover {
background-color: #4569ce;
}
</style>
<body class="" style="background-color: #232128">
<div class="landing text-light">
<!-- Header with logo position: sticky/fixed -->
<header class="text-left">
<div class="logo-div">
<img src="./assets//img/logo.jpeg" alt="Logo" class="img img-fluid" />
</div>
</header>
<!-- Main screen -->
<main>
<div class="text-center">
<div class="d-flex flex-direction-row">
<div
id="demo"
class="carousel d-flex align-items-center"
data-ride="carousel"
style="min-width: 700px; min-height: 600px"
>
<ul class="carousel-indicators">
<li data-target="#demo" data-slide-to="0" class="active"></li>
<li data-target="#demo" data-slide-to="1"></li>
<li data-target="#demo" data-slide-to="2"></li>
</ul>
<div class="carousel-inner">
<div class="carousel-item active">
<img src="./assets/img/1.png" alt="Los Angeles" />
<div class="carousel-caption">
<!-- <h3 class="text-dark">Back pain?</h3>
<p class="text-dark">
The reason could be bad sitting posture
</p> -->
</div>
</div>
<div class="carousel-item">
<img
width="600"
style="margin: 100px 0"
src="https://buffer.com/resources/content/images/resources/wp-content/uploads/2013/11/Screen-Shot-2013-11-11-at-8.09.23-AM.png"
alt="Chicago"
/>
<div class="carousel-caption">
<!-- <h3>Chicago</h3>
<p>Thank you, Chicago!</p> -->
</div>
</div>
<div class="carousel-item">
<img
width="600"
src="https://scitechdaily.com/images/Human-Spinal-Cord.jpg"
width="80%"
alt="New York"
/>
<div class="carousel-caption">
<!-- <h3>New York</h3>
<p>We love the Big Apple!</p> -->
</div>
</div>
<div class="carousel-item">
<img
src="https://images.squarespace-cdn.com/content/v1/5601a1b2e4b0eaa138babe0c/1460050490690-ZYDR6C3LGLX0T3P06ZMU/ke17ZwdGBToddI8pDm48kN_oxOEgSHwyifItmiijwgFZw-zPPgdn4jUwVcJE1ZvWEtT5uBSRWt4vQZAgTJucoTqqXjS3CfNDSuuf31e0tVFCGwsdcQRbmn_Ph9Y1L2ib5ngnVgMZdvrTksiDaHAyK6EcAfnVBrEqrgp1UxUHGkY/bad+posture.png?format=1500w"
alt="Chicago"
/>
<div class="carousel-caption">
<!-- <h3>Chicago</h3>
<p>Thank you, Chicago!</p> -->
</div>
</div>
</div>
<a class="carousel-control-prev" href="#demo" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#demo" data-slide="next">
<span class="carousel-control-next-icon"></span>
</a>
</div>
<div
class="d-flex flex-column justify-content-center align-items-center p-5"
>
<p class="display-1">Our Vision</p>
<h4 style="margin-top: 2em">
We created this application to help users maintain a good
posture and save from early signs of postural imbalance and
protect your vision, this application uses a image classifier
from Google API. It notifies the user when he/she is sitting in
a bad position or is too close to the screen. We have also
included EchoAR models to educate the children about the harms
of sitting in a bad position and importance of healthy eyes 👀.
</h4>
<a href="#monitor">
<button
class="btn btn-primary m-2 font-weight-bold px-5"
style="border-radius: 9999px"
>
Try it Out
</button>
</a>
<a href="#models">
<button
type="button"
class="btn btn-primary m-2 font-weight-bold px-5"
style="border-radius: 999px"
>
Explore 3D AR Models
</button>
</a>
</div>
</div>
<div
id="monitor"
class="text-center d-flex flex-column justify-content-center align-items-center"
>
<canvas
style="
height: 50vh;
width: 50vh;
background-color: #3ba2c2;
border-radius: 50px;
margin-top: 15em;
"
id="canvas"
></canvas>
<div style="margin-bottom: 10em">
<button
class="font-weight-bold btn btn-primary px-5 text-light m-2"
style="border-radius: 9999px"
onclick="init()"
>
Monitor me.
</button>
<!-- Button trigger modal -->
</div>
</div>
</div>
</main>
<div id="models" class="d-flex flex-column p-5" style="margin: 10em 0">
<div>
<h2 class="text-center display-2">EchoAR Models</h2>
<div
class="d-flex flex-row justify-content-center align-items-center"
>
<div
class="d-flex flex-column mx-5 m-3 text-center align-items-center justify-content-center"
>
<img height="300" src="./assets/img/skeleton.jpeg" alt="" />
<h4>skeleton</h4>
<p><a href="https://go.echoar.xyz/3Rit">View Model</a></p>
</div>
<div
class="d-flex flex-column mx-5 m-3 text-center align-items-center justify-content-center"
>
<img height="300" src="./assets/img/heart.jpeg" alt="" />
<h4>heart</h4>
<p><a href="https://go.echoar.xyz/Mu5V">View Model</a></p>
</div>
</div>
</div>
<div class="d-flex flex-row">
<iframe
class="m-2"
width="100%"
height="480px"
src="https://poly.google.com/view/dBzk5erdQcg/embed?chrome=min"
frameborder="0"
style="border: none"
allowvr="yes"
allow="vr; xr; accelerometer; magnetometer; gyroscope; autoplay;"
allowfullscreen
mozallowfullscreen="true"
webkitallowfullscreen="true"
onmousewheel=""
></iframe>
</div>
</div>
<div
class="d-flex flex-column p-5 justify-content-center align-items-center"
style="margin: 15em 0"
>
<h1 class="display-2">The Team</h1>
<div class="d-flex flex-row text-center">
<div>
<img
class="img thumbnail mx-4"
src="https://avatars1.githubusercontent.com/u/31622972?s=460&u=c2ea190651b4ecf38bdc2b9937a057e7b696bfba&v=4"
/>
<h3 class="my-3">Aniket Singh Rawat</h3>
</div>
<div>
<img
class="img thumbnail mx-4"
src="https://avatars1.githubusercontent.com/u/59837325?s=460&u=95383e7cb90f583f51cf08fda740142021ba4e46&v=4"
/>
<h3 class="my-3">Apurva Sharma</h3>
</div>
<div>
<img
class="img thumbnail mx-4"
src="https://avatars1.githubusercontent.com/u/50591491?s=460&u=540db4411d6f8528c4aa560f94968e412c3680d0&v=4"
/>
<h3 class="my-3">Dev Sharma</h3>
</div>
</div>
</div>
</div>
<!-- Canvas with video -->
<!-- Posture Output -->
</body>
</html>