0
Well, it’s a simple project, a "website" which accesses the web cam, captures the image and sends it to a server.
I was able to implement the web cam with the following HTML5 javascript code:
<html>
<head>
<meta charset="utf-8">
<meta content="stuff, to, help, search, engines, not" name="keywords">
<meta content="What this page is about." name="description">
<meta content="Web Cam" name="title">
<title>Web Cam</title>
<style>
#container {
margin: 0px auto;
width: 500px;
height: 375px;
border: 10px #333 solid;
}
#videoElement {
width: 500px;
height: 375px;
background-color: #666;
}
</style>
</head>
<body>
<button id="snap">Snap Photo</button>
<div id="container">
<video autoplay="true" id="videoElement">
</video>
</div>
<script>
var video = document.querySelector("#videoElement");
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia || navigator.oGetUserMedia;
if (navigator.getUserMedia) {
navigator.getUserMedia({video: true}, handleVideo, videoError);
}
function handleVideo(stream) {
video.src = window.URL.createObjectURL(stream);
}
function videoError(e) {
// do something
}
</script>
<script>// Put event listeners into place
window.addEventListener("DOMContentLoaded", function () {
// Grab elements, create settings, etc.
var canvas = document.getElementById("canvas"),
context = canvas.getContext("2d"),
video = document.getElementById("video"),
videoObj = {"video": true},
errBack = function (error) {
console.log("Video capture error: ", error.code);
};
// Put video listeners into place
if (navigator.getUserMedia) { // Standard
navigator.getUserMedia(videoObj, function (stream) {
video.src = stream;
video.play();
}, errBack);
} else if (navigator.webkitGetUserMedia) { // WebKit-prefixed
navigator.webkitGetUserMedia(videoObj, function (stream) {
video.src = window.webkitURL.createObjectURL(stream);
video.play();
}, errBack);
}
else if (navigator.mozGetUserMedia) { // Firefox-prefixed
navigator.mozGetUserMedia(videoObj, function (stream) {
video.src = window.URL.createObjectURL(stream);
video.play();
}, errBack);
}
}, false);</script>
</body>
</html>
My current problem is about how to put this background image and adjust the camera so that it is this size 3x4 and that when pressing a button it takes the photo and leaves it static in place of the badge.
The part of uploading the photo to a Servlet and so on, I can do but that initial part is very difficult for me.
Your problem is not the same as the title "Place webcam image inside a static img", your problem is with the image overlay, make a title that matches the problem.
– Guilherme Nascimento
Thank you very much!
– paccamicio
paccamicio can’t understand where your html image is
– Guilherme Nascimento
Oops, I deleted it from the code, it was in a <div> but it just didn’t work, I tried all the <div> overlay etc..
– paccamicio