Improved support on Code 39 barcodes

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

38
dist/quagga.js vendored

@ -598,6 +598,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,
REVERSE : -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,11 +6607,14 @@ define(
// find start pattern
if (self._toPattern(counter) === self.ASTERISK) {
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];
for ( j = 0; j < 7; j++) {
@ -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'
]

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

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

@ -162,6 +162,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,
REVERSE : -1

@ -79,6 +79,8 @@ define(
} while(decodedChar !== '*');
result.pop();
return {
code : result.join(""),
start : start.start,
@ -116,6 +118,7 @@ define(
var numCounters = counters.length,
maxNarrowWidth = 0,
numWideBars = numCounters,
wideBarWidth = 0,
self = this,
pattern,
i;
@ -128,18 +131,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),
@ -148,7 +158,8 @@ define(
counterPos = 0,
isWhite = false,
i,
j;
j,
whiteSpaceMustStart;
for ( i = offset; i < self._row.length; i++) {
if (self._row[i] ^ isWhite) {
@ -158,11 +169,14 @@ define(
// find start pattern
if (self._toPattern(counter) === self.ASTERISK) {
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];
for ( j = 0; j < 7; j++) {

@ -16,7 +16,7 @@ define(function(){
debug: false,
controls: false,
locate: true,
numOfWorkers: 0,
numOfWorkers: 4,
scriptName: 'quagga.js',
visual: {
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