Sunday, 23 April 2017

JavaScript: Read WebCam and take snap shot

JavaScript: Read WebCam and take snap shot


<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>

</head>
<body>
<video id="video"></video>
<canvas id="canvas"></canvas><br>
<button onclick="snap();">Snap</button>
<script type="text/javascript">
alert("coming11");
var video = document.getElementById('video');
var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');
alert("coming22");
navigator.getUserMedia = navigator.getUserMedia ||
navigator.webkidGetUserMedia ||
navigator.monzGetUserMedia ||
navigator.oGetUserMedia ||
navigator.msGetUserMedia;
alert("coming3");
if(navigator.getUserMedia){
navigator.getUserMedia({video:true}, streamWebCam, throwError);
}

function streamWebCam (stream) {
video.src = wendow.URL.createObjectURL(stream);
video.play();
}

function throwError (e){
alert(e.name);
}

function snap(){
canvas.width=video.clientWidth;
canvas.height=video.height;
canvas.drawImage(video,0,0);
}
</script>
</body>
</html>

https://www.youtube.com/watch?v=K_NP_a78Jpk

Webcam integrating with java code - http://webcam-capture.sarxos.pl/