[IMP] web: ZXingBarcodeDetector support corner points

Adds to the ZXingBarcodeDetector the missing data into the return values
of detect method.

Note: ZXingBarcodeDetector is a wrapper that implements the interface of
the native BarcodeDetector

> * boundingBox: A DOMRectReadOnly, which returns the dimensions of a
> rectangle representing the extent of a detected barcode, aligned with
> the image.
> * cornerPoints: The x and y co-ordinates of the four corner points of
> the detected barcode relative to the image, starting with the top left
> and working clockwise. This may not be square due to perspective
> distortions within the image.

Ref:
https://developer.mozilla.org/en-US/docs/Web/API/BarcodeDetector

Part-of: odoo/odoo#112855
This commit is contained in:
Romeo Fragomeli
2023-02-17 12:07:20 +01:00
parent 2cf9a8a479
commit 5d211327c1
@@ -77,12 +77,22 @@ export function buildZXingBarcodeDetector(ZXing) {
const binaryBitmap = new ZXing.BinaryBitmap(new ZXing.HybridBinarizer(luminanceSource));
try {
const result = this.reader.decode(binaryBitmap);
const { resultPoints } = result;
const boundingBox = DOMRectReadOnly.fromRect({
x: resultPoints[0].x,
y: resultPoints[0].y,
height: Math.max(1, Math.abs(resultPoints[1].y - resultPoints[0].y)),
width: Math.max(1, Math.abs(resultPoints[1].x - resultPoints[0].x)),
});
const cornerPoints = resultPoints;
const format = Array.from(ZXingFormats).find(
([k, val]) => val === result.getBarcodeFormat()
);
const rawValue = result.getText();
return [
{
boundingBox,
cornerPoints,
format,
rawValue,
},