Commit 12af734f authored by Shik Chen's avatar Shik Chen Committed by Chromium LUCI CQ

CCA: Select the best one if there are multiple QR codes detected

This CL shows the content of the QR code that is closet to the center of
the camera frame if there are multiple QR codes detects.

Bug: b/172879638
Test: Manually with two QR codes
Change-Id: I236bf0a5652b67339051bb3603011209464de6f0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2631549
Commit-Queue: Inker Kuo <inker@chromium.org>
Reviewed-by: default avatarInker Kuo <inker@chromium.org>
Auto-Submit: Shik Chen <shik@chromium.org>
Cr-Commit-Position: refs/heads/master@{#844002}
parent a8a024c7
......@@ -33,8 +33,29 @@ class BarcodeWorker {
return null;
}
// TODO(b/172879638): Handle multiple barcodes.
return codes[0].rawValue;
const cx = bitmap.width / 2;
const cy = bitmap.height / 2;
/**
* @param {!DetectedBarcode} code
* @return {number}
*/
const distanceToCenter = (code) => {
const {left, right, top, bottom} = code.boundingBox;
const x = (left + right) / 2;
const y = (top + bottom) / 2;
return Math.hypot(x - cx, y - cy);
};
let bestCode = codes[0];
let minDistance = distanceToCenter(codes[0]);
for (let i = 1; i < codes.length; i++) {
const distance = distanceToCenter(codes[i]);
if (distance < minDistance) {
bestCode = codes[i];
minDistance = distance;
}
}
return bestCode.rawValue;
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment