Skip to content

Commit 4c84808

Browse files
kathocclaude
andcommitted
Strengthen camera QR decoding with inversion and binarization retries
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent a271c71 commit 4c84808

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

index.html

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -883,18 +883,25 @@ <h2 class="card-title"><span>結果</span><span class="counter" id="scanCount">0
883883
setScanStatus(message, 'error');
884884
}
885885

886+
let scanFrameCounter = 0;
887+
886888
function scanLoop() {
887889
if (!scannerActive || !scannerVideo.videoWidth || !scannerVideo.videoHeight) {
888890
scanAnimationFrame = requestAnimationFrame(scanLoop);
889891
return;
890892
}
891893

892-
const ctx = scanCanvas.getContext('2d', { willReadFrequently: true });
893-
scanCanvas.width = scannerVideo.videoWidth;
894-
scanCanvas.height = scannerVideo.videoHeight;
895-
ctx.drawImage(scannerVideo, 0, 0, scanCanvas.width, scanCanvas.height);
896-
const imageData = ctx.getImageData(0, 0, scanCanvas.width, scanCanvas.height);
897-
const code = jsQR(imageData.data, imageData.width, imageData.height, { inversionAttempts: 'dontInvert' });
894+
const width = scannerVideo.videoWidth;
895+
const height = scannerVideo.videoHeight;
896+
const draw = (ctx) => ctx.drawImage(scannerVideo, 0, 0, width, height);
897+
898+
let code = runDecodePass(width, height, draw);
899+
if (!(code && code.data)) {
900+
const phase = scanFrameCounter % 3;
901+
const threshold = phase === 0 ? 80 : phase === 1 ? 128 : 160;
902+
code = runDecodePass(width, height, draw, threshold);
903+
}
904+
scanFrameCounter += 1;
898905

899906
if (code && code.data) {
900907
stopScanner('QR を検出したのでカメラを停止しました。', 'success');

0 commit comments

Comments
 (0)