diff --git a/examples/live_w_locator.js b/examples/live_w_locator.js
index 1632c20..5a8a183 100644
--- a/examples/live_w_locator.js
+++ b/examples/live_w_locator.js
@@ -1,27 +1,103 @@
$(function() {
var App = {
init : function() {
- Quagga.init({
- inputStream : {
- name : "Live",
- type : "LiveStream"
- },
- decoder : {
- readers : ["code_128_reader"]
- }
- }, function() {
+ Quagga.init(this.state, function() {
App.attachListeners();
Quagga.start();
});
},
- attachListeners : function() {
- $(".controls .reader-group").on("change", "input", function(e) {
+ attachListeners: function() {
+ var self = this;
+
+ $(".controls").on("click", "button.stop", function(e) {
+ e.preventDefault();
+ Quagga.stop();
+ });
+
+ $(".controls .reader-config-group").on("change", "input, select", function(e) {
e.preventDefault();
- Quagga.setReaders([e.target.value + "_reader"]);
+ var $target = $(e.target),
+ value = $target.attr("type") === "checkbox" ? $target.prop("checked") : $target.val(),
+ name = $target.attr("name"),
+ state = self._convertNameToState(name);
+
+ console.log("Value of "+ state + " changed to " + value);
+ self.setState(state, value);
+ });
+ },
+ _accessByPath: function(obj, path, val) {
+ var parts = path.split('.'),
+ depth = parts.length,
+ setter = (typeof val !== "undefined") ? true : false;
+
+ return parts.reduce(function(o, key, i) {
+ if (setter && (i + 1) === depth) {
+ o[key] = val;
+ }
+ return key in o ? o[key] : {};
+ }, obj);
+ },
+ _convertNameToState: function(name) {
+ return name.replace("_", ".").split("-").reduce(function(result, value) {
+ return result + value.charAt(0).toUpperCase() + value.substring(1);
});
},
- detachListeners : function() {
- $(".controls .reader-group").off("change", "input");
+ detachListeners: function() {
+ $(".controls").off("click", "button.stop");
+ $(".controls .reader-config-group").off("change", "input, select");
+ },
+ setState: function(path, value) {
+ var self = this;
+
+ if (typeof self._accessByPath(self.inputMapper, path) === "function") {
+ value = self._accessByPath(self.inputMapper, path)(value);
+ }
+
+ self._accessByPath(self.state, path, value);
+
+ console.log(JSON.stringify(self.state));
+ App.detachListeners();
+ Quagga.stop();
+ App.init();
+ },
+ inputMapper: {
+ inputStream: {
+ constraints: function(value){
+ var values = value.split('x');
+ return {
+ width: parseInt(values[0]),
+ height: parseInt(values[1]),
+ facing: "environment"
+ }
+ }
+ },
+ numOfWorkers: function(value) {
+ return parseInt(value);
+ },
+ decoder: {
+ readers: function(value) {
+ return [value + "_reader"];
+ }
+ }
+ },
+ state: {
+ inputStream: {
+ type : "LiveStream",
+ constraints: {
+ width: 640,
+ height: 480,
+ facing: "environment" // or user
+ }
+ },
+ locator: {
+ patchSize: "medium",
+ halfSample: true
+ },
+ numOfWorkers: 4,
+ decoder: {
+ readers : ["code_128_reader"]
+ },
+ locate: true
},
lastResult : null
};
diff --git a/examples/static_images.html b/examples/static_images.html
index 47804ea..a3d6bb9 100644
--- a/examples/static_images.html
+++ b/examples/static_images.html
@@ -7,25 +7,29 @@ showInMenu: false
Working with static images
- 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.
- Hit the next 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
- Code128 and EAN encoded barcodes.
+
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. Hit the next button to try a
+ different image. You can also switch between different test-sets,
+ depending on the barcode-type.
-
- Next
-
- Code128
-
- EAN
-
- Code39
-
- Codabar
-
-
-
+
+
+ Next
+
+
+ Barcode-Type
+
+ Code 128
+ Code 39
+ EAN
+ EAN-8
+ UPC
+ UPC-E
+ Codabar
+
+
+
diff --git a/examples/static_images.js b/examples/static_images.js
index fc3f703..e12e727 100644
--- a/examples/static_images.js
+++ b/examples/static_images.js
@@ -1,16 +1,7 @@
$(function() {
var App = {
init: function() {
- Quagga.init({
- inputStream: { name: "Test",
- type: "ImageStream",
- src: site.baseurl + "/test/fixtures/" + App.config.reader + "/",
- length: App.config.length
- },
- decoder : {
- readers : [App.config.reader + "_reader"]
- }
- }, function() {
+ Quagga.init(this.state, function() {
App.attachListeners();
Quagga.start();
});
@@ -20,22 +11,85 @@ $(function() {
length: 10
},
attachListeners: function() {
+ var self = this;
+
$(".controls").on("click", "button.next", function(e) {
e.preventDefault();
Quagga.start();
});
-
- $(".controls .reader-group").on("change", "input", function(e) {
+
+ $(".controls .reader-config-group").on("change", "input, select", function(e) {
e.preventDefault();
- App.detachListeners();
- Quagga.stop();
- App.config.reader = e.target.value;
- App.init();
+ var $target = $(e.target),
+ value = $target.attr("type") === "checkbox" ? $target.prop("checked") : $target.val(),
+ name = $target.attr("name"),
+ states = self._convertNameToStates(name);
+
+ console.log("Value of "+ states + " changed to " + value);
+ self.setState(states, value);
});
},
detachListeners: function() {
$(".controls").off("click", "button.next");
- $(".controls .reader-group").off("change", "input");
+ $(".controls .reader-config-group").off("change", "input, select");
+ },
+ _accessByPath: function(obj, path, val) {
+ var parts = path.split('.'),
+ depth = parts.length,
+ setter = (typeof val !== "undefined") ? true : false;
+
+ return parts.reduce(function(o, key, i) {
+ if (setter && (i + 1) === depth) {
+ o[key] = val;
+ }
+ return key in o ? o[key] : {};
+ }, obj);
+ },
+ _convertNameToStates: function(names) {
+ return names.split(";").map(this._convertNameToState.bind(this));
+ },
+ _convertNameToState: function(name) {
+ return name.replace("_", ".").split("-").reduce(function(result, value) {
+ return result + value.charAt(0).toUpperCase() + value.substring(1);
+ });
+ },
+ setState: function(paths, value) {
+ var self = this;
+
+ paths.forEach(function(path) {
+ var mappedValue;
+ if (typeof self._accessByPath(self.inputMapper, path) === "function") {
+ mappedValue = self._accessByPath(self.inputMapper, path)(value);
+ }
+ self._accessByPath(self.state, path, mappedValue);
+ });
+
+ console.log(JSON.stringify(self.state));
+ App.detachListeners();
+ Quagga.stop();
+ App.init();
+ },
+ inputMapper: {
+ decoder: {
+ readers: function(value) {
+ return [value + "_reader"];
+ }
+ },
+ inputStream: {
+ src: function(value) {
+ return site.baseurl + "/test/fixtures/" + value + "/"
+ }
+ }
+ },
+ state: {
+ inputStream: { name: "Test",
+ type: "ImageStream",
+ src: site.baseurl + "/test/fixtures/code_128/",
+ length: 10
+ },
+ decoder : {
+ readers : ["code_128_reader"]
+ }
}
};
diff --git a/index.md b/index.md
index 78ea421..55b629e 100644
--- a/index.md
+++ b/index.md
@@ -7,16 +7,17 @@ showInMenu: true
quaggaJS
========
-- [Changelog](#changelog) (2015-04-25)
+- [Changelog](#changelog) (2015-04-30)
## What is QuaggaJS?
QuaggaJS is a barcode-scanner entirely written in JavaScript supporting real-
time localization and decoding of various types of barcodes such as __EAN__,
-__CODE128__, __CODE39__ and __CODABAR__. The library is also capable of using
-`getUserMedia` to get direct access to the user's camera stream. Although the
-code relies on heavy image-processing even recent smartphones are capable of
-locating and decoding barcodes in real-time.
+__CODE 128__, __CODE 39__, __EAN 8__, __UPC-A__, __UPC-C__ and __CODABAR__.
+The library is also capable of using `getUserMedia` to get direct access to
+the user's camera stream. Although the code relies on heavy image-processing
+even recent smartphones are capable of locating and decoding barcodes in
+real-time.
Try some [examples](http://serratus.github.io/quaggaJS/examples) and check out
the blog post ([How barcode-localization works in QuaggaJS][oberhofer_co_how])
@@ -298,6 +299,15 @@ work.
## Changelog
+### 2015-04-30
+- Features
+ - Added support for [UPC-A and UPC-E][upc_wiki] barcodes
+ - Added support for [EAN-8][ean_8_wiki] barcodes
+- Improvements
+ - Added extended configuration to the
+ [live-video example]({{ site.baseurl }}/examples/live_w_locator.html)
+ - Releasing resources when calling ``Quagga.stop()``
+
### 2015-04-25
- Improvements
- Added extended configuration to the
@@ -353,5 +363,7 @@ introduced to the API.
[karmaUrl]: http://karma-runner.github.io/
[code39_wiki]: http://en.wikipedia.org/wiki/Code_39
[codabar_wiki]: http://en.wikipedia.org/wiki/Codabar
+[upc_wiki]: http://en.wikipedia.org/wiki/Universal_Product_Code
+[ean_8_wiki]: http://en.wikipedia.org/wiki/EAN-8
[oberhofer_co_how]: http://www.oberhofer.co/how-barcode-localization-works-in-quaggajs/
[github_examples]: http://serratus.github.io/quaggaJS/examples
diff --git a/test/fixtures/code_128/image-001.jpg b/test/fixtures/code_128/image-001.jpg
index 8156afb..2075809 100644
Binary files a/test/fixtures/code_128/image-001.jpg and b/test/fixtures/code_128/image-001.jpg differ
diff --git a/test/fixtures/ean/image-001.jpg b/test/fixtures/ean/image-001.jpg
index 507e666..36adff7 100644
Binary files a/test/fixtures/ean/image-001.jpg and b/test/fixtures/ean/image-001.jpg differ
diff --git a/test/fixtures/ean_8/image-001.jpg b/test/fixtures/ean_8/image-001.jpg
new file mode 100644
index 0000000..feec877
Binary files /dev/null and b/test/fixtures/ean_8/image-001.jpg differ
diff --git a/test/fixtures/ean_8/image-002.jpg b/test/fixtures/ean_8/image-002.jpg
new file mode 100644
index 0000000..a448baa
Binary files /dev/null and b/test/fixtures/ean_8/image-002.jpg differ
diff --git a/test/fixtures/ean_8/image-003.jpg b/test/fixtures/ean_8/image-003.jpg
new file mode 100644
index 0000000..e7aed95
Binary files /dev/null and b/test/fixtures/ean_8/image-003.jpg differ
diff --git a/test/fixtures/ean_8/image-004.jpg b/test/fixtures/ean_8/image-004.jpg
new file mode 100644
index 0000000..a755b1e
Binary files /dev/null and b/test/fixtures/ean_8/image-004.jpg differ
diff --git a/test/fixtures/ean_8/image-005.jpg b/test/fixtures/ean_8/image-005.jpg
new file mode 100644
index 0000000..25168a7
Binary files /dev/null and b/test/fixtures/ean_8/image-005.jpg differ
diff --git a/test/fixtures/ean_8/image-006.jpg b/test/fixtures/ean_8/image-006.jpg
new file mode 100644
index 0000000..a326735
Binary files /dev/null and b/test/fixtures/ean_8/image-006.jpg differ
diff --git a/test/fixtures/ean_8/image-007.jpg b/test/fixtures/ean_8/image-007.jpg
new file mode 100644
index 0000000..21a2b0a
Binary files /dev/null and b/test/fixtures/ean_8/image-007.jpg differ
diff --git a/test/fixtures/ean_8/image-008.jpg b/test/fixtures/ean_8/image-008.jpg
new file mode 100644
index 0000000..3482e80
Binary files /dev/null and b/test/fixtures/ean_8/image-008.jpg differ
diff --git a/test/fixtures/ean_8/image-009.jpg b/test/fixtures/ean_8/image-009.jpg
new file mode 100644
index 0000000..e07bd2a
Binary files /dev/null and b/test/fixtures/ean_8/image-009.jpg differ
diff --git a/test/fixtures/ean_8/image-010.jpg b/test/fixtures/ean_8/image-010.jpg
new file mode 100644
index 0000000..97d2ba4
Binary files /dev/null and b/test/fixtures/ean_8/image-010.jpg differ
diff --git a/test/fixtures/upc/image-001.jpg b/test/fixtures/upc/image-001.jpg
new file mode 100644
index 0000000..2c2ce01
Binary files /dev/null and b/test/fixtures/upc/image-001.jpg differ
diff --git a/test/fixtures/upc/image-002.jpg b/test/fixtures/upc/image-002.jpg
new file mode 100644
index 0000000..6fa5d69
Binary files /dev/null and b/test/fixtures/upc/image-002.jpg differ
diff --git a/test/fixtures/upc/image-003.jpg b/test/fixtures/upc/image-003.jpg
new file mode 100644
index 0000000..de4b192
Binary files /dev/null and b/test/fixtures/upc/image-003.jpg differ
diff --git a/test/fixtures/upc/image-004.jpg b/test/fixtures/upc/image-004.jpg
new file mode 100644
index 0000000..2e17c6c
Binary files /dev/null and b/test/fixtures/upc/image-004.jpg differ
diff --git a/test/fixtures/upc/image-005.jpg b/test/fixtures/upc/image-005.jpg
new file mode 100644
index 0000000..45f3103
Binary files /dev/null and b/test/fixtures/upc/image-005.jpg differ
diff --git a/test/fixtures/upc/image-006.jpg b/test/fixtures/upc/image-006.jpg
new file mode 100644
index 0000000..0ba1946
Binary files /dev/null and b/test/fixtures/upc/image-006.jpg differ
diff --git a/test/fixtures/upc/image-007.jpg b/test/fixtures/upc/image-007.jpg
new file mode 100644
index 0000000..214dac5
Binary files /dev/null and b/test/fixtures/upc/image-007.jpg differ
diff --git a/test/fixtures/upc/image-008.jpg b/test/fixtures/upc/image-008.jpg
new file mode 100644
index 0000000..292f737
Binary files /dev/null and b/test/fixtures/upc/image-008.jpg differ
diff --git a/test/fixtures/upc/image-009.jpg b/test/fixtures/upc/image-009.jpg
new file mode 100644
index 0000000..250ae6b
Binary files /dev/null and b/test/fixtures/upc/image-009.jpg differ
diff --git a/test/fixtures/upc/image-010.jpg b/test/fixtures/upc/image-010.jpg
new file mode 100644
index 0000000..da3be38
Binary files /dev/null and b/test/fixtures/upc/image-010.jpg differ
diff --git a/test/fixtures/upc_e/image-001.jpg b/test/fixtures/upc_e/image-001.jpg
new file mode 100644
index 0000000..d017f20
Binary files /dev/null and b/test/fixtures/upc_e/image-001.jpg differ
diff --git a/test/fixtures/upc_e/image-002.jpg b/test/fixtures/upc_e/image-002.jpg
new file mode 100644
index 0000000..ba71ce7
Binary files /dev/null and b/test/fixtures/upc_e/image-002.jpg differ
diff --git a/test/fixtures/upc_e/image-003.jpg b/test/fixtures/upc_e/image-003.jpg
new file mode 100644
index 0000000..b2603e5
Binary files /dev/null and b/test/fixtures/upc_e/image-003.jpg differ
diff --git a/test/fixtures/upc_e/image-004.jpg b/test/fixtures/upc_e/image-004.jpg
new file mode 100644
index 0000000..8e4e542
Binary files /dev/null and b/test/fixtures/upc_e/image-004.jpg differ
diff --git a/test/fixtures/upc_e/image-005.jpg b/test/fixtures/upc_e/image-005.jpg
new file mode 100644
index 0000000..79314dd
Binary files /dev/null and b/test/fixtures/upc_e/image-005.jpg differ
diff --git a/test/fixtures/upc_e/image-006.jpg b/test/fixtures/upc_e/image-006.jpg
new file mode 100644
index 0000000..1b83176
Binary files /dev/null and b/test/fixtures/upc_e/image-006.jpg differ
diff --git a/test/fixtures/upc_e/image-007.jpg b/test/fixtures/upc_e/image-007.jpg
new file mode 100644
index 0000000..00e90c5
Binary files /dev/null and b/test/fixtures/upc_e/image-007.jpg differ
diff --git a/test/fixtures/upc_e/image-008.jpg b/test/fixtures/upc_e/image-008.jpg
new file mode 100644
index 0000000..054f486
Binary files /dev/null and b/test/fixtures/upc_e/image-008.jpg differ
diff --git a/test/fixtures/upc_e/image-009.jpg b/test/fixtures/upc_e/image-009.jpg
new file mode 100644
index 0000000..59a6c77
Binary files /dev/null and b/test/fixtures/upc_e/image-009.jpg differ
diff --git a/test/fixtures/upc_e/image-010.jpg b/test/fixtures/upc_e/image-010.jpg
new file mode 100644
index 0000000..1bafdf7
Binary files /dev/null and b/test/fixtures/upc_e/image-010.jpg differ