Ring scanner: seed the crop read, try three candidates
This commit is contained in:
@@ -16,14 +16,16 @@ export function makeRingScanner(opts = {}) {
|
||||
const x0 = Math.max(0, Math.round(t.cx - half)), y0 = Math.max(0, Math.round(t.cy - half));
|
||||
const w = Math.min(sw, Math.round(t.cx + half)) - x0, h = Math.min(sh, Math.round(t.cy + half)) - y0;
|
||||
if (w < 24 || h < 24) return null;
|
||||
const k = Math.min(1, CROP / Math.max(w, h));
|
||||
const k = Math.min(1, (opts.crop || CROP) / Math.max(w, h));
|
||||
crop.width = Math.round(w * k); crop.height = Math.round(h * k);
|
||||
cctx.imageSmoothingQuality = "high";
|
||||
cctx.drawImage(src, x0, y0, w, h, 0, 0, crop.width, crop.height);
|
||||
const d = reader.read(grayOf(cctx.getImageData(0, 0, crop.width, crop.height)), now);
|
||||
const seed = { cx: (t.cx - x0) * k - 0.5, cy: (t.cy - y0) * k - 0.5, r: t.unit * CENTER * k, A: t.A && t.A.map((v) => v * k) };
|
||||
const d = reader.read(grayOf(cctx.getImageData(0, 0, crop.width, crop.height)), now, seed);
|
||||
if (!d.cand) return null;
|
||||
// only a blob with a sync ring keeps the crop alive, anything else falls back to the whole frame
|
||||
const at = d.token || d.soft ? now : t.at ?? now - 500;
|
||||
track = { cx: x0 + (d.cand.cx + 0.5) / k, cy: y0 + (d.cand.cy + 0.5) / k, unit: d.cand.r / CENTER / k, at };
|
||||
// only a blob with a sync ring keeps the crop alive, anything else goes back to the whole frame
|
||||
if (!d.token && !d.soft) { track = null; return d; }
|
||||
track = { cx: x0 + (d.cand.cx + 0.5) / k, cy: y0 + (d.cand.cy + 0.5) / k, unit: d.cand.r / CENTER / k, A: d.cand.A.map((v) => v / k), at: now };
|
||||
return d;
|
||||
}
|
||||
|
||||
@@ -40,10 +42,10 @@ export function makeRingScanner(opts = {}) {
|
||||
// plain bilinear at 3x reduction skips pixels and keeps the noise
|
||||
wctx.imageSmoothingQuality = "high";
|
||||
wctx.drawImage(src, 0, 0, wide.width, wide.height);
|
||||
const cands = locate(grayOf(wctx.getImageData(0, 0, wide.width, wide.height)), { max: 2 });
|
||||
const cands = locate(grayOf(wctx.getImageData(0, 0, wide.width, wide.height)), { max: 3 });
|
||||
let last = null;
|
||||
for (const c of cands) {
|
||||
const d = readAt(src, sw, sh, { cx: (c.cx + 0.5) / k, cy: (c.cy + 0.5) / k, unit: c.r / CENTER / k }, now);
|
||||
const d = readAt(src, sw, sh, { cx: (c.cx + 0.5) / k, cy: (c.cy + 0.5) / k, unit: c.r / CENTER / k, A: c.A.map((v) => v / k) }, now);
|
||||
if (d && d.token) return d;
|
||||
last = d || last;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user