feat: add enable_detection switch to skip text detection

enable_detection: false 跳过检测模型,直接把整图当一行文本送识别。
实测:单行图可正确识别;多行整图因识别模型固定缩放到高 48px 会返回空结果,已加告警。

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
zimoyin
2026-10-13 15:59:25 +08:00
parent 6821d0d137
commit a7d4ff6454
8 changed files with 162 additions and 16 deletions
+40
View File
@@ -171,6 +171,46 @@ def test_document_rows_empty_document() -> None:
assert OCRTaskQueue.document_rows(document) == []
def test_parse_recognition_output_handles_list_and_scalar() -> None:
from ocr_server.ocr import OCRService
listed = OCRService._parse_recognition_output(
[{"rec_text": ["MU2379", "03DEC"], "rec_score": [0.97, 0.95]}]
)
assert [item["text"] for item in listed] == ["MU2379", "03DEC"]
assert listed[0]["confidence"] == 0.97
scalar = OCRService._parse_recognition_output(
[{"rec_text": "MU2379", "rec_score": 0.97}]
)
assert scalar == [{"text": "MU2379", "confidence": 0.97, "polygon": []}]
def test_parse_recognition_output_with_word_box_tuple() -> None:
from ocr_server.ocr import OCRService
parsed = OCRService._parse_recognition_output(
[{"rec_text": [("MU2379", [[1, 2, 3]])], "rec_score": [0.97]}]
)
assert parsed == [{"text": "MU2379", "confidence": 0.97, "polygon": []}]
def test_parse_recognition_output_skips_empty() -> None:
from ocr_server.ocr import OCRService
assert OCRService._parse_recognition_output([{"rec_text": [""], "rec_score": [0.0]}]) == []
assert OCRService._parse_recognition_output([{"rec_text": [], "rec_score": []}]) == []
assert OCRService._parse_recognition_output([None, "junk"]) == []
def test_enable_detection_defaults_to_true() -> None:
from ocr_server.config import Settings
assert Settings().enable_detection is True
assert Settings(enable_detection=False).enable_detection is False
def test_progress_is_monotonic_and_includes_checkpoints() -> None:
from ocr_server.ocr import OCRService