mirror of
https://github.com/serratus/quaggaJS.git
synced 2026-08-13 05:31:37 +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 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 stop after finding a
|
The `multiple` property tells the decoder if it should continue decoding after
|
||||||
single result. If multiple is set to `true`, the `result` object will have a
|
finding a valid barcode. If multiple is set to `true`, the results will be
|
||||||
`barcodes` array, each of which is a `result` object with it's own `codeResult`,
|
returned as an array of result objects. Each object in the array will have a
|
||||||
`box`, `line`, etc.
|
`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.
|
||||||
|
|||||||
+11
-9
@@ -267,21 +267,23 @@ export default {
|
|||||||
return decodeFromBoundingBox(box);
|
return decodeFromBoundingBox(box);
|
||||||
},
|
},
|
||||||
decodeFromBoundingBoxes: function(boxes) {
|
decodeFromBoundingBoxes: function(boxes) {
|
||||||
var i, result, barcodes = [];
|
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 (!config.multiple) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (multiple) {
|
||||||
barcodes.push(result);
|
barcodes.push(result);
|
||||||
|
} else if (result.codeResult) {
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.multiple) {
|
if (multiple) {
|
||||||
return {
|
return {
|
||||||
barcodes
|
barcodes
|
||||||
};
|
};
|
||||||
|
|||||||
+13
-13
@@ -178,6 +178,10 @@ function transformResult(result) {
|
|||||||
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]);
|
||||||
@@ -202,39 +206,35 @@ function transformResult(result) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function addResult (result, imageData) {
|
function addResult (result, imageData) {
|
||||||
var i;
|
|
||||||
|
|
||||||
if (!imageData || !_resultCollector) {
|
if (!imageData || !_resultCollector) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.barcodes) {
|
if (result.barcodes) {
|
||||||
for (i = 0; i < result.barcodes.length; i++) {
|
result.barcodes.filter(barcode => barcode.codeResult)
|
||||||
addResult(result.barcodes[i], imageData);
|
.forEach(barcode => addResult(barcode, imageData));
|
||||||
}
|
} else if (result.codeResult) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result.codeResult) {
|
|
||||||
_resultCollector.addResult(imageData, _inputStream.getCanvasSize(), result.codeResult);
|
_resultCollector.addResult(imageData, _inputStream.getCanvasSize(), result.codeResult);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function hasCodeResult (result) {
|
function hasCodeResult (result) {
|
||||||
return result && result.barcodes ?
|
return result && (result.barcodes ?
|
||||||
result.barcodes.some(barcode => barcode.codeResult) :
|
result.barcodes.some(barcode => barcode.codeResult) :
|
||||||
result.codeResult;
|
result.codeResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
function publishResult(result, imageData) {
|
function publishResult(result, imageData) {
|
||||||
|
const resultToPublish = result && (result.barcodes || result);
|
||||||
|
|
||||||
if (result && _onUIThread) {
|
if (result && _onUIThread) {
|
||||||
transformResult(result);
|
transformResult(result);
|
||||||
addResult(result, imageData);
|
addResult(result, imageData);
|
||||||
}
|
}
|
||||||
|
|
||||||
Events.publish("processed", result);
|
Events.publish("processed", resultToPublish);
|
||||||
if (hasCodeResult(result)) {
|
if (hasCodeResult(result)) {
|
||||||
Events.publish("detected", result);
|
Events.publish("detected", resultToPublish);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user