Improved support on Code 39 barcodes

pull/19/head
Christoph Oberhofer 11 years ago
parent 7638bc41eb
commit b91246c699

46
dist/quagga.js vendored

@ -597,6 +597,18 @@ define(
} }
return result; 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 = { BarcodeReader.DIRECTION = {
FORWARD : 1, FORWARD : 1,
@ -6505,6 +6517,8 @@ define(
} while(decodedChar !== '*'); } while(decodedChar !== '*');
result.pop(); result.pop();
return { return {
code : result.join(""), code : result.join(""),
start : start.start, start : start.start,
@ -6542,6 +6556,7 @@ define(
var numCounters = counters.length, var numCounters = counters.length,
maxNarrowWidth = 0, maxNarrowWidth = 0,
numWideBars = numCounters, numWideBars = numCounters,
wideBarWidth = 0,
self = this, self = this,
pattern, pattern,
i; i;
@ -6554,18 +6569,25 @@ define(
if (counters[i] > maxNarrowWidth) { if (counters[i] > maxNarrowWidth) {
pattern |= 1 << (numCounters - 1 - i); pattern |= 1 << (numCounters - 1 - i);
numWideBars++; numWideBars++;
wideBarWidth += counters[i];
} }
} }
if (numWideBars === 3) { 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 pattern;
} }
} }
return -1; return -1;
}; };
Code39Reader.prototype._findEnd = function() {
};
Code39Reader.prototype._findStart = function() { Code39Reader.prototype._findStart = function() {
var self = this, var self = this,
offset = self._nextSet(self._row), offset = self._nextSet(self._row),
@ -6574,7 +6596,8 @@ define(
counterPos = 0, counterPos = 0,
isWhite = false, isWhite = false,
i, i,
j; j,
whiteSpaceMustStart;
for ( i = offset; i < self._row.length; i++) { for ( i = offset; i < self._row.length; i++) {
if (self._row[i] ^ isWhite) { if (self._row[i] ^ isWhite) {
@ -6584,10 +6607,13 @@ define(
// find start pattern // find start pattern
if (self._toPattern(counter) === self.ASTERISK) { if (self._toPattern(counter) === self.ASTERISK) {
return { whiteSpaceMustStart = Math.floor(Math.max(0, patternStart - ((i - patternStart) / 4)));
start: patternStart, if (self._matchRange(whiteSpaceMustStart, patternStart, 0)) {
end: i return {
}; start: patternStart,
end: i
};
}
} }
patternStart += counter[0] + counter[1]; patternStart += counter[0] + counter[1];
@ -7016,7 +7042,7 @@ define('config',[],function(){
} }
}, },
tracking: false, tracking: false,
debug: false, debug: true,
controls: false, controls: false,
locate: true, locate: true,
numOfWorkers: 0, numOfWorkers: 0,
@ -7026,9 +7052,9 @@ define('config',[],function(){
}, },
decoder:{ decoder:{
drawBoundingBox: false, drawBoundingBox: false,
showFrequency: false, showFrequency: true,
drawScanline: false, drawScanline: false,
showPattern: false, showPattern: true,
readers: [ readers: [
'code_128_reader' 'code_128_reader'
] ]

@ -43,7 +43,7 @@
<ul class="thumbnails"></ul> <ul class="thumbnails"></ul>
</div> </div>
<div id="interactive" class="viewport"></div> <div id="interactive" class="viewport"></div>
<div id="debug"></div> <div id="debug" class="detection"></div>
</section> </section>
<footer> <footer>
<p> <p>

@ -17,7 +17,7 @@ $(function() {
}, },
config: { config: {
reader: "code_39", reader: "code_39",
length: 4 length: 10
}, },
attachListeners: function() { attachListeners: function() {
$(".controls").on("click", "button.next", function(e) { $(".controls").on("click", "button.next", function(e) {

@ -161,6 +161,18 @@ define(
} }
return result; 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 = { BarcodeReader.DIRECTION = {
FORWARD : 1, FORWARD : 1,

@ -79,6 +79,8 @@ define(
} while(decodedChar !== '*'); } while(decodedChar !== '*');
result.pop(); result.pop();
return { return {
code : result.join(""), code : result.join(""),
start : start.start, start : start.start,
@ -116,6 +118,7 @@ define(
var numCounters = counters.length, var numCounters = counters.length,
maxNarrowWidth = 0, maxNarrowWidth = 0,
numWideBars = numCounters, numWideBars = numCounters,
wideBarWidth = 0,
self = this, self = this,
pattern, pattern,
i; i;
@ -128,18 +131,25 @@ define(
if (counters[i] > maxNarrowWidth) { if (counters[i] > maxNarrowWidth) {
pattern |= 1 << (numCounters - 1 - i); pattern |= 1 << (numCounters - 1 - i);
numWideBars++; numWideBars++;
wideBarWidth += counters[i];
} }
} }
if (numWideBars === 3) { 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 pattern;
} }
} }
return -1; return -1;
}; };
Code39Reader.prototype._findEnd = function() {
};
Code39Reader.prototype._findStart = function() { Code39Reader.prototype._findStart = function() {
var self = this, var self = this,
offset = self._nextSet(self._row), offset = self._nextSet(self._row),
@ -148,7 +158,8 @@ define(
counterPos = 0, counterPos = 0,
isWhite = false, isWhite = false,
i, i,
j; j,
whiteSpaceMustStart;
for ( i = offset; i < self._row.length; i++) { for ( i = offset; i < self._row.length; i++) {
if (self._row[i] ^ isWhite) { if (self._row[i] ^ isWhite) {
@ -158,10 +169,13 @@ define(
// find start pattern // find start pattern
if (self._toPattern(counter) === self.ASTERISK) { if (self._toPattern(counter) === self.ASTERISK) {
return { whiteSpaceMustStart = Math.floor(Math.max(0, patternStart - ((i - patternStart) / 4)));
start: patternStart, if (self._matchRange(whiteSpaceMustStart, patternStart, 0)) {
end: i return {
}; start: patternStart,
end: i
};
}
} }
patternStart += counter[0] + counter[1]; patternStart += counter[0] + counter[1];

@ -16,7 +16,7 @@ define(function(){
debug: false, debug: false,
controls: false, controls: false,
locate: true, locate: true,
numOfWorkers: 0, numOfWorkers: 4,
scriptName: 'quagga.js', scriptName: 'quagga.js',
visual: { visual: {
show: true show: true

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Loading…
Cancel
Save