mirror of
https://github.com/serratus/quaggaJS.git
synced 2026-08-13 05:31:37 +08:00
feat: allow multiple barcodes to be decoded
This commit is contained in:
+13
-2
@@ -267,14 +267,25 @@ export default {
|
||||
return decodeFromBoundingBox(box);
|
||||
},
|
||||
decodeFromBoundingBoxes: function(boxes) {
|
||||
var i, result;
|
||||
var i, result, barcodes = [];
|
||||
for ( i = 0; i < boxes.length; i++) {
|
||||
result = decodeFromBoundingBox(boxes[i]);
|
||||
if (result && result.codeResult) {
|
||||
result.box = boxes[i];
|
||||
return result;
|
||||
|
||||
if (!config.multiple) {
|
||||
return result;
|
||||
}
|
||||
|
||||
barcodes.push(result);
|
||||
}
|
||||
}
|
||||
|
||||
if (config.multiple) {
|
||||
return {
|
||||
barcodes
|
||||
};
|
||||
}
|
||||
},
|
||||
setReaders: function(readers) {
|
||||
config.readers = readers;
|
||||
|
||||
+26
-5
@@ -168,10 +168,16 @@ function transformResult(result) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (result.barcodes) {
|
||||
for (i = 0; i < result.barcodes.length; i++) {
|
||||
transformResult(result.barcodes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (result.line && result.line.length === 2) {
|
||||
moveLine(result.line);
|
||||
}
|
||||
|
||||
if (result.boxes && result.boxes.length > 0) {
|
||||
for (i = 0; i < result.boxes.length; i++) {
|
||||
moveBox(result.boxes[i]);
|
||||
@@ -195,14 +201,29 @@ function transformResult(result) {
|
||||
}
|
||||
}
|
||||
|
||||
function addResult (result, imageData) {
|
||||
var i;
|
||||
|
||||
if (!imageData || !result || !_resultCollector) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (result.barcodes) {
|
||||
for (i = 0; i < result.barcodes.length; i++) {
|
||||
addResult(result.barcodes[i], imageData);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (result.codeResult) {
|
||||
_resultCollector.addResult(imageData, _inputStream.getCanvasSize(), result.codeResult);
|
||||
}
|
||||
}
|
||||
|
||||
function publishResult(result, imageData) {
|
||||
if (_onUIThread) {
|
||||
transformResult(result);
|
||||
if (imageData && result && result.codeResult) {
|
||||
if (_resultCollector) {
|
||||
_resultCollector.addResult(imageData, _inputStream.getCanvasSize(), result.codeResult);
|
||||
}
|
||||
}
|
||||
addResult(result, imageData);
|
||||
}
|
||||
|
||||
Events.publish("processed", result);
|
||||
|
||||
Reference in New Issue
Block a user