Ring decoder: vanishing line search when the fit misses (screens at 30-45 deg), sync score ignores a one-sided glare; glare bench

This commit is contained in:
2026-08-16 23:18:47 +01:00
parent 4c8db53aac
commit 867f6c46b9
5 changed files with 142 additions and 12 deletions
+44 -4
View File
@@ -1,6 +1,6 @@
"""ring code bench: renders codes with perspective, blur, washed contrast and clutter in headless chrome,
runs the real decoder and prints read rates. usage: uv run python tools/ringbench.py [trials per cell]
env: SUITE=legacy,far,seq,neg (default all) PIPES=legacy,cap960,scan DIAG=legacy|native FAR_D=80,100 NEG=300
env: SUITE=legacy,far,glare,seq,neg (default all but glare) PIPES=legacy,cap960,scan DIAG=legacy|native FAR_D=80,100 NEG=300
IV=700 FADE_K=0.3 (sequence code interval and wipe share) CPU=6 (slow phone) V1=1 (decoder and dash design from before the far-reading work, the baseline)"""
import asyncio
import base64
@@ -22,7 +22,7 @@ sys.path.insert(0, str(ROOT / "tools"))
from cdp import Browser # noqa: E402
from rotatyvote import ringcode # noqa: E402
PORT = 8200
PORT = int(os.environ.get("BENCH_PORT", "8200"))
V1 = bool(os.environ.get("V1"))
rng = random.Random(11)
@@ -55,7 +55,7 @@ def code(r):
# washed projector: (black level, white level) of the screen as the camera sees it
WASH = {0.45: (80, 195), 0.3: (105, 181)}
WASH = {1.0: (0, 255), 0.45: (80, 195), 0.3: (105, 181)}
SENSORS = {1280: (1280, 720), 1920: (1920, 1080)}
@@ -84,6 +84,44 @@ def far_trials(n):
return out
def glare_trials(n):
"""a reflection on the screen lights part of the code, often with a laptop lid or screen seen at an angle"""
r = random.Random(53)
out = []
for d, tilt, strength, contrast in itertools.product([150, 250, 350], [0, 30, 45], [0.35, 0.6], [1.0, 0.45]):
for _ in range(n):
t = camera(r, d, contrast, r.choice([0.7, 1.5]), 1920)
a, k = r.uniform(0, 6.283), r.uniform(0.1, 0.6)
tint = r.choice([(255, 235, 245), (255, 250, 230), (230, 240, 255)])
t.update(code(r), tilt=tilt, glare=[k * math.cos(a), k * math.sin(a), r.uniform(0.5, 1.1), strength, tint],
glareS=strength, jpeg=r.choice([0, 0.6]))
out.append(t)
return out
async def run_glare(p, n, pipes):
diag = os.environ.get("DIAG")
res = await chunks(p, "runFar", "trials", glare_trials(n), {"pipes": pipes, "keep": 3, "diag": diag}, 10)
print(f"\n== reflection on the screen, single frames ({len(res)} frames), 1920 sensor ==")
table(res, ("d", "tilt", "glareS", "contrast"), pipes)
for pn in pipes:
wrong = sum(1 for r in res if r[pn]["token"] and not r[pn]["ok"])
print(f" {pn}: read {100 * sum(r[pn]['ok'] for r in res) / len(res):.0f} %, false tokens {wrong}")
if diag:
# where failing frames break when the true geometry is substituted stage by stage
for key in ("tilt", "glareS"):
for v in sorted({r[key] for r in res}):
sub = [r for r in res if r[key] == v and not r[pipes[0]]["ok"]]
st = collections.Counter(r["diag"]["stage"] for r in sub)
print(f" {key} {v}: {len(sub)} failures by stage {dict(st)} oracle sync {sum((r['diag']['oracleScore'] or 0) for r in sub) / max(1, len(sub)):.2f}"
f" byte errs with true geometry {sum(r['diag']['byteErr'] for r in sub) / max(1, len(sub)):.1f}")
out = ROOT / "tools" / "bench_out"
out.mkdir(exist_ok=True)
for i, r in enumerate(res[:3]):
if r.get("png"):
(out / f"glare_{i}.jpg").write_bytes(base64.b64decode(r["png"].split(",")[1]))
def neg_trials(n):
"""nothing to read: no code on the screen, bare dark discs, discs with pie-like arcs around"""
r = random.Random(31)
@@ -227,7 +265,7 @@ async def main():
break
except httpx.HTTPError:
await asyncio.sleep(0.1)
b = Browser(9336)
b = Browser(int(os.environ.get("CDP_PORT", "9336")))
await b.start()
p = await b.page(960, 720)
throttle = float(os.environ.get("CPU", "1"))
@@ -243,6 +281,8 @@ async def main():
await run_legacy(p, n)
if "far" in suites:
await run_far(p, n, pipes, os.environ.get("DIAG"))
if "glare" in suites:
await run_glare(p, n, pipes)
if "seq" in suites:
await run_seq(p, max(1, n // 2), pipes)
if "neg" in suites: