|
@@ -390,12 +390,15 @@ class EnhancedDocPipeline:
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
logger.warning(f"⚠️ Pre-OCR text box detection for layout evaluation failed: {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
|
|
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
|
|
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如果可用)
|
|
# 调用layout检测(传递OCR spans如果可用)
|
|
|
if ocr_spans_for_layout is not None and hasattr(self.layout_detector, 'detect'):
|
|
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 = Path(output_dir) / "debug_comparison"
|
|
|
debug_dir.mkdir(parents=True, exist_ok=True)
|
|
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)
|
|
cv2.imwrite(str(output_path), vis_image)
|
|
|
|
|
|
|
|
# 保存对比 JSON
|
|
# 保存对比 JSON
|
|
@@ -646,7 +649,7 @@ class EnhancedDocPipeline:
|
|
|
'pdf_blocks': pdf_text_blocks
|
|
'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:
|
|
with open(json_path, 'w', encoding='utf-8') as f:
|
|
|
json.dump(comparison_data, f, ensure_ascii=False, indent=2)
|
|
json.dump(comparison_data, f, ensure_ascii=False, indent=2)
|
|
|
|
|
|