检测侧:补扫没救回漏检,改成勾中口算卡时裁剪重读(312->321/330)

- scanflow._gap_bands/_gap_blocks:找出没被框盖住但有字的条带,裁出来补切一次
  (OCR_GAP_SCAN=0 可关,一页最多 2 条);实测在 3 张漏检图上救回 0 道,
  因为那 3 道不是空条带,而是框在、内容读歪(27+69 读成 77+69)
- recognize_block 增加 crop_card 分支:勾中口算卡时裁出来重读,两版小题求并集
  (宁多不漏;整页版吞行、裁剪版丢题,谁也说不全)
- bench/verify_effect.py:同一份整页结果内比 page 与 page∪crop,
  不跨调用比——腾讯切题两次调用本身就不完全一致
- bench/run.py --gap / --verify-cards;gold_expr.py --results
- tests/test_gap_scan.py 5 例;卡片重读 2 例;179 单测 + 4 套冒烟全绿
This commit is contained in:
2026-11-19 21:35:10 +08:00
parent 55e44ec1f5
commit 9f8ef886f0
10 changed files with 462 additions and 15 deletions
+15 -2
View File
@@ -75,7 +75,7 @@ def _to_block(i: int, q: dict) -> dict:
return {"i": i, "box": q.get("box"), "stem": q["stem"],
"judge_type": q.get("detected_as") or q.get("judge_type"),
"options": q.get("options"), "page_answer": q.get("page_answer"),
"subs": q.get("subs") or []}
"subs": q.get("subs") or [], "from_gap": False}
def main(argv=None) -> int:
@@ -86,6 +86,10 @@ def main(argv=None) -> int:
help="只用 OCR 缓存,缺的不发请求(额度用完后重算指标用)")
ap.add_argument("--skip-done", action="store_true",
help="跳过 results.jsonl 里已经跑成功过的图(省额度)")
ap.add_argument("--gap", action="store_true",
help="开启补扫(检测漏块,每张可能多 1–2 次调用)")
ap.add_argument("--verify-cards", action="store_true",
help="口算卡裁出来重读一次(每张多 1–3 次调用)")
ap.add_argument("--out", default=str(RESULTS))
args = ap.parse_args(argv)
@@ -121,7 +125,16 @@ def main(argv=None) -> int:
if args.no_api:
res = _detect_from_cache_only(data, fp.name)
else:
res = scanflow.detect(data, fp.name)
res = scanflow.detect(data, fp.name, gap_scan=args.gap)
if args.verify_cards and not args.no_api:
# 口算卡在整页结果里偶尔会读歪(27+69 → 77+69):
# 裁出这一块再读一次,题更多就信裁剪版(与入库时的逻辑一致)
src = scanflow._img_path(res["draft_id"])
for b in res.get("blocks") or []:
if b.get("subs"):
fixed = scanflow.recognize_block(src, b)
if fixed.get("source") == "crop_card":
b["subs"] = fixed["subs"]
ok, code, blocks = True, "", res.get("blocks") or []
except Exception as e: # noqa: BLE001
ok, code, blocks = False, getattr(e, "code", type(e).__name__), []