소스 검색

feat(优化调试选项合并): 在MinerUWiredTableRecognizer类中更新debug_options合并逻辑,添加default_subdir参数以支持默认子目录配置,提升调试输出路径的灵活性和可维护性。

zhch158_admin 5 일 전
부모
커밋
5a5b23b3a0
1개의 변경된 파일20개의 추가작업 그리고 11개의 파일을 삭제
  1. 20 11
      ocr_tools/universal_doc_parser/models/adapters/mineru_wired_table.py

+ 20 - 11
ocr_tools/universal_doc_parser/models/adapters/mineru_wired_table.py

@@ -60,7 +60,11 @@ class MinerUWiredTableRecognizer:
 
         # 初始化各个功能模块
         self.debug_utils = WiredTableDebugUtils()
-        self.debug_options = self.debug_utils.merge_debug_options(self.config, self.config.get("debug_options"))
+        self.debug_options = self.debug_utils.merge_debug_options(
+            self.config,
+            self.config.get("debug_options"),
+            default_subdir="table_recognition_wired",
+        )
         self.ocr_formatter = OCRFormatter()
         self.skew_detector = SkewDetector(self.config)
         self.grid_recovery = GridRecovery()
@@ -239,10 +243,13 @@ class MinerUWiredTableRecognizer:
             h, w = table_image.shape[:2]
             
             # 调试选项合并(需要在 run_unet 之前初始化,因为内部函数会引用)
-            dbg = self.debug_utils.merge_debug_options(self.config, debug_options or {})
-            debug_dir = None
-            if dbg and dbg.enabled and dbg.output_dir:
-                debug_dir = dbg.output_dir
+            dbg = self.debug_utils.merge_debug_options(
+                self.config,
+                debug_options or {},
+                default_subdir="table_recognition_wired",
+            )
+            debug_root = self.debug_utils.resolve_debug_output_dir(dbg)
+            debug_dir = str(debug_root) if debug_root else None
             
             # 定义内部函数以方便复用 UNet 推理
             def run_unet(img_in):
@@ -461,14 +468,15 @@ class MinerUWiredTableRecognizer:
             # 策略调整:默认对所有单元格进行 Cropped OCR,以解决 Header 误合并和文本分配错误问题。
             # Full-page OCR 结果仅作为 Fallback(在 text_filling.py 中逻辑是: 如果 Cropped OCR 结果为空或低分,才保留原值)
             if hasattr(self, 'ocr_engine') and self.ocr_engine:
-                # 从 debug_options 中获取输出目录
-                output_dir = dbg.output_dir if dbg and dbg.enabled else None
+                cell_ocr_dir = None
+                if debug_root is not None:
+                    cell_ocr_dir = str(debug_root / "tablecell_ocr")
                 texts = self.text_filler.second_pass_ocr_fill(
-                    table_image, bboxes_merged, texts, scores, 
+                    table_image, bboxes_merged, texts, scores,
                     need_reocr_indices=need_reocr_indices,
                     pdf_type=pdf_type,
                     force_all=False,  # Force Per-Cell OCR
-                    output_dir=output_dir
+                    output_dir=cell_ocr_dir,
                 )
 
             for i, cell in enumerate(merged_cells):
@@ -537,8 +545,9 @@ class MinerUWiredTableRecognizer:
             try:
                 # 合并传入的 debug_options
                 merged_debug_opts = self.debug_utils.merge_debug_options(
-                    self.config, 
-                    override=debug_options or self.debug_options.__dict__
+                    self.config,
+                    override=debug_options or self.debug_options.__dict__,
+                    default_subdir="table_recognition_wired",
                 )
                 return self.recognize_v4(table_image, ocr_boxes, pdf_type=pdf_type, debug_options=merged_debug_opts.__dict__)
             except Exception: