fix: keep word boxes when filtering by confidence

i2t 每次请求都会调用 filter_document,之前它会丢弃 words,导致 return_word_box 的结果无法返回。

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
zimoyin
2026-10-13 14:40:21 +08:00
parent 52696aca90
commit 6821d0d137
2 changed files with 43 additions and 5 deletions
+10 -5
View File
@@ -240,8 +240,13 @@ class OCRTaskQueue:
@classmethod
def filter_document(cls, document: OCRDocument, min_confidence: float) -> OCRDocument:
# The compact response is intentionally rebuilt from its own polygon map.
selected = [
{
# words 必须一并带上:这个函数在每次 i2t 请求里都会被调用(即使
# min_confidence 为 0),漏掉就会让 return_word_box 的结果全部丢失。
selected: list[dict[str, Any]] = []
for item in document.polygon.values():
if item.confidence < min_confidence:
continue
segment: dict[str, Any] = {
"text": item.text,
"confidence": item.confidence,
"polygon": [
@@ -251,9 +256,9 @@ class OCRTaskQueue:
[item.Location.xtop, item.Location.ybottom],
],
}
for item in document.polygon.values()
if item.confidence >= min_confidence
]
if item.words:
segment["words"] = item.words
selected.append(segment)
return cls.build_document(selected)
@classmethod