Ring lab phone page: stream size and fps, decode time, save a raw video frame; bench FPS option
This commit is contained in:
@@ -13,8 +13,11 @@
|
||||
<div>Images lues<b id="ring">0 %</b></div>
|
||||
<div>Codes distincts<b id="count">0 / 5</b></div>
|
||||
<div>Mode vu<b id="mode">aucun</b></div>
|
||||
<div>Flux caméra<b id="res">-</b></div>
|
||||
<div>Temps de calcul<b id="ms">-</b></div>
|
||||
</div>
|
||||
<button id="go">Démarrer la caméra</button>
|
||||
<button id="snap" class="ghost">Enregistrer l'image vidéo</button>
|
||||
<button id="again" class="ghost">Nouvel essai</button>
|
||||
<p class="hist" id="hist"></p>
|
||||
</main></body></html>
|
||||
|
||||
+23
-3
@@ -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");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user