Skip to content
Snippets Groups Projects
Commit 2b649137 authored by Reiter, Christoph's avatar Reiter, Christoph :snake:
Browse files

qr-scanner: only check max 5 times per second for a QR code

Still raw the image and everything all the time to keep the experience smooth.
One more improvement would be to also skip the image data extraction, but that can
be done after the clipping work.
parent 927a3aa5
No related branches found
No related tags found
1 merge request!4qr-scanner: only check max 5 times per second for a QR code
Pipeline #13574 passed
...@@ -221,6 +221,9 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) { ...@@ -221,6 +221,9 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) {
requestAnimationFrame(tick); requestAnimationFrame(tick);
}).catch((e) => { console.log(e); that.askPermission = true;}); }).catch((e) => { console.log(e); that.askPermission = true;});
let lastVideoTime = -1;
let lastCode = null;
function tick() { function tick() {
if (that.sourceChanged) { if (that.sourceChanged) {
video.srcObject.getTracks().forEach(function(track) { video.srcObject.getTracks().forEach(function(track) {
...@@ -291,9 +294,19 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) { ...@@ -291,9 +294,19 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) {
imageData = canvas.getImageData(maskStartX , maskStartY, maskWidth, maskHeight); imageData = canvas.getImageData(maskStartX , maskStartY, maskWidth, maskHeight);
} }
var code = jsQR(imageData.data, imageData.width, imageData.height, { let code = null;
inversionAttempts: "dontInvert", // We only check for QR codes 5 times a second to improve performance
}); let shouldAnalyze = Math.abs(lastVideoTime - video.currentTime) >= 1/5;
if (shouldAnalyze) {
lastVideoTime = video.currentTime;
code = jsQR(imageData.data, imageData.width, imageData.height, {
inversionAttempts: "dontInvert",
});
lastCode = code;
} else {
code = lastCode;
}
if (code) { if (code) {
let topLeftCorner = code.location.topLeftCorner; let topLeftCorner = code.location.topLeftCorner;
let topRightCorner = code.location.topRightCorner; let topRightCorner = code.location.topRightCorner;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment