mirror of
https://github.com/serratus/quaggaJS.git
synced 2026-08-12 21:21:42 +08:00
feat: return multiple as array instead of object
This commit is contained in:
@@ -381,10 +381,11 @@ 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 correct type (EAN-13 vs. UPC-A).
|
||||
|
||||
The `multiple` property tells the decoder if it should stop after finding a
|
||||
single result. If multiple is set to `true`, the `result` object will have a
|
||||
`barcodes` array, each of which is a `result` object with it's own `codeResult`,
|
||||
`box`, `line`, etc.
|
||||
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
|
||||
`showPattern` are mostly of interest during debugging and visualization.
|
||||
|
||||
+11
-9
@@ -267,21 +267,23 @@ export default {
|
||||
return decodeFromBoundingBox(box);
|
||||
},
|
||||
decodeFromBoundingBoxes: function(boxes) {
|
||||
var i, result, barcodes = [];
|
||||
var i, result,
|
||||
barcodes = [],
|
||||
multiple = config.multiple;
|
||||
|
||||
for ( i = 0; i < boxes.length; i++) {
|
||||
result = decodeFromBoundingBox(boxes[i]);
|
||||
if (result && result.codeResult) {
|
||||
result.box = boxes[i];
|
||||
|
||||
if (!config.multiple) {
|
||||
return result;
|
||||
}
|
||||
const box = boxes[i];
|
||||
result = decodeFromBoundingBox(box) || {};
|
||||
result.box = box;
|
||||
|
||||
if (multiple) {
|
||||
barcodes.push(result);
|
||||
} else if (result.codeResult) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
if (config.multiple) {
|
||||
if (multiple) {
|
||||
return {
|
||||
barcodes
|
||||
};
|
||||
|
||||
+13
-13
@@ -178,6 +178,10 @@ function transformResult(result) {
|
||||
moveLine(result.line);
|
||||
}
|
||||
|
||||
if (result.box) {
|
||||
moveBox(result.box);
|
||||
}
|
||||
|
||||
if (result.boxes && result.boxes.length > 0) {
|
||||
for (i = 0; i < result.boxes.length; i++) {
|
||||
moveBox(result.boxes[i]);
|
||||
@@ -202,39 +206,35 @@ function transformResult(result) {
|
||||
}
|
||||
|
||||
function addResult (result, imageData) {
|
||||
var i;
|
||||
|
||||
if (!imageData || !_resultCollector) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (result.barcodes) {
|
||||
for (i = 0; i < result.barcodes.length; i++) {
|
||||
addResult(result.barcodes[i], imageData);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (result.codeResult) {
|
||||
result.barcodes.filter(barcode => barcode.codeResult)
|
||||
.forEach(barcode => addResult(barcode, imageData));
|
||||
} else if (result.codeResult) {
|
||||
_resultCollector.addResult(imageData, _inputStream.getCanvasSize(), result.codeResult);
|
||||
}
|
||||
}
|
||||
|
||||
function hasCodeResult (result) {
|
||||
return result && result.barcodes ?
|
||||
return result && (result.barcodes ?
|
||||
result.barcodes.some(barcode => barcode.codeResult) :
|
||||
result.codeResult;
|
||||
result.codeResult);
|
||||
}
|
||||
|
||||
function publishResult(result, imageData) {
|
||||
const resultToPublish = result && (result.barcodes || result);
|
||||
|
||||
if (result && _onUIThread) {
|
||||
transformResult(result);
|
||||
addResult(result, imageData);
|
||||
}
|
||||
|
||||
Events.publish("processed", result);
|
||||
Events.publish("processed", resultToPublish);
|
||||
if (hasCodeResult(result)) {
|
||||
Events.publish("detected", result);
|
||||
Events.publish("detected", resultToPublish);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user