commit
d23e824876
@ -0,0 +1,80 @@
|
|||||||
|
{
|
||||||
|
"settings" : {
|
||||||
|
"ecmascript": 6,
|
||||||
|
"jsx": true
|
||||||
|
},
|
||||||
|
"env": {
|
||||||
|
"browser": true,
|
||||||
|
"node": true
|
||||||
|
},
|
||||||
|
"ecmaFeatures": {
|
||||||
|
"blockBindings": true,
|
||||||
|
"forOf": true,
|
||||||
|
"blockBindings": true,
|
||||||
|
"defaultParams": true,
|
||||||
|
"globalReturn": false,
|
||||||
|
"modules": true,
|
||||||
|
"objectLiteralShorthandMethods": true,
|
||||||
|
"objectLiteralShorthandProperties": true,
|
||||||
|
"templateStrings": true,
|
||||||
|
"spread": true,
|
||||||
|
"jsx": true,
|
||||||
|
"arrowFunctions": true,
|
||||||
|
"classes": true,
|
||||||
|
"destructuring": true,
|
||||||
|
"objectLiteralComputedProperties": true
|
||||||
|
},
|
||||||
|
"globals": {},
|
||||||
|
"rules": {
|
||||||
|
"no-unused-expressions": 1,
|
||||||
|
"no-extra-boolean-cast": 1,
|
||||||
|
"no-multi-spaces": 2,
|
||||||
|
"no-underscore-dangle": 0,
|
||||||
|
"comma-dangle": 2,
|
||||||
|
"camelcase": 0,
|
||||||
|
"curly": 2,
|
||||||
|
"eqeqeq": 2,
|
||||||
|
"guard-for-in": 2,
|
||||||
|
"wrap-iife": 0,
|
||||||
|
"no-use-before-define": [1, "nofunc"],
|
||||||
|
"new-cap": 2,
|
||||||
|
"quotes": 0,
|
||||||
|
"strict": 0,
|
||||||
|
"no-caller": 2,
|
||||||
|
"no-empty": 1,
|
||||||
|
"no-new": 2,
|
||||||
|
"no-plusplus": 0,
|
||||||
|
"no-unused-vars": 1,
|
||||||
|
"no-trailing-spaces": 2,
|
||||||
|
|
||||||
|
// STYLE
|
||||||
|
"max-params": [2, 7],
|
||||||
|
"key-spacing": [1, {
|
||||||
|
beforeColon: false,
|
||||||
|
afterColon: true
|
||||||
|
}],
|
||||||
|
"indent": [2, 4],
|
||||||
|
"brace-style": [2, "1tbs"],
|
||||||
|
"comma-spacing": [2, {before: false, after: true}],
|
||||||
|
"comma-style": [2, "last"],
|
||||||
|
"consistent-this": [1, "self"],
|
||||||
|
"eol-last": 0,
|
||||||
|
"new-cap": 0,
|
||||||
|
"new-parens": 2,
|
||||||
|
"no-array-constructor": 2,
|
||||||
|
"no-mixed-spaces-and-tabs": 2,
|
||||||
|
"no-multiple-empty-lines": 2,
|
||||||
|
"semi-spacing": 2,
|
||||||
|
"dot-notation": 2,
|
||||||
|
"no-spaced-func": 1,
|
||||||
|
"no-shadow": 2,
|
||||||
|
"no-undef": 2,
|
||||||
|
"padded-blocks": [2, "never"],
|
||||||
|
"semi": [2, "always"],
|
||||||
|
"space-after-keywords": [2, "always"],
|
||||||
|
"space-infix-ops": 2,
|
||||||
|
"max-len" : [1, 120],
|
||||||
|
"consistent-return": 2,
|
||||||
|
"yoda": 2
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,101 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8"/>
|
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
|
|
||||||
|
|
||||||
<title>index</title>
|
|
||||||
<meta name="description" content=""/>
|
|
||||||
<meta name="author" content="Christoph Oberhofer"/>
|
|
||||||
|
|
||||||
<meta name="viewport" content="width=device-width; initial-scale=1.0"/>
|
|
||||||
<link rel="stylesheet" type="text/css" href="css/styles.css"/>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<header>
|
|
||||||
<div class="headline">
|
|
||||||
<h1>QuaggaJS</h1>
|
|
||||||
|
|
||||||
<h2>An advanced barcode-scanner written in JavaScript</h2>
|
|
||||||
</div>
|
|
||||||
</header>
|
|
||||||
<section id="container" class="container">
|
|
||||||
<h3>Working with file-input</h3>
|
|
||||||
|
|
||||||
<p>This example let's you select an image from your local filesystem.
|
|
||||||
QuaggaJS then tries to decode the barcode using
|
|
||||||
the preferred method (<strong>Code128</strong> or <strong>EAN</strong>).
|
|
||||||
There is no server interaction needed as the
|
|
||||||
file is simply accessed through the <a
|
|
||||||
href="http://www.w3.org/TR/file-upload/">File API</a>.</p>
|
|
||||||
|
|
||||||
<p>This also works great on a wide range of mobile-phones where the camera
|
|
||||||
access through <code>getUserMedia</code> is still very limited.</p>
|
|
||||||
|
|
||||||
<div class="controls">
|
|
||||||
<fieldset class="input-group">
|
|
||||||
<input type="file" capture/>
|
|
||||||
<button>Rerun</button>
|
|
||||||
</fieldset>
|
|
||||||
<fieldset class="reader-config-group">
|
|
||||||
<label>
|
|
||||||
<span>Barcode-Type</span>
|
|
||||||
<select name="decoder_readers">
|
|
||||||
<option value="code_128" selected="selected">Code 128</option>
|
|
||||||
<option value="code_39">Code 39</option>
|
|
||||||
<option value="code_39_vin">Code 39 VIN</option>
|
|
||||||
<option value="ean">EAN</option>
|
|
||||||
<option value="ean_8">EAN-8</option>
|
|
||||||
<option value="upc">UPC</option>
|
|
||||||
<option value="upc_e">UPC-E</option>
|
|
||||||
<option value="codabar">Codabar</option>
|
|
||||||
</select>
|
|
||||||
</label>
|
|
||||||
<label>
|
|
||||||
<span>Resolution (long side)</span>
|
|
||||||
<select name="input-stream_size">
|
|
||||||
<option value="320">320px</option>
|
|
||||||
<option selected="selected" value="640">640px</option>
|
|
||||||
<option value="800">800px</option>
|
|
||||||
<option value="1280">1280px</option>
|
|
||||||
<option value="1600">1600px</option>
|
|
||||||
<option value="1920">1920px</option>
|
|
||||||
</select>
|
|
||||||
</label>
|
|
||||||
<label>
|
|
||||||
<span>Patch-Size</span>
|
|
||||||
<select name="locator_patch-size">
|
|
||||||
<option value="x-small">x-small</option>
|
|
||||||
<option value="small">small</option>
|
|
||||||
<option selected="selected" value="medium">medium</option>
|
|
||||||
<option value="large">large</option>
|
|
||||||
<option value="x-large">x-large</option>
|
|
||||||
</select>
|
|
||||||
</label>
|
|
||||||
<label>
|
|
||||||
<span>Half-Sample</span>
|
|
||||||
<input type="checkbox" checked="checked"
|
|
||||||
name="locator_half-sample" />
|
|
||||||
</label>
|
|
||||||
<label>
|
|
||||||
<span>Single Channel</span>
|
|
||||||
<input type="checkbox" name="input-stream_single-channel" />
|
|
||||||
</label>
|
|
||||||
</fieldset>
|
|
||||||
</div>
|
|
||||||
<div id="result_strip">
|
|
||||||
<ul class="thumbnails"></ul>
|
|
||||||
</div>
|
|
||||||
<div id="interactive" class="viewport"></div>
|
|
||||||
<div id="debug" class="detection"></div>
|
|
||||||
</section>
|
|
||||||
<footer>
|
|
||||||
<p>
|
|
||||||
© Copyright by Christoph Oberhofer
|
|
||||||
</p>
|
|
||||||
</footer>
|
|
||||||
<script src="../src/vendor/jquery-1.9.0.min.js" type="text/javascript"></script>
|
|
||||||
<script data-main="file_input_require.js" src="../node_modules/requirejs/require.js"></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -1,161 +0,0 @@
|
|||||||
requirejs.config({
|
|
||||||
"baseUrl" : "../src",
|
|
||||||
"shim" : {
|
|
||||||
"typedefs" : {
|
|
||||||
"deps" : [],
|
|
||||||
"exports" : "typedefs"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
"paths" : {
|
|
||||||
"typedefs" : "typedefs",
|
|
||||||
"gl-matrix": "../node_modules/gl-matrix/dist/gl-matrix-min"
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
requirejs(['quagga'], function(Quagga) {
|
|
||||||
var App = {
|
|
||||||
init: function() {
|
|
||||||
App.attachListeners();
|
|
||||||
},
|
|
||||||
attachListeners: function() {
|
|
||||||
var self = this;
|
|
||||||
|
|
||||||
$(".controls input[type=file]").on("change", function(e) {
|
|
||||||
if (e.target.files && e.target.files.length) {
|
|
||||||
App.decode(URL.createObjectURL(e.target.files[0]));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$(".controls button").on("click", function(e) {
|
|
||||||
var input = document.querySelector(".controls input[type=file]");
|
|
||||||
if (input.files && input.files.length) {
|
|
||||||
App.decode(URL.createObjectURL(input.files[0]));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$(".controls .reader-config-group").on("change", "input, select", function(e) {
|
|
||||||
e.preventDefault();
|
|
||||||
var $target = $(e.target),
|
|
||||||
value = $target.attr("type") === "checkbox" ? $target.prop("checked") : $target.val(),
|
|
||||||
name = $target.attr("name"),
|
|
||||||
state = self._convertNameToState(name);
|
|
||||||
|
|
||||||
console.log("Value of "+ state + " changed to " + value);
|
|
||||||
self.setState(state, value);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
_accessByPath: function(obj, path, val) {
|
|
||||||
var parts = path.split('.'),
|
|
||||||
depth = parts.length,
|
|
||||||
setter = (typeof val !== "undefined") ? true : false;
|
|
||||||
|
|
||||||
return parts.reduce(function(o, key, i) {
|
|
||||||
if (setter && (i + 1) === depth) {
|
|
||||||
o[key] = val;
|
|
||||||
}
|
|
||||||
return key in o ? o[key] : {};
|
|
||||||
}, obj);
|
|
||||||
},
|
|
||||||
_convertNameToState: function(name) {
|
|
||||||
return name.replace("_", ".").split("-").reduce(function(result, value) {
|
|
||||||
return result + value.charAt(0).toUpperCase() + value.substring(1);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
detachListeners: function() {
|
|
||||||
$(".controls input[type=file]").off("change");
|
|
||||||
$(".controls .reader-config-group").off("change", "input, select");
|
|
||||||
$(".controls button").off("click");
|
|
||||||
},
|
|
||||||
decode: function(src) {
|
|
||||||
var self = this,
|
|
||||||
config = $.extend({}, self.state, {src: src});
|
|
||||||
|
|
||||||
Quagga.decodeSingle(config, function(result) {});
|
|
||||||
},
|
|
||||||
setState: function(path, value) {
|
|
||||||
var self = this;
|
|
||||||
|
|
||||||
if (typeof self._accessByPath(self.inputMapper, path) === "function") {
|
|
||||||
value = self._accessByPath(self.inputMapper, path)(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
self._accessByPath(self.state, path, value);
|
|
||||||
|
|
||||||
console.log(JSON.stringify(self.state));
|
|
||||||
App.detachListeners();
|
|
||||||
App.init();
|
|
||||||
},
|
|
||||||
inputMapper: {
|
|
||||||
inputStream: {
|
|
||||||
size: function(value){
|
|
||||||
return parseInt(value);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
numOfWorkers: function(value) {
|
|
||||||
return parseInt(value);
|
|
||||||
},
|
|
||||||
decoder: {
|
|
||||||
readers: function(value) {
|
|
||||||
return [value + "_reader"];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
state: {
|
|
||||||
inputStream: {
|
|
||||||
size: 640,
|
|
||||||
singleChannel: false
|
|
||||||
},
|
|
||||||
locator: {
|
|
||||||
patchSize: "medium",
|
|
||||||
halfSample: true,
|
|
||||||
showCanvas: true
|
|
||||||
},
|
|
||||||
numOfWorkers: 0,
|
|
||||||
decoder: {
|
|
||||||
readers: ["code_128_reader"],
|
|
||||||
showFrequency: true,
|
|
||||||
showPattern: true
|
|
||||||
},
|
|
||||||
locate: true,
|
|
||||||
src: null
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
App.init();
|
|
||||||
|
|
||||||
Quagga.onProcessed(function(result) {
|
|
||||||
var drawingCtx = Quagga.canvas.ctx.overlay,
|
|
||||||
drawingCanvas = Quagga.canvas.dom.overlay;
|
|
||||||
|
|
||||||
if (result) {
|
|
||||||
if (result.boxes) {
|
|
||||||
drawingCtx.clearRect(0, 0, parseInt(drawingCanvas.getAttribute("width")), parseInt(drawingCanvas.getAttribute("height")));
|
|
||||||
result.boxes.filter(function (box) {
|
|
||||||
return box !== result.box;
|
|
||||||
}).forEach(function (box) {
|
|
||||||
Quagga.ImageDebug.drawPath(box, {x: 0, y: 1}, drawingCtx, {color: "green", lineWidth: 2});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result.box) {
|
|
||||||
Quagga.ImageDebug.drawPath(result.box, {x: 0, y: 1}, drawingCtx, {color: "#00F", lineWidth: 2});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result.codeResult && result.codeResult.code) {
|
|
||||||
Quagga.ImageDebug.drawPath(result.line, {x: 'x', y: 'y'}, drawingCtx, {color: 'red', lineWidth: 3});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Quagga.onDetected(function(result) {
|
|
||||||
var code = result.codeResult.code,
|
|
||||||
$node,
|
|
||||||
canvas = Quagga.canvas.dom.image;
|
|
||||||
|
|
||||||
$node = $('<li><div class="thumbnail"><div class="imgWrapper"><img /></div><div class="caption"><h4 class="code"></h4></div></div></li>');
|
|
||||||
$node.find("img").attr("src", canvas.toDataURL());
|
|
||||||
$node.find("h4.code").html(code + " (" + result.codeResult.format + ")");
|
|
||||||
$("#result_strip ul.thumbnails").prepend($node);
|
|
||||||
});
|
|
||||||
});
|
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,33 @@
|
|||||||
|
var ConcatSource = require("webpack-core/lib/ConcatSource");
|
||||||
|
var OriginalSource = require("webpack-core/lib/OriginalSource");
|
||||||
|
|
||||||
|
function MyUmdPlugin(options) {
|
||||||
|
this.name = options.library;
|
||||||
|
}
|
||||||
|
module.exports = MyUmdPlugin;
|
||||||
|
MyUmdPlugin.prototype.apply = function(compiler) {
|
||||||
|
compiler.plugin("this-compilation", function(compilation) {
|
||||||
|
var mainTemplate = compilation.mainTemplate;
|
||||||
|
compilation.templatesPlugin("render-with-entry", function(source, chunk, hash) {
|
||||||
|
|
||||||
|
var amdFactory = "factory";
|
||||||
|
return new ConcatSource(new OriginalSource(
|
||||||
|
"(function webpackUniversalModuleDefinition(root, factory) {\n" +
|
||||||
|
" if(typeof exports === 'object' && typeof module === 'object')\n" +
|
||||||
|
" module.exports = factory(factory.toString());\n" +
|
||||||
|
" else if(typeof exports === 'object')\n" +
|
||||||
|
" exports[\"" + this.name + "\"] = factory(factory.toString());\n" +
|
||||||
|
" else\n" +
|
||||||
|
" root[\"" + this.name + "\"] = factory(factory.toString());\n" +
|
||||||
|
"})(this, function(__factorySource__) {\nreturn ", "webpack/myModuleDefinition"), source, "\n});\n");
|
||||||
|
}.bind(this));
|
||||||
|
mainTemplate.plugin("global-hash-paths", function(paths) {
|
||||||
|
if(this.name) paths = paths.concat(this.name);
|
||||||
|
return paths;
|
||||||
|
}.bind(this));
|
||||||
|
mainTemplate.plugin("hash", function(hash) {
|
||||||
|
hash.update("umd");
|
||||||
|
hash.update(this.name + "");
|
||||||
|
}.bind(this));
|
||||||
|
}.bind(this));
|
||||||
|
};
|
@ -1,53 +0,0 @@
|
|||||||
define(['array_helper'], function(ArrayHelper){
|
|
||||||
describe('init', function() {
|
|
||||||
it('initializes an array with the given value', function() {
|
|
||||||
var input = [0, 0, 0];
|
|
||||||
ArrayHelper.init(input, 5);
|
|
||||||
expect(input).to.deep.equal([5, 5, 5]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('shuffle', function() {
|
|
||||||
before(function() {
|
|
||||||
sinon.stub(Math, 'random').returns(0.5);
|
|
||||||
});
|
|
||||||
|
|
||||||
after(function() {
|
|
||||||
sinon.restore(Math);
|
|
||||||
});
|
|
||||||
it('shuffles the content of an array', function() {
|
|
||||||
var input = [1, 2, 3];
|
|
||||||
expect(ArrayHelper.shuffle(input)).to.deep.equal([3, 1, 2]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('toPointList', function() {
|
|
||||||
it('converts an Array to a List of poitns', function() {
|
|
||||||
var input = [[1, 2], [2, 2], [3, 2]];
|
|
||||||
expect(ArrayHelper.toPointList(input)).to.equal("[[1,2],\r\n[2,2],\r\n[3,2]]");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('threshold', function() {
|
|
||||||
it('returns all elements above the given threshold', function() {
|
|
||||||
var input = [1, 2, 3];
|
|
||||||
expect(ArrayHelper.threshold(input, 2, function(score) {
|
|
||||||
return score * 1.5;
|
|
||||||
})).to.deep.equal([2, 3]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('maxIndex', function() {
|
|
||||||
it('gets the index of the biggest element in the array', function() {
|
|
||||||
var input = [1, 2, 3];
|
|
||||||
expect(ArrayHelper.maxIndex(input)).to.equal(2);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('max', function() {
|
|
||||||
it('gets the biggest element in the array', function() {
|
|
||||||
var input = [1, 3, 2];
|
|
||||||
expect(ArrayHelper.max(input)).to.equal(3);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,131 +0,0 @@
|
|||||||
|
|
||||||
define(['barcode_locator', 'config', 'html_utils'],
|
|
||||||
function(BarcodeLocator, Config, HtmlUtils){
|
|
||||||
|
|
||||||
describe('checkImageConstraints', function() {
|
|
||||||
var config,
|
|
||||||
inputStream,
|
|
||||||
imageSize,
|
|
||||||
streamConfig = {};
|
|
||||||
|
|
||||||
beforeEach(function() {
|
|
||||||
imageSize = {
|
|
||||||
x: 640, y: 480
|
|
||||||
};
|
|
||||||
config = HtmlUtils.mergeObjects({}, Config);
|
|
||||||
inputStream = {
|
|
||||||
getWidth: function() {
|
|
||||||
return imageSize.x;
|
|
||||||
},
|
|
||||||
getHeight: function() {
|
|
||||||
return imageSize.y;
|
|
||||||
},
|
|
||||||
setWidth: function() {},
|
|
||||||
setHeight: function() {},
|
|
||||||
setTopRight: function() {},
|
|
||||||
setCanvasSize: function() {},
|
|
||||||
getConfig: function() {
|
|
||||||
return streamConfig;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
sinon.stub(inputStream, "setWidth", function(width) {
|
|
||||||
imageSize.x = width;
|
|
||||||
});
|
|
||||||
sinon.stub(inputStream, "setHeight", function(height) {
|
|
||||||
imageSize.y = height;
|
|
||||||
});
|
|
||||||
sinon.stub(inputStream, "setTopRight");
|
|
||||||
sinon.stub(inputStream, "setCanvasSize");
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(function() {
|
|
||||||
inputStream.setWidth.restore();
|
|
||||||
inputStream.setHeight.restore();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not adjust the image-size if not needed', function() {
|
|
||||||
var expected = {x: imageSize.x, y: imageSize.y};
|
|
||||||
BarcodeLocator.checkImageConstraints(inputStream, config.locator);
|
|
||||||
expect(inputStream.getWidth()).to.be.equal(expected.x);
|
|
||||||
expect(inputStream.getHeight()).to.be.equal(expected.y);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should adjust the image-size', function() {
|
|
||||||
var expected = {x: imageSize.x, y: imageSize.y};
|
|
||||||
|
|
||||||
config.locator.halfSample = true;
|
|
||||||
imageSize.y += 1;
|
|
||||||
BarcodeLocator.checkImageConstraints(inputStream, config.locator);
|
|
||||||
expect(inputStream.getWidth()).to.be.equal(expected.x);
|
|
||||||
expect(inputStream.getHeight()).to.be.equal(expected.y);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should adjust the image-size', function() {
|
|
||||||
var expected = {x: imageSize.x, y: imageSize.y};
|
|
||||||
|
|
||||||
imageSize.y += 1;
|
|
||||||
config.locator.halfSample = false;
|
|
||||||
BarcodeLocator.checkImageConstraints(inputStream, config.locator);
|
|
||||||
expect(inputStream.getHeight()).to.be.equal(expected.y);
|
|
||||||
expect(inputStream.getWidth()).to.be.equal(expected.x);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should take the defined area into account", function() {
|
|
||||||
var expectedSize = {
|
|
||||||
x: 420,
|
|
||||||
y: 315
|
|
||||||
},
|
|
||||||
expectedTopRight = {
|
|
||||||
x: 115,
|
|
||||||
y: 52
|
|
||||||
},
|
|
||||||
expectedCanvasSize = {
|
|
||||||
x: 640,
|
|
||||||
y: 480
|
|
||||||
};
|
|
||||||
|
|
||||||
streamConfig.area = {
|
|
||||||
top: "11%",
|
|
||||||
right: "15%",
|
|
||||||
bottom: "20%",
|
|
||||||
left: "18%"
|
|
||||||
};
|
|
||||||
|
|
||||||
config.locator.halfSample = false;
|
|
||||||
BarcodeLocator.checkImageConstraints(inputStream, config.locator);
|
|
||||||
expect(inputStream.getHeight()).to.be.equal(expectedSize.y);
|
|
||||||
expect(inputStream.getWidth()).to.be.equal(expectedSize.x);
|
|
||||||
expect(inputStream.setTopRight.getCall(0).args[0]).to.deep.equal(expectedTopRight);
|
|
||||||
expect(inputStream.setCanvasSize.getCall(0).args[0]).to.deep.equal(expectedCanvasSize);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should return the original size if set to full image", function() {
|
|
||||||
var expectedSize = {
|
|
||||||
x: 640,
|
|
||||||
y: 480
|
|
||||||
},
|
|
||||||
expectedTopRight = {
|
|
||||||
x: 0,
|
|
||||||
y: 0
|
|
||||||
},
|
|
||||||
expectedCanvasSize = {
|
|
||||||
x: 640,
|
|
||||||
y: 480
|
|
||||||
};
|
|
||||||
|
|
||||||
streamConfig.area = {
|
|
||||||
top: "0%",
|
|
||||||
right: "0%",
|
|
||||||
bottom: "0%",
|
|
||||||
left: "0%"
|
|
||||||
};
|
|
||||||
|
|
||||||
config.locator.halfSample = false;
|
|
||||||
BarcodeLocator.checkImageConstraints(inputStream, config.locator);
|
|
||||||
expect(inputStream.getHeight()).to.be.equal(expectedSize.y);
|
|
||||||
expect(inputStream.getWidth()).to.be.equal(expectedSize.x);
|
|
||||||
expect(inputStream.setTopRight.getCall(0).args[0]).to.deep.equal(expectedTopRight);
|
|
||||||
expect(inputStream.setCanvasSize.getCall(0).args[0]).to.deep.equal(expectedCanvasSize);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,123 +0,0 @@
|
|||||||
define(['camera_access'], function(CameraAccess){
|
|
||||||
var originalURL,
|
|
||||||
originalMediaStreamTrack,
|
|
||||||
video,
|
|
||||||
stream;
|
|
||||||
|
|
||||||
beforeEach(function() {
|
|
||||||
var tracks = [{
|
|
||||||
stop: function() {}
|
|
||||||
}];
|
|
||||||
|
|
||||||
originalURL = window.URL;
|
|
||||||
originalMediaStreamTrack = window.MediaStreamTrack;
|
|
||||||
window.MediaStreamTrack = {};
|
|
||||||
window.URL = null;
|
|
||||||
|
|
||||||
|
|
||||||
stream = {
|
|
||||||
getVideoTracks: function() {
|
|
||||||
return tracks;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
sinon.spy(tracks[0], "stop");
|
|
||||||
|
|
||||||
video = {
|
|
||||||
src: null,
|
|
||||||
addEventListener: function() {
|
|
||||||
|
|
||||||
},
|
|
||||||
removeEventListener: function() {
|
|
||||||
|
|
||||||
},
|
|
||||||
play: function() {
|
|
||||||
|
|
||||||
},
|
|
||||||
videoWidth: 320,
|
|
||||||
videoHeight: 480
|
|
||||||
};
|
|
||||||
sinon.stub(video, "addEventListener", function(event, cb) {
|
|
||||||
cb();
|
|
||||||
});
|
|
||||||
sinon.stub(video, "play");
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(function() {
|
|
||||||
window.URL = originalURL;
|
|
||||||
window.MediaStreamTrack = originalMediaStreamTrack;
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('success', function() {
|
|
||||||
beforeEach(function() {
|
|
||||||
sinon.stub(navigator, "getUserMedia", function(constraints, success) {
|
|
||||||
success(stream);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(function() {
|
|
||||||
navigator.getUserMedia.restore();
|
|
||||||
});
|
|
||||||
describe('request', function () {
|
|
||||||
it('should request the camera', function (done) {
|
|
||||||
CameraAccess.request(video, {}, function () {
|
|
||||||
expect(navigator.getUserMedia.calledOnce).to.equal(true);
|
|
||||||
expect(video.src).to.deep.equal(stream);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('release', function () {
|
|
||||||
it('should release the camera', function (done) {
|
|
||||||
CameraAccess.request(video, {}, function () {
|
|
||||||
expect(video.src).to.deep.equal(stream);
|
|
||||||
CameraAccess.release();
|
|
||||||
expect(video.src.getVideoTracks()).to.have.length(1);
|
|
||||||
expect(video.src.getVideoTracks()[0].stop.calledOnce).to.equal(true);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('failure', function() {
|
|
||||||
describe("permission denied", function(){
|
|
||||||
before(function() {
|
|
||||||
sinon.stub(navigator, "getUserMedia", function(constraints, success, failure) {
|
|
||||||
failure(new Error());
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
after(function() {
|
|
||||||
navigator.getUserMedia.restore();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should throw if getUserMedia not available', function(done) {
|
|
||||||
CameraAccess.request(video, {}, function(err) {
|
|
||||||
expect(err).to.be.defined;
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("not available", function(){
|
|
||||||
var originalGetUserMedia;
|
|
||||||
|
|
||||||
before(function() {
|
|
||||||
originalGetUserMedia = navigator.getUserMedia;
|
|
||||||
navigator.getUserMedia = undefined;
|
|
||||||
});
|
|
||||||
|
|
||||||
after(function() {
|
|
||||||
navigator.getUserMedia = originalGetUserMedia;
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should throw if getUserMedia not available', function(done) {
|
|
||||||
CameraAccess.request(video, {}, function(err) {
|
|
||||||
expect(err).to.be.defined;
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,145 +0,0 @@
|
|||||||
|
|
||||||
define(['cv_utils'], function(CVUtils){
|
|
||||||
describe('imageRef', function() {
|
|
||||||
it('gets the image Reference for a coordinate', function() {
|
|
||||||
var res = CVUtils.imageRef(1, 2);
|
|
||||||
expect(res.x).to.equal(1);
|
|
||||||
expect(res.y).to.equal(2);
|
|
||||||
expect(res.toVec2()[0]).to.equal(1);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('calculatePatchSize', function() {
|
|
||||||
it('should not throw an error in case of valid image size', function() {
|
|
||||||
var expected = {x: 32, y: 32},
|
|
||||||
patchSize = CVUtils.calculatePatchSize("medium", {x: 640, y: 480});
|
|
||||||
|
|
||||||
expect(patchSize).to.be.deep.equal(expected);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should thow an error if image size it not valid', function() {
|
|
||||||
var expected = {x: 32, y: 32},
|
|
||||||
patchSize = CVUtils.calculatePatchSize("medium", {x: 640, y: 480});
|
|
||||||
|
|
||||||
expect(patchSize).to.be.deep.equal(expected);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('_parseCSSDimensionValues', function() {
|
|
||||||
it("should convert a percentual value correctly", function() {
|
|
||||||
var expected = {
|
|
||||||
value: 10,
|
|
||||||
unit: "%"
|
|
||||||
},
|
|
||||||
result = CVUtils._parseCSSDimensionValues("10%");
|
|
||||||
|
|
||||||
expect(result).to.be.deep.equal(expected);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should convert a 0% value correctly", function() {
|
|
||||||
var expected = {
|
|
||||||
value: 100,
|
|
||||||
unit: "%"
|
|
||||||
},
|
|
||||||
result = CVUtils._parseCSSDimensionValues("100%");
|
|
||||||
|
|
||||||
expect(result).to.be.deep.equal(expected);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should convert a 100% value correctly", function() {
|
|
||||||
var expected = {
|
|
||||||
value: 0,
|
|
||||||
unit: "%"
|
|
||||||
},
|
|
||||||
result = CVUtils._parseCSSDimensionValues("0%");
|
|
||||||
|
|
||||||
expect(result).to.be.deep.equal(expected);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should convert a pixel value to percentage", function() {
|
|
||||||
var expected = {
|
|
||||||
value: 26.3,
|
|
||||||
unit: "%"
|
|
||||||
},
|
|
||||||
result = CVUtils._parseCSSDimensionValues("26.3px");
|
|
||||||
|
|
||||||
console.log(result);
|
|
||||||
expect(result).to.be.deep.equal(expected);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("_dimensionsConverters", function(){
|
|
||||||
var context;
|
|
||||||
|
|
||||||
beforeEach(function() {
|
|
||||||
context = {
|
|
||||||
width: 640,
|
|
||||||
height: 480
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should convert a top-value correclty", function() {
|
|
||||||
var expected = 48,
|
|
||||||
result = CVUtils._dimensionsConverters.top({value: 10, unit: "%"}, context);
|
|
||||||
|
|
||||||
expect(result).to.be.equal(expected);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should convert a right-value correclty", function() {
|
|
||||||
var expected = 640 - 128,
|
|
||||||
result = CVUtils._dimensionsConverters.right({value: 20, unit: "%"}, context);
|
|
||||||
|
|
||||||
expect(result).to.be.equal(expected);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should convert a bottom-value correclty", function() {
|
|
||||||
var expected = 480 - 77,
|
|
||||||
result = CVUtils._dimensionsConverters.bottom({value: 16, unit: "%"}, context);
|
|
||||||
|
|
||||||
expect(result).to.be.equal(expected);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should convert a left-value correclty", function() {
|
|
||||||
var expected = 57,
|
|
||||||
result = CVUtils._dimensionsConverters.left({value: 9, unit: "%"}, context);
|
|
||||||
|
|
||||||
expect(result).to.be.equal(expected);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("computeImageArea", function() {
|
|
||||||
it("should calculate an image-area", function() {
|
|
||||||
var expected = {
|
|
||||||
sx: 115,
|
|
||||||
sy: 48,
|
|
||||||
sw: 429,
|
|
||||||
sh: 336
|
|
||||||
},
|
|
||||||
result = CVUtils.computeImageArea(640, 480, {
|
|
||||||
top: "10%",
|
|
||||||
right: "15%",
|
|
||||||
bottom: "20%",
|
|
||||||
left: "18%"
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(result).to.be.deep.equal(expected);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should calculate full image-area", function() {
|
|
||||||
var expected = {
|
|
||||||
sx: 0,
|
|
||||||
sy: 0,
|
|
||||||
sw: 640,
|
|
||||||
sh: 480
|
|
||||||
},
|
|
||||||
result = CVUtils.computeImageArea(640, 480, {
|
|
||||||
top: "0%",
|
|
||||||
right: "0%",
|
|
||||||
bottom: "0%",
|
|
||||||
left: "0%"
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(result).to.be.deep.equal(expected);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,114 +0,0 @@
|
|||||||
define(['events'], function(Events){
|
|
||||||
beforeEach(function() {
|
|
||||||
Events.unsubscribe();
|
|
||||||
});
|
|
||||||
describe("subscribe", function() {
|
|
||||||
|
|
||||||
|
|
||||||
it("should call one callback for a single event", function() {
|
|
||||||
var callbackA = sinon.stub(),
|
|
||||||
callbackB = sinon.stub();
|
|
||||||
|
|
||||||
Events.subscribe("test", callbackA);
|
|
||||||
Events.subscribe("test", callbackB);
|
|
||||||
Events.publish("test");
|
|
||||||
|
|
||||||
expect(callbackA.calledOnce).to.be.equal(true);
|
|
||||||
expect(callbackB.calledOnce).to.be.equal(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should call one callback twice if published twice", function() {
|
|
||||||
var callback = sinon.stub();
|
|
||||||
|
|
||||||
Events.subscribe("test", callback);
|
|
||||||
|
|
||||||
Events.publish("test");
|
|
||||||
Events.publish("test");
|
|
||||||
|
|
||||||
expect(callback.calledTwice).to.be.equal(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should call the callback asynchronuously", function(done) {
|
|
||||||
var test = {
|
|
||||||
callback: function() {
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
sinon.stub(test, "callback", function() {
|
|
||||||
expect(test.callback.calledOnce).to.be.true;
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
Events.subscribe("test", test.callback, true);
|
|
||||||
Events.publish("test");
|
|
||||||
expect(test.callback.called).to.be.false;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("once", function() {
|
|
||||||
it("should call the callback once, even when published twice", function() {
|
|
||||||
var callbackA = sinon.stub(),
|
|
||||||
callbackB = sinon.stub();
|
|
||||||
|
|
||||||
Events.once("test", callbackA);
|
|
||||||
Events.subscribe("test", callbackB);
|
|
||||||
|
|
||||||
Events.publish("test");
|
|
||||||
Events.publish("test");
|
|
||||||
|
|
||||||
expect(callbackA.calledOnce).to.be.equal(true);
|
|
||||||
expect(callbackB.calledTwice).to.be.equal(true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("unsubscribe", function() {
|
|
||||||
it("should unsubscribe all callbacks from a single event", function() {
|
|
||||||
var callbackA = sinon.stub(),
|
|
||||||
callbackB = sinon.stub(),
|
|
||||||
callbackC = sinon.stub();
|
|
||||||
|
|
||||||
Events.subscribe("test", callbackA);
|
|
||||||
Events.subscribe("test", callbackB);
|
|
||||||
Events.subscribe("testC", callbackC);
|
|
||||||
|
|
||||||
Events.publish("test");
|
|
||||||
|
|
||||||
expect(callbackC.called).to.be.equal(false);
|
|
||||||
expect(callbackA.calledOnce).to.be.equal(true);
|
|
||||||
expect(callbackB.calledOnce).to.be.equal(true);
|
|
||||||
|
|
||||||
Events.publish("testC");
|
|
||||||
|
|
||||||
expect(callbackC.calledOnce).to.be.equal(true);
|
|
||||||
expect(callbackA.calledOnce).to.be.equal(true);
|
|
||||||
expect(callbackB.calledOnce).to.be.equal(true);
|
|
||||||
|
|
||||||
Events.unsubscribe("test");
|
|
||||||
Events.publish("test");
|
|
||||||
|
|
||||||
expect(callbackC.calledOnce).to.be.equal(true);
|
|
||||||
expect(callbackA.calledOnce).to.be.equal(true);
|
|
||||||
expect(callbackB.calledOnce).to.be.equal(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should unsubscribe a single callback from a single event", function() {
|
|
||||||
var callbackA = sinon.stub(),
|
|
||||||
callbackB = sinon.stub();
|
|
||||||
|
|
||||||
Events.subscribe("test", callbackA);
|
|
||||||
Events.subscribe("test", callbackB);
|
|
||||||
|
|
||||||
Events.publish("test");
|
|
||||||
|
|
||||||
expect(callbackA.calledOnce).to.be.equal(true);
|
|
||||||
expect(callbackB.calledOnce).to.be.equal(true);
|
|
||||||
|
|
||||||
|
|
||||||
Events.unsubscribe("test", callbackB);
|
|
||||||
Events.publish("test");
|
|
||||||
|
|
||||||
expect(callbackA.calledTwice).to.be.equal(true);
|
|
||||||
expect(callbackB.calledOnce).to.be.equal(true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,248 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
define(['quagga', 'async'], function(Quagga, async) {
|
|
||||||
describe('decodeSingle', function () {
|
|
||||||
var baseFolder = "base/test/fixtures/";
|
|
||||||
|
|
||||||
function generateConfig() {
|
|
||||||
return {
|
|
||||||
inputStream: {
|
|
||||||
size: 640
|
|
||||||
},
|
|
||||||
locator: {
|
|
||||||
patchSize: "medium",
|
|
||||||
halfSample: true
|
|
||||||
},
|
|
||||||
numOfWorkers: 0,
|
|
||||||
decoder: {
|
|
||||||
readers: ["ean_reader"]
|
|
||||||
},
|
|
||||||
locate: true,
|
|
||||||
src: null
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
this.timeout(10000);
|
|
||||||
|
|
||||||
function _runTestSet(testSet, config) {
|
|
||||||
var readers = config.decoder.readers.slice(),
|
|
||||||
format,
|
|
||||||
folder;
|
|
||||||
|
|
||||||
if (typeof readers[0] === 'string'){
|
|
||||||
format = readers[0];
|
|
||||||
} else {
|
|
||||||
format = readers[0].format;
|
|
||||||
}
|
|
||||||
|
|
||||||
folder = baseFolder + format.split('_').slice(0, -1).join('_') + "/";
|
|
||||||
|
|
||||||
it('should decode ' + folder + " correctly", function(done) {
|
|
||||||
async.eachSeries(testSet, function (sample, callback) {
|
|
||||||
config.src = folder + sample.name;
|
|
||||||
config.readers = readers;
|
|
||||||
Quagga.decodeSingle(config, function(result) {
|
|
||||||
console.log(sample.name);
|
|
||||||
expect(result.codeResult.code).to.equal(sample.result);
|
|
||||||
expect(result.codeResult.format).to.equal(sample.format);
|
|
||||||
callback();
|
|
||||||
});
|
|
||||||
}, function() {
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("EAN", function() {
|
|
||||||
var config = generateConfig(),
|
|
||||||
testSet = [
|
|
||||||
{"name": "image-001.jpg", "result": "3574660239843"},
|
|
||||||
{"name": "image-002.jpg", "result": "8032754490297"},
|
|
||||||
{"name": "image-003.jpg", "result": "4006209700068"},
|
|
||||||
/* {"name": "image-004.jpg", "result": "9002233139084"}, */
|
|
||||||
/* {"name": "image-005.jpg", "result": "8004030044005"}, */
|
|
||||||
{"name": "image-006.jpg", "result": "4003626011159"},
|
|
||||||
{"name": "image-007.jpg", "result": "2111220009686"},
|
|
||||||
{"name": "image-008.jpg", "result": "9000275609022"},
|
|
||||||
{"name": "image-009.jpg", "result": "9004593978587"},
|
|
||||||
{"name": "image-010.jpg", "result": "9002244845578"}
|
|
||||||
];
|
|
||||||
|
|
||||||
testSet.forEach(function(sample) {
|
|
||||||
sample.format = "ean_13";
|
|
||||||
});
|
|
||||||
|
|
||||||
config.decoder.readers = ['ean_reader'];
|
|
||||||
_runTestSet(testSet, config);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("Code128", function() {
|
|
||||||
var config = generateConfig(),
|
|
||||||
testSet = [
|
|
||||||
{"name": "image-001.jpg", "result": "0001285112001000040801"},
|
|
||||||
// {"name": "image-002.jpg", "result": "FANAVF1461710"},
|
|
||||||
// {"name": "image-003.jpg", "result": "673023"},
|
|
||||||
// {"name": "image-004.jpg", "result": "010210150301625334"},
|
|
||||||
{"name": "image-005.jpg", "result": "419055603900009001012999"},
|
|
||||||
{"name": "image-006.jpg", "result": "419055603900009001012999"},
|
|
||||||
{"name": "image-007.jpg", "result": "T 000003552345"},
|
|
||||||
{"name": "image-008.jpg", "result": "FANAVF1461710"},
|
|
||||||
{"name": "image-009.jpg", "result": "0001285112001000040801"},
|
|
||||||
{"name": "image-010.jpg", "result": "673023"}
|
|
||||||
];
|
|
||||||
|
|
||||||
testSet.forEach(function(sample) {
|
|
||||||
sample.format = "code_128";
|
|
||||||
});
|
|
||||||
|
|
||||||
config.decoder.readers = ['code_128_reader'];
|
|
||||||
_runTestSet(testSet, config);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("Code39", function() {
|
|
||||||
var config = generateConfig(),
|
|
||||||
testSet = [
|
|
||||||
{"name": "image-001.jpg", "result": "B3% $DAD$"},
|
|
||||||
{"name": "image-003.jpg", "result": "CODE39"},
|
|
||||||
{"name": "image-004.jpg", "result": "QUAGGAJS"},
|
|
||||||
/* {"name": "image-005.jpg", "result": "CODE39"}, */
|
|
||||||
{"name": "image-006.jpg", "result": "2/4-8/16-32"},
|
|
||||||
{"name": "image-007.jpg", "result": "2/4-8/16-32"},
|
|
||||||
{"name": "image-008.jpg", "result": "CODE39"},
|
|
||||||
{"name": "image-009.jpg", "result": "2/4-8/16-32"},
|
|
||||||
{"name": "image-010.jpg", "result": "CODE39"}
|
|
||||||
];
|
|
||||||
|
|
||||||
testSet.forEach(function(sample) {
|
|
||||||
sample.format = "code_39";
|
|
||||||
});
|
|
||||||
|
|
||||||
config.decoder.readers = ['code_39_reader'];
|
|
||||||
_runTestSet(testSet, config);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("EAN-8", function() {
|
|
||||||
var config = generateConfig(),
|
|
||||||
testSet = [
|
|
||||||
{"name": "image-001.jpg", "result": "42191605"},
|
|
||||||
{"name": "image-002.jpg", "result": "42191605"},
|
|
||||||
{"name": "image-003.jpg", "result": "90311208"},
|
|
||||||
{"name": "image-004.jpg", "result": "24057257"},
|
|
||||||
{"name": "image-005.jpg", "result": "90162602"},
|
|
||||||
{"name": "image-006.jpg", "result": "24036153"},
|
|
||||||
{"name": "image-007.jpg", "result": "42176817"},
|
|
||||||
{"name": "image-008.jpg", "result": "42191605"},
|
|
||||||
{"name": "image-009.jpg", "result": "42242215"},
|
|
||||||
{"name": "image-010.jpg", "result": "42184799"}
|
|
||||||
];
|
|
||||||
|
|
||||||
testSet.forEach(function(sample) {
|
|
||||||
sample.format = "ean_8";
|
|
||||||
});
|
|
||||||
|
|
||||||
config.decoder.readers = ['ean_8_reader'];
|
|
||||||
_runTestSet(testSet, config);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("UPC", function() {
|
|
||||||
var config = generateConfig(),
|
|
||||||
testSet = [
|
|
||||||
{"name": "image-001.jpg", "result": "882428015268"},
|
|
||||||
{"name": "image-002.jpg", "result": "882428015268"},
|
|
||||||
{"name": "image-003.jpg", "result": "882428015084"},
|
|
||||||
{"name": "image-004.jpg", "result": "882428015343"},
|
|
||||||
{"name": "image-005.jpg", "result": "882428015343"},
|
|
||||||
/* {"name": "image-006.jpg", "result": "882428015046"}, */
|
|
||||||
{"name": "image-007.jpg", "result": "882428015084"},
|
|
||||||
{"name": "image-008.jpg", "result": "882428015046"},
|
|
||||||
{"name": "image-009.jpg", "result": "039047013551"},
|
|
||||||
{"name": "image-010.jpg", "result": "039047013551"}
|
|
||||||
];
|
|
||||||
|
|
||||||
testSet.forEach(function(sample) {
|
|
||||||
sample.format = "upc_a";
|
|
||||||
});
|
|
||||||
|
|
||||||
config.decoder.readers = ['upc_reader'];
|
|
||||||
_runTestSet(testSet, config);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("UPC-E", function() {
|
|
||||||
var config = generateConfig(),
|
|
||||||
testSet = [
|
|
||||||
{"name": "image-001.jpg", "result": "04965802"},
|
|
||||||
{"name": "image-002.jpg", "result": "04965802"},
|
|
||||||
{"name": "image-003.jpg", "result": "03897425"},
|
|
||||||
{"name": "image-004.jpg", "result": "05096893"},
|
|
||||||
{"name": "image-005.jpg", "result": "05096893"},
|
|
||||||
{"name": "image-006.jpg", "result": "05096893"},
|
|
||||||
{"name": "image-007.jpg", "result": "03897425"},
|
|
||||||
{"name": "image-008.jpg", "result": "01264904"},
|
|
||||||
/*{"name": "image-009.jpg", "result": "01264904"},*/
|
|
||||||
{"name": "image-010.jpg", "result": "01264904"}
|
|
||||||
];
|
|
||||||
|
|
||||||
testSet.forEach(function(sample) {
|
|
||||||
sample.format = "upc_e";
|
|
||||||
});
|
|
||||||
|
|
||||||
config.decoder.readers = ['upc_e_reader'];
|
|
||||||
_runTestSet(testSet, config);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("Codabar", function() {
|
|
||||||
var config = generateConfig(),
|
|
||||||
testSet = [
|
|
||||||
{"name": "image-001.jpg", "result": "A10/53+17-70D"},
|
|
||||||
{"name": "image-002.jpg", "result": "B546745735B"},
|
|
||||||
{"name": "image-003.jpg", "result": "C$399.95A"},
|
|
||||||
{"name": "image-004.jpg", "result": "B546745735B"},
|
|
||||||
{"name": "image-005.jpg", "result": "C$399.95A"},
|
|
||||||
{"name": "image-006.jpg", "result": "B546745735B"},
|
|
||||||
{"name": "image-007.jpg", "result": "C$399.95A"},
|
|
||||||
{"name": "image-008.jpg", "result": "A16:9/4:3/3:2D"},
|
|
||||||
{"name": "image-009.jpg", "result": "C$399.95A"},
|
|
||||||
{"name": "image-010.jpg", "result": "C$399.95A"}
|
|
||||||
];
|
|
||||||
|
|
||||||
testSet.forEach(function(sample) {
|
|
||||||
sample.format = "codabar";
|
|
||||||
});
|
|
||||||
|
|
||||||
config.decoder.readers = ['codabar_reader'];
|
|
||||||
_runTestSet(testSet, config);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("I2of5 with localization", function() {
|
|
||||||
var config = {
|
|
||||||
inputStream: {
|
|
||||||
size: 800,
|
|
||||||
singleChannel: false
|
|
||||||
},
|
|
||||||
locator: {
|
|
||||||
patchSize: "small",
|
|
||||||
halfSample: false
|
|
||||||
},
|
|
||||||
numOfWorkers: 0,
|
|
||||||
decoder: {
|
|
||||||
readers: ["i2of5_reader"],
|
|
||||||
},
|
|
||||||
locate: true,
|
|
||||||
src: null
|
|
||||||
}, testSet = [
|
|
||||||
{"name": "image-001.jpg", "result": "2167361334"},
|
|
||||||
{"name": "image-002.jpg", "result": "2167361334"},
|
|
||||||
{"name": "image-003.jpg", "result": "2167361334"},
|
|
||||||
{"name": "image-004.jpg", "result": "2167361334"},
|
|
||||||
{"name": "image-005.jpg", "result": "2167361334"}
|
|
||||||
];
|
|
||||||
|
|
||||||
testSet.forEach(function(sample) {
|
|
||||||
sample.format = "i2of5";
|
|
||||||
});
|
|
||||||
|
|
||||||
_runTestSet(testSet, config);
|
|
||||||
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,103 +0,0 @@
|
|||||||
|
|
||||||
define(['result_collector', 'image_debug'], function(ResultCollector, ImageDebug) {
|
|
||||||
var canvasMock,
|
|
||||||
imageSize,
|
|
||||||
config;
|
|
||||||
|
|
||||||
beforeEach(function() {
|
|
||||||
imageSize = {x: 320, y: 240};
|
|
||||||
config = {
|
|
||||||
capture: true,
|
|
||||||
capacity: 20,
|
|
||||||
blacklist: [{code: "3574660239843", format: "ean_13"}],
|
|
||||||
filter: function(codeResult) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
canvasMock = {
|
|
||||||
getContext: function() {
|
|
||||||
return {};
|
|
||||||
},
|
|
||||||
toDataURL: sinon.spy(),
|
|
||||||
width: 0,
|
|
||||||
height: 0
|
|
||||||
};
|
|
||||||
sinon.stub(document, "createElement", function(type) {
|
|
||||||
if (type === "canvas") {
|
|
||||||
return canvasMock;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(function() {
|
|
||||||
document.createElement.restore();
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
describe('create', function () {
|
|
||||||
it("should return a new collector", function() {
|
|
||||||
ResultCollector.create(config);
|
|
||||||
expect(document.createElement.calledOnce).to.be.equal(true);
|
|
||||||
expect(document.createElement.getCall(0).args[0]).to.equal("canvas");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('addResult', function() {
|
|
||||||
beforeEach(function() {
|
|
||||||
sinon.stub(ImageDebug, "drawImage", function() {});
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(function() {
|
|
||||||
ImageDebug.drawImage.restore();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should not add result if capacity is full", function(){
|
|
||||||
config.capacity = 1;
|
|
||||||
var collector = ResultCollector.create(config);
|
|
||||||
collector.addResult([], imageSize, {});
|
|
||||||
collector.addResult([], imageSize, {});
|
|
||||||
collector.addResult([], imageSize, {});
|
|
||||||
expect(collector.getResults()).to.have.length(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should only add results which match constraints", function(){
|
|
||||||
var collector = ResultCollector.create(config),
|
|
||||||
results;
|
|
||||||
|
|
||||||
collector.addResult([], imageSize, {code: "423423443", format: "ean_13"});
|
|
||||||
collector.addResult([], imageSize, {code: "3574660239843", format: "ean_13"});
|
|
||||||
collector.addResult([], imageSize, {code: "3574660239843", format: "code_128"});
|
|
||||||
|
|
||||||
results = collector.getResults();
|
|
||||||
expect(results).to.have.length(2);
|
|
||||||
|
|
||||||
results.forEach(function(result) {
|
|
||||||
expect(result).not.to.deep.equal(config.blacklist[0]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should add result if no filter is set", function() {
|
|
||||||
delete config.filter;
|
|
||||||
var collector = ResultCollector.create(config);
|
|
||||||
|
|
||||||
collector.addResult([], imageSize, {code: "423423443", format: "ean_13"});
|
|
||||||
expect(collector.getResults()).to.have.length(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should not add results if filter returns false", function() {
|
|
||||||
config.filter = function(){ return false };
|
|
||||||
var collector = ResultCollector.create(config);
|
|
||||||
|
|
||||||
collector.addResult([], imageSize, {code: "423423443", format: "ean_13"});
|
|
||||||
expect(collector.getResults()).to.have.length(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should add result if no blacklist is set", function() {
|
|
||||||
delete config.blacklist;
|
|
||||||
var collector = ResultCollector.create(config);
|
|
||||||
|
|
||||||
collector.addResult([], imageSize, {code: "3574660239843", format: "ean_13"});
|
|
||||||
expect(collector.getResults()).to.have.length(1);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,40 +0,0 @@
|
|||||||
/* jshint undef: true, unused: true, browser:true, devel: true */
|
|
||||||
/* global define */
|
|
||||||
|
|
||||||
define([], function() {
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
function createNode(htmlStr) {
|
|
||||||
var temp = document.createElement('div');
|
|
||||||
|
|
||||||
temp.innerHTML = htmlStr;
|
|
||||||
while (temp.firstChild) {
|
|
||||||
return temp.firstChild;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function mergeObjects(obj1, obj2) {
|
|
||||||
for (var p in obj2) {
|
|
||||||
try {
|
|
||||||
if (obj2[p].constructor == Object) {
|
|
||||||
obj1[p] = mergeObjects(obj1[p], obj2[p]);
|
|
||||||
} else {
|
|
||||||
obj1[p] = obj2[p];
|
|
||||||
}
|
|
||||||
} catch(e) {
|
|
||||||
obj1[p] = obj2[p];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return obj1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
createNode : function(htmlStr) {
|
|
||||||
return createNode(htmlStr);
|
|
||||||
},
|
|
||||||
mergeObjects : function(obj1, obj2) {
|
|
||||||
return mergeObjects(obj1, obj2);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
@ -1,55 +0,0 @@
|
|||||||
var allTestFiles = [];
|
|
||||||
var TEST_REGEXP = /(spec|test)\.js$/i;
|
|
||||||
|
|
||||||
var pathToModule = function(path) {
|
|
||||||
return path.replace(/^\/base\//, '').replace(/\.js$/, '');
|
|
||||||
};
|
|
||||||
|
|
||||||
Object.keys(window.__karma__.files).forEach(function(file) {
|
|
||||||
if (TEST_REGEXP.test(file)) {
|
|
||||||
allTestFiles.push(pathToModule(file));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
require.config({
|
|
||||||
baseUrl: '/base',
|
|
||||||
|
|
||||||
paths: {
|
|
||||||
'array_helper': 'src/array_helper',
|
|
||||||
'cv_utils': 'src/cv_utils',
|
|
||||||
'typedefs': 'src/typedefs',
|
|
||||||
'cluster': 'src/cluster',
|
|
||||||
'camera_access': 'src/camera_access',
|
|
||||||
'events': 'src/events',
|
|
||||||
'html_utils': 'src/html_utils',
|
|
||||||
'quagga': 'src/quagga',
|
|
||||||
'barcode_decoder': 'src/barcode_decoder',
|
|
||||||
'barcode_locator': 'src/barcode_locator',
|
|
||||||
'barcode_reader': 'src/barcode_reader',
|
|
||||||
'bresenham': 'src/bresenham',
|
|
||||||
'codabar_reader': 'src/codabar_reader',
|
|
||||||
'code_39_reader': 'src/code_39_reader',
|
|
||||||
'code_39_vin_reader': 'src/code_39_vin_reader',
|
|
||||||
'code_128_reader': 'src/code_128_reader',
|
|
||||||
'config': 'src/config',
|
|
||||||
'ean_8_reader': 'src/ean_8_reader',
|
|
||||||
'ean_reader': 'src/ean_reader',
|
|
||||||
'frame_grabber': 'src/frame_grabber',
|
|
||||||
'image_debug': 'src/image_debug',
|
|
||||||
'image_loader': 'src/image_loader',
|
|
||||||
'image_wrapper': 'src/image_wrapper',
|
|
||||||
'input_stream': 'src/input_stream',
|
|
||||||
'rasterizer': 'src/rasterizer',
|
|
||||||
'skeletonizer': 'src/skeletonizer',
|
|
||||||
'subImage': 'src/subImage',
|
|
||||||
'tracer': 'src/tracer',
|
|
||||||
'upc_e_reader': 'src/upc_e_reader',
|
|
||||||
'upc_reader': 'src/upc_reader',
|
|
||||||
'async': 'node_modules/async/lib/async',
|
|
||||||
'gl-matrix': 'node_modules/gl-matrix/dist/gl-matrix-min',
|
|
||||||
'result_collector': 'src/result_collector',
|
|
||||||
'i2of5_reader': 'src/i2of5_reader'
|
|
||||||
},
|
|
||||||
deps: allTestFiles,
|
|
||||||
callback: window.__karma__.start
|
|
||||||
});
|
|
@ -0,0 +1,245 @@
|
|||||||
|
const Quagga = require('../../src/quagga');
|
||||||
|
const async = require('async');
|
||||||
|
|
||||||
|
describe('decodeSingle', function () {
|
||||||
|
var baseFolder = "base/test/fixtures/";
|
||||||
|
|
||||||
|
function generateConfig() {
|
||||||
|
return {
|
||||||
|
inputStream: {
|
||||||
|
size: 640
|
||||||
|
},
|
||||||
|
locator: {
|
||||||
|
patchSize: "medium",
|
||||||
|
halfSample: true
|
||||||
|
},
|
||||||
|
numOfWorkers: 0,
|
||||||
|
decoder: {
|
||||||
|
readers: ["ean_reader"]
|
||||||
|
},
|
||||||
|
locate: true,
|
||||||
|
src: null
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
this.timeout(10000);
|
||||||
|
|
||||||
|
function _runTestSet(testSet, config) {
|
||||||
|
var readers = config.decoder.readers.slice(),
|
||||||
|
format,
|
||||||
|
folder;
|
||||||
|
|
||||||
|
if (typeof readers[0] === 'string'){
|
||||||
|
format = readers[0];
|
||||||
|
} else {
|
||||||
|
format = readers[0].format;
|
||||||
|
}
|
||||||
|
|
||||||
|
folder = baseFolder + format.split('_').slice(0, -1).join('_') + "/";
|
||||||
|
|
||||||
|
it('should decode ' + folder + " correctly", function(done) {
|
||||||
|
async.eachSeries(testSet, function (sample, callback) {
|
||||||
|
config.src = folder + sample.name;
|
||||||
|
config.readers = readers;
|
||||||
|
Quagga.decodeSingle(config, function(result) {
|
||||||
|
console.log(sample.name);
|
||||||
|
expect(result.codeResult.code).to.equal(sample.result);
|
||||||
|
expect(result.codeResult.format).to.equal(sample.format);
|
||||||
|
callback();
|
||||||
|
});
|
||||||
|
}, function() {
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("EAN", function() {
|
||||||
|
var config = generateConfig(),
|
||||||
|
testSet = [
|
||||||
|
{"name": "image-001.jpg", "result": "3574660239843"},
|
||||||
|
{"name": "image-002.jpg", "result": "8032754490297"},
|
||||||
|
{"name": "image-003.jpg", "result": "4006209700068"},
|
||||||
|
/* {"name": "image-004.jpg", "result": "9002233139084"}, */
|
||||||
|
/* {"name": "image-005.jpg", "result": "8004030044005"}, */
|
||||||
|
{"name": "image-006.jpg", "result": "4003626011159"},
|
||||||
|
{"name": "image-007.jpg", "result": "2111220009686"},
|
||||||
|
{"name": "image-008.jpg", "result": "9000275609022"},
|
||||||
|
{"name": "image-009.jpg", "result": "9004593978587"},
|
||||||
|
{"name": "image-010.jpg", "result": "9002244845578"}
|
||||||
|
];
|
||||||
|
|
||||||
|
testSet.forEach(function(sample) {
|
||||||
|
sample.format = "ean_13";
|
||||||
|
});
|
||||||
|
|
||||||
|
config.decoder.readers = ['ean_reader'];
|
||||||
|
_runTestSet(testSet, config);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Code128", function() {
|
||||||
|
var config = generateConfig(),
|
||||||
|
testSet = [
|
||||||
|
{"name": "image-001.jpg", "result": "0001285112001000040801"},
|
||||||
|
// {"name": "image-002.jpg", "result": "FANAVF1461710"},
|
||||||
|
// {"name": "image-003.jpg", "result": "673023"},
|
||||||
|
// {"name": "image-004.jpg", "result": "010210150301625334"},
|
||||||
|
{"name": "image-005.jpg", "result": "419055603900009001012999"},
|
||||||
|
{"name": "image-006.jpg", "result": "419055603900009001012999"},
|
||||||
|
{"name": "image-007.jpg", "result": "T 000003552345"},
|
||||||
|
{"name": "image-008.jpg", "result": "FANAVF1461710"},
|
||||||
|
{"name": "image-009.jpg", "result": "0001285112001000040801"},
|
||||||
|
{"name": "image-010.jpg", "result": "673023"}
|
||||||
|
];
|
||||||
|
|
||||||
|
testSet.forEach(function(sample) {
|
||||||
|
sample.format = "code_128";
|
||||||
|
});
|
||||||
|
|
||||||
|
config.decoder.readers = ['code_128_reader'];
|
||||||
|
_runTestSet(testSet, config);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Code39", function() {
|
||||||
|
var config = generateConfig(),
|
||||||
|
testSet = [
|
||||||
|
{"name": "image-001.jpg", "result": "B3% $DAD$"},
|
||||||
|
{"name": "image-003.jpg", "result": "CODE39"},
|
||||||
|
{"name": "image-004.jpg", "result": "QUAGGAJS"},
|
||||||
|
/* {"name": "image-005.jpg", "result": "CODE39"}, */
|
||||||
|
{"name": "image-006.jpg", "result": "2/4-8/16-32"},
|
||||||
|
{"name": "image-007.jpg", "result": "2/4-8/16-32"},
|
||||||
|
{"name": "image-008.jpg", "result": "CODE39"},
|
||||||
|
{"name": "image-009.jpg", "result": "2/4-8/16-32"},
|
||||||
|
{"name": "image-010.jpg", "result": "CODE39"}
|
||||||
|
];
|
||||||
|
|
||||||
|
testSet.forEach(function(sample) {
|
||||||
|
sample.format = "code_39";
|
||||||
|
});
|
||||||
|
|
||||||
|
config.decoder.readers = ['code_39_reader'];
|
||||||
|
_runTestSet(testSet, config);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("EAN-8", function() {
|
||||||
|
var config = generateConfig(),
|
||||||
|
testSet = [
|
||||||
|
{"name": "image-001.jpg", "result": "42191605"},
|
||||||
|
{"name": "image-002.jpg", "result": "42191605"},
|
||||||
|
{"name": "image-003.jpg", "result": "90311208"},
|
||||||
|
{"name": "image-004.jpg", "result": "24057257"},
|
||||||
|
{"name": "image-005.jpg", "result": "90162602"},
|
||||||
|
{"name": "image-006.jpg", "result": "24036153"},
|
||||||
|
{"name": "image-007.jpg", "result": "42176817"},
|
||||||
|
{"name": "image-008.jpg", "result": "42191605"},
|
||||||
|
{"name": "image-009.jpg", "result": "42242215"},
|
||||||
|
{"name": "image-010.jpg", "result": "42184799"}
|
||||||
|
];
|
||||||
|
|
||||||
|
testSet.forEach(function(sample) {
|
||||||
|
sample.format = "ean_8";
|
||||||
|
});
|
||||||
|
|
||||||
|
config.decoder.readers = ['ean_8_reader'];
|
||||||
|
_runTestSet(testSet, config);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("UPC", function() {
|
||||||
|
var config = generateConfig(),
|
||||||
|
testSet = [
|
||||||
|
{"name": "image-001.jpg", "result": "882428015268"},
|
||||||
|
{"name": "image-002.jpg", "result": "882428015268"},
|
||||||
|
{"name": "image-003.jpg", "result": "882428015084"},
|
||||||
|
{"name": "image-004.jpg", "result": "882428015343"},
|
||||||
|
{"name": "image-005.jpg", "result": "882428015343"},
|
||||||
|
/* {"name": "image-006.jpg", "result": "882428015046"}, */
|
||||||
|
{"name": "image-007.jpg", "result": "882428015084"},
|
||||||
|
{"name": "image-008.jpg", "result": "882428015046"},
|
||||||
|
{"name": "image-009.jpg", "result": "039047013551"},
|
||||||
|
{"name": "image-010.jpg", "result": "039047013551"}
|
||||||
|
];
|
||||||
|
|
||||||
|
testSet.forEach(function(sample) {
|
||||||
|
sample.format = "upc_a";
|
||||||
|
});
|
||||||
|
|
||||||
|
config.decoder.readers = ['upc_reader'];
|
||||||
|
_runTestSet(testSet, config);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("UPC-E", function() {
|
||||||
|
var config = generateConfig(),
|
||||||
|
testSet = [
|
||||||
|
{"name": "image-001.jpg", "result": "04965802"},
|
||||||
|
{"name": "image-002.jpg", "result": "04965802"},
|
||||||
|
{"name": "image-003.jpg", "result": "03897425"},
|
||||||
|
{"name": "image-004.jpg", "result": "05096893"},
|
||||||
|
{"name": "image-005.jpg", "result": "05096893"},
|
||||||
|
{"name": "image-006.jpg", "result": "05096893"},
|
||||||
|
{"name": "image-007.jpg", "result": "03897425"},
|
||||||
|
{"name": "image-008.jpg", "result": "01264904"},
|
||||||
|
/*{"name": "image-009.jpg", "result": "01264904"},*/
|
||||||
|
{"name": "image-010.jpg", "result": "01264904"}
|
||||||
|
];
|
||||||
|
|
||||||
|
testSet.forEach(function(sample) {
|
||||||
|
sample.format = "upc_e";
|
||||||
|
});
|
||||||
|
|
||||||
|
config.decoder.readers = ['upc_e_reader'];
|
||||||
|
_runTestSet(testSet, config);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Codabar", function() {
|
||||||
|
var config = generateConfig(),
|
||||||
|
testSet = [
|
||||||
|
{"name": "image-001.jpg", "result": "A10/53+17-70D"},
|
||||||
|
{"name": "image-002.jpg", "result": "B546745735B"},
|
||||||
|
{"name": "image-003.jpg", "result": "C$399.95A"},
|
||||||
|
{"name": "image-004.jpg", "result": "B546745735B"},
|
||||||
|
{"name": "image-005.jpg", "result": "C$399.95A"},
|
||||||
|
{"name": "image-006.jpg", "result": "B546745735B"},
|
||||||
|
{"name": "image-007.jpg", "result": "C$399.95A"},
|
||||||
|
{"name": "image-008.jpg", "result": "A16:9/4:3/3:2D"},
|
||||||
|
{"name": "image-009.jpg", "result": "C$399.95A"},
|
||||||
|
{"name": "image-010.jpg", "result": "C$399.95A"}
|
||||||
|
];
|
||||||
|
|
||||||
|
testSet.forEach(function(sample) {
|
||||||
|
sample.format = "codabar";
|
||||||
|
});
|
||||||
|
|
||||||
|
config.decoder.readers = ['codabar_reader'];
|
||||||
|
_runTestSet(testSet, config);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("I2of5 with localization", function() {
|
||||||
|
var config = {
|
||||||
|
inputStream: {
|
||||||
|
size: 800,
|
||||||
|
singleChannel: false
|
||||||
|
},
|
||||||
|
locator: {
|
||||||
|
patchSize: "small",
|
||||||
|
halfSample: false
|
||||||
|
},
|
||||||
|
numOfWorkers: 0,
|
||||||
|
decoder: {
|
||||||
|
readers: ["i2of5_reader"]
|
||||||
|
},
|
||||||
|
locate: true,
|
||||||
|
src: null
|
||||||
|
},
|
||||||
|
testSet = [
|
||||||
|
{"name": "image-001.jpg", "result": "2167361334"},
|
||||||
|
{"name": "image-002.jpg", "result": "2167361334"},
|
||||||
|
{"name": "image-003.jpg", "result": "2167361334"},
|
||||||
|
{"name": "image-004.jpg", "result": "2167361334"},
|
||||||
|
{"name": "image-005.jpg", "result": "2167361334"}
|
||||||
|
];
|
||||||
|
testSet.forEach(function(sample) {
|
||||||
|
sample.format = "i2of5";
|
||||||
|
});
|
||||||
|
_runTestSet(testSet, config);
|
||||||
|
});
|
||||||
|
});
|
@ -0,0 +1,53 @@
|
|||||||
|
const ArrayHelper = require('../../src/array_helper');
|
||||||
|
|
||||||
|
describe('init', function() {
|
||||||
|
it('initializes an array with the given value', function() {
|
||||||
|
var input = [0, 0, 0];
|
||||||
|
ArrayHelper.init(input, 5);
|
||||||
|
expect(input).to.deep.equal([5, 5, 5]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('shuffle', function() {
|
||||||
|
before(function() {
|
||||||
|
sinon.stub(Math, 'random').returns(0.5);
|
||||||
|
});
|
||||||
|
|
||||||
|
after(function() {
|
||||||
|
sinon.restore(Math);
|
||||||
|
});
|
||||||
|
it('shuffles the content of an array', function() {
|
||||||
|
var input = [1, 2, 3];
|
||||||
|
expect(ArrayHelper.shuffle(input)).to.deep.equal([3, 1, 2]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('toPointList', function() {
|
||||||
|
it('converts an Array to a List of poitns', function() {
|
||||||
|
var input = [[1, 2], [2, 2], [3, 2]];
|
||||||
|
expect(ArrayHelper.toPointList(input)).to.equal("[[1,2],\r\n[2,2],\r\n[3,2]]");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('threshold', function() {
|
||||||
|
it('returns all elements above the given threshold', function() {
|
||||||
|
var input = [1, 2, 3];
|
||||||
|
expect(ArrayHelper.threshold(input, 2, function(score) {
|
||||||
|
return score * 1.5;
|
||||||
|
})).to.deep.equal([2, 3]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('maxIndex', function() {
|
||||||
|
it('gets the index of the biggest element in the array', function() {
|
||||||
|
var input = [1, 2, 3];
|
||||||
|
expect(ArrayHelper.maxIndex(input)).to.equal(2);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('max', function() {
|
||||||
|
it('gets the biggest element in the array', function() {
|
||||||
|
var input = [1, 3, 2];
|
||||||
|
expect(ArrayHelper.max(input)).to.equal(3);
|
||||||
|
});
|
||||||
|
});
|
@ -0,0 +1,130 @@
|
|||||||
|
const BarcodeLocator = require('../../src/barcode_locator');
|
||||||
|
const Config = require('../../src/config');
|
||||||
|
const merge = require('lodash/object/merge');
|
||||||
|
|
||||||
|
describe('checkImageConstraints', function() {
|
||||||
|
var config,
|
||||||
|
inputStream,
|
||||||
|
imageSize,
|
||||||
|
streamConfig = {};
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
imageSize = {
|
||||||
|
x: 640, y: 480
|
||||||
|
};
|
||||||
|
config = merge({}, Config);
|
||||||
|
inputStream = {
|
||||||
|
getWidth: function() {
|
||||||
|
return imageSize.x;
|
||||||
|
},
|
||||||
|
getHeight: function() {
|
||||||
|
return imageSize.y;
|
||||||
|
},
|
||||||
|
setWidth: function() {},
|
||||||
|
setHeight: function() {},
|
||||||
|
setTopRight: function() {},
|
||||||
|
setCanvasSize: function() {},
|
||||||
|
getConfig: function() {
|
||||||
|
return streamConfig;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
sinon.stub(inputStream, "setWidth", function(width) {
|
||||||
|
imageSize.x = width;
|
||||||
|
});
|
||||||
|
sinon.stub(inputStream, "setHeight", function(height) {
|
||||||
|
imageSize.y = height;
|
||||||
|
});
|
||||||
|
sinon.stub(inputStream, "setTopRight");
|
||||||
|
sinon.stub(inputStream, "setCanvasSize");
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function() {
|
||||||
|
inputStream.setWidth.restore();
|
||||||
|
inputStream.setHeight.restore();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not adjust the image-size if not needed', function() {
|
||||||
|
var expected = {x: imageSize.x, y: imageSize.y};
|
||||||
|
BarcodeLocator.checkImageConstraints(inputStream, config.locator);
|
||||||
|
expect(inputStream.getWidth()).to.be.equal(expected.x);
|
||||||
|
expect(inputStream.getHeight()).to.be.equal(expected.y);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should adjust the image-size', function() {
|
||||||
|
var expected = {x: imageSize.x, y: imageSize.y};
|
||||||
|
|
||||||
|
config.locator.halfSample = true;
|
||||||
|
imageSize.y += 1;
|
||||||
|
BarcodeLocator.checkImageConstraints(inputStream, config.locator);
|
||||||
|
expect(inputStream.getWidth()).to.be.equal(expected.x);
|
||||||
|
expect(inputStream.getHeight()).to.be.equal(expected.y);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should adjust the image-size', function() {
|
||||||
|
var expected = {x: imageSize.x, y: imageSize.y};
|
||||||
|
|
||||||
|
imageSize.y += 1;
|
||||||
|
config.locator.halfSample = false;
|
||||||
|
BarcodeLocator.checkImageConstraints(inputStream, config.locator);
|
||||||
|
expect(inputStream.getHeight()).to.be.equal(expected.y);
|
||||||
|
expect(inputStream.getWidth()).to.be.equal(expected.x);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should take the defined area into account", function() {
|
||||||
|
var expectedSize = {
|
||||||
|
x: 420,
|
||||||
|
y: 315
|
||||||
|
},
|
||||||
|
expectedTopRight = {
|
||||||
|
x: 115,
|
||||||
|
y: 52
|
||||||
|
},
|
||||||
|
expectedCanvasSize = {
|
||||||
|
x: 640,
|
||||||
|
y: 480
|
||||||
|
};
|
||||||
|
|
||||||
|
streamConfig.area = {
|
||||||
|
top: "11%",
|
||||||
|
right: "15%",
|
||||||
|
bottom: "20%",
|
||||||
|
left: "18%"
|
||||||
|
};
|
||||||
|
|
||||||
|
config.locator.halfSample = false;
|
||||||
|
BarcodeLocator.checkImageConstraints(inputStream, config.locator);
|
||||||
|
expect(inputStream.getHeight()).to.be.equal(expectedSize.y);
|
||||||
|
expect(inputStream.getWidth()).to.be.equal(expectedSize.x);
|
||||||
|
expect(inputStream.setTopRight.getCall(0).args[0]).to.deep.equal(expectedTopRight);
|
||||||
|
expect(inputStream.setCanvasSize.getCall(0).args[0]).to.deep.equal(expectedCanvasSize);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return the original size if set to full image", function() {
|
||||||
|
var expectedSize = {
|
||||||
|
x: 640,
|
||||||
|
y: 480
|
||||||
|
},
|
||||||
|
expectedTopRight = {
|
||||||
|
x: 0,
|
||||||
|
y: 0
|
||||||
|
},
|
||||||
|
expectedCanvasSize = {
|
||||||
|
x: 640,
|
||||||
|
y: 480
|
||||||
|
};
|
||||||
|
|
||||||
|
streamConfig.area = {
|
||||||
|
top: "0%",
|
||||||
|
right: "0%",
|
||||||
|
bottom: "0%",
|
||||||
|
left: "0%"
|
||||||
|
};
|
||||||
|
|
||||||
|
config.locator.halfSample = false;
|
||||||
|
BarcodeLocator.checkImageConstraints(inputStream, config.locator);
|
||||||
|
expect(inputStream.getHeight()).to.be.equal(expectedSize.y);
|
||||||
|
expect(inputStream.getWidth()).to.be.equal(expectedSize.x);
|
||||||
|
expect(inputStream.setTopRight.getCall(0).args[0]).to.deep.equal(expectedTopRight);
|
||||||
|
expect(inputStream.setCanvasSize.getCall(0).args[0]).to.deep.equal(expectedCanvasSize);
|
||||||
|
});
|
||||||
|
});
|
@ -0,0 +1,116 @@
|
|||||||
|
const CameraAccess = require('../../src/camera_access');
|
||||||
|
|
||||||
|
var originalURL,
|
||||||
|
originalMediaStreamTrack,
|
||||||
|
video,
|
||||||
|
stream;
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
var tracks = [{
|
||||||
|
stop: function() {}
|
||||||
|
}];
|
||||||
|
|
||||||
|
originalURL = window.URL;
|
||||||
|
originalMediaStreamTrack = window.MediaStreamTrack;
|
||||||
|
window.MediaStreamTrack = {};
|
||||||
|
window.URL = null;
|
||||||
|
|
||||||
|
stream = {
|
||||||
|
getVideoTracks: function() {
|
||||||
|
return tracks;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
sinon.spy(tracks[0], "stop");
|
||||||
|
|
||||||
|
video = {
|
||||||
|
src: null,
|
||||||
|
addEventListener: function() {},
|
||||||
|
removeEventListener: function() {},
|
||||||
|
play: function() {},
|
||||||
|
videoWidth: 320,
|
||||||
|
videoHeight: 480
|
||||||
|
};
|
||||||
|
sinon.stub(video, "addEventListener", function(event, cb) {
|
||||||
|
cb();
|
||||||
|
});
|
||||||
|
sinon.stub(video, "play");
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function() {
|
||||||
|
window.URL = originalURL;
|
||||||
|
window.MediaStreamTrack = originalMediaStreamTrack;
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('success', function() {
|
||||||
|
beforeEach(function() {
|
||||||
|
sinon.stub(navigator, "getUserMedia", function(constraints, success) {
|
||||||
|
success(stream);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function() {
|
||||||
|
navigator.getUserMedia.restore();
|
||||||
|
});
|
||||||
|
describe('request', function () {
|
||||||
|
it('should request the camera', function (done) {
|
||||||
|
CameraAccess.request(video, {}, function () {
|
||||||
|
expect(navigator.getUserMedia.calledOnce).to.equal(true);
|
||||||
|
expect(video.src).to.deep.equal(stream);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('release', function () {
|
||||||
|
it('should release the camera', function (done) {
|
||||||
|
CameraAccess.request(video, {}, function () {
|
||||||
|
expect(video.src).to.deep.equal(stream);
|
||||||
|
CameraAccess.release();
|
||||||
|
expect(video.src.getVideoTracks()).to.have.length(1);
|
||||||
|
expect(video.src.getVideoTracks()[0].stop.calledOnce).to.equal(true);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('failure', function() {
|
||||||
|
describe("permission denied", function(){
|
||||||
|
before(function() {
|
||||||
|
sinon.stub(navigator, "getUserMedia", function(constraints, success, failure) {
|
||||||
|
failure(new Error());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
after(function() {
|
||||||
|
navigator.getUserMedia.restore();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw if getUserMedia not available', function(done) {
|
||||||
|
CameraAccess.request(video, {}, function(err) {
|
||||||
|
expect(err).to.be.defined;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("not available", function(){
|
||||||
|
var originalGetUserMedia;
|
||||||
|
|
||||||
|
before(function() {
|
||||||
|
originalGetUserMedia = navigator.getUserMedia;
|
||||||
|
navigator.getUserMedia = undefined;
|
||||||
|
});
|
||||||
|
|
||||||
|
after(function() {
|
||||||
|
navigator.getUserMedia = originalGetUserMedia;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw if getUserMedia not available', function(done) {
|
||||||
|
CameraAccess.request(video, {}, function(err) {
|
||||||
|
expect(err).to.be.defined;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@ -0,0 +1,144 @@
|
|||||||
|
const CVUtils = require('../../src/cv_utils');
|
||||||
|
|
||||||
|
describe('imageRef', function() {
|
||||||
|
it('gets the image Reference for a coordinate', function() {
|
||||||
|
var res = CVUtils.imageRef(1, 2);
|
||||||
|
expect(res.x).to.equal(1);
|
||||||
|
expect(res.y).to.equal(2);
|
||||||
|
expect(res.toVec2()[0]).to.equal(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('calculatePatchSize', function() {
|
||||||
|
it('should not throw an error in case of valid image size', function() {
|
||||||
|
var expected = {x: 32, y: 32},
|
||||||
|
patchSize = CVUtils.calculatePatchSize("medium", {x: 640, y: 480});
|
||||||
|
|
||||||
|
expect(patchSize).to.be.deep.equal(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should thow an error if image size it not valid', function() {
|
||||||
|
var expected = {x: 32, y: 32},
|
||||||
|
patchSize = CVUtils.calculatePatchSize("medium", {x: 640, y: 480});
|
||||||
|
|
||||||
|
expect(patchSize).to.be.deep.equal(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('_parseCSSDimensionValues', function() {
|
||||||
|
it("should convert a percentual value correctly", function() {
|
||||||
|
var expected = {
|
||||||
|
value: 10,
|
||||||
|
unit: "%"
|
||||||
|
},
|
||||||
|
result = CVUtils._parseCSSDimensionValues("10%");
|
||||||
|
|
||||||
|
expect(result).to.be.deep.equal(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should convert a 0% value correctly", function() {
|
||||||
|
var expected = {
|
||||||
|
value: 100,
|
||||||
|
unit: "%"
|
||||||
|
},
|
||||||
|
result = CVUtils._parseCSSDimensionValues("100%");
|
||||||
|
|
||||||
|
expect(result).to.be.deep.equal(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should convert a 100% value correctly", function() {
|
||||||
|
var expected = {
|
||||||
|
value: 0,
|
||||||
|
unit: "%"
|
||||||
|
},
|
||||||
|
result = CVUtils._parseCSSDimensionValues("0%");
|
||||||
|
|
||||||
|
expect(result).to.be.deep.equal(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should convert a pixel value to percentage", function() {
|
||||||
|
var expected = {
|
||||||
|
value: 26.3,
|
||||||
|
unit: "%"
|
||||||
|
},
|
||||||
|
result = CVUtils._parseCSSDimensionValues("26.3px");
|
||||||
|
|
||||||
|
console.log(result);
|
||||||
|
expect(result).to.be.deep.equal(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("_dimensionsConverters", function(){
|
||||||
|
var context;
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
context = {
|
||||||
|
width: 640,
|
||||||
|
height: 480
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should convert a top-value correclty", function() {
|
||||||
|
var expected = 48,
|
||||||
|
result = CVUtils._dimensionsConverters.top({value: 10, unit: "%"}, context);
|
||||||
|
|
||||||
|
expect(result).to.be.equal(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should convert a right-value correclty", function() {
|
||||||
|
var expected = 640 - 128,
|
||||||
|
result = CVUtils._dimensionsConverters.right({value: 20, unit: "%"}, context);
|
||||||
|
|
||||||
|
expect(result).to.be.equal(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should convert a bottom-value correclty", function() {
|
||||||
|
var expected = 480 - 77,
|
||||||
|
result = CVUtils._dimensionsConverters.bottom({value: 16, unit: "%"}, context);
|
||||||
|
|
||||||
|
expect(result).to.be.equal(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should convert a left-value correclty", function() {
|
||||||
|
var expected = 57,
|
||||||
|
result = CVUtils._dimensionsConverters.left({value: 9, unit: "%"}, context);
|
||||||
|
|
||||||
|
expect(result).to.be.equal(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("computeImageArea", function() {
|
||||||
|
it("should calculate an image-area", function() {
|
||||||
|
var expected = {
|
||||||
|
sx: 115,
|
||||||
|
sy: 48,
|
||||||
|
sw: 429,
|
||||||
|
sh: 336
|
||||||
|
},
|
||||||
|
result = CVUtils.computeImageArea(640, 480, {
|
||||||
|
top: "10%",
|
||||||
|
right: "15%",
|
||||||
|
bottom: "20%",
|
||||||
|
left: "18%"
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result).to.be.deep.equal(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should calculate full image-area", function() {
|
||||||
|
var expected = {
|
||||||
|
sx: 0,
|
||||||
|
sy: 0,
|
||||||
|
sw: 640,
|
||||||
|
sh: 480
|
||||||
|
},
|
||||||
|
result = CVUtils.computeImageArea(640, 480, {
|
||||||
|
top: "0%",
|
||||||
|
right: "0%",
|
||||||
|
bottom: "0%",
|
||||||
|
left: "0%"
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result).to.be.deep.equal(expected);
|
||||||
|
});
|
||||||
|
});
|
@ -0,0 +1,114 @@
|
|||||||
|
const Events = require('../../src/events');
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
Events.unsubscribe();
|
||||||
|
});
|
||||||
|
describe("subscribe", function() {
|
||||||
|
|
||||||
|
|
||||||
|
it("should call one callback for a single event", function() {
|
||||||
|
var callbackA = sinon.stub(),
|
||||||
|
callbackB = sinon.stub();
|
||||||
|
|
||||||
|
Events.subscribe("test", callbackA);
|
||||||
|
Events.subscribe("test", callbackB);
|
||||||
|
Events.publish("test");
|
||||||
|
|
||||||
|
expect(callbackA.calledOnce).to.be.equal(true);
|
||||||
|
expect(callbackB.calledOnce).to.be.equal(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should call one callback twice if published twice", function() {
|
||||||
|
var callback = sinon.stub();
|
||||||
|
|
||||||
|
Events.subscribe("test", callback);
|
||||||
|
|
||||||
|
Events.publish("test");
|
||||||
|
Events.publish("test");
|
||||||
|
|
||||||
|
expect(callback.calledTwice).to.be.equal(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should call the callback asynchronuously", function(done) {
|
||||||
|
var test = {
|
||||||
|
callback: function() {
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
sinon.stub(test, "callback", function() {
|
||||||
|
expect(test.callback.calledOnce).to.be.true;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
Events.subscribe("test", test.callback, true);
|
||||||
|
Events.publish("test");
|
||||||
|
expect(test.callback.called).to.be.false;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("once", function() {
|
||||||
|
it("should call the callback once, even when published twice", function() {
|
||||||
|
var callbackA = sinon.stub(),
|
||||||
|
callbackB = sinon.stub();
|
||||||
|
|
||||||
|
Events.once("test", callbackA);
|
||||||
|
Events.subscribe("test", callbackB);
|
||||||
|
|
||||||
|
Events.publish("test");
|
||||||
|
Events.publish("test");
|
||||||
|
|
||||||
|
expect(callbackA.calledOnce).to.be.equal(true);
|
||||||
|
expect(callbackB.calledTwice).to.be.equal(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("unsubscribe", function() {
|
||||||
|
it("should unsubscribe all callbacks from a single event", function() {
|
||||||
|
var callbackA = sinon.stub(),
|
||||||
|
callbackB = sinon.stub(),
|
||||||
|
callbackC = sinon.stub();
|
||||||
|
|
||||||
|
Events.subscribe("test", callbackA);
|
||||||
|
Events.subscribe("test", callbackB);
|
||||||
|
Events.subscribe("testC", callbackC);
|
||||||
|
|
||||||
|
Events.publish("test");
|
||||||
|
|
||||||
|
expect(callbackC.called).to.be.equal(false);
|
||||||
|
expect(callbackA.calledOnce).to.be.equal(true);
|
||||||
|
expect(callbackB.calledOnce).to.be.equal(true);
|
||||||
|
|
||||||
|
Events.publish("testC");
|
||||||
|
|
||||||
|
expect(callbackC.calledOnce).to.be.equal(true);
|
||||||
|
expect(callbackA.calledOnce).to.be.equal(true);
|
||||||
|
expect(callbackB.calledOnce).to.be.equal(true);
|
||||||
|
|
||||||
|
Events.unsubscribe("test");
|
||||||
|
Events.publish("test");
|
||||||
|
|
||||||
|
expect(callbackC.calledOnce).to.be.equal(true);
|
||||||
|
expect(callbackA.calledOnce).to.be.equal(true);
|
||||||
|
expect(callbackB.calledOnce).to.be.equal(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should unsubscribe a single callback from a single event", function() {
|
||||||
|
var callbackA = sinon.stub(),
|
||||||
|
callbackB = sinon.stub();
|
||||||
|
|
||||||
|
Events.subscribe("test", callbackA);
|
||||||
|
Events.subscribe("test", callbackB);
|
||||||
|
|
||||||
|
Events.publish("test");
|
||||||
|
|
||||||
|
expect(callbackA.calledOnce).to.be.equal(true);
|
||||||
|
expect(callbackB.calledOnce).to.be.equal(true);
|
||||||
|
|
||||||
|
|
||||||
|
Events.unsubscribe("test", callbackB);
|
||||||
|
Events.publish("test");
|
||||||
|
|
||||||
|
expect(callbackA.calledTwice).to.be.equal(true);
|
||||||
|
expect(callbackB.calledOnce).to.be.equal(true);
|
||||||
|
});
|
||||||
|
});
|
@ -0,0 +1,103 @@
|
|||||||
|
const ResultCollector = require('../../src/result_collector');
|
||||||
|
const ImageDebug = require('../../src/image_debug');
|
||||||
|
|
||||||
|
var canvasMock,
|
||||||
|
imageSize,
|
||||||
|
config;
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
imageSize = {x: 320, y: 240};
|
||||||
|
config = {
|
||||||
|
capture: true,
|
||||||
|
capacity: 20,
|
||||||
|
blacklist: [{code: "3574660239843", format: "ean_13"}],
|
||||||
|
filter: function() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
canvasMock = {
|
||||||
|
getContext: function() {
|
||||||
|
return {};
|
||||||
|
},
|
||||||
|
toDataURL: sinon.spy(),
|
||||||
|
width: 0,
|
||||||
|
height: 0
|
||||||
|
};
|
||||||
|
sinon.stub(document, "createElement", function(type) {
|
||||||
|
if (type === "canvas") {
|
||||||
|
return canvasMock;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function() {
|
||||||
|
document.createElement.restore();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
describe('create', function () {
|
||||||
|
it("should return a new collector", function() {
|
||||||
|
ResultCollector.create(config);
|
||||||
|
expect(document.createElement.calledOnce).to.be.equal(true);
|
||||||
|
expect(document.createElement.getCall(0).args[0]).to.equal("canvas");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('addResult', function() {
|
||||||
|
beforeEach(function() {
|
||||||
|
sinon.stub(ImageDebug, "drawImage", function() {});
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function() {
|
||||||
|
ImageDebug.drawImage.restore();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should not add result if capacity is full", function(){
|
||||||
|
config.capacity = 1;
|
||||||
|
var collector = ResultCollector.create(config);
|
||||||
|
collector.addResult([], imageSize, {});
|
||||||
|
collector.addResult([], imageSize, {});
|
||||||
|
collector.addResult([], imageSize, {});
|
||||||
|
expect(collector.getResults()).to.have.length(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should only add results which match constraints", function(){
|
||||||
|
var collector = ResultCollector.create(config),
|
||||||
|
results;
|
||||||
|
|
||||||
|
collector.addResult([], imageSize, {code: "423423443", format: "ean_13"});
|
||||||
|
collector.addResult([], imageSize, {code: "3574660239843", format: "ean_13"});
|
||||||
|
collector.addResult([], imageSize, {code: "3574660239843", format: "code_128"});
|
||||||
|
|
||||||
|
results = collector.getResults();
|
||||||
|
expect(results).to.have.length(2);
|
||||||
|
|
||||||
|
results.forEach(function(result) {
|
||||||
|
expect(result).not.to.deep.equal(config.blacklist[0]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should add result if no filter is set", function() {
|
||||||
|
delete config.filter;
|
||||||
|
var collector = ResultCollector.create(config);
|
||||||
|
|
||||||
|
collector.addResult([], imageSize, {code: "423423443", format: "ean_13"});
|
||||||
|
expect(collector.getResults()).to.have.length(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should not add results if filter returns false", function() {
|
||||||
|
config.filter = () => (false);
|
||||||
|
var collector = ResultCollector.create(config);
|
||||||
|
|
||||||
|
collector.addResult([], imageSize, {code: "423423443", format: "ean_13"});
|
||||||
|
expect(collector.getResults()).to.have.length(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should add result if no blacklist is set", function() {
|
||||||
|
delete config.blacklist;
|
||||||
|
var collector = ResultCollector.create(config);
|
||||||
|
|
||||||
|
collector.addResult([], imageSize, {code: "3574660239843", format: "ean_13"});
|
||||||
|
expect(collector.getResults()).to.have.length(1);
|
||||||
|
});
|
||||||
|
});
|
@ -0,0 +1,8 @@
|
|||||||
|
require('events').EventEmitter.prototype._maxListeners = 0;
|
||||||
|
require('core-js/es5');
|
||||||
|
|
||||||
|
const testsContext = require.context("./integration", true, /.*js$/);
|
||||||
|
testsContext.keys().forEach(testsContext);
|
||||||
|
|
||||||
|
const componentsContext = require.context('../src/', true, /\.*js$/);
|
||||||
|
componentsContext.keys().forEach(componentsContext);
|
@ -0,0 +1,8 @@
|
|||||||
|
require('events').EventEmitter.prototype._maxListeners = 0;
|
||||||
|
require('core-js/es5');
|
||||||
|
|
||||||
|
const testsContext = require.context("./spec", true, /.*js$/);
|
||||||
|
testsContext.keys().forEach(testsContext);
|
||||||
|
|
||||||
|
const componentsContext = require.context('../src/', true, /\.*js$/);
|
||||||
|
componentsContext.keys().forEach(componentsContext);
|
@ -0,0 +1,39 @@
|
|||||||
|
var webpack = require('webpack'),
|
||||||
|
MyUmdPlugin = require('./plugins/umd'),
|
||||||
|
path = require('path');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
entry: [
|
||||||
|
'./src/quagga.js'
|
||||||
|
],
|
||||||
|
devtool: 'source-map',
|
||||||
|
module: {
|
||||||
|
loaders: [{
|
||||||
|
test: /\.jsx?$/,
|
||||||
|
exclude: /node_modules/,
|
||||||
|
loader: 'babel'
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
resolve: {
|
||||||
|
extensions: ['', '.js', '.jsx'],
|
||||||
|
alias: {
|
||||||
|
'input_stream$': path.resolve(__dirname, 'src/input_stream'),
|
||||||
|
'frame_grabber$': path.resolve(__dirname, 'src/frame_grabber')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
output: {
|
||||||
|
path: __dirname + '/dist',
|
||||||
|
publicPath: '/',
|
||||||
|
filename: 'quagga.js',
|
||||||
|
sourceMapFilename: 'quagga.map'
|
||||||
|
},
|
||||||
|
devServer: {
|
||||||
|
contentBase: './',
|
||||||
|
hot: true
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
new MyUmdPlugin({
|
||||||
|
library: 'Quagga'
|
||||||
|
})
|
||||||
|
]
|
||||||
|
};
|
@ -0,0 +1,11 @@
|
|||||||
|
var webpack = require('webpack');
|
||||||
|
module.exports = require('./webpack.config.js');
|
||||||
|
|
||||||
|
module.exports.plugins.unshift(
|
||||||
|
new webpack.optimize.UglifyJsPlugin()
|
||||||
|
);
|
||||||
|
|
||||||
|
module.exports.output.filename = 'quagga.min.js';
|
||||||
|
|
||||||
|
module.exports.output.sourceMapFilename = null;
|
||||||
|
module.exports.devtool = null;
|
@ -0,0 +1,24 @@
|
|||||||
|
var webpack = require('webpack'),
|
||||||
|
path = require('path');
|
||||||
|
|
||||||
|
module.exports = require('./webpack.config.js');
|
||||||
|
|
||||||
|
module.exports.resolve = {
|
||||||
|
extensions: ['', '.js', '.jsx'],
|
||||||
|
alias: {
|
||||||
|
'input_stream$': path.resolve(__dirname, 'lib/input_stream'),
|
||||||
|
'frame_grabber$': path.resolve(__dirname, 'lib/frame_grabber')
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.externals = [
|
||||||
|
"get-pixels",
|
||||||
|
"gl-matrix",
|
||||||
|
"lodash",
|
||||||
|
"ndarray",
|
||||||
|
"ndarray-linear-interpolate"
|
||||||
|
];
|
||||||
|
module.exports.output.libraryTarget = "commonjs2";
|
||||||
|
module.exports.plugins = [];
|
||||||
|
module.exports.output.path = __dirname + '/lib';
|
||||||
|
module.exports.output.filename = 'quagga.js';
|
Loading…
Reference in New Issue