-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
85 lines (85 loc) · 2.67 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
<!DOCTYPE html>
<html lang="en" crossOriginIsolated="true">
<head>
<meta charset="utf-8" />
<title>multiple object tracking</title>
<script type="text/javascript" src="camshift.js"></script>
</head>
<body>
<h2>CamShift Example</h2>
<div>
<div class="control">
<button id="startAndStop" disabled>Start</button>
</div>
</div>
<p class="err" id="errorMessage"></p>
<div>
<table cellpadding="0" cellspacing="0" width="0" border="0">
<tr>
<td>
<video id="videoInput" width="640" height="640" muted loop></video>
</td>
<td>
<canvas id="canvasOutput" width="640" height="640"></canvas>
</td>
<td>
<canvas id="canvasOutput2" width="320" height="240"></canvas>
</td>
<td></td>
<td></td>
</tr>
<tr>
<td>
<div class="caption">videoInput</div>
</td>
<td>
<div class="caption">canvasOutput</div>
</td>
<td></td>
</tr>
<tr>
<canvas id="templateCanvasInput" width="320" height="240"></canvas>
</tr>
</table>
</div>
<script src="https://webrtc.github.io/adapter/adapter-5.0.4.js" type="text/javascript"></script>
<script src="utils.js" type="text/javascript"></script>
<script type="text/javascript">
let utils = new Utils("errorMessage");
let streaming = false;
let videoInput = document.getElementById("videoInput");
let startAndStop = document.getElementById("startAndStop");
let canvasOutput = document.getElementById("canvasOutput");
let canvasContext = canvasOutput.getContext("2d");
startAndStop.addEventListener("click", () => {
if (!streaming) {
utils.clearError();
videoInput.play().then(() => {
onVideoStarted();
});
} else {
videoInput.currentTime = 0;
onVideoStopped();
}
});
function onVideoStarted() {
streaming = true;
startAndStop.innerText = "Stop";
videoInput.height =
videoInput.width * (videoInput.videoHeight / videoInput.videoWidth);
window.ImageProcessors.CamShift();
}
function onVideoStopped() {
streaming = false;
canvasContext.clearRect(0, 0, canvasOutput.width, canvasOutput.height);
startAndStop.innerText = "Start";
}
utils.loadOpenCv(() => {
videoInput.addEventListener("canplay", () => {
startAndStop.removeAttribute("disabled");
});
videoInput.src = "assets/video1.mp4";
});
</script>
</body>
</html>