Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Camera Capture with Additional Overlay

I have developed a WebApplication, which basically allows User to register and upload Photographs But As its a Mobile Ready web app, User can capture real time photo and upload it. Now I have been asked to check if its possible to provide a Human Like Overlay while capturing the picture, so in other words When User try to capture he can see a SHOULDER WITH HEAD OUTLINE on the screen, so he matches himself into the outline and capture it..

I m using HTML5 and do understand that it will be either through some plugin or else NATIVE APP (which doesnt help me in this case).

So Anyone out there tried such things or do know if we can do it or not ? (see attached to understand more ) enter image description here

Thank you in advance.

like image 691
Swapnil Avatar asked May 21 '16 01:05

Swapnil


1 Answers

That will depend on the devices you need to support.

For the ones that do support getUserMedia API, it's quite simple, you just have to position your overlay over the video stream you get from the camera, and take a snapshot of this video using a canvas.

navigator.mediaDevices.getUserMedia({
  video: true
})
.then(function(stream) {

  vid.onloadedmetadata = function() {
    this.width = overlay.width = this.videoWidth;
    this.height = overlay.height = this.videoHeight;
  }
  vid.srcObject = stream;
  vid.play();
  overlay.onclick = function() {
    var c = document.createElement('canvas');
    c.width = vid.videoWidth;
    c.height = vid.videoHeight;
    c.getContext('2d').drawImage(vid, 0, 0);
    c.toBlob(doWhatYouWantWithTheCapturedImage);
  };
})
.catch(function(err) {
  console.error(err);
  document.body.innerHTML = '<a href="https://jsfiddle.net/3m4gj7dq/">Please try from jsfiddle</a>';
});

function doWhatYouWantWithTheCapturedImage(blob) {
  var url = URL.createObjectURL(blob);
  var img = new Image();
  img.onload = function() {
    URL.revokeObjectURL(url);
  };
  img.src = url;
  URL.revokeObjectURL(vid.src);
  overlay.parentNode.appendChild(img);
  vid.parentNode.removeChild(vid);
  overlay.parentNode.removeChild(overlay);
}
#overlay {
  position: absolute;
  top: 0;
  left: 0;
  object-fit: contain;
}
<video id="vid"></video>
<img id="overlay" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASwAAAC0CAYAAAAuPxHvAAAKjElEQVR4nO3de4gdZxnH8S+KF9ikaNKYZuNqadU/hNZmNV5gawRb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BrIBZVlcBT2SHkMrkAezaXGb3AR/LDiGVwbuJNWwqr6uI7tFS4+0GVmeH0Fk9gO3B1HCXEv0FVX7vweeMarjt2LKrSh7DfpBqqFcCLwALsoOoZSuJCrBS43wW+EZ2CE3bb4F3ZIeQuu0prCZaRZ8DvpkdQuqma4iZ7aqe84BTQF92EKlb7sG2UlV2B7AxO4TUDa8BniNapauaLgXGs0NI3bAem0vUwT5gRXYIqdOewrdMdbCcqOQg1dYVwE+yQ6ht/ggsyg4hdcpdwGeyQ6htNgG3ZYeQOuGlwPM4s71OXgc8kx1C6oQVwPezQ6jt9mIVh674N3zO49Hed3H3AAAAAElFTkSuQmCC"
/>

But this API is not supported by iOS < 11.

What you seem to be using however, is served directly by the OS, just as a file input dialog, and can't be modified/personalized.

like image 73
Kaiido Avatar answered Sep 28 '22 18:09

Kaiido