Advertisement
BrU32

JS Canvas Webcam Auto Check If it Is Covered/Respond W Pic

Feb 11th, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. <center>
  2. <body bgcolor="black">
  3. <video id="video" width="640" height="480" autoplay></video>
  4. <b>
  5. <button id="t" hidden><b>Test Now!!</button>
  6. <canvas id="canvas" width="640" height="480"></canvas>
  7. <script>
  8. document.addEventListener("DOMContentLoaded", function() {
  9. var canvas = document.getElementById('canvas');
  10. var context = canvas.getContext('2d');
  11. var video = document.getElementById('video');
  12. var mediaConfig = { video: true,audio:false};
  13. var errBack = function(e) {
  14. console.log('An error has occurred!', e)
  15. };
  16. if(navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
  17. navigator.mediaDevices.getUserMedia(mediaConfig).then(function(stream) {
  18. video.src = window.URL.createObjectURL(stream);
  19. video.play();
  20. });
  21. }
  22. var cct=getBase64Image(video)
  23. var ctt=getBase64Image(video);
  24. var doc=document.getElementById('t');
  25. document.addEventListener('mousemove', function() {
  26.  
  27. context.drawImage(video, 0, 0, 640, 480);
  28. ctt=getBase64Image(video);
  29. var dexrnd=Math
  30. if(ctt>491990){
  31.  
  32. Load_Img('https://api.audiotool.com/track/dj_bru_-_acid_step/2/cover/640x480.jpg?showDefault=true')
  33. return 0;
  34. }else{
  35. // alert('Webcam Is Visible!!')
  36. }
  37.  
  38. });
  39. }, false);
  40. function getBase64Image(img) {
  41.  
  42. var canvas = document.createElement("canvas");
  43. canvas.width = img.width;
  44. canvas.height = img.height;
  45.  
  46. var ctx = canvas.getContext("2d");
  47. ctx.drawImage(img, 0, 0);
  48.  
  49. var dataURL = canvas.toDataURL("image/png");
  50.  
  51. return dataURL.length-4000;
  52. }
  53. function Load_Img(path){
  54. var h,w;
  55. h=('500');
  56. w=('500')
  57. var canvas = document.getElementById("canvas");
  58. var ctx = canvas.getContext("2d");
  59. var img = new Image();
  60. img.src=(path);
  61. ctx.drawImage(img, 1, 1,h,w);
  62.  
  63. }
  64. </script>
  65.  
  66. </body>
  67. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement