Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Augmented Reality.js

Augmented Reality.js

Eduardo Lundgren

November 20, 2013
Tweet

More Decks by Eduardo Lundgren

Other Decks in Technology

Transcript

  1. STEP 2 Play webcam's content into a video element function

    onSuccess(stream) { var video = document.querySelector('video'); video.src = window.URL.createObjectURL(stream); video.onloadedmetadata = function(e) { // Ready }; } Friday, October 25, 13
  2. STEP 1 COLOR TRACKING Import tracking.js core <script src="tracking.js"></script> Import

    tracking.js color module <script src="tracker/color.js"></script> Friday, October 25, 13
  3. STEP 2 COLOR TRACKING Gets user's camera and renders it

    var videoCamera = new tracking .VideoCamera() .render(); Friday, October 25, 13
  4. STEP 3 COLOR TRACKING Register tracking for yellow color videoCamera.track({

    type: 'color', color: 'yellow', onFound: function() {}, onNotFound: function() {} }); Friday, October 25, 13
  5. STEP 4 COLOR TRACKING Paint all detected pixels onFound: function(track)

    { var pixels = track.pixels, ctx = videoCamera.canvas.context; for (var i = 0, len = pixels.length; i < len; i += 2) { ctx.fillStyle = "rgb(255,0,255)"; ctx.fillRect(pixels[i], pixels[i+1], 2, 2); } ctx.fillStyle = "rgb(0,0,0)"; ctx.fillRect(track.x, track.y, 5, 5); } Friday, October 25, 13
  6. STEP 1 FACE DETECTION Register human tracking for frontal face

    videoCamera.track({ type: 'human', data: 'frontal_face', onFound: function() {}, onNotFound: function() {} }); Friday, October 25, 13
  7. STEP 2 FACE DETECTION Paint all detected faces rectangles onFound:

    function(track) { for (var i = 0, len = track.length; i < len; i++) { var rect = track[i]; ctx.strokeStyle = "rgb(0,255,0)"; ctx.strokeRect( rect.x, rect.y, rect.size, rect.size); } } Friday, October 25, 13