Skip to content

Commit dad0b1d

Browse files
committed
Merged multiple-results
2 parents 0781616 + 2c14a48 commit dad0b1d

File tree

8 files changed

+199
-66
lines changed

8 files changed

+199
-66
lines changed

.eslintrc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"ecmaFeatures": {
1111
"blockBindings": true,
1212
"forOf": true,
13-
"blockBindings": true,
1413
"defaultParams": true,
1514
"globalReturn": false,
1615
"modules": true,
@@ -59,7 +58,6 @@
5958
"comma-style": [2, "last"],
6059
"consistent-this": [1, "self"],
6160
"eol-last": 0,
62-
"new-cap": 0,
6361
"new-parens": 2,
6462
"no-array-constructor": 2,
6563
"no-mixed-spaces-and-tabs": 2,

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,8 @@ options within the `decoder` are for debugging/visualization purposes only.
361361
showPattern: false,
362362
readers: [
363363
'code_128_reader'
364-
]
364+
],
365+
multiple: false
365366
}
366367
```
367368

@@ -384,6 +385,12 @@ more possible clashes, or false-positives. One should take care of the order
384385
the readers are given, since some might return a value even though it is not
385386
the correct type (EAN-13 vs. UPC-A).
386387

388+
The `multiple` property tells the decoder if it should continue decoding after
389+
finding a valid barcode. If multiple is set to `true`, the results will be
390+
returned as an array of result objects. Each object in the array will have a
391+
`box`, and may have a `codeResult` depending on the success of decoding the
392+
individual box.
393+
387394
The remaining properties `drawBoundingBox`, `showFrequency`, `drawScanline` and
388395
`showPattern` are mostly of interest during debugging and visualization.
389396

dist/quagga.js

Lines changed: 64 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/quagga.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/quagga.js

Lines changed: 64 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
"babel-loader": "^5.3.2",
1212
"chai": "^3.4.1",
1313
"core-js": "^1.2.1",
14+
"eslint": "^1.10.3",
1415
"grunt": "^0.4.5",
15-
"grunt-cli": "0.1.13",
16+
"grunt-cli": "^0.1.13",
1617
"grunt-contrib-nodeunit": "^0.4.1",
1718
"grunt-karma": "^0.12.1",
1819
"isparta-loader": "^1.0.0",
@@ -23,7 +24,7 @@
2324
"karma-mocha": "~0.2.0",
2425
"karma-phantomjs-launcher": "^0.2.1",
2526
"karma-sinon": "^1.0.4",
26-
"karma-sinon-chai": "~0.2.0",
27+
"karma-sinon-chai": "^1.1.0",
2728
"karma-source-map-support": "^1.1.0",
2829
"karma-webpack": "^1.7.0",
2930
"mocha": "^2.3.2",
@@ -39,7 +40,8 @@
3940
"test": "grunt test",
4041
"integrationtest": "grunt integrationtest",
4142
"build": "webpack && webpack --config webpack.config.min.js && grunt uglyasm && webpack --config webpack.node.config.js",
42-
"watch": "webpack --watch"
43+
"watch": "webpack --watch",
44+
"lint": "eslint src"
4345
},
4446
"repository": {
4547
"type": "git",

src/barcode_decoder.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,14 +267,27 @@ export default {
267267
return decodeFromBoundingBox(box);
268268
},
269269
decodeFromBoundingBoxes: function(boxes) {
270-
var i, result;
270+
var i, result,
271+
barcodes = [],
272+
multiple = config.multiple;
273+
271274
for ( i = 0; i < boxes.length; i++) {
272-
result = decodeFromBoundingBox(boxes[i]);
273-
if (result && result.codeResult) {
274-
result.box = boxes[i];
275+
const box = boxes[i];
276+
result = decodeFromBoundingBox(box) || {};
277+
result.box = box;
278+
279+
if (multiple) {
280+
barcodes.push(result);
281+
} else if (result.codeResult) {
275282
return result;
276283
}
277284
}
285+
286+
if (multiple) {
287+
return {
288+
barcodes
289+
};
290+
}
278291
},
279292
setReaders: function(readers) {
280293
config.readers = readers;

src/quagga.js

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function initInputStream(cb) {
7474
function getViewPort() {
7575
var target = _config.inputStream.target;
7676
// Check if target is already a DOM element
77-
if(target && target.nodeName && target.nodeType === 1) {
77+
if (target && target.nodeName && target.nodeType === 1) {
7878
return target;
7979
} else {
8080
// Use '#interactive.viewport' as a fallback selector (backwards compatibility)
@@ -176,14 +176,24 @@ function transformResult(result) {
176176
yOffset = topRight.y,
177177
i;
178178

179-
if (!result || (xOffset === 0 && yOffset === 0)) {
179+
if (xOffset === 0 && yOffset === 0) {
180180
return;
181181
}
182182

183+
if (result.barcodes) {
184+
for (i = 0; i < result.barcodes.length; i++) {
185+
transformResult(result.barcodes[i]);
186+
}
187+
}
183188

184189
if (result.line && result.line.length === 2) {
185190
moveLine(result.line);
186191
}
192+
193+
if (result.box) {
194+
moveBox(result.box);
195+
}
196+
187197
if (result.boxes && result.boxes.length > 0) {
188198
for (i = 0; i < result.boxes.length; i++) {
189199
moveBox(result.boxes[i]);
@@ -207,19 +217,36 @@ function transformResult(result) {
207217
}
208218
}
209219

220+
function addResult (result, imageData) {
221+
if (!imageData || !_resultCollector) {
222+
return;
223+
}
224+
225+
if (result.barcodes) {
226+
result.barcodes.filter(barcode => barcode.codeResult)
227+
.forEach(barcode => addResult(barcode, imageData));
228+
} else if (result.codeResult) {
229+
_resultCollector.addResult(imageData, _inputStream.getCanvasSize(), result.codeResult);
230+
}
231+
}
232+
233+
function hasCodeResult (result) {
234+
return result && (result.barcodes ?
235+
result.barcodes.some(barcode => barcode.codeResult) :
236+
result.codeResult);
237+
}
238+
210239
function publishResult(result, imageData) {
211-
if (_onUIThread) {
240+
const resultToPublish = result && (result.barcodes || result);
241+
242+
if (result && _onUIThread) {
212243
transformResult(result);
213-
if (imageData && result && result.codeResult) {
214-
if (_resultCollector) {
215-
_resultCollector.addResult(imageData, _inputStream.getCanvasSize(), result.codeResult);
216-
}
217-
}
244+
addResult(result, imageData);
218245
}
219246

220-
Events.publish("processed", result);
221-
if (result && result.codeResult) {
222-
Events.publish("detected", result);
247+
Events.publish("processed", resultToPublish);
248+
if (hasCodeResult(result)) {
249+
Events.publish("detected", resultToPublish);
223250
}
224251
}
225252

0 commit comments

Comments
 (0)