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