Advertisement
BrU32

JS Constant Cam Security Check V2

Mar 10th, 2017
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. <center>
  2.  
  3. <div id="container">
  4. <video autoplay id="video">
  5. </div>
  6.  
  7.  
  8. <canvas id="canvas" width="500" height="500"></canvas>
  9. <p>
  10.  
  11. <input type="button" value="Move Mouse Here!!" id="save" />
  12.  
  13.  
  14.  
  15. <script>
  16. var video = document.querySelector("#video");
  17.  
  18. // check for getUserMedia support
  19. navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia || navigator.oGetUserMedia;
  20.  
  21. if (navigator.getUserMedia) {
  22. // get webcam feed if available
  23. navigator.getUserMedia({video: true}, handleVideo, videoError);
  24. }
  25.  
  26. function handleVideo(stream) {
  27. // if found attach feed to video element
  28. video.src = window.URL.createObjectURL(stream);
  29. }
  30.  
  31. function videoError(e) {
  32. // no webcam found - do something
  33. }
  34. var v,canvas,context,w,h;
  35. var imgtag = document.getElementById('imgtag'); // get reference to img tag
  36. var select = document.getElementById('fileselect'); // get reference to file select input element
  37.  
  38. document.addEventListener('mousemove', function(){
  39. // when DOM loaded, get canvas 2D context and store width and height of element
  40. v = document.getElementById('video');
  41. canvas = document.getElementById('canvas');
  42. context = canvas.getContext('2d');
  43. w = canvas.width;
  44. h = canvas.height;
  45.  
  46. },777);
  47.  
  48. function draw(v,c,w,h) {
  49.  
  50. if(v.paused || v.ended) {
  51. return 0; // if no video, exit here
  52. }
  53. context.drawImage(v,120,0,w,h); // draw video feed to canvas
  54.  
  55. var uri = canvas.toDataURL("image/png").length; // convert canvas to data URI
  56.  
  57. if(uri>352000){ // uncomment line to log URI for testing
  58. alert('Person Detected!!');
  59. // imgtag.src = uri; // add URI to IMG tag src
  60. }
  61. }
  62. save.addEventListener('mousemove',function(e){
  63.  
  64. draw(v,context,w,h); // when save button is clicked, draw video feed to canvas
  65.  
  66. });
  67.  
  68. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement