-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
75 lines (69 loc) · 2 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
<html>
<head>
<script src="hog.js"></script>
</head>
<body>
<video autoplay style="display:none;"></video>
<script>
var errorCallback = function(e) {
console.log('Reeeejected!', e);
};
navigator.getUserMedia = navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||
navigator.msGetUserMedia;
var video = document.querySelector('video');
var width;
var height;
function timerCallback(vid){
if (video.paused || video.ended) {
return;
}
computeFrame(vid);
setTimeout(function () {
timerCallback(vid);
}, 0);
}
computed = false;
var computeFrame = function(vid) {
c1 = document.getElementById("c1");
ctx1 = c1.getContext("2d");
c2 = document.getElementById("c2");
ctx2 = c2.getContext("2d");
c3 = document.getElementById("c3");
ctx3 = c3.getContext("2d");
ctx1.drawImage(video, 0, 0, width, height);
var frame = ctx1.getImageData(0, 0, width, height);
var l = frame.data.length / 4;
if (!computed) {
hog(width, height, 8, frame, ctx3);
//computed = true;
}
for (var i = 0; i < l; i++) {
frame.data[i * 4 + 0] = 10;
frame.data[i * 4 + 1] = 10;
frame.data[i * 4 + 2] = 10;
//if (g < 50 && r < 50 && b < 50)
// frame.data[i * 4 + 3] = 0;
}
ctx2.putImageData(frame, 0, 0);
return;
}
if (navigator.getUserMedia) {
navigator.getUserMedia({audio: true, video: true}, function(stream) {
video.src = window.URL.createObjectURL(stream);
video.addEventListener("play", function() {
width = video.videoWidth / 2;
height = video.videoHeight / 2;
timerCallback(this);
}, false);
}, errorCallback);
} else {
video.src = 'somevideo.webm'; // fallback.
}
</script>
<canvas id="c1" width="1080" height="720" style="display:none;"></canvas>
<canvas id="c2" width="1080" height="720"></canvas>
<canvas id="c3" width="1080" height="720"></canvas>
</body>
</html>