From b91246c6990e41d665ce286c183330d121b8d064 Mon Sep 17 00:00:00 2001 From: Christoph Oberhofer Date: Wed, 4 Mar 2015 22:23:59 +0100 Subject: [PATCH] Improved support on Code 39 barcodes --- dist/quagga.js | 46 ++++++++++++++++++++++------ example/static_images.html | 2 +- example/static_images.js | 2 +- src/barcode_reader.js | 12 ++++++++ src/code_39_reader.js | 28 ++++++++++++----- src/config.js | 2 +- test/fixtures/code_39/image-001.jpg | Bin 0 -> 85859 bytes test/fixtures/code_39/image-002.jpg | Bin 0 -> 84301 bytes test/fixtures/code_39/image-003.jpg | Bin 0 -> 71742 bytes test/fixtures/code_39/image-004.jpg | Bin 0 -> 68838 bytes test/fixtures/code_39/image-005.jpg | Bin 0 -> 75154 bytes test/fixtures/code_39/image-006.jpg | Bin 0 -> 85025 bytes test/fixtures/code_39/image-007.jpg | Bin 0 -> 84227 bytes test/fixtures/code_39/image-008.jpg | Bin 0 -> 65317 bytes test/fixtures/code_39/image-009.jpg | Bin 0 -> 80514 bytes test/fixtures/code_39/image-010.jpg | Bin 0 -> 63980 bytes 16 files changed, 72 insertions(+), 20 deletions(-) create mode 100644 test/fixtures/code_39/image-001.jpg create mode 100644 test/fixtures/code_39/image-002.jpg create mode 100644 test/fixtures/code_39/image-003.jpg create mode 100644 test/fixtures/code_39/image-004.jpg create mode 100644 test/fixtures/code_39/image-005.jpg create mode 100644 test/fixtures/code_39/image-006.jpg create mode 100644 test/fixtures/code_39/image-007.jpg create mode 100644 test/fixtures/code_39/image-008.jpg create mode 100644 test/fixtures/code_39/image-009.jpg create mode 100644 test/fixtures/code_39/image-010.jpg diff --git a/dist/quagga.js b/dist/quagga.js index bf35b5e..522e58a 100644 --- a/dist/quagga.js +++ b/dist/quagga.js @@ -597,6 +597,18 @@ define( } return result; }; + + BarcodeReader.prototype._matchRange = function(start, end, value) { + var i; + + start = start < 0 ? 0 : start; + for (i = start; i < end; i++) { + if (this._row[i] !== value) { + return false; + } + } + return true; + }; BarcodeReader.DIRECTION = { FORWARD : 1, @@ -6505,6 +6517,8 @@ define( } while(decodedChar !== '*'); result.pop(); + + return { code : result.join(""), start : start.start, @@ -6542,6 +6556,7 @@ define( var numCounters = counters.length, maxNarrowWidth = 0, numWideBars = numCounters, + wideBarWidth = 0, self = this, pattern, i; @@ -6554,18 +6569,25 @@ define( if (counters[i] > maxNarrowWidth) { pattern |= 1 << (numCounters - 1 - i); numWideBars++; + wideBarWidth += counters[i]; } } if (numWideBars === 3) { + for (i = 0; i < numCounters && numWideBars > 0; i++) { + if (counters[i] > maxNarrowWidth) { + numWideBars--; + if ((counters[i] * 3) >= wideBarWidth) { + return -1; + } + } + } return pattern; } } return -1; }; - Code39Reader.prototype._findEnd = function() { - }; Code39Reader.prototype._findStart = function() { var self = this, offset = self._nextSet(self._row), @@ -6574,7 +6596,8 @@ define( counterPos = 0, isWhite = false, i, - j; + j, + whiteSpaceMustStart; for ( i = offset; i < self._row.length; i++) { if (self._row[i] ^ isWhite) { @@ -6584,10 +6607,13 @@ define( // find start pattern if (self._toPattern(counter) === self.ASTERISK) { - return { - start: patternStart, - end: i - }; + whiteSpaceMustStart = Math.floor(Math.max(0, patternStart - ((i - patternStart) / 4))); + if (self._matchRange(whiteSpaceMustStart, patternStart, 0)) { + return { + start: patternStart, + end: i + }; + } } patternStart += counter[0] + counter[1]; @@ -7016,7 +7042,7 @@ define('config',[],function(){ } }, tracking: false, - debug: false, + debug: true, controls: false, locate: true, numOfWorkers: 0, @@ -7026,9 +7052,9 @@ define('config',[],function(){ }, decoder:{ drawBoundingBox: false, - showFrequency: false, + showFrequency: true, drawScanline: false, - showPattern: false, + showPattern: true, readers: [ 'code_128_reader' ] diff --git a/example/static_images.html b/example/static_images.html index 713b3de..e95d159 100644 --- a/example/static_images.html +++ b/example/static_images.html @@ -43,7 +43,7 @@
-
+