-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebcam.js
44 lines (31 loc) · 1.23 KB
/
webcam.js
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
function video_s(){
//var imag;
'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');
processFile(imag.src);
// console.log(imag.src);
}
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;
});
}
// processFile(imag.src);
}