-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.html
56 lines (47 loc) · 1.4 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
<!DOCTYPE html>
<html>
<head>
<title>WebCam Effects</title>
</head>
<body>
<video id="video-stream" style="display:none;" width=545 height=344></video>
<canvas id="canvas-video" width=545 height=344></canvas>
<canvas id="canvas-effects" width=545 height=344></canvas>
<script type="text/javascript">
(function(){
var video = document.getElementById('video-stream'),
canvas = document.getElementById('canvas-video'),
canvasEffect = document.getElementById('canvas-effects'),
ctx = canvas.getContext('2d'),
ctxEffects = canvasEffect.getContext('2d'),
processor = new Worker('image-worker.js');
w = video.width,
h = video.height;
/* Setup WebWorker messaging */
processor.onmessage = function(event){
ctxEffects.putImageData(event.data.dstData, 0, 0);
};
/* Setup video stream and canvas */
navigator.getUserMedia =
navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||
navigator.msGetUserMedia;
navigator.getUserMedia({video:true}, function(stream){
video.src = URL.createObjectURL(stream);
video.play();
setInterval(render, 10);
}, function(error){
console.log('error', error);
});
var render = function(){
ctx.drawImage(video, 0, 0, w, h);
var srcData = ctx.getImageData(0,0,w,h);
processor.postMessage({
imageData: srcData
});
};
})();
</script>
</body>
</html>