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}))
@ -173,7 +173,6 @@ export default {
codeResult: result, codeResult: result,
barcodeLine: barcodeLine barcodeLine: barcodeLine
}; };
} }
/** /**

@ -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, '');

@ -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++;
@ -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,9 +267,7 @@ 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 = {
@ -279,7 +278,10 @@ CVUtils.Tracer = {
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;
@ -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];
@ -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() {
@ -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) {

@ -1,4 +1,4 @@
export default function() { export default (function() {
var events = {}; var events = {};
function getEvent(eventName) { function getEvent(eventName) {
@ -79,4 +79,4 @@ export default function() {
} }
} }
}; };
}(); })();

@ -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;
} }

@ -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;
}
}; };
/** /**
@ -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) {

@ -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';
@ -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);
} }
} }
@ -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) {
@ -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,7 +396,7 @@ 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 */

@ -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];

@ -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,7 +194,7 @@ 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);
} }

@ -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;
} }

@ -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;

@ -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