检测侧:补扫没救回漏检,改成勾中口算卡时裁剪重读(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
+29 -6
View File
@@ -186,13 +186,36 @@ class NoWastefulCropTest(unittest.TestCase):
sp.assert_called_once()
self.assertEqual(r["source"], "crop")
def test_card_block_skips_crop(self):
def test_card_block_rechecks_and_takes_more(self):
"""口算卡会被整块读歪(27+69 读成 77+69):勾到它时裁出来重读,题更多就信裁剪版。"""
from backend import scanflow
block = {"i": 0, "box": {"x": 1, "y": 1, "w": 300, "h": 300}, "stem": "10-6= 7+8=",
block = {"i": 0, "box": {"x": 1, "y": 1, "w": 300, "h": 300}, "stem": "34+25= 78-25= 77+69=",
"judge_type": "card", "options": None, "page_answer": "",
"subs": [{"stem": "10-6 =", "answer": "4"}]}
with mock.patch("backend.tencent_ocr.split_questions") as sp:
"subs": [{"stem": "34+25 =", "answer": "59"},
{"stem": "77+69 =", "answer": "146"}]}
with mock.patch("backend.scanflow._crop_bytes", return_value=b"jpg"), \
mock.patch("backend.tencent_ocr.split_questions", return_value={"ok": True, "questions": [
{"stem": "34+25=\n78-25=\n27+69=", "judge_type": "card",
"subs": [{"stem": "34+25 =", "answer": "59"},
{"stem": "78-25 =", "answer": "53"},
{"stem": "27+69 =", "answer": "96"}]}]}):
r = scanflow.recognize_block(Path("data/bench/raw/x.jpg"), block)
sp.assert_not_called()
self.assertEqual(len(r["subs"]), 1)
stems = [s["stem"] for s in r["subs"]]
self.assertEqual(r["source"], "crop_card")
self.assertIn("27+69 =", stems, "裁剪版读对的那道要进来")
self.assertIn("78-25 =", stems, "整页版吞掉的行也要补回来")
self.assertEqual(len(stems), 4, "宁多不漏:读歪的那条也留着,等逐条勾选再收拾")
def test_card_falls_back_when_crop_is_worse(self):
from backend import scanflow
block = {"i": 0, "box": {"x": 1, "y": 1, "w": 300, "h": 300}, "stem": "a",
"judge_type": "card", "options": None, "page_answer": "",
"subs": [{"stem": "1+1 =", "answer": "2"}, {"stem": "2+2 =", "answer": "4"}]}
with mock.patch("backend.scanflow._crop_bytes", return_value=b"jpg"), \
mock.patch("backend.tencent_ocr.split_questions",
return_value={"ok": False, "code": "X"}):
r = scanflow.recognize_block(Path("data/bench/raw/x.jpg"), block)
self.assertEqual(r["source"], "page")
self.assertEqual(len(r["subs"]), 2)