-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
62 lines (59 loc) · 1.65 KB
/
index.html
File metadata and controls
62 lines (59 loc) · 1.65 KB
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
<!DOCTYPE html>
<html lang="en">
<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>Face Tracking</title>
<style>
video,
canvas {
position: absolute;
border: 1px solid red;
}
</style>
</head>
<body>
<video
id="video"
width="320"
height="240"
preload
autoplay
loop
muted
src=""
></video>
<canvas id="canvas" width="320" height="240"> </canvas>
<script src="tracking-min.js"></script>
<script src="data/face-min.js"></script>
<script>
function init() {
const video = document.getElementById("video")
const canvas = document.getElementById("canvas")
const context = canvas.getContext("2d")
const tracker = new tracking.ObjectTracker("face")
tracking.track("#video", tracker, { camera: true })
tracker.on("track", event => {
context.clearRect(0, 0, canvas.width, canvas.height)
event.data.forEach(rect => {
context.strokeStyle = "#ff0000"
context.lineWidth = 2
context.strokeRect(rect.x, rect.y, rect.width, rect.height)
context.fillText(
`x: ${rect.x} w: ${rect.width}`,
rect.x + rect.width + 20,
rect.y + 20
)
context.fillText(
`y: ${rect.y} h: ${rect.height}`,
rect.x + rect.width + 20,
rect.y + 40
)
})
})
}
window.onload = init()
</script>
</body>
</html>