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);
|
return decodeFromBoundingBox(box);
|
||||||
},
|
},
|
||||||
decodeFromBoundingBoxes: function(boxes) {
|
decodeFromBoundingBoxes: function(boxes) {
|
||||||
var i, result;
|
var i, result, barcodes = [];
|
||||||
for ( i = 0; i < boxes.length; i++) {
|
for ( i = 0; i < boxes.length; i++) {
|
||||||
result = decodeFromBoundingBox(boxes[i]);
|
result = decodeFromBoundingBox(boxes[i]);
|
||||||
if (result && result.codeResult) {
|
if (result && result.codeResult) {
|
||||||
result.box = boxes[i];
|
result.box = boxes[i];
|
||||||
return result;
|
|
||||||
|
if (!config.multiple) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
barcodes.push(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (config.multiple) {
|
||||||
|
return {
|
||||||
|
barcodes
|
||||||
|
};
|
||||||
|
}
|
||||||
},
|
},
|
||||||
setReaders: function(readers) {
|
setReaders: function(readers) {
|
||||||
config.readers = readers;
|
config.readers = readers;
|
||||||
|
|||||||
+26
-5
@@ -168,10 +168,16 @@ function transformResult(result) {
|
|||||||
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.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]);
|
||||||
@@ -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) {
|
function publishResult(result, imageData) {
|
||||||
if (_onUIThread) {
|
if (_onUIThread) {
|
||||||
transformResult(result);
|
transformResult(result);
|
||||||
if (imageData && result && result.codeResult) {
|
addResult(result, imageData);
|
||||||
if (_resultCollector) {
|
|
||||||
_resultCollector.addResult(imageData, _inputStream.getCanvasSize(), result.codeResult);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Events.publish("processed", result);
|
Events.publish("processed", result);
|
||||||
|
|||||||
Reference in New Issue
Block a user