mirror of
https://github.com/serratus/quaggaJS.git
synced 2026-08-12 21:21:42 +08:00
Experimenting on i2of5 reader regarding different weights of bars and spaces
This commit is contained in:
+14
-4
@@ -89,11 +89,21 @@ define([
|
|||||||
}
|
}
|
||||||
|
|
||||||
function initReaders() {
|
function initReaders() {
|
||||||
var i;
|
config.readers.forEach(function(readerConfig) {
|
||||||
for ( i = 0; i < config.readers.length; i++) {
|
var reader,
|
||||||
console.log(config.readers[i]);
|
config = {};
|
||||||
_barcodeReaders.push(new readers[config.readers[i]]());
|
|
||||||
|
if (typeof readerConfig === 'object') {
|
||||||
|
reader = readerConfig.format;
|
||||||
|
config = readerConfig.config;
|
||||||
|
} else if (typeof readerConfig === 'string') {
|
||||||
|
reader = readerConfig;
|
||||||
}
|
}
|
||||||
|
_barcodeReaders.push(new readers[reader](config));
|
||||||
|
});
|
||||||
|
console.log("Registered Readers:" + _barcodeReaders
|
||||||
|
.map(function(reader) {return reader.FORMAT;})
|
||||||
|
.join(', '));
|
||||||
}
|
}
|
||||||
|
|
||||||
function initConfig() {
|
function initConfig() {
|
||||||
|
|||||||
@@ -5,8 +5,9 @@ define(
|
|||||||
function() {
|
function() {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
function BarcodeReader() {
|
function BarcodeReader(config) {
|
||||||
this._row = [];
|
this._row = [];
|
||||||
|
this.config = config || {};
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,6 +224,8 @@ define(
|
|||||||
PatternNotFoundException : "Pattern could not be found!"
|
PatternNotFoundException : "Pattern could not be found!"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
BarcodeReader.CONFIG_KEYS = {};
|
||||||
|
|
||||||
return (BarcodeReader);
|
return (BarcodeReader);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
+37
-21
@@ -10,6 +10,7 @@ define(
|
|||||||
|
|
||||||
function I2of5Reader(opts) {
|
function I2of5Reader(opts) {
|
||||||
BarcodeReader.call(this, opts);
|
BarcodeReader.call(this, opts);
|
||||||
|
this.barSpaceRatio = [1, 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
var N = 1,
|
var N = 1,
|
||||||
@@ -30,29 +31,37 @@ define(
|
|||||||
[W, N, N, W, N],
|
[W, N, N, W, N],
|
||||||
[N, W, N, W, N]
|
[N, W, N, W, N]
|
||||||
]},
|
]},
|
||||||
SINGLE_CODE_ERROR: {value: 1},
|
SINGLE_CODE_ERROR: {value: 0.7},
|
||||||
AVG_CODE_ERROR: {value: 0.38},
|
AVG_CODE_ERROR: {value: 0.38},
|
||||||
|
MAX_CORRECTION_FACTOR: {value: 2},
|
||||||
FORMAT: {value: "i2of5", writeable: false}
|
FORMAT: {value: "i2of5", writeable: false}
|
||||||
};
|
};
|
||||||
|
|
||||||
I2of5Reader.prototype = Object.create(BarcodeReader.prototype, properties);
|
I2of5Reader.prototype = Object.create(BarcodeReader.prototype, properties);
|
||||||
I2of5Reader.prototype.constructor = I2of5Reader;
|
I2of5Reader.prototype.consconstructor = I2of5Reader;
|
||||||
|
|
||||||
I2of5Reader.prototype._matchPattern = function(counter, code) {
|
I2of5Reader.prototype._matchPattern = function(counter, code) {
|
||||||
|
if (this.config.normalizeBarSpaceWidth) {
|
||||||
var i,
|
var i,
|
||||||
counterSum = [0, 0],
|
counterSum = [0, 0],
|
||||||
codeSum = [0, 0],
|
codeSum = [0, 0],
|
||||||
correction = [0, 0];
|
correction = [0, 0],
|
||||||
|
correctionRatio = this.MAX_CORRECTION_FACTOR,
|
||||||
|
correctionRatioInverse = 1 / correctionRatio;
|
||||||
|
|
||||||
for (i = 0; i < counter.length; i++) {
|
for (i = 0; i < counter.length; i++) {
|
||||||
counterSum[i % 2] += counter[i];
|
counterSum[i % 2] += counter[i];
|
||||||
codeSum[i % 2] += code[i]
|
codeSum[i % 2] += code[i]
|
||||||
}
|
}
|
||||||
correction[0] = codeSum[0]/counterSum[0];
|
correction[0] = codeSum[0] / counterSum[0];
|
||||||
correction[1] = codeSum[1]/counterSum[1];
|
correction[1] = codeSum[1] / counterSum[1];
|
||||||
|
|
||||||
|
correction[0] = Math.max(Math.min(correction[0], correctionRatio), correctionRatioInverse);
|
||||||
|
correction[1] = Math.max(Math.min(correction[1], correctionRatio), correctionRatioInverse);
|
||||||
|
this.barSpaceRatio = correction;
|
||||||
for (i = 0; i < counter.length; i++) {
|
for (i = 0; i < counter.length; i++) {
|
||||||
counter[i] *= correction[i % 2];
|
counter[i] *= this.barSpaceRatio[i % 2];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return BarcodeReader.prototype._matchPattern.call(this, counter, code);
|
return BarcodeReader.prototype._matchPattern.call(this, counter, code);
|
||||||
};
|
};
|
||||||
@@ -129,17 +138,18 @@ define(
|
|||||||
var self = this,
|
var self = this,
|
||||||
leadingWhitespaceStart,
|
leadingWhitespaceStart,
|
||||||
offset = self._nextSet(self._row),
|
offset = self._nextSet(self._row),
|
||||||
startInfo;
|
startInfo,
|
||||||
|
narrowBarWidth = 1;
|
||||||
|
|
||||||
while(!startInfo) {
|
while(!startInfo) {
|
||||||
startInfo = self._findPattern(self.START_PATTERN, offset, false, true);
|
startInfo = self._findPattern(self.START_PATTERN, offset, false, true);
|
||||||
if (!startInfo) {
|
if (!startInfo) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
leadingWhitespaceStart = startInfo.start - (startInfo.end - startInfo.start);
|
narrowBarWidth = Math.floor((startInfo.end - startInfo.start) / 4);
|
||||||
|
leadingWhitespaceStart = startInfo.start - narrowBarWidth*5;
|
||||||
if (leadingWhitespaceStart >= 0) {
|
if (leadingWhitespaceStart >= 0) {
|
||||||
if (self._matchRange(leadingWhitespaceStart, startInfo.start, 0)) {
|
if (self._matchRange(leadingWhitespaceStart, startInfo.start, 0)) {
|
||||||
startInfo.narrowBarWidth = Math.floor((startInfo.end - startInfo.start) / 4);
|
|
||||||
return startInfo;
|
return startInfo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -242,8 +252,8 @@ define(
|
|||||||
|
|
||||||
while (pos < counterLength) {
|
while (pos < counterLength) {
|
||||||
for (i = 0; i < 5; i++) {
|
for (i = 0; i < 5; i++) {
|
||||||
counterPair[0][i] = counters[pos];
|
counterPair[0][i] = counters[pos]*this.barSpaceRatio[0];
|
||||||
counterPair[1][i] = counters[pos + 1];
|
counterPair[1][i] = counters[pos + 1]*this.barSpaceRatio[1];
|
||||||
pos += 2;
|
pos += 2;
|
||||||
}
|
}
|
||||||
codes = self._decodePair(counterPair);
|
codes = self._decodePair(counterPair);
|
||||||
@@ -275,20 +285,12 @@ define(
|
|||||||
if (!startInfo) {
|
if (!startInfo) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
decodedCodes.push(startInfo);
|
||||||
|
|
||||||
endInfo = self._findEnd();
|
endInfo = self._findEnd();
|
||||||
if (!endInfo) {
|
if (!endInfo) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
console.log(startInfo);
|
|
||||||
console.log(endInfo);
|
|
||||||
|
|
||||||
code = {
|
|
||||||
code : startInfo.code,
|
|
||||||
start : startInfo.start,
|
|
||||||
end : startInfo.end
|
|
||||||
};
|
|
||||||
decodedCodes.push(code);
|
|
||||||
|
|
||||||
counters = self._fillCounters(startInfo.end, endInfo.start, false);
|
counters = self._fillCounters(startInfo.end, endInfo.start, false);
|
||||||
if (!self._verifyCounterLength(counters)) {
|
if (!self._verifyCounterLength(counters)) {
|
||||||
@@ -298,16 +300,30 @@ define(
|
|||||||
if (!code) {
|
if (!code) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
if (result.length % 2 !== 0 ||
|
||||||
|
result.length < 6) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
decodedCodes.push(endInfo);
|
||||||
return {
|
return {
|
||||||
code : result.join(""),
|
code : result.join(""),
|
||||||
start : startInfo.start,
|
start : startInfo.start,
|
||||||
end : code.end,
|
end : endInfo.end,
|
||||||
startInfo : startInfo,
|
startInfo : startInfo,
|
||||||
decodedCodes : decodedCodes
|
decodedCodes : decodedCodes
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
I2of5Reader.CONFIG_KEYS = {
|
||||||
|
normalizeBarSpaceWidth: {
|
||||||
|
'type': 'boolean',
|
||||||
|
'default': false,
|
||||||
|
'description': 'If true, the reader tries to normalize the' +
|
||||||
|
'width-difference between bars and spaces'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (I2of5Reader);
|
return (I2of5Reader);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
Reference in New Issue
Block a user