Explorar o código

feat(pipeline_manager): enhance debug mode settings for layout detection

- Improved debug mode configuration to apply settings for both SmartLayoutRouter and standard layout detectors.
- Updated output file naming conventions for comparison images and JSON files to include 'ocr' for clarity.
- Enhanced the ability to set debug-related attributes such as output directory and page name, improving debugging capabilities during layout processing.
zhch158_admin hai 3 días
pai
achega
1087572e4f
Modificáronse 1 ficheiros con 9 adicións e 6 borrados
  1. 9 6
      ocr_tools/universal_doc_parser/core/pipeline_manager_v2.py

+ 9 - 6
ocr_tools/universal_doc_parser/core/pipeline_manager_v2.py

@@ -390,12 +390,15 @@ class EnhancedDocPipeline:
                     except Exception as e:
                         logger.warning(f"⚠️ Pre-OCR text box detection for layout evaluation failed: {e}")
             
-            # 如果是 SmartLayoutRouter 且启用调试模式,设置调试信息
-            if hasattr(self.layout_detector, 'set_ocr_recognizer'):
-                # 这是 SmartLayoutRouter
-                if self.debug_mode and output_dir:
+            # 启用调试模式,设置调试信息(参考 layout_model_router.py 的实现)
+            if self.debug_mode:
+                # 对于 SmartLayoutRouter 或普通 layout detector,都设置这些属性
+                if hasattr(self.layout_detector, 'debug_mode'):
                     self.layout_detector.debug_mode = self.debug_mode  # type: ignore
+                if output_dir and hasattr(self.layout_detector, 'output_dir'):
                     self.layout_detector.output_dir = output_dir  # type: ignore
+                if page_name and hasattr(self.layout_detector, 'page_name'):
+                    self.layout_detector.page_name = page_name  # type: ignore
             
             # 调用layout检测(传递OCR spans如果可用)
             if ocr_spans_for_layout is not None and hasattr(self.layout_detector, 'detect'):
@@ -633,7 +636,7 @@ class EnhancedDocPipeline:
             # 保存对比图像
             debug_dir = Path(output_dir) / "debug_comparison"
             debug_dir.mkdir(parents=True, exist_ok=True)
-            output_path = debug_dir / f"{page_name}_comparison.jpg"
+            output_path = debug_dir / f"{page_name}_ocr_comparison.jpg"
             cv2.imwrite(str(output_path), vis_image)
             
             # 保存对比 JSON
@@ -646,7 +649,7 @@ class EnhancedDocPipeline:
                 'pdf_blocks': pdf_text_blocks
             }
             
-            json_path = debug_dir / f"{page_name}_comparison.json"
+            json_path = debug_dir / f"{page_name}_ocr_comparison.json"
             with open(json_path, 'w', encoding='utf-8') as f:
                 json.dump(comparison_data, f, ensure_ascii=False, indent=2)