Advertisement
cfjedimaster

Untitled

Mar 19th, 2012
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 2.89 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
  5.  
  6. <style scoped>
  7.     video { -webkit-transform: scaleX(1); }
  8.     p { text-align: center; }
  9. </style>
  10. <script>
  11. var faceKey = "9a348d36a65e0b8ca3aa010eeb1b395f";
  12. var faceSecret = "6065c6275fca70d187c0d78e2e94d472";
  13.  
  14. function init() {
  15.  
  16.     if (navigator.webkitGetUserMedia) {
  17.  
  18.         navigator.webkitGetUserMedia('video', gotStream, noStream);
  19.  
  20.         var video = document.getElementById('monitor');
  21.         var canvas = document.getElementById('photo');
  22.  
  23.         function gotStream(stream) {
  24.  
  25.             video.src = webkitURL.createObjectURL(stream);
  26.             video.onerror = function () {
  27.                 stream.stop();
  28.                 streamError();
  29.             };
  30.             document.getElementById('splash').hidden = true;
  31.             document.getElementById('app').hidden = false;
  32.             $("#snapshotbutton").click(snapshot);
  33.         }
  34.  
  35.         function noStream() {
  36.             document.getElementById('errorMessage').textContent = 'No camera available.';
  37.         }
  38.  
  39.         function streamError() {
  40.             document.getElementById('errorMessage').textContent = 'Camera error.';
  41.         }
  42.  
  43.         function snapshot() {
  44.             canvas.width = video.videoWidth;
  45.             canvas.height = video.videoHeight;
  46.             canvas.getContext('2d').drawImage(video, 0, 0);
  47.             context = canvas.getContext("2d");
  48. //          imgdata = canvas.toDataURL("image/jpg");
  49.             imagedata = context.getImageData(0, 0, canvas.width,canvas.height);
  50.  
  51.                  var canvaspixelarray = imagedata.data;
  52.  
  53.  
  54.                  var canvaspixellen = canvaspixelarray.length;
  55.                  var bytearray = new Uint8Array(canvaspixellen);
  56. var s = "";
  57.                  for (var i=0;i<canvaspixellen;++i) {
  58.                       bytearray[i] = canvaspixelarray[i];
  59.                      s+= canvaspixelarray[i];
  60.                  }
  61.  
  62.  
  63.             console.log("ok");
  64.  
  65.             formdata = new FormData();
  66.             formdata.append("image",s);
  67.  
  68.             //begin face.com
  69.             /*
  70.             $.post("http://api.face.com/faces/detect.json?api_key="+faceKey+"&api_secret="+faceSecret+"&callback=", formdata,function(res, code) {
  71.                 console.dir(res);
  72.             });
  73.             */
  74.             $.ajax({
  75.                     url: "http://api.face.com/faces/detect.json?api_key="+faceKey+"&api_secret="+faceSecret+"&callback=",
  76.                     type: "POST",
  77.                     data: formdata,
  78.                     processData: false,
  79.                     contentType: false,
  80.                     success: function (res) {
  81.                         alert('wt');
  82.                     }
  83.                 });
  84.  
  85.         }
  86.  
  87.         function testme() {
  88.             console.log("no way");
  89.         }
  90.  
  91.     } else {
  92.         document.getElementById('errorMessage').textContent = 'No native camera support available.';
  93.     }
  94.  
  95. }
  96. </script>
  97. </head>
  98. <body onload="init()">
  99.  
  100.  
  101. <h1>Webkit WebRTC Video Element Demo</h1>
  102. <section id="splash">
  103.     <p id="errorMessage">Loading...</p>
  104. </section>
  105. <section id="app" hidden>
  106.     <p><video id="monitor" autoplay></video> <canvas id="photo"></canvas></p>
  107.     <p><input value="say cheese!" type=button value="&#x1F4F7;" id="snapshotbutton">
  108. </section>
  109.  
  110.  
  111.  
  112. <p>
  113. Credit: http://miernicki.com/cam.html
  114. </p>
  115.  
  116. </body>
  117. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement