-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
122 lines (119 loc) · 4.31 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
<!DOCTYPE html>
<html lang="zh-TW">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta http-equiv="X-UA-Compatible" content="ie=edge"/>
<title>Hand Track Test - August - Let's Write</title>
<link rel="canonical" href="https://letswritetw.github.io/medium-handtrack/"/>
<meta property="og:url" content="https://letswritetw.github.io/medium-handtrack/"/>
<meta property="og:site_name" content="Let's Write"/>
<meta property="og:title" content="Hand Track Test - August - Let's Write"/>
<meta itemprop="name" content="Hand Track Test - August - Let's Write"/>
<meta name="description" content="第一次測試handtrack.js,之後想想能拿來做什麼……"/>
<meta property="og:description" content="第一次測試handtrack.js,之後想想能拿來做什麼……"/>
<meta itemprop="description" content="第一次測試handtrack.js,之後想想能拿來做什麼……"/>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"/>
<style>
html, body, .container {
margin: 0;
padding: 0;
width: 100vw;
height: 100vh;
overflow: hidden;
}
#video {
display: none;
}
#canvas {
width: 100%;
max-width: 100%;
}
</style>
<link rel="shortcut icon" href="https://letswritetw.github.io/letswritetw/dist/img/logo_512.png"/>
<!-- Google Tag Manager-->
<script>
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-PGQ9WQT');
</script>
</head>
<body>
<!-- Google Tag Manager (noscript)-->
<noscript>
<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-PGQ9WQT" height="0" width="0" style="display:none;visibility:hidden"></iframe>
</noscript>
<div class="container-fluid" id="app">
<div class="row pt-3">
<div class="video col-8">
<video id="video"></video>
<canvas id="canvas"></canvas>
</div>
<div class="info col-4">
<div class="card">
<div class="card-header">偵測到的「手」資訊</div>
<ul class="list-group list-group-flush" v-for="box in boxs">
<li class="list-group-item" v-for="(b, i) in box.bbox">{{ tag(i) }} {{ Math.floor(b) }}</li>
<hr/>
</ul>
</div>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.10/vue.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/handtrackjs/dist/handtrack.min.js"></script>
<script>
const HandTrack = new Vue({
el: '#app',
data: {
boxs: null
},
methods: {
tag(i) {
switch(i) {
case 0:
return 'X:';
break;
case 1:
return 'Y:';
break;
case 2:
return '寬:';
break;
case 3:
return '長:';
break;
}
}
},
mounted() {
const video = document.getElementById('video');
const canvas = document.getElementById('canvas');
const context = canvas.getContext('2d');
const _this = this;
function runDetection() {
model.detect(video).then(predictions => {
_this.boxs = predictions;
model.renderPredictions(predictions, canvas, context, video);
requestAnimationFrame(runDetection);
});
}
handTrack
.startVideo(video)
.then(res => {
if(res) runDetection()
else console.log('err')
});
handTrack.load({
flipHorizontal: true,
maxNumBoxes: 20,
iouThreshold: 0.5,
scoreThreshold: 0.6,
}).then(lmodel => model = lmodel);
}
})
</script>
</body>
</html>