@ericblade/quagga2 1.13.0 → 1.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -2
- package/dist/quagga.js +182 -83
- package/dist/quagga.min.js +4 -4
- package/docs/reference/configuration.md +63 -0
- package/lib/quagga.js +175 -74
- package/package.json +3 -2
- package/type-definitions/quagga.d.ts +6 -0
|
@@ -644,6 +644,7 @@ Controls the barcode localization algorithm. Only relevant when `locate: true`.
|
|
|
644
644
|
locator: {
|
|
645
645
|
halfSample: true,
|
|
646
646
|
patchSize: "medium",
|
|
647
|
+
thresholding: "global",
|
|
647
648
|
debug: {
|
|
648
649
|
showCanvas: false,
|
|
649
650
|
showPatches: false,
|
|
@@ -734,6 +735,68 @@ locator: {
|
|
|
734
735
|
}
|
|
735
736
|
```
|
|
736
737
|
|
|
738
|
+
### `locator.thresholding` {#locator-thresholding}
|
|
739
|
+
|
|
740
|
+
**Type**: `string`
|
|
741
|
+
|
|
742
|
+
**Options**: `"global"` | `"patch"`
|
|
743
|
+
|
|
744
|
+
**Default**: `"global"`
|
|
745
|
+
|
|
746
|
+
**Description**: How the locator turns the image into black and white before it looks for bar
|
|
747
|
+
patterns.
|
|
748
|
+
|
|
749
|
+
- `"global"`: one Otsu threshold for the whole image.
|
|
750
|
+
- `"patch"`: one Otsu threshold per locator patch, computed from the patch and half a patch around
|
|
751
|
+
it. Patches without contrast are treated as background.
|
|
752
|
+
|
|
753
|
+
A single threshold can fail when large uniform areas make up much of the image, such as a white
|
|
754
|
+
background, a white border, or the empty corners of a rotated photo: they pull the threshold
|
|
755
|
+
above the barcode's light bars, so the barcode turns into one dark area and is not located.
|
|
756
|
+
Consider `"patch"` for such images, and validate it on representative inputs.
|
|
757
|
+
It can also lose correct reads or introduce additional wrong reads; it is not a
|
|
758
|
+
universal replacement for `"global"`. With `decoder.multiple: true`, one image can
|
|
759
|
+
produce both the expected value and an incorrect value.
|
|
760
|
+
|
|
761
|
+
The neighborhood is used only to choose the threshold for the central patch.
|
|
762
|
+
Pixels outside that neighborhood do not contribute to that threshold; they are
|
|
763
|
+
not replaced with white pixels. The contrast check uses that same neighborhood,
|
|
764
|
+
ignores its darkest and lightest 2% of pixels, and requires a gray-level range of
|
|
765
|
+
at least 40. These settings are fixed in this implementation.
|
|
766
|
+
|
|
767
|
+
This option changes only the locator's binary image. The decoder samples the
|
|
768
|
+
grayscale input along lines derived from the located boxes and binarizes those
|
|
769
|
+
lines separately. Different boxes can change both correct and incorrect results
|
|
770
|
+
even though the readers are unchanged.
|
|
771
|
+
|
|
772
|
+
The [thresholding comparison](../examples/locator_thresholding.html) shows the
|
|
773
|
+
binary image, candidate boxes, and decoded values for each mode. Build with
|
|
774
|
+
`npm run build:dev`, serve the repository root, and open
|
|
775
|
+
`docs/examples/locator_thresholding.html`. It uses the development bundle because
|
|
776
|
+
locator debug canvases are unavailable in the production bundle.
|
|
777
|
+
|
|
778
|
+
On the eight white-border fixtures, using Chrome 156, `inputStream.size: 640`,
|
|
779
|
+
`patchSize: "medium"`, the matching UPC or EAN reader, and `multiple: true`:
|
|
780
|
+
|
|
781
|
+
| `halfSample` | Global: expected value found | Patch: expected value found | Global / patch: images with other values |
|
|
782
|
+
|---|---|---|---|
|
|
783
|
+
| `true` | 2/8 | 8/8 | 0/8 / 0/8 |
|
|
784
|
+
| `false` | 2/8 | 4/8 | 0/8 / 1/8 |
|
|
785
|
+
|
|
786
|
+
With half sampling, all five UPC fixtures and `ean-001.jpg` gain the correct
|
|
787
|
+
read; `ean-003.jpg` and `ean-006.jpg` remain correct. Without half sampling,
|
|
788
|
+
patch mode returns `3574660130843` on `ean-001.jpg` instead of the expected
|
|
789
|
+
`3574660239843`, and loses the correct read on `ean-006.jpg`. These fixtures
|
|
790
|
+
illustrate the benefit and limitations; they are not a general accuracy estimate.
|
|
791
|
+
|
|
792
|
+
|
|
793
|
+
```javascript
|
|
794
|
+
locator: {
|
|
795
|
+
halfSample: true,
|
|
796
|
+
thresholding: "patch"
|
|
797
|
+
}
|
|
798
|
+
```
|
|
799
|
+
|
|
737
800
|
### `locator.debug` {#locator-debug}
|
|
738
801
|
|
|
739
802
|
**Type**: `object`
|
package/lib/quagga.js
CHANGED
|
@@ -344,9 +344,11 @@ __webpack_require__.d(__webpack_exports__, "computeIntegralImage", function() {
|
|
|
344
344
|
__webpack_require__.d(__webpack_exports__, "thresholdImage", function() { return /* binding */ thresholdImage; });
|
|
345
345
|
__webpack_require__.d(__webpack_exports__, "computeHistogram", function() { return /* binding */ computeHistogram; });
|
|
346
346
|
__webpack_require__.d(__webpack_exports__, "sharpenLine", function() { return /* binding */ sharpenLine; });
|
|
347
|
+
__webpack_require__.d(__webpack_exports__, "otsuThresholdFromHistogram", function() { return /* binding */ otsuThresholdFromHistogram; });
|
|
347
348
|
__webpack_require__.d(__webpack_exports__, "determineOtsuThreshold", function() { return /* binding */ determineOtsuThreshold; });
|
|
348
349
|
__webpack_require__.d(__webpack_exports__, "otsuThreshold", function() { return /* binding */ otsuThreshold; });
|
|
349
350
|
__webpack_require__.d(__webpack_exports__, "computeBinaryImage", function() { return /* binding */ computeBinaryImage; });
|
|
351
|
+
__webpack_require__.d(__webpack_exports__, "axialMean", function() { return /* binding */ axialMean; });
|
|
350
352
|
__webpack_require__.d(__webpack_exports__, "cluster", function() { return /* binding */ cv_utils_cluster; });
|
|
351
353
|
__webpack_require__.d(__webpack_exports__, "Tracer", function() { return /* binding */ Tracer; });
|
|
352
354
|
__webpack_require__.d(__webpack_exports__, "DILATE", function() { return /* binding */ DILATE; });
|
|
@@ -443,6 +445,9 @@ var array_helper = __webpack_require__(8);
|
|
|
443
445
|
}
|
|
444
446
|
});
|
|
445
447
|
// CONCATENATED MODULE: ./src/common/cv_utils.js
|
|
448
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
449
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
450
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
446
451
|
/* eslint-disable no-mixed-operators */
|
|
447
452
|
/* eslint-disable no-bitwise */
|
|
448
453
|
|
|
@@ -585,50 +590,40 @@ function sharpenLine(line) {
|
|
|
585
590
|
}
|
|
586
591
|
return line;
|
|
587
592
|
}
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* Otsu's threshold for a histogram; pixels below it are the dark class.
|
|
596
|
+
* @param {ArrayLike<number>} hist
|
|
597
|
+
* @returns {number} the threshold bin
|
|
598
|
+
*/
|
|
599
|
+
function otsuThresholdFromHistogram(hist) {
|
|
600
|
+
var max = hist.length - 1;
|
|
601
|
+
var total = 0;
|
|
602
|
+
var totalMoment = 0;
|
|
603
|
+
for (var i = 0; i <= max; i++) {
|
|
604
|
+
total += hist[i];
|
|
605
|
+
totalMoment += i * hist[i];
|
|
598
606
|
}
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
607
|
+
var vet = [0];
|
|
608
|
+
var p1 = hist[0];
|
|
609
|
+
var moment1 = 0;
|
|
610
|
+
for (var k = 1; k < max; k++) {
|
|
611
|
+
p1 += hist[k];
|
|
612
|
+
moment1 += k * hist[k];
|
|
613
|
+
var p2 = total - p1;
|
|
614
|
+
var p12 = p1 * p2;
|
|
615
|
+
if (p12 === 0) {
|
|
616
|
+
p12 = 1;
|
|
603
617
|
}
|
|
604
|
-
|
|
618
|
+
var m12 = moment1 * p2 - (totalMoment - moment1) * p1;
|
|
619
|
+
vet[k] = m12 * m12 / p12;
|
|
605
620
|
}
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
var m2;
|
|
613
|
-
var m12;
|
|
614
|
-
var max = (1 << bitsPerPixel) - 1;
|
|
615
|
-
hist = computeHistogram(imageWrapper, bitsPerPixel);
|
|
616
|
-
for (var k = 1; k < max; k++) {
|
|
617
|
-
p1 = px(0, k);
|
|
618
|
-
p2 = px(k + 1, max);
|
|
619
|
-
p12 = p1 * p2;
|
|
620
|
-
if (p12 === 0) {
|
|
621
|
-
p12 = 1;
|
|
622
|
-
}
|
|
623
|
-
m1 = mx(0, k) * p2;
|
|
624
|
-
m2 = mx(k + 1, max) * p1;
|
|
625
|
-
m12 = m1 - m2;
|
|
626
|
-
vet[k] = m12 * m12 / p12;
|
|
627
|
-
}
|
|
628
|
-
return array_helper["a" /* default */].maxIndex(vet);
|
|
629
|
-
}
|
|
630
|
-
var threshold = determineThreshold();
|
|
631
|
-
return threshold << bitShift;
|
|
621
|
+
return array_helper["a" /* default */].maxIndex(vet);
|
|
622
|
+
}
|
|
623
|
+
function determineOtsuThreshold(imageWrapper) {
|
|
624
|
+
var bitsPerPixel = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 8;
|
|
625
|
+
var bitShift = 8 - bitsPerPixel;
|
|
626
|
+
return otsuThresholdFromHistogram(computeHistogram(imageWrapper, bitsPerPixel)) << bitShift;
|
|
632
627
|
}
|
|
633
628
|
function otsuThreshold(imageWrapper, targetWrapper) {
|
|
634
629
|
var threshold = determineOtsuThreshold(imageWrapper);
|
|
@@ -686,6 +681,47 @@ function computeBinaryImage(imageWrapper, integralWrapper, targetWrapper) {
|
|
|
686
681
|
}
|
|
687
682
|
}
|
|
688
683
|
}
|
|
684
|
+
|
|
685
|
+
/**
|
|
686
|
+
* Mean of axial angles (period PI), unwrapped around their circular mean so that angles on both
|
|
687
|
+
* sides of the 0/PI wrap average correctly.
|
|
688
|
+
* @param {Array<number>} angles
|
|
689
|
+
* @returns {number} the mean in [0, PI]
|
|
690
|
+
*/
|
|
691
|
+
function axialMean(angles) {
|
|
692
|
+
var x = 0;
|
|
693
|
+
var y = 0;
|
|
694
|
+
var _iterator = _createForOfIteratorHelper(angles),
|
|
695
|
+
_step;
|
|
696
|
+
try {
|
|
697
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
698
|
+
var angle = _step.value;
|
|
699
|
+
x += Math.cos(2 * angle);
|
|
700
|
+
y += Math.sin(2 * angle);
|
|
701
|
+
}
|
|
702
|
+
} catch (err) {
|
|
703
|
+
_iterator.e(err);
|
|
704
|
+
} finally {
|
|
705
|
+
_iterator.f();
|
|
706
|
+
}
|
|
707
|
+
var center = Math.atan2(y, x) / 2;
|
|
708
|
+
var offset = 0;
|
|
709
|
+
var _iterator2 = _createForOfIteratorHelper(angles),
|
|
710
|
+
_step2;
|
|
711
|
+
try {
|
|
712
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
713
|
+
var _angle = _step2.value;
|
|
714
|
+
var diff = _angle - center;
|
|
715
|
+
offset += diff - Math.PI * Math.round(diff / Math.PI);
|
|
716
|
+
}
|
|
717
|
+
} catch (err) {
|
|
718
|
+
_iterator2.e(err);
|
|
719
|
+
} finally {
|
|
720
|
+
_iterator2.f();
|
|
721
|
+
}
|
|
722
|
+
var mean = center + offset / angles.length;
|
|
723
|
+
return mean - Math.PI * Math.floor(mean / Math.PI);
|
|
724
|
+
}
|
|
689
725
|
function cv_utils_cluster(points, threshold, property) {
|
|
690
726
|
var i;
|
|
691
727
|
var k;
|
|
@@ -16026,6 +16062,8 @@ var START_END = [0x01A, 0x029, 0x00B, 0x00E];
|
|
|
16026
16062
|
var MIN_ENCODED_CHARS = 4;
|
|
16027
16063
|
var MAX_ACCEPTABLE = 2.0;
|
|
16028
16064
|
var PADDING = 1.5;
|
|
16065
|
+
// bits of the three spaces in a 7-element character pattern (bars are the even elements)
|
|
16066
|
+
var SPACE_MASK = 42;
|
|
16029
16067
|
;
|
|
16030
16068
|
;
|
|
16031
16069
|
var codabar_reader_NewCodabarReader = /*#__PURE__*/function (_BarcodeReader) {
|
|
@@ -16071,13 +16109,24 @@ var codabar_reader_NewCodabarReader = /*#__PURE__*/function (_BarcodeReader) {
|
|
|
16071
16109
|
var bitmask = 1 << numCounters - 1;
|
|
16072
16110
|
var threshold = 0;
|
|
16073
16111
|
var pattern = 0;
|
|
16112
|
+
var wideBars = 0;
|
|
16074
16113
|
for (var i = 0; i < numCounters; i++) {
|
|
16075
16114
|
threshold = (i & 1) === 0 ? barThreshold : spaceThreshold;
|
|
16076
16115
|
if (this._counters[offset + i] > threshold) {
|
|
16077
16116
|
pattern |= bitmask;
|
|
16117
|
+
if ((i & 1) === 0) {
|
|
16118
|
+
wideBars++;
|
|
16119
|
+
}
|
|
16078
16120
|
}
|
|
16079
16121
|
bitmask >>= 1;
|
|
16080
16122
|
}
|
|
16123
|
+
|
|
16124
|
+
// The only characters with three wide bars (: / . +) have no wide space.
|
|
16125
|
+
// Their three spaces are all narrow, so the midpoint between them says
|
|
16126
|
+
// nothing, and a space one pixel wider than the others would be read as wide.
|
|
16127
|
+
if (wideBars === 3) {
|
|
16128
|
+
pattern &= ~SPACE_MASK;
|
|
16129
|
+
}
|
|
16081
16130
|
return pattern;
|
|
16082
16131
|
}
|
|
16083
16132
|
}, {
|
|
@@ -16198,7 +16247,7 @@ var codabar_reader_NewCodabarReader = /*#__PURE__*/function (_BarcodeReader) {
|
|
|
16198
16247
|
for (var i = 0; i < result.length; i++) {
|
|
16199
16248
|
pattern = this._charToPattern(result[i]);
|
|
16200
16249
|
for (var j = 6; j >= 0; j--) {
|
|
16201
|
-
var kind = (j & 1) ===
|
|
16250
|
+
var kind = (j & 1) === 0 ? categorization.bar : categorization.space;
|
|
16202
16251
|
var cat = (pattern & 1) === 1 ? kind.wide : kind.narrow;
|
|
16203
16252
|
cat.size += this._counters[pos + j];
|
|
16204
16253
|
cat.counts++;
|
|
@@ -16487,7 +16536,8 @@ var code_128_reader_Code128Reader = /*#__PURE__*/function (_BarcodeReader) {
|
|
|
16487
16536
|
var done = false;
|
|
16488
16537
|
var shiftNext = false;
|
|
16489
16538
|
var unshift = shiftNext;
|
|
16490
|
-
|
|
16539
|
+
// result length before the last non-stop symbol (the check symbol) was decoded
|
|
16540
|
+
var resultLengthBeforeCheck = 0;
|
|
16491
16541
|
var multiplier = 0;
|
|
16492
16542
|
var rawResult = [];
|
|
16493
16543
|
var result = []; // TODO: i think this should be string only, but it creates problems if it is
|
|
@@ -16498,9 +16548,7 @@ var code_128_reader_Code128Reader = /*#__PURE__*/function (_BarcodeReader) {
|
|
|
16498
16548
|
code = this._decodeCode(code.end, code.correction);
|
|
16499
16549
|
if (code !== null) {
|
|
16500
16550
|
if (code.code !== this.STOP_CODE) {
|
|
16501
|
-
|
|
16502
|
-
}
|
|
16503
|
-
if (code.code !== this.STOP_CODE) {
|
|
16551
|
+
resultLengthBeforeCheck = result.length;
|
|
16504
16552
|
rawResult.push(code.code);
|
|
16505
16553
|
multiplier++;
|
|
16506
16554
|
checksum += multiplier * code.code;
|
|
@@ -16513,9 +16561,6 @@ var code_128_reader_Code128Reader = /*#__PURE__*/function (_BarcodeReader) {
|
|
|
16513
16561
|
} else if (code.code < 96) {
|
|
16514
16562
|
result.push(String.fromCharCode(code.code - 64));
|
|
16515
16563
|
} else {
|
|
16516
|
-
if (code.code !== this.STOP_CODE) {
|
|
16517
|
-
removeLastCharacter = false;
|
|
16518
|
-
}
|
|
16519
16564
|
switch (code.code) {
|
|
16520
16565
|
case this.CODE_SHIFT:
|
|
16521
16566
|
shiftNext = true;
|
|
@@ -16540,9 +16585,6 @@ var code_128_reader_Code128Reader = /*#__PURE__*/function (_BarcodeReader) {
|
|
|
16540
16585
|
if (code.code < 96) {
|
|
16541
16586
|
result.push(String.fromCharCode(32 + code.code));
|
|
16542
16587
|
} else {
|
|
16543
|
-
if (code.code !== this.STOP_CODE) {
|
|
16544
|
-
removeLastCharacter = false;
|
|
16545
|
-
}
|
|
16546
16588
|
switch (code.code) {
|
|
16547
16589
|
case this.CODE_SHIFT:
|
|
16548
16590
|
shiftNext = true;
|
|
@@ -16567,9 +16609,6 @@ var code_128_reader_Code128Reader = /*#__PURE__*/function (_BarcodeReader) {
|
|
|
16567
16609
|
if (code.code < 100) {
|
|
16568
16610
|
result.push(code.code < 10 ? '0' + code.code : code.code);
|
|
16569
16611
|
} else {
|
|
16570
|
-
if (code.code !== this.STOP_CODE) {
|
|
16571
|
-
removeLastCharacter = false;
|
|
16572
|
-
}
|
|
16573
16612
|
switch (code.code) {
|
|
16574
16613
|
case this.CODE_A:
|
|
16575
16614
|
codeset = this.CODE_A;
|
|
@@ -16609,10 +16648,8 @@ var code_128_reader_Code128Reader = /*#__PURE__*/function (_BarcodeReader) {
|
|
|
16609
16648
|
return null;
|
|
16610
16649
|
}
|
|
16611
16650
|
|
|
16612
|
-
//
|
|
16613
|
-
|
|
16614
|
-
result.splice(result.length - 1, 1);
|
|
16615
|
-
}
|
|
16651
|
+
// drop whatever the check symbol added to the result (e.g. FNC1_CHAR when its value is 102)
|
|
16652
|
+
result.length = resultLengthBeforeCheck;
|
|
16616
16653
|
return {
|
|
16617
16654
|
code: result.join(''),
|
|
16618
16655
|
start: startInfo.start,
|
|
@@ -20228,6 +20265,8 @@ var QuaggaJSCameraAccess = {
|
|
|
20228
20265
|
if (QuaggaJSCameraAccess.requestedVideoElement !== null) {
|
|
20229
20266
|
QuaggaJSCameraAccess.requestedVideoElement.pause();
|
|
20230
20267
|
}
|
|
20268
|
+
streamRef = null;
|
|
20269
|
+
QuaggaJSCameraAccess.requestedVideoElement = null;
|
|
20231
20270
|
return new Promise(function (resolve) {
|
|
20232
20271
|
setTimeout(function () {
|
|
20233
20272
|
if (tracks && tracks.length) {
|
|
@@ -20235,8 +20274,6 @@ var QuaggaJSCameraAccess = {
|
|
|
20235
20274
|
return track.stop();
|
|
20236
20275
|
});
|
|
20237
20276
|
}
|
|
20238
|
-
streamRef = null;
|
|
20239
|
-
QuaggaJSCameraAccess.requestedVideoElement = null;
|
|
20240
20277
|
resolve();
|
|
20241
20278
|
}, 0);
|
|
20242
20279
|
});
|
|
@@ -20413,6 +20450,8 @@ var DevConfig = {
|
|
|
20413
20450
|
halfSample: true,
|
|
20414
20451
|
patchSize: 'medium',
|
|
20415
20452
|
// x-small, small, medium, large, x-large
|
|
20453
|
+
thresholding: 'global',
|
|
20454
|
+
// global, patch
|
|
20416
20455
|
debug: {
|
|
20417
20456
|
showCanvas: false,
|
|
20418
20457
|
showPatches: false,
|
|
@@ -20457,7 +20496,9 @@ var NodeConfig = {
|
|
|
20457
20496
|
},
|
|
20458
20497
|
locator: {
|
|
20459
20498
|
halfSample: true,
|
|
20460
|
-
patchSize: 'medium'
|
|
20499
|
+
patchSize: 'medium',
|
|
20500
|
+
// x-small, small, medium, large, x-large
|
|
20501
|
+
thresholding: 'global' // global, patch
|
|
20461
20502
|
}
|
|
20462
20503
|
};
|
|
20463
20504
|
/* harmony default export */ var config_node = (NodeConfig);
|
|
@@ -20489,7 +20530,9 @@ var ProdConfig = {
|
|
|
20489
20530
|
},
|
|
20490
20531
|
locator: {
|
|
20491
20532
|
halfSample: true,
|
|
20492
|
-
patchSize: 'medium'
|
|
20533
|
+
patchSize: 'medium',
|
|
20534
|
+
// x-small, small, medium, large, x-large
|
|
20535
|
+
thresholding: 'global' // global, patch
|
|
20493
20536
|
}
|
|
20494
20537
|
};
|
|
20495
20538
|
/* harmony default export */ var config_prod = (ProdConfig);
|
|
@@ -21429,13 +21472,13 @@ function boxFromPatches(patches) {
|
|
|
21429
21472
|
var scale;
|
|
21430
21473
|
|
|
21431
21474
|
// draw all patches which are to be taken into consideration
|
|
21432
|
-
overAvg = 0;
|
|
21433
21475
|
for (i = 0; i < patches.length; i++) {
|
|
21434
21476
|
patch = patches[i];
|
|
21435
|
-
overAvg += patch.rad;
|
|
21436
21477
|
if (false) {}
|
|
21437
21478
|
}
|
|
21438
|
-
overAvg
|
|
21479
|
+
overAvg = Object(cv_utils["axialMean"])(patches.map(function (p) {
|
|
21480
|
+
return p.rad;
|
|
21481
|
+
}));
|
|
21439
21482
|
overAvg = (overAvg * 180 / Math.PI + 90) % 180 - 90;
|
|
21440
21483
|
if (overAvg < 0) {
|
|
21441
21484
|
overAvg += 180;
|
|
@@ -21485,11 +21528,72 @@ function boxFromPatches(patches) {
|
|
|
21485
21528
|
return box;
|
|
21486
21529
|
}
|
|
21487
21530
|
|
|
21531
|
+
// Patches whose gray values span fewer levels than this are background for 'patch' thresholding.
|
|
21532
|
+
var MIN_PATCH_CONTRAST = 40;
|
|
21533
|
+
function patchHistogram(x0, y0, x1, y1) {
|
|
21534
|
+
var _currentImageWrapper2 = _currentImageWrapper,
|
|
21535
|
+
data = _currentImageWrapper2.data;
|
|
21536
|
+
var width = _currentImageWrapper.size.x;
|
|
21537
|
+
var hist = new Int32Array(256);
|
|
21538
|
+
for (var y = y0; y < y1; y++) {
|
|
21539
|
+
for (var x = x0; x < x1; x++) {
|
|
21540
|
+
hist[data[y * width + x]]++;
|
|
21541
|
+
}
|
|
21542
|
+
}
|
|
21543
|
+
return hist;
|
|
21544
|
+
}
|
|
21545
|
+
function hasContrast(hist, count) {
|
|
21546
|
+
// Ignore the darkest and lightest 2% so that a few outliers do not count as contrast.
|
|
21547
|
+
var lo = 0;
|
|
21548
|
+
var hi = hist.length - 1;
|
|
21549
|
+
var skipped = 0;
|
|
21550
|
+
while (lo < hi && skipped + hist[lo] <= count * 0.02) {
|
|
21551
|
+
skipped += hist[lo++];
|
|
21552
|
+
}
|
|
21553
|
+
skipped = 0;
|
|
21554
|
+
while (hi > lo && skipped + hist[hi] <= count * 0.02) {
|
|
21555
|
+
skipped += hist[hi--];
|
|
21556
|
+
}
|
|
21557
|
+
return hi - lo >= MIN_PATCH_CONTRAST;
|
|
21558
|
+
}
|
|
21559
|
+
|
|
21560
|
+
// Otsu threshold per patch, over the patch plus a margin of half a patch; flat patches stay empty.
|
|
21561
|
+
function binarizePerPatch() {
|
|
21562
|
+
var _currentImageWrapper3 = _currentImageWrapper,
|
|
21563
|
+
data = _currentImageWrapper3.data;
|
|
21564
|
+
var target = _binaryImageWrapper.data;
|
|
21565
|
+
var width = _currentImageWrapper.size.x;
|
|
21566
|
+
var height = _currentImageWrapper.size.y;
|
|
21567
|
+
var marginX = Math.floor(_patchSize.x / 2);
|
|
21568
|
+
var marginY = Math.floor(_patchSize.y / 2);
|
|
21569
|
+
for (var py = 0; py < _numPatches.y; py++) {
|
|
21570
|
+
for (var px = 0; px < _numPatches.x; px++) {
|
|
21571
|
+
var x = px * _patchSize.x;
|
|
21572
|
+
var y = py * _patchSize.y;
|
|
21573
|
+
var x0 = Math.max(0, x - marginX);
|
|
21574
|
+
var y0 = Math.max(0, y - marginY);
|
|
21575
|
+
var x1 = Math.min(width, x + _patchSize.x + marginX);
|
|
21576
|
+
var y1 = Math.min(height, y + _patchSize.y + marginY);
|
|
21577
|
+
var hist = patchHistogram(x0, y0, x1, y1);
|
|
21578
|
+
var threshold = hasContrast(hist, (x1 - x0) * (y1 - y0)) ? Object(cv_utils["otsuThresholdFromHistogram"])(hist) : 0;
|
|
21579
|
+
for (var v = y; v < y + _patchSize.y; v++) {
|
|
21580
|
+
for (var u = x; u < x + _patchSize.x; u++) {
|
|
21581
|
+
target[v * width + u] = data[v * width + u] < threshold ? 1 : 0;
|
|
21582
|
+
}
|
|
21583
|
+
}
|
|
21584
|
+
}
|
|
21585
|
+
}
|
|
21586
|
+
}
|
|
21587
|
+
|
|
21488
21588
|
/**
|
|
21489
21589
|
* Creates a binary image of the current image
|
|
21490
21590
|
*/
|
|
21491
21591
|
function binarizeImage() {
|
|
21492
|
-
|
|
21592
|
+
if (barcode_locator_config.thresholding === 'patch') {
|
|
21593
|
+
binarizePerPatch();
|
|
21594
|
+
} else {
|
|
21595
|
+
Object(cv_utils["otsuThreshold"])(_currentImageWrapper, _binaryImageWrapper);
|
|
21596
|
+
}
|
|
21493
21597
|
_binaryImageWrapper.zeroBorder();
|
|
21494
21598
|
if (false) {}
|
|
21495
21599
|
}
|
|
@@ -21657,17 +21761,14 @@ function describePatch(moments, patchPos, x, y) {
|
|
|
21657
21761
|
// if at least 2 moments are found which have at least minComponentWeights covered
|
|
21658
21762
|
if (eligibleMoments.length >= 2) {
|
|
21659
21763
|
matchingMoments = similarMoments(eligibleMoments);
|
|
21660
|
-
avg = 0;
|
|
21661
|
-
// determine the similarity of the moments
|
|
21662
|
-
for (k = 0; k < matchingMoments.length; k++) {
|
|
21663
|
-
var _matchingMoments$k$ra, _matchingMoments$k;
|
|
21664
|
-
avg += (_matchingMoments$k$ra = (_matchingMoments$k = matchingMoments[k]) === null || _matchingMoments$k === void 0 ? void 0 : _matchingMoments$k.rad) !== null && _matchingMoments$k$ra !== void 0 ? _matchingMoments$k$ra : 0;
|
|
21665
|
-
}
|
|
21666
21764
|
|
|
21667
21765
|
// Only two of the moments are allowed not to fit into the equation
|
|
21668
21766
|
// add the patch to the set
|
|
21669
21767
|
if (matchingMoments.length > 1 && matchingMoments.length >= eligibleMoments.length / 4 * 3 && matchingMoments.length > moments.length / 4) {
|
|
21670
|
-
avg
|
|
21768
|
+
avg = Object(cv_utils["axialMean"])(matchingMoments.map(function (moment) {
|
|
21769
|
+
var _moment$rad;
|
|
21770
|
+
return (_moment$rad = moment === null || moment === void 0 ? void 0 : moment.rad) !== null && _moment$rad !== void 0 ? _moment$rad : 0;
|
|
21771
|
+
}));
|
|
21671
21772
|
patch = {
|
|
21672
21773
|
index: patchPos[1] * _numPatches.x + patchPos[0],
|
|
21673
21774
|
pos: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ericblade/quagga2",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.0",
|
|
4
4
|
"description": "An advanced barcode-scanner written in JavaScript",
|
|
5
5
|
"main": "lib/quagga.js",
|
|
6
6
|
"types": "type-definitions/quagga.d.ts",
|
|
@@ -159,7 +159,8 @@
|
|
|
159
159
|
"Andy Edinborough <andy@edinborough.org>",
|
|
160
160
|
"Claudio Cocciarelli <claudiococciarelli@gmail.com>",
|
|
161
161
|
"Hadrien Foucault <hadrien.foucault@gmail.com>",
|
|
162
|
-
"ghevge <ghevge@github.com>"
|
|
162
|
+
"ghevge <ghevge@github.com>",
|
|
163
|
+
"bardrop (https://github.com/bardrop)"
|
|
163
164
|
],
|
|
164
165
|
"license": "MIT",
|
|
165
166
|
"engines": {
|
|
@@ -1007,6 +1007,12 @@ export interface QuaggaJSConfigObject {
|
|
|
1007
1007
|
*/
|
|
1008
1008
|
patchSize?: string;
|
|
1009
1009
|
|
|
1010
|
+
/**
|
|
1011
|
+
* @default "global"
|
|
1012
|
+
* One Otsu threshold for the whole image ("global") or one per patch ("patch").
|
|
1013
|
+
*/
|
|
1014
|
+
thresholding?: 'global' | 'patch';
|
|
1015
|
+
|
|
1010
1016
|
willReadFrequently?: boolean;
|
|
1011
1017
|
debug?: {
|
|
1012
1018
|
/**
|