Ring code v2: logo disc locator, projective rectification, animated dashes, lab pages, bench tool
This commit is contained in:
+11
-14
@@ -1,4 +1,4 @@
|
||||
import { decode, grayOf } from "/static/js/ringcode.js";
|
||||
import { decodeFrame, grayOf } from "/static/js/ringcode.js";
|
||||
|
||||
const $ = (id) => document.getElementById(id);
|
||||
const video = $("v"), canvas = document.createElement("canvas"), ctx = canvas.getContext("2d", { willReadFrequently: true });
|
||||
@@ -31,18 +31,15 @@ async function loop() {
|
||||
canvas.height = Math.round(video.videoHeight * k);
|
||||
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
||||
frames++; fpsN++;
|
||||
let res = null;
|
||||
try { res = await QrScanner.scanImage(canvas, { qrEngine: engine, returnDetailedScanResult: true }); } catch { /* none */ }
|
||||
if (res) {
|
||||
qr++;
|
||||
if (res.data.includes("#")) {
|
||||
mode = "QR classique";
|
||||
tokens.add(res.data.split("#")[1]);
|
||||
} else {
|
||||
mode = "anneaux";
|
||||
const d = decode(grayOf(ctx.getImageData(0, 0, canvas.width, canvas.height)), res.cornerPoints);
|
||||
if (d && d.token) { ring++; tokens.add(d.token); }
|
||||
}
|
||||
const img = grayOf(ctx.getImageData(0, 0, canvas.width, canvas.height));
|
||||
const d = decodeFrame(img);
|
||||
if (d.found) qr++;
|
||||
if (d.token) { ring++; mode = "anneaux"; tokens.add(d.token); }
|
||||
else if (mode !== "anneaux") {
|
||||
// reference mode: the classic rotating qr
|
||||
let res = null;
|
||||
try { res = await QrScanner.scanImage(canvas, { qrEngine: engine, returnDetailedScanResult: true }); } catch { /* none */ }
|
||||
if (res && res.data.includes("#")) { mode = "QR classique"; tokens.add(res.data.split("#")[1]); }
|
||||
}
|
||||
if (tokens.size >= 5 && t0) {
|
||||
const s = (performance.now() - t0) / 1000;
|
||||
@@ -55,7 +52,7 @@ async function loop() {
|
||||
if (now - fpsT > 1000) { $("fps").textContent = (fpsN * 1000 / (now - fpsT)).toFixed(1); fpsT = now; fpsN = 0; }
|
||||
$("frames").textContent = frames;
|
||||
$("qr").textContent = `${Math.round((100 * qr) / Math.max(1, frames))} %`;
|
||||
$("ring").textContent = mode === "anneaux" ? `${Math.round((100 * ring) / Math.max(1, qr))} %` : "–";
|
||||
$("ring").textContent = `${Math.round((100 * ring) / Math.max(1, frames))} %`;
|
||||
$("count").textContent = `${Math.min(tokens.size, 5)} / 5`;
|
||||
$("mode").textContent = mode;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user