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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user