Barely working concept

This commit is contained in:
Christoph Oberhofer
2015-04-22 22:01:07 +02:00
parent 36f75d2a95
commit b7a6526c53
13 changed files with 184 additions and 28 deletions
+83
View File
@@ -0,0 +1,83 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title>Camera</title>
<script type="text/javascript">
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
window.URL = window.URL || window.webkitURL || window.mozURL || window.msURL;
function getUserMedia(constraints, success, failure) {
navigator.getUserMedia(constraints, function(stream) {
var videoSrc = (window.URL && window.URL.createObjectURL(stream)) || stream;
success.apply(null, [videoSrc]);
}, failure);
}
function initCamera(constraints, video, callback) {
getUserMedia(constraints, function (src) {
video.src = src;
video.addEventListener('loadeddata', function() {
var attempts = 10;
function checkVideo() {
if (attempts > 0) {
if (video.videoWidth > 0 && video.videoHeight > 0) {
console.log(video.videoWidth + "px x " + video.videoHeight + "px");
video.play();
callback();
} else {
window.setTimeout(checkVideo, 100);
}
} else {
callback('Unable to play video stream.');
}
attempts--;
}
checkVideo();
}, false);
}, function(e) {
console.log(e);
});
}
function copyToCanvas(video, ctx) {
( function frame() {
ctx.drawImage(video, 0, 0);
window.requestAnimationFrame(frame);
}());
}
window.addEventListener('load', function() {
var constraints = {
video: {
mandatory: {
minWidth: 1280,
minHeight: 720
}
}
},
video = document.createElement('video'),
canvas = document.createElement('canvas');
document.body.appendChild(video);
document.body.appendChild(canvas);
initCamera(constraints, video, function() {
canvas.setAttribute('width', video.videoWidth);
canvas.setAttribute('height', video.videoHeight);
copyToCanvas(video, canvas.getContext('2d'));
});
}, false);
</script>
</head>
<body>
</body>
</html>
+5 -1
View File
@@ -36,12 +36,16 @@
<div class="controls">
<input type="file" capture/>
<fieldset class="reader-group">
<label>UPC</label>
<input type="radio" name="reader" value="upc" checked />
<label>Code39</label>
<input type="radio" name="reader" value="codabar" />
<label>Code128</label>
<input type="radio" name="reader" value="code_128"/>
<label>EAN</label>
<input type="radio" name="reader" value="ean"/>
<label>Code39</label>
<input type="radio" name="reader" value="code_39" checked/>
<input type="radio" name="reader" value="code_39"/>
</fieldset>
</div>
<div id="result_strip">
+1 -2
View File
@@ -4,8 +4,7 @@ $(function() {
App.attachListeners();
},
config: {
reader: "code_39",
length: 10
reader: "upc"
},
attachListeners: function() {
$(".controls input[type=file]").on("change", function(e) {
+5 -1
View File
@@ -29,8 +29,12 @@
<div class="controls">
<button class="stop">Stop</button>
<fieldset class="reader-group">
<label>UPC</label>
<input type="radio" name="reader" value="upc" checked />
<label>Code39</label>
<input type="radio" name="reader" value="codabar" />
<label>Code128</label>
<input type="radio" name="reader" value="code_128" checked />
<input type="radio" name="reader" value="code_128" />
<label>EAN</label>
<input type="radio" name="reader" value="ean" />
<label>Code39</label>
+1 -1
View File
@@ -7,7 +7,7 @@ $(function() {
type : "LiveStream"
},
decoder : {
readers : ["code_128_reader"]
readers : ["upc_reader"]
}
}, function() {
App.attachListeners();
+4 -2
View File
@@ -31,8 +31,10 @@
<div class="controls">
<button class="next">Next</button>
<fieldset class="reader-group">
<label>Codabar</label>
<input type="radio" name="reader" value="codabar" checked />
<label>UPC</label>
<input type="radio" name="reader" value="upc" checked />
<label>Code39</label>
<input type="radio" name="reader" value="codabar" />
<label>Code39</label>
<input type="radio" name="reader" value="code_39" />
<label>Code128</label>
+1 -1
View File
@@ -16,7 +16,7 @@ $(function() {
});
},
config: {
reader: "codabar",
reader: "upc",
length: 10
},
attachListeners: function() {