mirror of
https://github.com/serratus/quaggaJS.git
synced 2026-08-12 21:21:42 +08:00
Merged multiple-results
This commit is contained in:
@@ -10,7 +10,6 @@
|
|||||||
"ecmaFeatures": {
|
"ecmaFeatures": {
|
||||||
"blockBindings": true,
|
"blockBindings": true,
|
||||||
"forOf": true,
|
"forOf": true,
|
||||||
"blockBindings": true,
|
|
||||||
"defaultParams": true,
|
"defaultParams": true,
|
||||||
"globalReturn": false,
|
"globalReturn": false,
|
||||||
"modules": true,
|
"modules": true,
|
||||||
@@ -59,7 +58,6 @@
|
|||||||
"comma-style": [2, "last"],
|
"comma-style": [2, "last"],
|
||||||
"consistent-this": [1, "self"],
|
"consistent-this": [1, "self"],
|
||||||
"eol-last": 0,
|
"eol-last": 0,
|
||||||
"new-cap": 0,
|
|
||||||
"new-parens": 2,
|
"new-parens": 2,
|
||||||
"no-array-constructor": 2,
|
"no-array-constructor": 2,
|
||||||
"no-mixed-spaces-and-tabs": 2,
|
"no-mixed-spaces-and-tabs": 2,
|
||||||
|
|||||||
@@ -361,7 +361,8 @@ options within the `decoder` are for debugging/visualization purposes only.
|
|||||||
showPattern: false,
|
showPattern: false,
|
||||||
readers: [
|
readers: [
|
||||||
'code_128_reader'
|
'code_128_reader'
|
||||||
]
|
],
|
||||||
|
multiple: false
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -384,6 +385,12 @@ more possible clashes, or false-positives. One should take care of the order
|
|||||||
the readers are given, since some might return a value even though it is not
|
the readers are given, since some might return a value even though it is not
|
||||||
the correct type (EAN-13 vs. UPC-A).
|
the correct type (EAN-13 vs. UPC-A).
|
||||||
|
|
||||||
|
The `multiple` property tells the decoder if it should continue decoding after
|
||||||
|
finding a valid barcode. If multiple is set to `true`, the results will be
|
||||||
|
returned as an array of result objects. Each object in the array will have a
|
||||||
|
`box`, and may have a `codeResult` depending on the success of decoding the
|
||||||
|
individual box.
|
||||||
|
|
||||||
The remaining properties `drawBoundingBox`, `showFrequency`, `drawScanline` and
|
The remaining properties `drawBoundingBox`, `showFrequency`, `drawScanline` and
|
||||||
`showPattern` are mostly of interest during debugging and visualization.
|
`showPattern` are mostly of interest during debugging and visualization.
|
||||||
|
|
||||||
|
|||||||
Vendored
+63
-20
File diff suppressed because one or more lines are too long
Vendored
+3
-3
File diff suppressed because one or more lines are too long
+63
-20
File diff suppressed because one or more lines are too long
+5
-3
@@ -11,8 +11,9 @@
|
|||||||
"babel-loader": "^5.3.2",
|
"babel-loader": "^5.3.2",
|
||||||
"chai": "^3.4.1",
|
"chai": "^3.4.1",
|
||||||
"core-js": "^1.2.1",
|
"core-js": "^1.2.1",
|
||||||
|
"eslint": "^1.10.3",
|
||||||
"grunt": "^0.4.5",
|
"grunt": "^0.4.5",
|
||||||
"grunt-cli": "0.1.13",
|
"grunt-cli": "^0.1.13",
|
||||||
"grunt-contrib-nodeunit": "^0.4.1",
|
"grunt-contrib-nodeunit": "^0.4.1",
|
||||||
"grunt-karma": "^0.12.1",
|
"grunt-karma": "^0.12.1",
|
||||||
"isparta-loader": "^1.0.0",
|
"isparta-loader": "^1.0.0",
|
||||||
@@ -23,7 +24,7 @@
|
|||||||
"karma-mocha": "~0.2.0",
|
"karma-mocha": "~0.2.0",
|
||||||
"karma-phantomjs-launcher": "^0.2.1",
|
"karma-phantomjs-launcher": "^0.2.1",
|
||||||
"karma-sinon": "^1.0.4",
|
"karma-sinon": "^1.0.4",
|
||||||
"karma-sinon-chai": "~0.2.0",
|
"karma-sinon-chai": "^1.1.0",
|
||||||
"karma-source-map-support": "^1.1.0",
|
"karma-source-map-support": "^1.1.0",
|
||||||
"karma-webpack": "^1.7.0",
|
"karma-webpack": "^1.7.0",
|
||||||
"mocha": "^2.3.2",
|
"mocha": "^2.3.2",
|
||||||
@@ -39,7 +40,8 @@
|
|||||||
"test": "grunt test",
|
"test": "grunt test",
|
||||||
"integrationtest": "grunt integrationtest",
|
"integrationtest": "grunt integrationtest",
|
||||||
"build": "webpack && webpack --config webpack.config.min.js && grunt uglyasm && webpack --config webpack.node.config.js",
|
"build": "webpack && webpack --config webpack.config.min.js && grunt uglyasm && webpack --config webpack.node.config.js",
|
||||||
"watch": "webpack --watch"
|
"watch": "webpack --watch",
|
||||||
|
"lint": "eslint src"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
+17
-4
@@ -267,14 +267,27 @@ export default {
|
|||||||
return decodeFromBoundingBox(box);
|
return decodeFromBoundingBox(box);
|
||||||
},
|
},
|
||||||
decodeFromBoundingBoxes: function(boxes) {
|
decodeFromBoundingBoxes: function(boxes) {
|
||||||
var i, result;
|
var i, result,
|
||||||
|
barcodes = [],
|
||||||
|
multiple = config.multiple;
|
||||||
|
|
||||||
for ( i = 0; i < boxes.length; i++) {
|
for ( i = 0; i < boxes.length; i++) {
|
||||||
result = decodeFromBoundingBox(boxes[i]);
|
const box = boxes[i];
|
||||||
if (result && result.codeResult) {
|
result = decodeFromBoundingBox(box) || {};
|
||||||
result.box = boxes[i];
|
result.box = box;
|
||||||
|
|
||||||
|
if (multiple) {
|
||||||
|
barcodes.push(result);
|
||||||
|
} else if (result.codeResult) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (multiple) {
|
||||||
|
return {
|
||||||
|
barcodes
|
||||||
|
};
|
||||||
|
}
|
||||||
},
|
},
|
||||||
setReaders: function(readers) {
|
setReaders: function(readers) {
|
||||||
config.readers = readers;
|
config.readers = readers;
|
||||||
|
|||||||
+36
-9
@@ -176,14 +176,24 @@ function transformResult(result) {
|
|||||||
yOffset = topRight.y,
|
yOffset = topRight.y,
|
||||||
i;
|
i;
|
||||||
|
|
||||||
if (!result || (xOffset === 0 && yOffset === 0)) {
|
if (xOffset === 0 && yOffset === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (result.barcodes) {
|
||||||
|
for (i = 0; i < result.barcodes.length; i++) {
|
||||||
|
transformResult(result.barcodes[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (result.line && result.line.length === 2) {
|
if (result.line && result.line.length === 2) {
|
||||||
moveLine(result.line);
|
moveLine(result.line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (result.box) {
|
||||||
|
moveBox(result.box);
|
||||||
|
}
|
||||||
|
|
||||||
if (result.boxes && result.boxes.length > 0) {
|
if (result.boxes && result.boxes.length > 0) {
|
||||||
for (i = 0; i < result.boxes.length; i++) {
|
for (i = 0; i < result.boxes.length; i++) {
|
||||||
moveBox(result.boxes[i]);
|
moveBox(result.boxes[i]);
|
||||||
@@ -207,19 +217,36 @@ function transformResult(result) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function publishResult(result, imageData) {
|
function addResult (result, imageData) {
|
||||||
if (_onUIThread) {
|
if (!imageData || !_resultCollector) {
|
||||||
transformResult(result);
|
return;
|
||||||
if (imageData && result && result.codeResult) {
|
}
|
||||||
if (_resultCollector) {
|
|
||||||
|
if (result.barcodes) {
|
||||||
|
result.barcodes.filter(barcode => barcode.codeResult)
|
||||||
|
.forEach(barcode => addResult(barcode, imageData));
|
||||||
|
} else if (result.codeResult) {
|
||||||
_resultCollector.addResult(imageData, _inputStream.getCanvasSize(), result.codeResult);
|
_resultCollector.addResult(imageData, _inputStream.getCanvasSize(), result.codeResult);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function hasCodeResult (result) {
|
||||||
|
return result && (result.barcodes ?
|
||||||
|
result.barcodes.some(barcode => barcode.codeResult) :
|
||||||
|
result.codeResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
Events.publish("processed", result);
|
function publishResult(result, imageData) {
|
||||||
if (result && result.codeResult) {
|
const resultToPublish = result && (result.barcodes || result);
|
||||||
Events.publish("detected", result);
|
|
||||||
|
if (result && _onUIThread) {
|
||||||
|
transformResult(result);
|
||||||
|
addResult(result, imageData);
|
||||||
|
}
|
||||||
|
|
||||||
|
Events.publish("processed", resultToPublish);
|
||||||
|
if (hasCodeResult(result)) {
|
||||||
|
Events.publish("detected", resultToPublish);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user