Selaa lähdekoodia

feat: 添加 pdf_type 参数以支持不同的 OCR 模式,优化二次 OCR 逻辑

zhch158_admin 6 päivää sitten
vanhempi
commit
9d7afeff31

+ 8 - 2
ocr_tools/universal_doc_parser/models/adapters/wired_table/text_filling.py

@@ -360,6 +360,7 @@ class TextFiller:
         texts: List[str],
         scores: Optional[List[float]] = None,
         need_reocr_indices: Optional[List[int]] = None,
+        pdf_type: str = 'ocr',  # 'ocr' 或 'txt'
         force_all: bool = False,
         output_dir: Optional[str] = None,
     ) -> List[str]:
@@ -378,6 +379,7 @@ class TextFiller:
             texts: 当前文本列表
             scores: 当前置信度列表
             need_reocr_indices: 需要二次 OCR 的单元格索引列表(OCR 误合并检测结果)
+            pdf_type: str,  # 'ocr' 或 'txt'
             force_all: 是否强制对所有单元格进行 OCR (Default: False)
             output_dir: 输出目录,如果提供则保存单元格OCR图片到 {output_dir}/tablecell_ocr/ 目录
         """
@@ -424,8 +426,12 @@ class TextFiller:
                 else:
                     # 1. 文本为空且置信度不是极高
                     if (not t or not t.strip()) and scores[i] < 0.95:
-                        need_reocr = True
-                        reocr_reason = "空文本"
+                        if pdf_type == 'txt':
+                            # PDF文本模式下,空文本不触发二次OCR
+                            need_reocr = False
+                        else:
+                            need_reocr = True
+                            reocr_reason = "空文本"
                     # 2. 置信度过低
                     elif scores[i] < trigger_score_thresh:
                         need_reocr = True