fix: give whole-image polygon in skip-detection mode
无检测模式下没有检测框,原先 polygon 为空,build_document 会丢弃无坐标的片段, 导致识别其实成功但响应 segments=0。改为用整张图的矩形作为兜底坐标。 Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -186,6 +186,25 @@ def test_parse_recognition_output_handles_list_and_scalar() -> None:
|
||||
assert scalar == [{"text": "MU2379", "confidence": 0.97, "polygon": []}]
|
||||
|
||||
|
||||
def test_parse_recognition_output_applies_fallback_polygon() -> None:
|
||||
"""无检测模式必须带上兜底坐标,否则 build_document 会把片段丢掉。"""
|
||||
from ocr_server.ocr import OCRService
|
||||
|
||||
whole = [[0, 0], [640, 0], [640, 42], [0, 42]]
|
||||
parsed = OCRService._parse_recognition_output(
|
||||
[{"rec_text": "MU2379", "rec_score": 0.97}], polygon=whole
|
||||
)
|
||||
|
||||
assert parsed[0]["polygon"] == whole
|
||||
|
||||
from ocr_server.task_queue import OCRTaskQueue
|
||||
|
||||
document = OCRTaskQueue.build_document(parsed)
|
||||
assert document.text == "MU2379"
|
||||
assert len(document.polygon) == 1
|
||||
assert document.polygon["text1"].text == "MU2379"
|
||||
|
||||
|
||||
def test_parse_recognition_output_with_word_box_tuple() -> None:
|
||||
from ocr_server.ocr import OCRService
|
||||
|
||||
|
||||
Reference in New Issue
Block a user