-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwalk.php
61 lines (46 loc) · 1.54 KB
/
walk.php
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Capturing environment</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
video, img {
max-width:100%;
}
</style>
</head>
<body>
<!--------------------------This code is basically using the getUserMedia to access the webcam------------->
<video autoplay></video>
<script>
(function() {
'use strict'; // to ask if user allows his webcam to be used
var video = document.querySelector('video'), canvas;
function pic() {
var imag = document.querySelector('img') || document.createElement('img');
var context;
var width = video.offsetWidth, height = video.offsetHeight;
canvas = canvas || document.createElement('canvas');
canvas.width = width;
canvas.height = height;
context = canvas.getContext('2d');
context.drawImage(video, 0, 0, width, height);
imag.src = canvas.toDataURL('image/png');
document.body.appendChild(imag);
console.log('hello')
}
if (navigator.mediaDevices) {
navigator.mediaDevices.getUserMedia({video: true})
.then(function(stream) {
video.src = window.URL.createObjectURL(stream);
video.addEventListener('click', pic);
})
.catch(function(error) {
document.body.textContent = 'Camera cannot be accessed. Error: ' + error.name;
});
}
})();
</script>
</body>
</html>