Fixed code-style errors

pull/72/head
Christoph Oberhofer 10 years ago
parent 8668e79b63
commit 03e9bee015

@ -65,11 +65,16 @@
"no-mixed-spaces-and-tabs": 2,
"no-multiple-empty-lines": 2,
"semi-spacing": 2,
"dot-notation": 2,
"no-spaced-func": 1,
"no-shadow": 2,
"no-undef": 2,
"padded-blocks": [2, "never"],
"semi": [2, "always"],
"space-after-keywords": [2, "always"],
"space-infix-ops": 2,
"max-len" : [1, 120]
"max-len" : [1, 120],
"consistent-return": 2,
"yoda": 2
}
}

@ -10,7 +10,7 @@ import EAN8Reader from './ean_8_reader';
import UPCEReader from './upc_e_reader';
import I2of5Reader from './i2of5_reader';
var readers = {
const READERS = {
code_128_reader: Code128Reader,
ean_reader: EANReader,
ean_8_reader: EAN8Reader,
@ -74,16 +74,16 @@ export default {
function initReaders() {
config.readers.forEach(function(readerConfig) {
var reader,
config = {};
configuration = {};
if (typeof readerConfig === 'object') {
reader = readerConfig.format;
config = readerConfig.config;
configuration = readerConfig.config;
} else if (typeof readerConfig === 'string') {
reader = readerConfig;
}
console.log("Before registering reader: ", reader);
_barcodeReaders.push(new readers[reader](config));
_barcodeReaders.push(new READERS[reader](configuration));
});
console.log("Registered Readers: " + _barcodeReaders
.map((reader) => JSON.stringify({format: reader.FORMAT, config: reader.config}))
@ -166,14 +166,13 @@ export default {
for ( i = 0; i < _barcodeReaders.length && result === null; i++) {
result = _barcodeReaders[i].decodePattern(barcodeLine.line);
}
if(result === null){
if (result === null){
return null;
}
return {
codeResult: result,
barcodeLine: barcodeLine
};
}
/**
@ -255,11 +254,11 @@ export default {
}
return {
codeResult : result.codeResult,
line : line,
angle : lineAngle,
pattern : result.barcodeLine.line,
threshold : result.barcodeLine.threshold
codeResult: result.codeResult,
line: line,
angle: lineAngle,
pattern: result.barcodeLine.line,
threshold: result.barcodeLine.threshold
};
}

@ -30,7 +30,7 @@ var _config,
_skeletonizer,
vec2 = glMatrix.vec2,
mat2 = glMatrix.mat2,
self = (typeof window !== 'undefined') ? window : self;
self = (typeof window !== 'undefined') ? window : self; // eslint-disable-line consistent-this
function initBuffers() {
var skeletonImageData;
@ -441,7 +441,6 @@ function rasterizeAngularSimilarity(patchesFound) {
var x,
y,
currentPatch,
patch,
idx,
dir,
current = {
@ -465,9 +464,8 @@ function rasterizeAngularSimilarity(patchesFound) {
continue;
}
patch = _imageToPatchGrid.data[idx];
if (_patchLabelGrid.data[idx] === 0) {
similarity = Math.abs(vec2.dot(patch.vec, currentPatch.vec));
similarity = Math.abs(vec2.dot(_imageToPatchGrid.data[idx].vec, currentPatch.vec));
if (similarity > threshold) {
trace(idx);
}

@ -16,9 +16,9 @@ export default {
updateCenter();
}
function add(point) {
pointMap[point.id] = point;
points.push(point);
function add(pointToAdd) {
pointMap[pointToAdd.id] = pointToAdd;
points.push(pointToAdd);
}
function updateCenter() {
@ -33,15 +33,15 @@ export default {
init();
return {
add: function(point) {
if (!pointMap[point.id]) {
add(point);
add: function(pointToAdd) {
if (!pointMap[pointToAdd.id]) {
add(pointToAdd);
updateCenter();
}
},
fits: function(point) {
fits: function(otherPoint) {
// check cosine similarity to center-angle
var similarity = Math.abs(vec2.dot(point.point.vec, center.vec));
var similarity = Math.abs(vec2.dot(otherPoint.point.vec, center.vec));
if (similarity > threshold) {
return true;
}
@ -55,10 +55,10 @@ export default {
}
};
},
createPoint: function(point, id, property) {
createPoint: function(newPoint, id, property) {
return {
rad: point[property],
point: point,
rad: newPoint[property],
point: newPoint,
id: id
};
}

@ -132,10 +132,11 @@ CodabarReader.prototype._thresholdResultPattern = function(result, startCounter)
}
["space", "bar"].forEach(function(key) {
var kind = categorization[key];
kind.wide.min = Math.floor((kind.narrow.size / kind.narrow.counts + kind.wide.size / kind.wide.counts) / 2);
kind.narrow.max = Math.ceil(kind.wide.min);
kind.wide.max = Math.ceil((kind.wide.size * self.MAX_ACCEPTABLE + self.PADDING) / kind.wide.counts);
var newkind = categorization[key];
newkind.wide.min =
Math.floor((newkind.narrow.size / newkind.narrow.counts + newkind.wide.size / newkind.wide.counts) / 2);
newkind.narrow.max = Math.ceil(newkind.wide.min);
newkind.wide.max = Math.ceil((newkind.wide.size * self.MAX_ACCEPTABLE + self.PADDING) / newkind.wide.counts);
});
return categorization;

@ -23,7 +23,7 @@ Code39VINReader.prototype._decode = function() {
var code = result.code;
if (!code) {
return;
return null;
}
code = code.replace(patterns.IOQ, '');

@ -1,5 +1,5 @@
import Cluster2 from './cluster';
import ArrayHelper from './array_helper';
import ArrayHelper from './array_helper';
import {vec2, vec3} from 'gl-matrix';
var CVUtils = {};
@ -11,15 +11,15 @@ var CVUtils = {};
*/
CVUtils.imageRef = function(x, y) {
var that = {
x : x,
y : y,
toVec2 : function() {
x: x,
y: y,
toVec2: function() {
return vec2.clone([this.x, this.y]);
},
toVec3 : function() {
toVec3: function() {
return vec3.clone([this.x, this.y, 1]);
},
round : function() {
round: function() {
this.x = this.x > 0.0 ? Math.floor(this.x + 0.5) : Math.floor(this.x - 0.5);
this.y = this.y > 0.0 ? Math.floor(this.y + 0.5) : Math.floor(this.y - 0.5);
return this;
@ -65,7 +65,8 @@ CVUtils.computeIntegralImage2 = function(imageWrapper, integralWrapper) {
posC = y * width;
posD = (y - 1) * width;
for ( x = 1; x < width; x++) {
integralImageData[posA] += imageData[posA] + integralImageData[posB] + integralImageData[posC] - integralImageData[posD];
integralImageData[posA] +=
imageData[posA] + integralImageData[posB] + integralImageData[posC] - integralImageData[posD];
posA++;
posB++;
posC++;
@ -133,7 +134,7 @@ CVUtils.sharpenLine = function(line) {
for (i = 1; i < length - 1; i++) {
right = line[i + 1];
// -1 4 -1 kernel
line[i-1] = (((center * 2) - left - right)) & 255;
line[i - 1] = (((center * 2) - left - right)) & 255;
left = center;
center = right;
}
@ -247,12 +248,12 @@ CVUtils.cluster = function(points, threshold, property) {
property = "rad";
}
function addToCluster(point) {
function addToCluster(newPoint) {
var found = false;
for ( k = 0; k < clusters.length; k++) {
cluster = clusters[k];
if (cluster.fits(point)) {
cluster.add(point);
if (cluster.fits(newPoint)) {
cluster.add(newPoint);
found = true;
}
}
@ -266,20 +267,21 @@ CVUtils.cluster = function(points, threshold, property) {
clusters.push(Cluster2.create(point, threshold));
}
}
return clusters;
};
CVUtils.Tracer = {
trace : function(points, vec) {
trace: function(points, vec) {
var iteration, maxIterations = 10, top = [], result = [], centerPos = 0, currentPos = 0;
function trace(idx, forward) {
var from, to, toIdx, predictedPos, thresholdX = 1, thresholdY = Math.abs(vec[1] / 10), found = false;
function match(pos, predicted) {
if (pos.x > (predicted.x - thresholdX) && pos.x < (predicted.x + thresholdX) && pos.y > (predicted.y - thresholdY) && pos.y < (predicted.y + thresholdY)) {
if (pos.x > (predicted.x - thresholdX)
&& pos.x < (predicted.x + thresholdX)
&& pos.y > (predicted.y - thresholdY)
&& pos.y < (predicted.y + thresholdY)) {
return true;
} else {
return false;
@ -292,13 +294,13 @@ CVUtils.Tracer = {
from = points[idx];
if (forward) {
predictedPos = {
x : from.x + vec[0],
y : from.y + vec[1]
x: from.x + vec[0],
y: from.y + vec[1]
};
} else {
predictedPos = {
x : from.x - vec[0],
y : from.y - vec[1]
x: from.x - vec[0],
y: from.y - vec[1]
};
}
@ -334,9 +336,7 @@ CVUtils.Tracer = {
result = top;
}
}
return result;
}
};
@ -344,7 +344,17 @@ CVUtils.DILATE = 1;
CVUtils.ERODE = 2;
CVUtils.dilate = function(inImageWrapper, outImageWrapper) {
var v, u, inImageData = inImageWrapper.data, outImageData = outImageWrapper.data, height = inImageWrapper.size.y, width = inImageWrapper.size.x, sum, yStart1, yStart2, xStart1, xStart2;
var v,
u,
inImageData = inImageWrapper.data,
outImageData = outImageWrapper.data,
height = inImageWrapper.size.y,
width = inImageWrapper.size.x,
sum,
yStart1,
yStart2,
xStart1,
xStart2;
for ( v = 1; v < height - 1; v++) {
for ( u = 1; u < width - 1; u++) {
@ -352,17 +362,26 @@ CVUtils.dilate = function(inImageWrapper, outImageWrapper) {
yStart2 = v + 1;
xStart1 = u - 1;
xStart2 = u + 1;
sum = inImageData[yStart1 * width + xStart1]/* + inImageData[yStart1*width+u] */ + inImageData[yStart1 * width + xStart2] +
/* inImageData[v*width+xStart1] + */
inImageData[v * width + u] + /* inImageData[v*width+xStart2] +*/
inImageData[yStart2 * width + xStart1]/* + inImageData[yStart2*width+u]*/ + inImageData[yStart2 * width + xStart2];
sum = inImageData[yStart1 * width + xStart1] + inImageData[yStart1 * width + xStart2] +
inImageData[v * width + u] +
inImageData[yStart2 * width + xStart1] + inImageData[yStart2 * width + xStart2];
outImageData[v * width + u] = sum > 0 ? 1 : 0;
}
}
};
CVUtils.erode = function(inImageWrapper, outImageWrapper) {
var v, u, inImageData = inImageWrapper.data, outImageData = outImageWrapper.data, height = inImageWrapper.size.y, width = inImageWrapper.size.x, sum, yStart1, yStart2, xStart1, xStart2;
var v,
u,
inImageData = inImageWrapper.data,
outImageData = outImageWrapper.data,
height = inImageWrapper.size.y,
width = inImageWrapper.size.x,
sum,
yStart1,
yStart2,
xStart1,
xStart2;
for ( v = 1; v < height - 1; v++) {
for ( u = 1; u < width - 1; u++) {
@ -370,10 +389,9 @@ CVUtils.erode = function(inImageWrapper, outImageWrapper) {
yStart2 = v + 1;
xStart1 = u - 1;
xStart2 = u + 1;
sum = inImageData[yStart1 * width + xStart1]/* + inImageData[yStart1*width+u] */ + inImageData[yStart1 * width + xStart2] +
/* inImageData[v*width+xStart1] + */
inImageData[v * width + u] + /* inImageData[v*width+xStart2] +*/
inImageData[yStart2 * width + xStart1]/* + inImageData[yStart2*width+u]*/ + inImageData[yStart2 * width + xStart2];
sum = inImageData[yStart1 * width + xStart1] + inImageData[yStart1 * width + xStart2] +
inImageData[v * width + u] +
inImageData[yStart2 * width + xStart1] + inImageData[yStart2 * width + xStart2];
outImageData[v * width + u] = sum === 5 ? 1 : 0;
}
}
@ -383,7 +401,10 @@ CVUtils.subtract = function(aImageWrapper, bImageWrapper, resultImageWrapper) {
if (!resultImageWrapper) {
resultImageWrapper = aImageWrapper;
}
var length = aImageWrapper.data.length, aImageData = aImageWrapper.data, bImageData = bImageWrapper.data, cImageData = resultImageWrapper.data;
var length = aImageWrapper.data.length,
aImageData = aImageWrapper.data,
bImageData = bImageWrapper.data,
cImageData = resultImageWrapper.data;
while (length--) {
cImageData[length] = aImageData[length] - bImageData[length];
@ -394,7 +415,10 @@ CVUtils.bitwiseOr = function(aImageWrapper, bImageWrapper, resultImageWrapper) {
if (!resultImageWrapper) {
resultImageWrapper = aImageWrapper;
}
var length = aImageWrapper.data.length, aImageData = aImageWrapper.data, bImageData = bImageWrapper.data, cImageData = resultImageWrapper.data;
var length = aImageWrapper.data.length,
aImageData = aImageWrapper.data,
bImageData = bImageWrapper.data,
cImageData = resultImageWrapper.data;
while (length--) {
cImageData[length] = aImageData[length] || bImageData[length];
@ -415,8 +439,8 @@ CVUtils.topGeneric = function(list, top, scoreFunc) {
for ( i = 0; i < top; i++) {
queue[i] = {
score : 0,
item : null
score: 0,
item: null
};
}
@ -461,7 +485,19 @@ CVUtils.grayAndHalfSampleFromCanvasData = function(canvasData, size, outArray) {
while (bottomRowIdx < endIdx) {
for ( i = 0; i < outWidth; i++) {
outArray[outImgIdx] = Math.floor(((0.299 * canvasData[topRowIdx * 4 + 0] + 0.587 * canvasData[topRowIdx * 4 + 1] + 0.114 * canvasData[topRowIdx * 4 + 2]) + (0.299 * canvasData[(topRowIdx + 1) * 4 + 0] + 0.587 * canvasData[(topRowIdx + 1) * 4 + 1] + 0.114 * canvasData[(topRowIdx + 1) * 4 + 2]) + (0.299 * canvasData[(bottomRowIdx) * 4 + 0] + 0.587 * canvasData[(bottomRowIdx) * 4 + 1] + 0.114 * canvasData[(bottomRowIdx) * 4 + 2]) + (0.299 * canvasData[(bottomRowIdx + 1) * 4 + 0] + 0.587 * canvasData[(bottomRowIdx + 1) * 4 + 1] + 0.114 * canvasData[(bottomRowIdx + 1) * 4 + 2])) / 4);
outArray[outImgIdx] = Math.floor((
(0.299 * canvasData[topRowIdx * 4 + 0] +
0.587 * canvasData[topRowIdx * 4 + 1] +
0.114 * canvasData[topRowIdx * 4 + 2]) +
(0.299 * canvasData[(topRowIdx + 1) * 4 + 0] +
0.587 * canvasData[(topRowIdx + 1) * 4 + 1] +
0.114 * canvasData[(topRowIdx + 1) * 4 + 2]) +
(0.299 * canvasData[(bottomRowIdx) * 4 + 0] +
0.587 * canvasData[(bottomRowIdx) * 4 + 1] +
0.114 * canvasData[(bottomRowIdx) * 4 + 2]) +
(0.299 * canvasData[(bottomRowIdx + 1) * 4 + 0] +
0.587 * canvasData[(bottomRowIdx + 1) * 4 + 1] +
0.114 * canvasData[(bottomRowIdx + 1) * 4 + 2])) / 4);
outImgIdx++;
topRowIdx = topRowIdx + 2;
bottomRowIdx = bottomRowIdx + 2;
@ -469,7 +505,6 @@ CVUtils.grayAndHalfSampleFromCanvasData = function(canvasData, size, outArray) {
topRowIdx = topRowIdx + inWidth;
bottomRowIdx = bottomRowIdx + inWidth;
}
};
CVUtils.computeGray = function(imageData, outArray, config) {
@ -483,14 +518,16 @@ CVUtils.computeGray = function(imageData, outArray, config) {
}
} else {
for (i = 0; i < l; i++) {
outArray[i] = Math.floor(0.299 * imageData[i * 4 + 0] + 0.587 * imageData[i * 4 + 1] + 0.114 * imageData[i * 4 + 2]);
outArray[i] = Math.floor(
0.299 * imageData[i * 4 + 0] + 0.587 * imageData[i * 4 + 1] + 0.114 * imageData[i * 4 + 2]);
}
}
};
CVUtils.loadImageArray = function(src, callback, canvas) {
if (!canvas)
if (!canvas) {
canvas = document.createElement('canvas');
}
var img = new Image();
img.callback = callback;
img.onload = function() {
@ -503,8 +540,8 @@ CVUtils.loadImageArray = function(src, callback, canvas) {
var data = ctx.getImageData(0, 0, this.width, this.height).data;
CVUtils.computeGray(data, array);
this.callback(array, {
x : this.width,
y : this.height
x: this.width,
y: this.height
}, this);
};
img.src = src;
@ -525,7 +562,8 @@ CVUtils.halfSample = function(inImgWrapper, outImgWrapper) {
var outImgIdx = 0;
while (bottomRowIdx < endIdx) {
for (var i = 0; i < outWidth; i++) {
outImg[outImgIdx] = Math.floor((inImg[topRowIdx] + inImg[topRowIdx + 1] + inImg[bottomRowIdx] + inImg[bottomRowIdx + 1]) / 4);
outImg[outImgIdx] = Math.floor(
(inImg[topRowIdx] + inImg[topRowIdx + 1] + inImg[bottomRowIdx] + inImg[bottomRowIdx + 1]) / 4);
outImgIdx++;
topRowIdx = topRowIdx + 2;
bottomRowIdx = bottomRowIdx + 2;
@ -536,7 +574,16 @@ CVUtils.halfSample = function(inImgWrapper, outImgWrapper) {
};
CVUtils.hsv2rgb = function(hsv, rgb) {
var h = hsv[0], s = hsv[1], v = hsv[2], c = v * s, x = c * (1 - Math.abs((h / 60) % 2 - 1)), m = v - c, r = 0, g = 0, b = 0;
var h = hsv[0],
s = hsv[1],
v = hsv[2],
c = v * s,
x = c * (1 - Math.abs((h / 60) % 2 - 1)),
m = v - c,
r = 0,
g = 0,
b = 0;
rgb = rgb || [0, 0, 0];
if (h < 60) {
@ -572,8 +619,8 @@ CVUtils._computeDivisors = function(n) {
for (i = 1; i < Math.sqrt(n) + 1; i++) {
if (n % i === 0) {
divisors.push(i);
if (i !== n/i) {
largeDivisors.unshift(Math.floor(n/i));
if (i !== n / i) {
largeDivisors.unshift(Math.floor(n / i));
}
}
}
@ -614,25 +661,25 @@ CVUtils.calculatePatchSize = function(patchSize, imgSize) {
},
nrOfPatchesIdx = nrOfPatchesMap[patchSize] || nrOfPatchesMap.medium,
nrOfPatches = nrOfPatchesList[nrOfPatchesIdx],
desiredPatchSize = Math.floor(wideSide/nrOfPatches),
desiredPatchSize = Math.floor(wideSide / nrOfPatches),
optimalPatchSize;
function findPatchSizeForDivisors(divisors) {
var i = 0,
found = divisors[Math.floor(divisors.length/2)];
found = divisors[Math.floor(divisors.length / 2)];
while(i < (divisors.length - 1) && divisors[i] < desiredPatchSize) {
while (i < (divisors.length - 1) && divisors[i] < desiredPatchSize) {
i++;
}
if (i > 0) {
if (Math.abs(divisors[i] - desiredPatchSize) > Math.abs(divisors[i-1] - desiredPatchSize)) {
found = divisors[i-1];
if (Math.abs(divisors[i] - desiredPatchSize) > Math.abs(divisors[i - 1] - desiredPatchSize)) {
found = divisors[i - 1];
} else {
found = divisors[i];
}
}
if (desiredPatchSize / found < nrOfPatchesList[nrOfPatchesIdx+1] / nrOfPatchesList[nrOfPatchesIdx] &&
desiredPatchSize / found > nrOfPatchesList[nrOfPatchesIdx-1]/nrOfPatchesList[nrOfPatchesIdx] ) {
if (desiredPatchSize / found < nrOfPatchesList[nrOfPatchesIdx + 1] / nrOfPatchesList[nrOfPatchesIdx] &&
desiredPatchSize / found > nrOfPatchesList[nrOfPatchesIdx - 1] / nrOfPatchesList[nrOfPatchesIdx] ) {
return {x: found, y: found};
}
return null;
@ -650,9 +697,9 @@ CVUtils.calculatePatchSize = function(patchSize, imgSize) {
CVUtils._parseCSSDimensionValues = function(value) {
var dimension = {
value: parseFloat(value),
unit: value.indexOf("%") === value.length-1 ? "%" : "%"
};
value: parseFloat(value),
unit: value.indexOf("%") === value.length - 1 ? "%" : "%"
};
return dimension;
};

@ -5,13 +5,13 @@ function EANReader(opts) {
}
var properties = {
CODE_L_START : {value: 0},
MODULO : {value: 7},
CODE_G_START : {value: 10},
START_PATTERN : {value: [1 / 3 * 7, 1 / 3 * 7, 1 / 3 * 7]},
STOP_PATTERN : {value: [1 / 3 * 7, 1 / 3 * 7, 1 / 3 * 7]},
MIDDLE_PATTERN : {value: [1 / 5 * 7, 1 / 5 * 7, 1 / 5 * 7, 1 / 5 * 7, 1 / 5 * 7]},
CODE_PATTERN : {value: [
CODE_L_START: {value: 0},
MODULO: {value: 7},
CODE_G_START: {value: 10},
START_PATTERN: {value: [1 / 3 * 7, 1 / 3 * 7, 1 / 3 * 7]},
STOP_PATTERN: {value: [1 / 3 * 7, 1 / 3 * 7, 1 / 3 * 7]},
MIDDLE_PATTERN: {value: [1 / 5 * 7, 1 / 5 * 7, 1 / 5 * 7, 1 / 5 * 7, 1 / 5 * 7]},
CODE_PATTERN: {value: [
[3, 2, 1, 1],
[2, 2, 2, 1],
[2, 1, 2, 2],
@ -33,7 +33,7 @@ var properties = {
[3, 1, 2, 1],
[2, 1, 1, 3]
]},
CODE_FREQUENCY : {value: [0, 11, 13, 14, 19, 25, 28, 21, 22, 26]},
CODE_FREQUENCY: {value: [0, 11, 13, 14, 19, 25, 28, 21, 22, 26]},
SINGLE_CODE_ERROR: {value: 0.67},
AVG_CODE_ERROR: {value: 0.27},
FORMAT: {value: "ean_13", writeable: false}
@ -50,10 +50,10 @@ EANReader.prototype._decodeCode = function(start, coderange) {
isWhite = !self._row[offset],
counterPos = 0,
bestMatch = {
error : Number.MAX_VALUE,
code : -1,
start : start,
end : start
error: Number.MAX_VALUE,
code: -1,
start: start,
end: start
},
code,
error,
@ -99,10 +99,10 @@ EANReader.prototype._findPattern = function(pattern, offset, isWhite, tryHarder,
i,
counterPos = 0,
bestMatch = {
error : Number.MAX_VALUE,
code : -1,
start : 0,
end : 0
error: Number.MAX_VALUE,
code: -1,
start: 0,
end: 0
},
error,
j,
@ -175,7 +175,7 @@ EANReader.prototype._findStart = function() {
offset = self._nextSet(self._row),
startInfo;
while(!startInfo) {
while (!startInfo) {
startInfo = self._findPattern(self.START_PATTERN, offset);
if (!startInfo) {
return null;
@ -280,9 +280,9 @@ EANReader.prototype._decode = function() {
return null;
}
code = {
code : startInfo.code,
start : startInfo.start,
end : startInfo.end
code: startInfo.code,
start: startInfo.start,
end: startInfo.end
};
decodedCodes.push(code);
code = self._decodePayload(code, result, decodedCodes);
@ -302,12 +302,12 @@ EANReader.prototype._decode = function() {
}
return {
code : result.join(""),
start : startInfo.start,
end : code.end,
codeset : "",
startInfo : startInfo,
decodedCodes : decodedCodes
code: result.join(""),
start: startInfo.start,
end: code.end,
codeset: "",
startInfo: startInfo,
decodedCodes: decodedCodes
};
};

@ -1,10 +1,10 @@
export default function() {
export default (function() {
var events = {};
function getEvent(eventName) {
if (!events[eventName]) {
events[eventName] = {
subscribers : []
subscribers: []
};
}
return events[eventName];
@ -29,8 +29,8 @@ export default function() {
if ( typeof callback === "function") {
subscription = {
callback : callback,
async : async
callback: callback,
async: async
};
} else {
subscription = callback;
@ -43,10 +43,10 @@ export default function() {
}
return {
subscribe : function(event, callback, async) {
subscribe: function(event, callback, async) {
return subscribe(event, callback, async);
},
publish : function(eventName, data) {
publish: function(eventName, data) {
var event = getEvent(eventName),
subscribers = event.subscribers;
@ -79,4 +79,4 @@ export default function() {
}
}
};
}();
})();

@ -52,7 +52,7 @@ FrameGrabber.create = function(inputStream, canvas) {
if (frame) {
_ctx.drawImage(frame, 0, 0, _canvasSize.x, _canvasSize.y);
ctxData = _ctx.getImageData(_sx, _sy, _size.x, _size.y).data;
if(doHalfSample){
if (doHalfSample){
CVUtils.grayAndHalfSampleFromCanvasData(ctxData, _size, _data);
} else {
CVUtils.computeGray(ctxData, _data, _streamConfig);

@ -15,7 +15,7 @@ function getDefaulConfig() {
var config = {};
Object.keys(I2of5Reader.CONFIG_KEYS).forEach(function(key) {
config[key] = I2of5Reader.CONFIG_KEYS[key]['default'];
config[key] = I2of5Reader.CONFIG_KEYS[key].default;
});
return config;
}
@ -23,26 +23,26 @@ function getDefaulConfig() {
var N = 1,
W = 3,
properties = {
MODULO : {value: 10},
START_PATTERN : {value: [N*2.5, N*2.5, N*2.5, N*2.5]},
STOP_PATTERN : {value: [N*2, N*2, W*2]},
CODE_PATTERN : {value: [
[N, N, W, W, N],
[W, N, N, N, W],
[N, W, N, N, W],
[W, W, N, N, N],
[N, N, W, N, W],
[W, N, W, N, N],
[N, W, W, N, N],
[N, N, N, W, W],
[W, N, N, W, N],
[N, W, N, W, N]
]},
SINGLE_CODE_ERROR: {value: 0.78, writable: true},
AVG_CODE_ERROR: {value: 0.38, writable: true},
MAX_CORRECTION_FACTOR: {value: 5},
FORMAT: {value: "i2of5"}
};
MODULO: {value: 10},
START_PATTERN: {value: [N * 2.5, N * 2.5, N * 2.5, N * 2.5]},
STOP_PATTERN: {value: [N * 2, N * 2, W * 2]},
CODE_PATTERN: {value: [
[N, N, W, W, N],
[W, N, N, N, W],
[N, W, N, N, W],
[W, W, N, N, N],
[N, N, W, N, W],
[W, N, W, N, N],
[N, W, W, N, N],
[N, N, N, W, W],
[W, N, N, W, N],
[N, W, N, W, N]
]},
SINGLE_CODE_ERROR: {value: 0.78, writable: true},
AVG_CODE_ERROR: {value: 0.38, writable: true},
MAX_CORRECTION_FACTOR: {value: 5},
FORMAT: {value: "i2of5"}
};
I2of5Reader.prototype = Object.create(BarcodeReader.prototype, properties);
I2of5Reader.prototype.constructor = I2of5Reader;
@ -79,10 +79,10 @@ I2of5Reader.prototype._findPattern = function(pattern, offset, isWhite, tryHarde
i,
counterPos = 0,
bestMatch = {
error : Number.MAX_VALUE,
code : -1,
start : 0,
end : 0
error: Number.MAX_VALUE,
code: -1,
start: 0,
end: 0
},
error,
j,
@ -148,13 +148,13 @@ I2of5Reader.prototype._findStart = function() {
startInfo,
narrowBarWidth = 1;
while(!startInfo) {
while (!startInfo) {
startInfo = self._findPattern(self.START_PATTERN, offset, false, true);
if (!startInfo) {
return null;
}
narrowBarWidth = Math.floor((startInfo.end - startInfo.start) / 4);
leadingWhitespaceStart = startInfo.start - narrowBarWidth*10;
leadingWhitespaceStart = startInfo.start - narrowBarWidth * 10;
if (leadingWhitespaceStart >= 0) {
if (self._matchRange(leadingWhitespaceStart, startInfo.start, 0)) {
return startInfo;
@ -224,10 +224,10 @@ I2of5Reader.prototype._decodeCode = function(counter) {
epsilon = self.AVG_CODE_ERROR,
code,
bestMatch = {
error : Number.MAX_VALUE,
code : -1,
start : 0,
end : 0
error: Number.MAX_VALUE,
code: -1,
start: 0,
end: 0
};
for ( j = 0; j < counter.length; j++) {
@ -259,8 +259,8 @@ I2of5Reader.prototype._decodePayload = function(counters, result, decodedCodes)
while (pos < counterLength) {
for (i = 0; i < 5; i++) {
counterPair[0][i] = counters[pos]*this.barSpaceRatio[0];
counterPair[1][i] = counters[pos + 1]*this.barSpaceRatio[1];
counterPair[0][i] = counters[pos] * this.barSpaceRatio[0];
counterPair[1][i] = counters[pos + 1] * this.barSpaceRatio[1];
pos += 2;
}
codes = self._decodePair(counterPair);
@ -314,11 +314,11 @@ I2of5Reader.prototype._decode = function() {
decodedCodes.push(endInfo);
return {
code : result.join(""),
start : startInfo.start,
end : endInfo.end,
startInfo : startInfo,
decodedCodes : decodedCodes
code: result.join(""),
start: startInfo.start,
end: endInfo.end,
startInfo: startInfo,
decodedCodes: decodedCodes
};
};

@ -25,10 +25,10 @@ export default {
canvasDataPos = data.length,
value;
if (canvasDataPos/imageDataPos !== 4) {
if (canvasDataPos / imageDataPos !== 4) {
return false;
}
while(imageDataPos--){
while (imageDataPos--){
value = imageData[imageDataPos];
data[--canvasDataPos] = 255;
data[--canvasDataPos] = value;

@ -15,17 +15,17 @@ ImageLoader.load = function(directory, callback, offset, size, sequence) {
}
}
htmlImagesArray.notLoaded = [];
htmlImagesArray.addImage = function(img) {
htmlImagesArray.notLoaded.push(img);
htmlImagesArray.addImage = function(image) {
htmlImagesArray.notLoaded.push(image);
};
htmlImagesArray.loaded = function(loadedImg) {
var notloadedImgs = htmlImagesArray.notLoaded;
for (var x = 0; x < notloadedImgs.length; x++) {
if (notloadedImgs[x] == loadedImg) {
if (notloadedImgs[x] === loadedImg) {
notloadedImgs.splice(x, 1);
for (var y = 0; y < htmlImagesSrcArray.length; y++) {
var imgName = htmlImagesSrcArray[y].substr(htmlImagesSrcArray[y].lastIndexOf("/"));
if (loadedImg.src.lastIndexOf(imgName) != -1) {
if (loadedImg.src.lastIndexOf(imgName) !== -1) {
htmlImagesArray[y] = loadedImg;
break;
}

@ -1,7 +1,7 @@
import SubImage from './subImage';
import CVUtils from './cv_utils';
import ArrayHelper from './array_helper';
import {vec2, mat2} from 'gl-matrix';
import {vec2} from 'gl-matrix';
/**
* Represents a basic image combining the data and size.
@ -25,7 +25,6 @@ function ImageWrapper(size, data, ArrayType, initialize) {
ArrayHelper.init(this.data, 0);
}
}
} else {
this.data = data;
}
@ -40,77 +39,10 @@ function ImageWrapper(size, data, ArrayType, initialize) {
* @see cvd/image.h
*/
ImageWrapper.prototype.inImageWithBorder = function(imgRef, border) {
return (imgRef.x >= border) && (imgRef.y >= border) && (imgRef.x < (this.size.x - border)) && (imgRef.y < (this.size.y - border));
};
/**
* Transforms an image according to the given affine-transformation matrix.
* @param inImg ImageWrapper a image containing the information to be extracted.
* @param outImg ImageWrapper the image to be filled. The whole image out image is filled by the in image.
* @param M mat2 the matrix used to map point in the out matrix to those in the in matrix
* @param inOrig vec2 origin in the in image
* @param outOrig vec2 origin in the out image
* @returns Number the number of pixels not in the in image
* @see cvd/vision.h
*/
ImageWrapper.transform = function(inImg, outImg, M, inOrig, outOrig) {
var w = outImg.size.x, h = outImg.size.y, iw = inImg.size.x, ih = inImg.size.y;
var across = vec2.clone([M[0], M[2]]);
var down = vec2.clone([M[1], M[3]]);
var defaultValue = 0;
var p0 = vec2.subtract(inOrig, mat2.xVec2(M, outOrig, vec2.clone()), vec2.clone());
var min_x = p0[0], min_y = p0[1];
var max_x = min_x, max_y = min_y;
var p, i, j;
var sampleFunc = ImageWrapper.sample;
if (across[0] < 0)
min_x += w * across[0];
else
max_x += w * across[0];
if (down[0] < 0)
min_x += h * down[0];
else
max_x += h * down[0];
if (across[1] < 0)
min_y += w * across[1];
else
max_y += w * across[1];
if (down[1] < 0)
min_y += h * down[1];
else
max_y += h * down[1];
var carrigeReturn = vec2.subtract(down, vec2.scale(across, w, vec2.clone()), vec2.clone());
if (min_x >= 0 && min_y >= 0 && max_x < iw - 1 && max_y < ih - 1) {
p = p0;
for ( i = 0; i < h; ++i, vec2.add(p, carrigeReturn))
for ( j = 0; j < w; ++j, vec2.add(p, across))
outImg.set(j, i, sampleFunc(inImg, p[0], p[1]));
return 0;
} else {
var x_bound = iw - 1;
var y_bound = ih - 1;
var count = 0;
p = p0;
for ( i = 0; i < h; ++i, vec2.add(p, carrigeReturn)) {
for ( j = 0; j < w; ++j, vec2.add(p, across)) {
if (0 <= p[0] && 0 <= p[1] && p[0] < x_bound && p[1] < y_bound) {
outImg.set(j, i, sampleFunc(inImg, p[0], p[1]));
} else {
outImg.set(j, i, defaultValue); ++count;
}
}
}
return count;
}
return (imgRef.x >= border)
&& (imgRef.y >= border)
&& (imgRef.x < (this.size.x - border))
&& (imgRef.y < (this.size.y - border));
};
/**
@ -203,8 +135,8 @@ ImageWrapper.prototype.getSafe = function(x, y) {
if (!this.indexMapping) {
this.indexMapping = {
x : [],
y : []
x: [],
y: []
};
for (i = 0; i < this.size.x; i++) {
this.indexMapping.x[i] = i;
@ -252,7 +184,6 @@ ImageWrapper.prototype.invert = function() {
while (length--) {
data[length] = data[length] ? 0 : 1;
}
};
ImageWrapper.prototype.convolve = function(kernel) {
@ -262,7 +193,7 @@ ImageWrapper.prototype.convolve = function(kernel) {
accu = 0;
for ( ky = -kSize; ky <= kSize; ky++) {
for ( kx = -kSize; kx <= kSize; kx++) {
accu += kernel[ky+kSize][kx + kSize] * this.getSafe(x + kx, y + ky);
accu += kernel[ky + kSize][kx + kSize] * this.getSafe(x + kx, y + ky);
}
}
this.data[y * this.size.x + x] = accu;
@ -297,14 +228,14 @@ ImageWrapper.prototype.moments = function(labelcount) {
for ( i = 0; i < labelcount; i++) {
labelsum[i] = {
m00 : 0,
m01 : 0,
m10 : 0,
m11 : 0,
m02 : 0,
m20 : 0,
theta : 0,
rad : 0
m00: 0,
m01: 0,
m10: 0,
m11: 0,
m02: 0,
m20: 0,
theta: 0,
rad: 0
};
}

@ -15,8 +15,10 @@ InputStream.createVideoStream = function(video) {
var width = video.videoWidth,
height = video.videoHeight;
_calculatedWidth = _config.size ? width/height > 1 ? _config.size : Math.floor((width/height) * _config.size) : width;
_calculatedHeight = _config.size ? width/height > 1 ? Math.floor((height/width) * _config.size) : _config.size : height;
_calculatedWidth =
_config.size ? width / height > 1 ? _config.size : Math.floor((width / height) * _config.size) : width;
_calculatedHeight =
_config.size ? width / height > 1 ? Math.floor((height / width) * _config.size) : _config.size : height;
_canvasSize.x = _calculatedWidth;
_canvasSize.y = _calculatedHeight;
@ -72,8 +74,9 @@ InputStream.createVideoStream = function(video) {
};
that.setCurrentTime = function(time) {
if (_config.type !== "LiveStream")
if (_config.type !== "LiveStream") {
video.currentTime = time;
}
};
that.addEventListener = function(event, f, bool) {
@ -175,8 +178,10 @@ InputStream.createImageStream = function() {
imgArray = imgs;
width = imgs[0].width;
height = imgs[0].height;
calculatedWidth = _config.size ? width/height > 1 ? _config.size : Math.floor((width/height) * _config.size) : width;
calculatedHeight = _config.size ? width/height > 1 ? Math.floor((height/width) * _config.size) : _config.size : height;
calculatedWidth =
_config.size ? width / height > 1 ? _config.size : Math.floor((width / height) * _config.size) : width;
calculatedHeight =
_config.size ? width / height > 1 ? Math.floor((height / width) * _config.size) : _config.size : height;
_canvasSize.x = calculatedWidth;
_canvasSize.y = calculatedHeight;
loaded = true;
@ -209,12 +214,12 @@ InputStream.createImageStream = function() {
return calculatedHeight;
};
that.setWidth = function(width) {
calculatedWidth = width;
that.setWidth = function(newWidth) {
calculatedWidth = newWidth;
};
that.setHeight = function(height) {
calculatedHeight = height;
that.setHeight = function(newHeight) {
calculatedHeight = newHeight;
};
that.getRealWidth = function() {
@ -277,9 +282,9 @@ InputStream.createImageStream = function() {
return _topRight;
};
that.setCanvasSize = function(size) {
_canvasSize.x = size.x;
_canvasSize.y = size.y;
that.setCanvasSize = function(canvasSize) {
_canvasSize.x = canvasSize.x;
_canvasSize.y = canvasSize.y;
};
that.getCanvasSize = function() {

@ -1,15 +1,15 @@
import TypeDefs from './typedefs';
import TypeDefs from './typedefs'; // eslint-disable-line no-unused-vars
import InputStream from './input_stream';
import ImageWrapper from './image_wrapper';
import BarcodeLocator from './barcode_locator';
import BarcodeDecoder from './barcode_decoder';
import FrameGrabber from './frame_grabber';
import Config from './config';
import Events from './events';
import CameraAccess from './camera_access';
import ImageDebug from './image_debug';
import {vec2} from 'gl-matrix';
import ResultCollector from './result_collector';
import ImageWrapper from './image_wrapper';
import BarcodeLocator from './barcode_locator';
import BarcodeDecoder from './barcode_decoder';
import FrameGrabber from './frame_grabber';
import Config from './config';
import Events from './events';
import CameraAccess from './camera_access';
import ImageDebug from './image_debug';
import {vec2} from 'gl-matrix';
import ResultCollector from './result_collector';
const merge = require('lodash/object/merge');
@ -17,13 +17,13 @@ var _inputStream,
_framegrabber,
_stopped,
_canvasContainer = {
ctx : {
image : null,
overlay : null
ctx: {
image: null,
overlay: null
},
dom : {
image : null,
overlay : null
dom: {
image: null,
overlay: null
}
},
_inputImageWrapper,
@ -63,12 +63,12 @@ function initConfig() {
function initInputStream(cb) {
var video;
if (_config.inputStream.type == "VideoStream") {
if (_config.inputStream.type === "VideoStream") {
video = document.createElement("video");
_inputStream = InputStream.createVideoStream(video);
} else if (_config.inputStream.type == "ImageStream") {
} else if (_config.inputStream.type === "ImageStream") {
_inputStream = InputStream.createImageStream();
} else if (_config.inputStream.type == "LiveStream") {
} else if (_config.inputStream.type === "LiveStream") {
var $viewport = document.querySelector("#interactive.viewport");
if ($viewport) {
video = $viewport.querySelector("video");
@ -122,7 +122,7 @@ function initCanvas() {
if (!_canvasContainer.dom.image) {
_canvasContainer.dom.image = document.createElement("canvas");
_canvasContainer.dom.image.className = "imgBuffer";
if ($viewport && _config.inputStream.type == "ImageStream") {
if ($viewport && _config.inputStream.type === "ImageStream") {
$viewport.appendChild(_canvasContainer.dom.image);
}
}
@ -154,18 +154,18 @@ function initBuffers(imageWrapper) {
_inputImageWrapper = imageWrapper;
} else {
_inputImageWrapper = new ImageWrapper({
x : _inputStream.getWidth(),
y : _inputStream.getHeight()
x: _inputStream.getWidth(),
y: _inputStream.getHeight()
});
}
console.log(_inputImageWrapper.size);
_boxSize = [
vec2.clone([0, 0]),
vec2.clone([0, _inputImageWrapper.size.y]),
vec2.clone([_inputImageWrapper.size.x, _inputImageWrapper.size.y]),
vec2.clone([_inputImageWrapper.size.x, 0])
];
vec2.clone([0, 0]),
vec2.clone([0, _inputImageWrapper.size.y]),
vec2.clone([_inputImageWrapper.size.x, _inputImageWrapper.size.y]),
vec2.clone([_inputImageWrapper.size.x, 0])
];
BarcodeLocator.init(_inputImageWrapper, _config.locator);
}
@ -204,7 +204,7 @@ function transformResult(result) {
function moveBox(box) {
var corner = box.length;
while(corner--) {
while (corner--) {
box[corner][0] += xOffset;
box[corner][1] += yOffset;
}
@ -286,7 +286,7 @@ function start() {
( function frame() {
if (!_stopped) {
update();
if (_onUIThread && _config.inputStream.type == "LiveStream") {
if (_onUIThread && _config.inputStream.type === "LiveStream") {
window.requestAnimFrame(frame);
}
}
@ -346,17 +346,15 @@ function initWorker(cb) {
function workerInterface(factory) {
/* eslint-disable no-undef*/
window = self;
if (factory) {
/* jshint ignore:start */
var Quagga = factory();
if (!Quagga) {
self.postMessage({'event': 'error', message: 'Quagga could not be created'});
return;
}
/* jshint ignore:end */
}
/* jshint ignore:start */
var imageWrapper;
self.onmessage = function(e) {
@ -364,8 +362,8 @@ function workerInterface(factory) {
var config = e.data.config;
config.numOfWorkers = 0;
imageWrapper = new Quagga.ImageWrapper({
x : e.data.size.x,
y : e.data.size.y
x: e.data.size.x,
y: e.data.size.y
}, new Uint8Array(e.data.imageData));
Quagga.init(config, ready, imageWrapper);
Quagga.onProcessed(onProcessed);
@ -378,13 +376,18 @@ function workerInterface(factory) {
};
function onProcessed(result) {
self.postMessage({'event': 'processed', imageData: imageWrapper.data, result: result}, [imageWrapper.data.buffer]);
self.postMessage({
'event': 'processed',
imageData: imageWrapper.data,
result: result
}, [imageWrapper.data.buffer]);
}
function ready() {
function ready() { // eslint-disable-line
self.postMessage({'event': 'initialized', imageData: imageWrapper.data}, [imageWrapper.data.buffer]);
}
/* jshint ignore:end */
/* eslint-enable */
}
function generateWorkerBlob() {
@ -393,12 +396,12 @@ function generateWorkerBlob() {
/* jshint ignore:start */
if (typeof __factorySource__ !== 'undefined') {
factorySource = __factorySource__;
factorySource = __factorySource__; // eslint-disable-line no-undef
}
/* jshint ignore:end */
blob = new Blob(['(' + workerInterface.toString() + ')(' + factorySource + ');'],
{type : 'text/javascript'});
{type: 'text/javascript'});
return window.URL.createObjectURL(blob);
}
@ -414,7 +417,7 @@ function setReaders(readers) {
}
export default {
init : function(config, cb, imageWrapper) {
init: function(config, cb, imageWrapper) {
_config = merge({}, Config, config);
if (imageWrapper) {
_onUIThread = false;
@ -424,10 +427,10 @@ export default {
initInputStream(cb);
}
},
start : function() {
start: function() {
start();
},
stop : function() {
stop: function() {
_stopped = true;
_workerPool.forEach(function(workerThread) {
workerThread.worker.terminate();
@ -442,7 +445,7 @@ export default {
pause: function() {
_stopped = true;
},
onDetected : function(callback) {
onDetected: function(callback) {
Events.subscribe("detected", callback);
},
offDetected: function(callback) {
@ -462,12 +465,12 @@ export default {
_resultCollector = resultCollector;
}
},
canvas : _canvasContainer,
decodeSingle : function(config, resultCallback) {
canvas: _canvasContainer,
decodeSingle: function(config, resultCallback) {
config = merge({
inputStream: {
type : "ImageStream",
sequence : false,
type: "ImageStream",
sequence: false,
size: 800,
src: config.src
},

@ -4,26 +4,26 @@ import Tracer from './tracer';
* http://www.codeproject.com/Tips/407172/Connected-Component-Labeling-and-Vectorization
*/
var Rasterizer = {
createContour2D : function() {
createContour2D: function() {
return {
dir : null,
index : null,
firstVertex : null,
insideContours : null,
nextpeer : null,
prevpeer : null
dir: null,
index: null,
firstVertex: null,
insideContours: null,
nextpeer: null,
prevpeer: null
};
},
CONTOUR_DIR : {
CW_DIR : 0,
CCW_DIR : 1,
UNKNOWN_DIR : 2
CONTOUR_DIR: {
CW_DIR: 0,
CCW_DIR: 1,
UNKNOWN_DIR: 2
},
DIR : {
OUTSIDE_EDGE : -32767,
INSIDE_EDGE : -32766
DIR: {
OUTSIDE_EDGE: -32767,
INSIDE_EDGE: -32766
},
create : function(imageWrapper, labelWrapper) {
create: function(imageWrapper, labelWrapper) {
var imageData = imageWrapper.data,
labelData = labelWrapper.data,
width = imageWrapper.size.x,
@ -31,7 +31,7 @@ var Rasterizer = {
tracer = Tracer.create(imageWrapper, labelWrapper);
return {
rasterize : function(depthlabel) {
rasterize: function(depthlabel) {
var color,
bc,
lc,
@ -81,7 +81,8 @@ var Rasterizer = {
cc = p;
}
} else {
vertex = tracer.contourTracing(cy, cx, Rasterizer.DIR.INSIDE_EDGE, color, labelindex);
vertex = tracer
.contourTracing(cy, cx, Rasterizer.DIR.INSIDE_EDGE, color, labelindex);
if (vertex !== null) {
p = Rasterizer.createContour2D();
p.firstVertex = vertex;
@ -108,7 +109,8 @@ var Rasterizer = {
} else {
labelData[pos] = labelindex;
}
} else if (labelData[pos] === Rasterizer.DIR.OUTSIDE_EDGE || labelData[pos] === Rasterizer.DIR.INSIDE_EDGE) {
} else if (labelData[pos] === Rasterizer.DIR.OUTSIDE_EDGE
|| labelData[pos] === Rasterizer.DIR.INSIDE_EDGE) {
labelindex = 0;
if (labelData[pos] === Rasterizer.DIR.INSIDE_EDGE) {
bc = imageData[pos];
@ -127,12 +129,12 @@ var Rasterizer = {
sc = sc.nextpeer;
}
return {
cc : cc,
count : connectedCount
cc: cc,
count: connectedCount
};
},
debug: {
drawContour : function(canvas, firstContour) {
drawContour: function(canvas, firstContour) {
var ctx = canvas.getContext("2d"),
pq = firstContour,
iq,
@ -163,7 +165,7 @@ var Rasterizer = {
}
}
switch(q.dir) {
switch (q.dir) {
case Rasterizer.CONTOUR_DIR.CW_DIR:
ctx.strokeStyle = "red";
break;
@ -181,7 +183,7 @@ var Rasterizer = {
do {
p = p.next;
ctx.lineTo(p.x, p.y);
} while(p !== q.firstVertex);
} while (p !== q.firstVertex);
ctx.stroke();
}
}

@ -27,7 +27,10 @@ export default {
capture = config.capture === true;
function matchesConstraints(codeResult) {
return capacity && codeResult && !contains(codeResult, config.blacklist) && passesFilter(codeResult, config.filter);
return capacity
&& codeResult
&& !contains(codeResult, config.blacklist)
&& passesFilter(codeResult, config.filter);
}
return {

@ -26,8 +26,12 @@ function Skeletonizer(stdlib, foreign, buffer) {
yStart2 = (offset + size) | 0;
xStart1 = (u - 1) | 0;
xStart2 = (u + 1) | 0;
sum = ((images[(inImagePtr + yStart1 + xStart1) | 0] | 0) + (images[(inImagePtr + yStart1 + xStart2) | 0] | 0) + (images[(inImagePtr + offset + u) | 0] | 0) + (images[(inImagePtr + yStart2 + xStart1) | 0] | 0) + (images[(inImagePtr + yStart2 + xStart2) | 0] | 0)) | 0;
if ((sum | 0) == (5 | 0)) {
sum = ((images[(inImagePtr + yStart1 + xStart1) | 0] | 0)
+ (images[(inImagePtr + yStart1 + xStart2) | 0] | 0)
+ (images[(inImagePtr + offset + u) | 0] | 0)
+ (images[(inImagePtr + yStart2 + xStart1) | 0] | 0)
+ (images[(inImagePtr + yStart2 + xStart2) | 0] | 0)) | 0;
if ((sum | 0) === (5 | 0)) {
images[(outImagePtr + offset + u) | 0] = 1;
} else {
images[(outImagePtr + offset + u) | 0] = 0;
@ -48,7 +52,8 @@ function Skeletonizer(stdlib, foreign, buffer) {
while ((length | 0) > 0) {
length = (length - 1) | 0;
images[(outImagePtr + length) | 0] = ((images[(aImagePtr + length) | 0] | 0) - (images[(bImagePtr + length) | 0] | 0)) | 0;
images[(outImagePtr + length) | 0] =
((images[(aImagePtr + length) | 0] | 0) - (images[(bImagePtr + length) | 0] | 0)) | 0;
}
}
@ -63,7 +68,8 @@ function Skeletonizer(stdlib, foreign, buffer) {
while ((length | 0) > 0) {
length = (length - 1) | 0;
images[(outImagePtr + length) | 0] = ((images[(aImagePtr + length) | 0] | 0) | (images[(bImagePtr + length) | 0] | 0)) | 0;
images[(outImagePtr + length) | 0] =
((images[(aImagePtr + length) | 0] | 0) | (images[(bImagePtr + length) | 0] | 0)) | 0;
}
}
@ -117,7 +123,11 @@ function Skeletonizer(stdlib, foreign, buffer) {
yStart2 = (offset + size) | 0;
xStart1 = (u - 1) | 0;
xStart2 = (u + 1) | 0;
sum = ((images[(inImagePtr + yStart1 + xStart1) | 0] | 0) + (images[(inImagePtr + yStart1 + xStart2) | 0] | 0) + (images[(inImagePtr + offset + u) | 0] | 0) + (images[(inImagePtr + yStart2 + xStart1) | 0] | 0) + (images[(inImagePtr + yStart2 + xStart2) | 0] | 0)) | 0;
sum = ((images[(inImagePtr + yStart1 + xStart1) | 0] | 0)
+ (images[(inImagePtr + yStart1 + xStart2) | 0] | 0)
+ (images[(inImagePtr + offset + u) | 0] | 0)
+ (images[(inImagePtr + yStart2 + xStart1) | 0] | 0)
+ (images[(inImagePtr + yStart2 + xStart2) | 0] | 0)) | 0;
if ((sum | 0) > (0 | 0)) {
images[(outImagePtr + offset + u) | 0] = 1;
} else {
@ -184,12 +194,12 @@ function Skeletonizer(stdlib, foreign, buffer) {
bitwiseOr(skelImagePtr, tempImagePtr, skelImagePtr);
memcpy(erodedImagePtr, subImagePtr);
sum = countNonZero(subImagePtr) | 0;
done = ((sum | 0) == 0 | 0);
} while(!done);
done = ((sum | 0) === 0 | 0);
} while (!done);
}
return {
skeletonize : skeletonize
skeletonize: skeletonize
};
}
/* @preserve ASM END */

@ -9,8 +9,8 @@
function SubImage(from, size, I) {
if (!I) {
I = {
data : null,
size : size
data: null,
size: size
};
}
this.data = I.data;

@ -2,8 +2,8 @@
* http://www.codeproject.com/Tips/407172/Connected-Component-Labeling-and-Vectorization
*/
var Tracer = {
searchDirections : [[0, 1], [1, 1], [1, 0], [1, -1], [0, -1], [-1, -1], [-1, 0], [-1, 1]],
create : function(imageWrapper, labelWrapper) {
searchDirections: [[0, 1], [1, 1], [1, 0], [1, -1], [0, -1], [-1, -1], [-1, 0], [-1, 1]],
create: function(imageWrapper, labelWrapper) {
var imageData = imageWrapper.data,
labelData = labelWrapper.data,
searchDirections = this.searchDirections,
@ -36,11 +36,11 @@ var Tracer = {
function vertex2D(x, y, dir) {
return {
dir : dir,
x : x,
y : y,
next : null,
prev : null
dir: dir,
x: x,
y: y,
next: null,
prev: null
};
}
@ -50,9 +50,9 @@ var Tracer = {
P,
ldir,
current = {
cx : sx,
cy : sy,
dir : 0
cx: sx,
cy: sy,
dir: 0
};
if (trace(current, color, label, edgelabel)) {
@ -67,7 +67,7 @@ var Tracer = {
do {
current.dir = (current.dir + 6) % 8;
trace(current, color, label, edgelabel);
if (ldir != current.dir) {
if (ldir !== current.dir) {
Cv.dir = current.dir;
P = vertex2D(current.cx, current.cy, 0);
P.prev = Cv;
@ -80,7 +80,7 @@ var Tracer = {
Cv.y = current.cy;
}
ldir = current.dir;
} while(current.cx != sx || current.cy != sy);
} while (current.cx !== sx || current.cy !== sy);
Fv.prev = Cv.prev;
Cv.prev.next = Fv;
}
@ -88,10 +88,10 @@ var Tracer = {
}
return {
trace : function(current, color, label, edgelabel) {
trace: function(current, color, label, edgelabel) {
return trace(current, color, label, edgelabel);
},
contourTracing : function(sy, sx, label, color, edgelabel) {
contourTracing: function(sy, sx, label, color, edgelabel) {
return contourTracing(sy, sx, label, color, edgelabel);
}
};

@ -5,7 +5,7 @@ function UPCEReader() {
}
var properties = {
CODE_FREQUENCY : {value: [
CODE_FREQUENCY: {value: [
[ 56, 52, 50, 49, 44, 38, 35, 42, 41, 37 ],
[7, 11, 13, 14, 19, 25, 28, 21, 22, 26]]},
STOP_PATTERN: { value: [1 / 6 * 7, 1 / 6 * 7, 1 / 6 * 7, 1 / 6 * 7, 1 / 6 * 7, 1 / 6 * 7]},
@ -40,13 +40,12 @@ UPCEReader.prototype._decodePayload = function(code, result, decodedCodes) {
};
UPCEReader.prototype._determineParity = function(codeFrequency, result) {
var self =this,
i,
var i,
nrSystem;
for (nrSystem = 0; nrSystem < self.CODE_FREQUENCY.length; nrSystem++){
for ( i = 0; i < self.CODE_FREQUENCY[nrSystem].length; i++) {
if (codeFrequency === self.CODE_FREQUENCY[nrSystem][i]) {
for (nrSystem = 0; nrSystem < this.CODE_FREQUENCY.length; nrSystem++){
for ( i = 0; i < this.CODE_FREQUENCY[nrSystem].length; i++) {
if (codeFrequency === this.CODE_FREQUENCY[nrSystem][i]) {
result.unshift(nrSystem);
result.push(i);
return true;
@ -66,8 +65,8 @@ UPCEReader.prototype._convertToUPCA = function(result) {
.concat(result.slice(3, 6));
} else if (lastDigit === 3) {
upca = upca.concat(result.slice(1, 4))
.concat([0 ,0, 0, 0, 0])
.concat(result.slice(4,6));
.concat([0, 0, 0, 0, 0])
.concat(result.slice(4, 6));
} else if (lastDigit === 4) {
upca = upca.concat(result.slice(1, 5))
.concat([0, 0, 0, 0, 0, result[5]]);
@ -93,7 +92,7 @@ UPCEReader.prototype._verifyTrailingWhitespace = function(endInfo) {
var self = this,
trailingWhitespaceEnd;
trailingWhitespaceEnd = endInfo.end + ((endInfo.end - endInfo.start)/2);
trailingWhitespaceEnd = endInfo.end + ((endInfo.end - endInfo.start) / 2);
if (trailingWhitespaceEnd < self._row.length) {
if (self._matchRange(endInfo.end, trailingWhitespaceEnd, 0)) {
return endInfo;

@ -14,7 +14,6 @@ UPCReader.prototype.constructor = UPCReader;
UPCReader.prototype._decode = function() {
var result = EANReader.prototype._decode.call(this);
console.log("result", result);
if (result && result.code && result.code.length === 13 && result.code.charAt(0) === "0") {
result.code = result.code.substring(1);
return result;

Loading…
Cancel
Save