补扫:默认关(要开用 gap_scan=True),修坐标没除 1.4 倍导致的越界框(240 测试)
This commit is contained in:
+15
-4
@@ -53,12 +53,16 @@ class GapScanTest(unittest.TestCase):
|
||||
]}
|
||||
m = self._calls(second)
|
||||
with mock.patch.object(scanflow.tencent_ocr, "split_questions", m):
|
||||
d = scanflow.detect(_page(), "p.jpg")
|
||||
d = scanflow.detect(_page(), "p.jpg", gap_scan=True)
|
||||
self.assertEqual(len(d["blocks"]), 2, "漏掉的条带应当被补回来")
|
||||
added = d["blocks"][1]
|
||||
self.assertTrue(added.get("from_gap"))
|
||||
# 坐标要平移回整页:补扫裁的是 y≈476 以下
|
||||
self.assertGreater(added["box"]["y"], 400)
|
||||
# 补扫图放大过 1.4 倍,框要除回去,并且不能跑出页面
|
||||
box = added["box"]
|
||||
self.assertLessEqual(box["y"] + box["h"], 800)
|
||||
self.assertLessEqual(box["x"] + box["w"], 400)
|
||||
|
||||
def test_no_duplicate_when_same_stem(self):
|
||||
second = {"ok": True, "questions": [
|
||||
@@ -66,14 +70,21 @@ class GapScanTest(unittest.TestCase):
|
||||
]}
|
||||
m = self._calls(second)
|
||||
with mock.patch.object(scanflow.tencent_ocr, "split_questions", m):
|
||||
d = scanflow.detect(_page(), "p.jpg")
|
||||
d = scanflow.detect(_page(), "p.jpg", gap_scan=True)
|
||||
self.assertEqual(len(d["blocks"]), 1, "同一道题不能进两次")
|
||||
self.assertEqual(m.call_count, 2, "仍然会补扫一次,只是结果被去重")
|
||||
|
||||
def test_default_is_off(self):
|
||||
"""默认不补扫:这是钱,上一次证明过救不回来。"""
|
||||
m = self._calls({"ok": True, "questions": []})
|
||||
with mock.patch.object(scanflow.tencent_ocr, "split_questions", m):
|
||||
scanflow.detect(_page(), "p.jpg")
|
||||
self.assertEqual(m.call_count, 1, "默认不该补扫;要用就显式开")
|
||||
|
||||
def test_blank_page_no_extra_call(self):
|
||||
m = self._calls({"ok": True, "questions": []})
|
||||
with mock.patch.object(scanflow.tencent_ocr, "split_questions", m):
|
||||
d = scanflow.detect(_page(band=None), "p.jpg")
|
||||
d = scanflow.detect(_page(band=None), "p.jpg", gap_scan=True)
|
||||
self.assertEqual(len(d["blocks"]), 1)
|
||||
self.assertEqual(m.call_count, 1, "页面没有未覆盖的墨迹,不该再调用")
|
||||
|
||||
@@ -92,7 +103,7 @@ class GapScanTest(unittest.TestCase):
|
||||
]}
|
||||
m = self._calls(many)
|
||||
with mock.patch.object(scanflow.tencent_ocr, "split_questions", m):
|
||||
d = scanflow.detect(_page(band=(200, 760)), "p.jpg")
|
||||
d = scanflow.detect(_page(band=(200, 760)), "p.jpg", gap_scan=True)
|
||||
# GAP_MAX=2 条带 → 最多 2 次补扫 + 1 次整页
|
||||
self.assertLessEqual(m.call_count, 1 + scanflow.GAP_MAX)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user