Improved versions of the examples-pages. Now including the possibility to switch between Code128 and EAN.

pull/5/head
Christoph Oberhofer 11 years ago
parent 5e4c3aeb55
commit d806d48b0f

8
dist/quagga.js vendored

@ -6641,6 +6641,11 @@ define('barcode_decoder',["bresenham", "image_debug", 'code_128_reader', 'ean_re
return result; return result;
} }
} }
},
setReaders: function(readers) {
config.readers = readers;
_barcodeReaders.length = 0;
initReaders();
} }
}; };
} }
@ -7175,6 +7180,9 @@ function(Code128Reader, EANReader, InputStream, ImageWrapper, BarcodeLocator, Ba
isInitialized : function() { isInitialized : function() {
return _initialized; return _initialized;
}, },
setReaders: function(readers) {
_decoder.setReaders(readers);
},
canvas : _canvasContainer, canvas : _canvasContainer,
decodeSingle : function(config, resultCallback) { decodeSingle : function(config, resultCallback) {
config.inputStream = { config.inputStream = {

File diff suppressed because one or more lines are too long

@ -33,43 +33,57 @@
margin-left: -640px; margin-left: -640px;
} }
/* line 15, ../sass/_viewport.scss */ /* line 16, ../sass/_viewport.scss */
.controls .reader-group {
float: right;
border: none;
}
/* line 22, ../sass/_viewport.scss */
#result_strip { #result_strip {
margin: 10px 0; margin: 10px 0;
border-top: 1px solid #EEE; border-top: 1px solid #EEE;
border-bottom: 1px solid #EEE; border-bottom: 1px solid #EEE;
padding: 10px 0; padding: 10px 0;
overflow: auto;
} }
/* line 21, ../sass/_viewport.scss */ /* line 28, ../sass/_viewport.scss */
#result_strip ul.thumbnails { #result_strip ul.thumbnails {
padding: 0; padding: 0;
margin: 0; margin: 0;
list-style-type: none; list-style-type: none;
width: auto;
overflow-x: auto;
overflow-y: hidden;
white-space: nowrap;
} }
/* line 26, ../sass/_viewport.scss */ /* line 37, ../sass/_viewport.scss */
#result_strip ul.thumbnails > li { #result_strip ul.thumbnails > li {
float: left; display: inline-block;
vertical-align: middle;
width: 160px; width: 160px;
} }
/* line 29, ../sass/_viewport.scss */ /* line 41, ../sass/_viewport.scss */
#result_strip ul.thumbnails > li .thumbnail { #result_strip ul.thumbnails > li .thumbnail {
padding: 5px; padding: 5px;
margin: 4px; margin: 4px;
border: 1px dashed #CCC; border: 1px dashed #CCC;
} }
/* line 34, ../sass/_viewport.scss */ /* line 46, ../sass/_viewport.scss */
#result_strip ul.thumbnails > li .thumbnail img { #result_strip ul.thumbnails > li .thumbnail img {
max-width: 140px; max-width: 140px;
} }
/* line 38, ../sass/_viewport.scss */ /* line 49, ../sass/_viewport.scss */
#result_strip ul.thumbnails > li .thumbnail .caption {
white-space: normal;
}
/* line 51, ../sass/_viewport.scss */
#result_strip ul.thumbnails > li .thumbnail .caption h4 { #result_strip ul.thumbnails > li .thumbnail .caption h4 {
text-align: center; text-align: center;
word-wrap: break-word; word-wrap: break-word;
height: 40px; height: 40px;
margin: 0px; margin: 0px;
} }
/* line 48, ../sass/_viewport.scss */ /* line 61, ../sass/_viewport.scss */
#result_strip ul.thumbnails:after { #result_strip ul.thumbnails:after {
content: ""; content: "";
display: table; display: table;

@ -22,11 +22,18 @@
<section id="container" class="container"> <section id="container" class="container">
<h3>The user's camera</h3> <h3>The user's camera</h3>
<p>If your platform supports the <strong>getUserMedia</strong> API call, you can try the real-time locating and decoding features. <p>If your platform supports the <strong>getUserMedia</strong> API call, you can try the real-time locating and decoding features.
Simply allow the page to access your web-cam and point it to a barcode encoded with <strong>Code128</strong>. Simply allow the page to access your web-cam and point it to a barcode. You can switch between <strong>Code128</strong>
and <strong>EAN</strong> to test different scenarios.
It works best if your camera has built-in auto-focus. It works best if your camera has built-in auto-focus.
</p> </p>
<div class="controls"> <div class="controls">
<button class="next">Start/Continue</button> <fieldset class="reader-group">
<label>Code128</label>
<input type="radio" name="reader" value="code_128" checked />
<label>EAN</label>
<input type="radio" name="reader" value="ean" />
</fieldset>
<br clear="all" />
</div> </div>
<div id="result_strip"> <div id="result_strip">
<ul class="thumbnails"></ul> <ul class="thumbnails"></ul>

@ -1,28 +1,44 @@
$(function() { $(function() {
Quagga.init({ var App = {
inputStream : { init : function() {
name : "Live", Quagga.init({
type : "LiveStream" inputStream : {
name : "Live",
type : "LiveStream"
},
decoder : {
readers : ["code_128_reader"]
},
readyFunc : function() {
App.attachListeners();
Quagga.start();
}
});
}, },
decoder : { attachListeners : function() {
readers : ['code_128_reader'] $(".controls .reader-group").on("change", "input", function(e) {
e.preventDefault();
Quagga.setReaders([e.target.value + "_reader"]);
});
}, },
readyFunc : function() { detachListeners : function() {
Quagga.start(); $(".controls .reader-group").off("change", "input");
} },
}); lastResult : null
};
App.init();
Quagga.onDetected(function(result) { Quagga.onDetected(function(result) {
Quagga.stop(); if (App.lastResult !== result) {
var $node = null, canvas = Quagga.canvas.dom.image; App.lastResult = result;
var $node = null, canvas = Quagga.canvas.dom.image;
$node = $('<li><div class="thumbnail"><div class="imgWrapper"><img /></div><div class="caption"><h4 class="code"></h4></div></div></li>'); $node = $('<li><div class="thumbnail"><div class="imgWrapper"><img /></div><div class="caption"><h4 class="code"></h4></div></div></li>');
$node.find("img").attr("src", canvas.toDataURL()); $node.find("img").attr("src", canvas.toDataURL());
$node.find("h4.code").html(result); $node.find("h4.code").html(result);
$("#result_strip ul.thumbnails").prepend($node); $("#result_strip ul.thumbnails").prepend($node);
}); }
$(".controls").on("click", "button.next", function(e) {
Quagga.start();
}); });
});
});

@ -12,19 +12,31 @@
} }
} }
.controls {
.reader-group {
float: right;
border: none;
}
}
#result_strip{ #result_strip{
margin: 10px 0; margin: 10px 0;
border-top: 1px solid #EEE; border-top: 1px solid #EEE;
border-bottom: 1px solid #EEE; border-bottom: 1px solid #EEE;
padding: 10px 0; padding: 10px 0;
overflow: auto;
ul.thumbnails{ ul.thumbnails{
padding: 0; padding: 0;
margin: 0; margin: 0;
list-style-type: none; list-style-type: none;
width: auto;
overflow-x: auto;
overflow-y: hidden;
white-space: nowrap;
& > li{ & > li{
float: left; display: inline-block;
vertical-align: middle;
width: $videoWidth/4; width: $videoWidth/4;
.thumbnail{ .thumbnail{
padding: 5px; padding: 5px;
@ -35,6 +47,7 @@
max-width: $videoWidth/4 - 20px; max-width: $videoWidth/4 - 20px;
} }
.caption{ .caption{
white-space: normal;
h4{ h4{
text-align: center; text-align: center;
word-wrap: break-word; word-wrap: break-word;

@ -24,9 +24,18 @@
<h3>Working with static images</h3> <h3>Working with static images</h3>
<p>This examples uses static image files as input which are loaded from the server on startup. <p>This examples uses static image files as input which are loaded from the server on startup.
The locating and decoding process takes place inside the browser. The locating and decoding process takes place inside the browser.
Hit the <strong>next</strong> button to try a different image</p> Hit the <strong>next</strong> button to try a different image. You can also switch between
two different test-sets. Each of those contains 10 images, demonstrating the capabilities of decoding
<strong>Code128</strong> and <strong>EAN</strong> encoded barcodes.
</p>
<div class="controls"> <div class="controls">
<button class="next">Next</button> <button class="next">Next</button>
<fieldset class="reader-group">
<label>Code128</label>
<input type="radio" name="reader" value="code_128" checked />
<label>EAN</label>
<input type="radio" name="reader" value="ean" />
</fieldset>
</div> </div>
<div id="result_strip"> <div id="result_strip">
<ul class="thumbnails"></ul> <ul class="thumbnails"></ul>

@ -1,17 +1,46 @@
$(function() { $(function() {
Quagga.init({ var App = {
inputStream: { name: "Test", init: function() {
type: "ImageStream", Quagga.init({
src: "/test/fixtures/code_128/", inputStream: { name: "Test",
length: 10 type: "ImageStream",
src: "/test/fixtures/" + App.config.reader + "/",
length: App.config.length
},
decoder : {
readers : [App.config.reader + "_reader"]
},
readyFunc : function() {
App.attachListeners();
Quagga.start();
}
});
}, },
decoder : { config: {
readers : ['code_128_reader'] reader: "code_128",
length: 10
}, },
readyFunc : function() { attachListeners: function() {
Quagga.start(); $(".controls").on("click", "button.next", function(e) {
e.preventDefault();
Quagga.start();
});
$(".controls .reader-group").on("change", "input", function(e) {
e.preventDefault();
App.detachListeners();
Quagga.stop();
App.config.reader = e.target.value;
App.init();
});
},
detachListeners: function() {
$(".controls").off("click", "button.next");
$(".controls .reader-group").off("change", "input");
} }
}); };
App.init();
Quagga.onDetected(function(result) { Quagga.onDetected(function(result) {
var $node = null, canvas = Quagga.canvas.dom.image; var $node = null, canvas = Quagga.canvas.dom.image;
@ -21,8 +50,4 @@ $(function() {
$node.find("h4.code").html(result); $node.find("h4.code").html(result);
$("#result_strip ul.thumbnails").prepend($node); $("#result_strip ul.thumbnails").prepend($node);
}); });
$(".controls").on("click", "button.next", function(e) {
Quagga.start();
});
}); });

@ -238,6 +238,11 @@ define(["bresenham", "image_debug", 'code_128_reader', 'ean_reader'], function(B
return result; return result;
} }
} }
},
setReaders: function(readers) {
config.readers = readers;
_barcodeReaders.length = 0;
initReaders();
} }
}; };
} }

@ -198,6 +198,9 @@ function(Code128Reader, EANReader, InputStream, ImageWrapper, BarcodeLocator, Ba
isInitialized : function() { isInitialized : function() {
return _initialized; return _initialized;
}, },
setReaders: function(readers) {
_decoder.setReaders(readers);
},
canvas : _canvasContainer, canvas : _canvasContainer,
decodeSingle : function(config, resultCallback) { decodeSingle : function(config, resultCallback) {
config.inputStream = { config.inputStream = {

Loading…
Cancel
Save