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-mixed-spaces-and-tabs": 2,
"no-multiple-empty-lines": 2, "no-multiple-empty-lines": 2,
"semi-spacing": 2, "semi-spacing": 2,
"dot-notation": 2,
"no-spaced-func": 1, "no-spaced-func": 1,
"no-shadow": 2,
"no-undef": 2,
"padded-blocks": [2, "never"], "padded-blocks": [2, "never"],
"semi": [2, "always"], "semi": [2, "always"],
"space-after-keywords": [2, "always"], "space-after-keywords": [2, "always"],
"space-infix-ops": 2, "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 UPCEReader from './upc_e_reader';
import I2of5Reader from './i2of5_reader'; import I2of5Reader from './i2of5_reader';
var readers = { const READERS = {
code_128_reader: Code128Reader, code_128_reader: Code128Reader,
ean_reader: EANReader, ean_reader: EANReader,
ean_8_reader: EAN8Reader, ean_8_reader: EAN8Reader,
@ -74,16 +74,16 @@ export default {
function initReaders() { function initReaders() {
config.readers.forEach(function(readerConfig) { config.readers.forEach(function(readerConfig) {
var reader, var reader,
config = {}; configuration = {};
if (typeof readerConfig === 'object') { if (typeof readerConfig === 'object') {
reader = readerConfig.format; reader = readerConfig.format;
config = readerConfig.config; configuration = readerConfig.config;
} else if (typeof readerConfig === 'string') { } else if (typeof readerConfig === 'string') {
reader = readerConfig; reader = readerConfig;
} }
console.log("Before registering reader: ", reader); console.log("Before registering reader: ", reader);
_barcodeReaders.push(new readers[reader](config)); _barcodeReaders.push(new READERS[reader](configuration));
}); });
console.log("Registered Readers: " + _barcodeReaders console.log("Registered Readers: " + _barcodeReaders
.map((reader) => JSON.stringify({format: reader.FORMAT, config: reader.config})) .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++) { for ( i = 0; i < _barcodeReaders.length && result === null; i++) {
result = _barcodeReaders[i].decodePattern(barcodeLine.line); result = _barcodeReaders[i].decodePattern(barcodeLine.line);
} }
if(result === null){ if (result === null){
return null; return null;
} }
return { return {
codeResult: result, codeResult: result,
barcodeLine: barcodeLine barcodeLine: barcodeLine
}; };
} }
/** /**
@ -255,11 +254,11 @@ export default {
} }
return { return {
codeResult : result.codeResult, codeResult: result.codeResult,
line : line, line: line,
angle : lineAngle, angle: lineAngle,
pattern : result.barcodeLine.line, pattern: result.barcodeLine.line,
threshold : result.barcodeLine.threshold threshold: result.barcodeLine.threshold
}; };
} }

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

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

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

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

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

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

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

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

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

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

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

@ -1,7 +1,7 @@
import SubImage from './subImage'; import SubImage from './subImage';
import CVUtils from './cv_utils'; import CVUtils from './cv_utils';
import ArrayHelper from './array_helper'; 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. * Represents a basic image combining the data and size.
@ -25,7 +25,6 @@ function ImageWrapper(size, data, ArrayType, initialize) {
ArrayHelper.init(this.data, 0); ArrayHelper.init(this.data, 0);
} }
} }
} else { } else {
this.data = data; this.data = data;
} }
@ -40,77 +39,10 @@ function ImageWrapper(size, data, ArrayType, initialize) {
* @see cvd/image.h * @see cvd/image.h
*/ */
ImageWrapper.prototype.inImageWithBorder = function(imgRef, border) { 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)); 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;
}
}; };
/** /**
@ -203,8 +135,8 @@ ImageWrapper.prototype.getSafe = function(x, y) {
if (!this.indexMapping) { if (!this.indexMapping) {
this.indexMapping = { this.indexMapping = {
x : [], x: [],
y : [] y: []
}; };
for (i = 0; i < this.size.x; i++) { for (i = 0; i < this.size.x; i++) {
this.indexMapping.x[i] = i; this.indexMapping.x[i] = i;
@ -252,7 +184,6 @@ ImageWrapper.prototype.invert = function() {
while (length--) { while (length--) {
data[length] = data[length] ? 0 : 1; data[length] = data[length] ? 0 : 1;
} }
}; };
ImageWrapper.prototype.convolve = function(kernel) { ImageWrapper.prototype.convolve = function(kernel) {
@ -262,7 +193,7 @@ ImageWrapper.prototype.convolve = function(kernel) {
accu = 0; accu = 0;
for ( ky = -kSize; ky <= kSize; ky++) { for ( ky = -kSize; ky <= kSize; ky++) {
for ( kx = -kSize; kx <= kSize; kx++) { 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; this.data[y * this.size.x + x] = accu;
@ -297,14 +228,14 @@ ImageWrapper.prototype.moments = function(labelcount) {
for ( i = 0; i < labelcount; i++) { for ( i = 0; i < labelcount; i++) {
labelsum[i] = { labelsum[i] = {
m00 : 0, m00: 0,
m01 : 0, m01: 0,
m10 : 0, m10: 0,
m11 : 0, m11: 0,
m02 : 0, m02: 0,
m20 : 0, m20: 0,
theta : 0, theta: 0,
rad : 0 rad: 0
}; };
} }

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

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

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

@ -27,7 +27,10 @@ export default {
capture = config.capture === true; capture = config.capture === true;
function matchesConstraints(codeResult) { 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 { return {

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

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

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

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

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

Loading…
Cancel
Save