Ring scanner: seed the crop read, try three candidates

This commit is contained in:
2026-08-16 19:47:45 +01:00
parent c96f9b42c1
commit 1d6028715b
3 changed files with 23 additions and 11 deletions
+9 -3
View File
@@ -814,7 +814,13 @@ function readRings(S, opts) {
// whole frame: find center discs, read the first one that yields a valid token
export function decodeFrame(img, opts = {}) {
const cands = locate(img, opts);
// seed: where the disc was a moment ago, or on a smaller copy of the frame. refit there before searching again
let cands = [];
if (opts.seed) {
const s = opts.seed, k = s.r / CENTER, fit = discFit(img, { cx: s.cx, cy: s.cy, A: s.A || [k, 0, 0, k], r: s.r }), rn = fit && ringness(img, fit);
if (rn) cands = [{ ...fit, ...rn }];
}
if (!cands.length) cands = locate(img, opts);
let last = null;
for (const c of cands) {
const r = decodeAt(img, c, opts);
@@ -840,8 +846,8 @@ export function makeReader(opts = {}) {
return false;
};
return {
read(img, now = Date.now()) {
const d = decodeFrame(img, opts);
read(img, now = Date.now(), seed = null) {
const d = decodeFrame(img, { ...opts, seed });
let token = d.token, via = "frame";
if (!token && d.soft && opts.accumulate !== false) {
if (acc && similar(acc, d.soft) > 0.3) { for (let i = 0; i < acc.length; i++) acc[i] += d.soft[i]; frames++; }