diff --git a/static/ringlab/phone.html b/static/ringlab/phone.html index 838525d..c746f5a 100644 --- a/static/ringlab/phone.html +++ b/static/ringlab/phone.html @@ -13,8 +13,11 @@
Images lues0 %
Codes distincts0 / 5
Mode vuaucun
+
Flux caméra-
+
Temps de calcul-
+

diff --git a/static/ringlab/phone.js b/static/ringlab/phone.js index e9483de..a625e12 100644 --- a/static/ringlab/phone.js +++ b/static/ringlab/phone.js @@ -5,7 +5,7 @@ const rings = makeRingScanner(); const $ = (id) => document.getElementById(id); const video = $("v"), canvas = document.createElement("canvas"), ctx = canvas.getContext("2d", { willReadFrequently: true }); let engine, running = false, frames = 0, qr = 0, ring = 0, t0 = 0, fpsT = performance.now(), fpsN = 0; -let tokens = new Set(), mode = "aucun"; +let tokens = new Set(), mode = "aucun", msAvg = 0; const history = []; function reset() { @@ -15,9 +15,12 @@ function reset() { async function start() { engine = await QrScanner.createQrEngine(); + // same request as the vote page, so what this page measures is what voters get const stream = await navigator.mediaDevices.getUserMedia({ - video: { facingMode: { ideal: "environment" }, width: { ideal: 1920 }, height: { ideal: 1080 } }, + video: { facingMode: { ideal: "environment" }, width: { ideal: 3840 }, height: { ideal: 2160 } }, }); + const set = stream.getVideoTracks()[0].getSettings(); + $("res").textContent = `${set.width}×${set.height} ${set.frameRate ? Math.round(set.frameRate) + " i/s" : ""}`; video.srcObject = stream; await video.play(); running = true; @@ -34,7 +37,9 @@ async function loop() { canvas.height = Math.round(video.videoHeight * k); ctx.drawImage(video, 0, 0, canvas.width, canvas.height); frames++; fpsN++; - const d = rings.scan(video, video.videoWidth, video.videoHeight); + const ts = performance.now(), d = rings.scan(video, video.videoWidth, video.videoHeight); + msAvg = msAvg ? msAvg * 0.9 + (performance.now() - ts) * 0.1 : performance.now() - ts; + $("ms").textContent = `${Math.round(msAvg)} ms`; if (d.cand) qr++; if (d.token) { ring++; mode = "anneaux"; tokens.add(d.token); } else if (mode !== "anneaux") { @@ -63,3 +68,18 @@ async function loop() { $("go").addEventListener("click", () => start().catch((e) => { $("state").textContent = `Caméra : ${e.message}`; })); $("again").addEventListener("click", reset); + +// one raw frame of the stream as the decoder sees it, to send back when a phone can't read the ring +$("snap").addEventListener("click", () => { + if (!video.videoWidth) return; + const c = document.createElement("canvas"); + c.width = video.videoWidth; c.height = video.videoHeight; + c.getContext("2d").drawImage(video, 0, 0); + c.toBlob((b) => { + const a = document.createElement("a"); + a.href = URL.createObjectURL(b); + a.download = `rotatyvote-frame-${video.videoWidth}x${video.videoHeight}-${Date.now()}.png`; + a.click(); + setTimeout(() => URL.revokeObjectURL(a.href), 5000); + }, "image/png"); +}); diff --git a/tools/ringbench.py b/tools/ringbench.py index 2e370c2..5fdacc6 100644 --- a/tools/ringbench.py +++ b/tools/ringbench.py @@ -136,7 +136,8 @@ def neg_trials(n): def seqs(n): r = random.Random(47) out = [] - for d, contrast, fps in itertools.product([60, 70, 80, 100, 120, 150], [0.45, 0.3], [15, 7]): + fpss = [int(x) for x in os.environ.get("FPS", "15,7").split(",")] + for d, contrast, fps in itertools.product([60, 70, 80, 100, 120, 150], [0.45, 0.3], fpss): for _ in range(n): s = camera(r, d, contrast, r.choice([0.7, 1.5]), 1920) iv = int(os.environ.get("IV", "500"))