Procházet zdrojové kódy

fix(优化水印处理与布局检测配置): 更新多个bank_statement配置文件,调整水印去除设置,启用检测前处理,优化布局检测模块,新增OCR识别和表格分类功能,提升整体OCR处理的准确性与灵活性。

zhch158_admin před 4 dny
rodič
revize
b210ab056b

+ 162 - 58
ocr_tools/universal_doc_parser/config/bank_statement_glm_vl.yaml

@@ -19,46 +19,57 @@ preprocessor:
     model_dir: null  # 使用默认路径
   unwarping:
     enabled: false
-  # -------------------------------------------------------
-  # 水印去除配置(适用于银行流水浅色斜向文字水印)
-  # -------------------------------------------------------
+  # 页级水印(细参见 ocr_utils/watermark/presets.py PAGE_WATERMARK_PRESETS)
   watermark_removal:
-    enabled: false           # 是否启用水印去除
-    method: threshold # threshold | masked | masked_adaptive
-    threshold: 175          # 全局阈值或掩膜失败时的回退阈值(140-180)
-    morph_close_kernel: 0   # 去水印后灰度图闭运算,0 跳过
-    # 去水印后对比度增强(text_restore 将笔画拉深,比全局 gamma 更接近原图)
+    enabled: false
+    detect_before_remove: true
+    method: threshold   # threshold | masked | masked_adaptive
+    threshold: 175
     contrast_enhancement:
-      enabled: true
-      method: text_restore   # text_restore | clahe | gamma | linear
-      text_black_target: 85  # 略提高,减轻去水印后笔画被拉花(原 75 过深)
-      background_threshold: 248
-      text_lo_percentile: 1.0
-      text_hi_percentile: 99.0
-      gamma: 0.75            # method=gamma 时生效
-      clip_limit: 2.0        # method=clahe
-      tile_grid_size: 8
-      black_percentile: 2.0  # method=linear
-      white_percentile: 98.0
+      enabled: false
+      method: text_restore
+      text_black_target: 85
     debug_options:
-      enabled: false              # 由命令行 --debug / --debug-layout 统一控制
-      output_dir: null            # null 时使用 pipeline 输出目录
-      prefix: ""                  # 文件名前缀(运行时注入 page_name)
-      subdir: watermark_removal   # 输出至 debug/watermark_removal/
-      save_compare: true          # 保存左右对比图 *_watermark_compare.*
-      image_format: "png"         # jpg / png
+      enabled: false
+      output_dir: null
+      prefix: ""
+      subdir: watermark_removal
+      save_compare: true
+      image_format: "png"
 
 # ============================================================
-# Layout 检测配置 - 使用 PP-DocLayoutV3
+# Layout 检测配置 - 智能路由器(按场景直接选择模型)
 # ============================================================
 layout_detection:
-  module: "paddle"
-  model_name: "PP-DocLayoutV3"
-  model_dir: "PaddlePaddle/PP-DocLayoutV3_safetensors"
-  device: "cpu"
-  conf: 0.3
-  num_threads: 4
-  batch_size: 1
+  module: "smart_router"
+  strategy: "scene"  # 按场景直接选择模型,不走ocr_eval
+
+  # 场景策略:指定场景直接选用的布局模型
+  scene_strategy:
+    bank_statement:
+      model: "docling"
+    financial_report:
+      model: "paddle_ppdoclayoutv3"
+  default_model: "docling"
+
+  # 配置多个模型
+  models:
+    docling:
+      module: "docling"
+      model_name: "docling-layout-old"
+      model_dir: "ds4sd/docling-layout-old"
+      device: "cpu"
+      conf: 0.3
+      num_threads: 4
+
+    paddle_ppdoclayoutv3:
+      module: "paddle"
+      model_name: "PP-DocLayoutV3"
+      model_dir: "PaddlePaddle/PP-DocLayoutV3_safetensors"
+      device: "cpu"
+      conf: 0.3
+      num_threads: 4
+      batch_size: 1
   
   # 后处理配置
   post_process:
@@ -70,7 +81,7 @@ layout_detection:
 
   # Debug 可视化(底图为 inference_image,与 Layout 检测输入一致)
   debug_options:
-    enabled: true              # 由命令行 --debug / --debug-layout 控制
+    enabled: false              # 由命令行 --debug / --debug-layout 控制
     output_dir: null            # null 时由 pipeline 按页注入
     prefix: ""
     subdir: layout_detection    # 输出至 debug/layout_detection/
@@ -80,7 +91,123 @@ layout_detection:
     image_format: "png"
 
 # ============================================================
-# VL识别配置 - 使用 GLM-OCR
+# OCR 识别配置
+# ============================================================
+ocr_recognition:
+  module: "mineru"
+  language: "ch"
+  det_threshold: 0.5
+  unclip_ratio: 1.5
+  enable_merge_det_boxes: false
+  batch_size: 8
+  device: "cpu"
+
+  # Debug 可视化(底图为 inference_image,与整页 OCR 输入一致)
+  debug_options:
+    enabled: false              # 由命令行 --debug / --debug-ocr 控制
+    output_dir: null
+    prefix: ""
+    subdir: ocr_recognition     # 输出至 debug/ocr_recognition/
+    save_json: true
+    image_format: png
+
+# ============================================================
+# 表格分类配置(自动区分有线/无线表格)
+# ============================================================
+table_classification:
+  enabled: true               # 启用自动表格分类
+  module: "paddle"            # 分类模型:paddle(MinerU PaddleTableClsModel)
+  confidence_threshold: 0.5   # 分类置信度阈值
+  batch_size: 16              # 批处理大小
+
+  # Debug 可视化配置
+  debug_options:
+    enabled: false              # 由命令行 --debug / --debug-table 统一控制
+    output_dir: null            # null 时由 pipeline 按页注入
+    prefix: ""
+    subdir: table_classification  # 输出至 debug/table_classification/
+    save_table_lines: true      # paddle 线条检测叠加图
+    image_format: "png"
+
+# ============================================================
+# 有线表格识别专用配置(MinerU UNet)
+# ============================================================
+table_recognition_wired:
+  use_wired_unet: false      # 不使用有线表格识别
+  upscale_ratio: 3.333
+  need_ocr: true
+  row_threshold: 10
+  col_threshold: 15
+  ocr_conf_threshold: 0.9       # 单元格 OCR 置信度阈值
+  cell_crop_margin: 2
+  use_custom_postprocess: true  # 是否使用自定义后处理(默认启用)
+
+  # 是否启用倾斜矫正
+  enable_deskew: true
+
+  # 🆕 启用多源单元格融合
+  use_cell_fusion: true
+  
+  # 融合引擎配置
+  cell_fusion:
+    # RT-DETR 模型路径(必需)
+    rtdetr_model_path: "/Users/zhch158/models/pytorch_models/Table/RT-DETR-L_wired_table_cell_det.onnx"
+    
+    # 融合权重
+    unet_weight: 0.6        # UNet 权重(结构性强)
+    rtdetr_weight: 0.4      # RT-DETR 权重(鲁棒性强)
+    
+    # 阈值配置
+    iou_merge_threshold: 0.7    # 高IoU合并阈值(>0.7则加权平均)
+    iou_nms_threshold: 0.5      # NMS去重阈值
+    rtdetr_conf_threshold: 0.5  # RT-DETR置信度阈值
+    
+    # 功能开关
+    enable_ocr_compensation: true      # 启用OCR边缘补偿
+
+  # 单元格二次 OCR(det 分行 + 整格/条带兜底 + 低分笔画增强重试)
+  second_pass_ocr:
+    reocr_mode: bank_statement       # 表体空单元必跑 + 同行多数非空则空格也跑
+    header_row: 0                    # 表头行号(0=首行)
+    row_peer_min_nonempty: 5         # 同行至少 N 个非空格时,本格空也触发二次 OCR
+    line_min_score: 0.8              # 低于此分的分行从文本与计分中丢弃
+    drop_low_score_blocks: true
+    whole_cell_fallback: true        # 整格 det=False 兜底 + 条带扫描
+    prefer_whole_on_tie: true
+    whole_longer_min_extra_chars: 2  # 整格/条带文本比分行多长至少 N 字则优先
+    strip_fallback_aspect_ratio: 1.8 # 高/宽>=该值且仅检出<=1行时滑动条带分行
+    suspicious_short_min_chars: 4    # 高分但过短仍跑整格/条带兜底(与 enhance_retry 无关)
+    cell_preprocess:
+      watermark:
+        enabled: true
+        method: threshold
+      denoise:
+        enabled: false   # 小格 median 易糊笔画;lab 用 --denoise 对比
+      contrast:
+        enabled: false   # Pass1 去水印后可选;lab 对比 text_restore
+        method: text_restore
+        text_black_target: 88
+      light:
+        upscale_min_side: 192  # 128, 192 用于难例日期列
+    enhance_retry:
+      enabled: false
+      # enabled: true 时 Pass2 预处理,默认见代码(cell_preprocess.enhance_retry 已废弃)
+
+  # Debug 可视化配置
+  debug_options:
+    enabled: false              # 由命令行 --debug / --debug-table 统一控制
+    output_dir: null            # null 时由 pipeline 按页注入
+    prefix: ""
+    subdir: table_recognition_wired  # 输出至 debug/table_recognition_wired/
+    save_table_lines: true
+    save_connected_components: true
+    save_grid_structure: true
+    save_text_overlay: true
+    image_format: "png"
+    # 单元格二次 OCR 裁剪图:debug/table_recognition_wired/tablecell_ocr/
+
+# ============================================================
+# VL识别配置 - 使用 GLM-OCR(无线表格 + seal识别)
 # ============================================================
 vl_recognition:
   module: "glmocr"
@@ -116,29 +243,6 @@ vl_recognition:
   
   # 场景特定配置
   table_recognition:
-    bank_statement_mode: true
-
-# ============================================================
-# OCR识别配置
-# ============================================================
-ocr_recognition:
-  module: "mineru" 
-  language: "ch"
-  det_threshold: 0.6
-  unclip_ratio: 1.5
-  enable_merge_det_boxes: false
-  batch_size: 8
-  device: "cpu"
-
-
-  # Debug 可视化(底图为 inference_image,与整页 OCR 输入一致)
-  debug_options:
-    enabled: false              # 由命令行 --debug / --debug-ocr 控制
-    output_dir: null
-    prefix: ""
-    subdir: ocr_recognition     # 输出至 debug/ocr_recognition/
-    save_json: true
-    image_format: png
 
 # ============================================================
 # 输出配置

+ 17 - 25
ocr_tools/universal_doc_parser/config/bank_statement_mineru_vl.yaml

@@ -19,35 +19,27 @@ preprocessor:
     model_dir: null  # 使用默认路径
   unwarping:
     enabled: false
-  # -------------------------------------------------------
-  # 水印去除配置(适用于银行流水浅色斜向文字水印)
-  # -------------------------------------------------------
+  # 页级水印(细参见 ocr_utils/watermark/presets.py PAGE_WATERMARK_PRESETS)
   watermark_removal:
-    enabled: false           # 是否启用水印去除
-    method: threshold # threshold | masked | masked_adaptive
-    threshold: 175          # 全局阈值或掩膜失败时的回退阈值(140-180)
-    morph_close_kernel: 0   # 去水印后灰度图闭运算,0 跳过
-    # 去水印后对比度增强(text_restore 将笔画拉深,比全局 gamma 更接近原图)
+    enabled: false
+    detect_before_remove: true
+    method: threshold   # threshold | masked | masked_adaptive
+    threshold: 175
     contrast_enhancement:
-      enabled: true
-      method: text_restore   # text_restore | clahe | gamma | linear
-      text_black_target: 85  # 略提高,减轻去水印后笔画被拉花(原 75 过深)
-      background_threshold: 248
-      text_lo_percentile: 1.0
-      text_hi_percentile: 99.0
-      gamma: 0.75            # method=gamma 时生效
-      clip_limit: 2.0        # method=clahe
-      tile_grid_size: 8
-      black_percentile: 2.0  # method=linear
-      white_percentile: 98.0
+      enabled: false
+      method: text_restore
+      text_black_target: 85
     debug_options:
-      enabled: false              # 由命令行 --debug / --debug-layout 统一控制
-      output_dir: null            # null 时使用 pipeline 输出目录
-      prefix: ""                  # 文件名前缀(运行时注入 page_name)
-      subdir: watermark_removal   # 输出至 debug/watermark_removal/
-      save_compare: true          # 保存左右对比图 *_watermark_compare.*
-      image_format: "png"         # jpg / png
+      enabled: false
+      output_dir: null
+      prefix: ""
+      subdir: watermark_removal
+      save_compare: true
+      image_format: "png"
 
+# ============================================================
+# Layout 检测配置 - 智能路由器(按场景直接选择模型)
+# ============================================================
 layout_detection:
   # MinerU-VL layout(通过 VLM 服务做版式检测)
   module: "mineru_vl"

+ 18 - 26
ocr_tools/universal_doc_parser/config/bank_statement_paddle_vl.yaml

@@ -19,35 +19,27 @@ preprocessor:
     model_dir: null  # 使用默认路径
   unwarping:
     enabled: false
-  # -------------------------------------------------------
-  # 水印去除配置(适用于银行流水浅色斜向文字水印)
-  # -------------------------------------------------------
+  # 页级水印(细参见 ocr_utils/watermark/presets.py PAGE_WATERMARK_PRESETS)
   watermark_removal:
-    enabled: false           # 是否启用水印去除
-    method: threshold # threshold | masked | masked_adaptive
-    threshold: 175          # 全局阈值或掩膜失败时的回退阈值(140-180)
-    morph_close_kernel: 0   # 去水印后灰度图闭运算,0 跳过
-    # 去水印后对比度增强(text_restore 将笔画拉深,比全局 gamma 更接近原图)
+    enabled: false
+    detect_before_remove: true
+    method: threshold   # threshold | masked | masked_adaptive
+    threshold: 175
     contrast_enhancement:
-      enabled: true
-      method: text_restore   # text_restore | clahe | gamma | linear
-      text_black_target: 85  # 略提高,减轻去水印后笔画被拉花(原 75 过深)
-      background_threshold: 248
-      text_lo_percentile: 1.0
-      text_hi_percentile: 99.0
-      gamma: 0.75            # method=gamma 时生效
-      clip_limit: 2.0        # method=clahe
-      tile_grid_size: 8
-      black_percentile: 2.0  # method=linear
-      white_percentile: 98.0
+      enabled: false
+      method: text_restore
+      text_black_target: 85
     debug_options:
-      enabled: false              # 由命令行 --debug / --debug-layout 统一控制
-      output_dir: null            # null 时使用 pipeline 输出目录
-      prefix: ""                  # 文件名前缀(运行时注入 page_name)
-      subdir: watermark_removal   # 输出至 debug/watermark_removal/
-      save_compare: true          # 保存左右对比图 *_watermark_compare.*
-      image_format: "png"         # jpg / png
+      enabled: false
+      output_dir: null
+      prefix: ""
+      subdir: watermark_removal
+      save_compare: true
+      image_format: "png"
 
+# ============================================================
+# Layout 检测配置 - 智能路由器(按场景直接选择模型)
+# ============================================================
 layout_detection:
   # module: "paddle"
   # model_name: "RT-DETR-H_layout_17cls"
@@ -104,7 +96,7 @@ vl_recognition:
 ocr_recognition:
   module: "mineru" 
   language: "ch"
-  det_threshold: 0.6
+  det_threshold: 0.5
   unclip_ratio: 1.5
   enable_merge_det_boxes: false
   batch_size: 8

+ 38 - 29
ocr_tools/universal_doc_parser/config/bank_statement_paddle_vl_local.yaml

@@ -22,34 +22,23 @@ preprocessor:
     model_dir: null  # 使用默认路径
   unwarping:
     enabled: false
-  # -------------------------------------------------------
-  # 水印去除配置(适用于银行流水浅色斜向文字水印)
-  # -------------------------------------------------------
+  # 页级水印(细参见 ocr_utils/watermark/presets.py PAGE_WATERMARK_PRESETS)
   watermark_removal:
-    enabled: false           # 是否启用水印去除
-    method: threshold # threshold | masked | masked_adaptive
-    threshold: 175          # 全局阈值或掩膜失败时的回退阈值(140-180)
-    morph_close_kernel: 0   # 去水印后灰度图闭运算,0 跳过
-    # 去水印后对比度增强(text_restore 将笔画拉深,比全局 gamma 更接近原图)
+    enabled: false
+    detect_before_remove: true
+    method: threshold   # threshold | masked | masked_adaptive
+    threshold: 175
     contrast_enhancement:
-      enabled: true
-      method: text_restore   # text_restore | clahe | gamma | linear
-      text_black_target: 85  # 略提高,减轻去水印后笔画被拉花(原 75 过深)
-      background_threshold: 248
-      text_lo_percentile: 1.0
-      text_hi_percentile: 99.0
-      gamma: 0.75            # method=gamma 时生效
-      clip_limit: 2.0        # method=clahe
-      tile_grid_size: 8
-      black_percentile: 2.0  # method=linear
-      white_percentile: 98.0
+      enabled: false
+      method: text_restore
+      text_black_target: 85
     debug_options:
-      enabled: false              # 由命令行 --debug / --debug-layout 统一控制
-      output_dir: null            # null 时使用 pipeline 输出目录
-      prefix: ""                  # 文件名前缀(运行时注入 page_name)
-      subdir: watermark_removal   # 输出至 debug/watermark_removal/
-      save_compare: true          # 保存左右对比图 *_watermark_compare.*
-      image_format: "png"         # jpg / png
+      enabled: false
+      output_dir: null
+      prefix: ""
+      subdir: watermark_removal
+      save_compare: true
+      image_format: "png"
 
 # ============================================================
 # Layout 检测配置 - 智能路由器(按场景直接选择模型)
@@ -180,13 +169,33 @@ table_recognition_wired:
     # 功能开关
     enable_ocr_compensation: true      # 启用OCR边缘补偿
 
-
-  # 单元格二次 OCR(det 分行 + 整格兜底 + 低分块过滤)
+  # 单元格二次 OCR(det 分行 + 整格/条带兜底 + 低分笔画增强重试)
   second_pass_ocr:
-    line_min_score: 0.8
+    reocr_mode: bank_statement       # 表体空单元必跑 + 同行多数非空则空格也跑
+    header_row: 0                    # 表头行号(0=首行)
+    row_peer_min_nonempty: 5         # 同行至少 N 个非空格时,本格空也触发二次 OCR
+    line_min_score: 0.8              # 低于此分的分行从文本与计分中丢弃
     drop_low_score_blocks: true
-    whole_cell_fallback: true
+    whole_cell_fallback: true        # 整格 det=False 兜底 + 条带扫描
     prefer_whole_on_tie: true
+    whole_longer_min_extra_chars: 2  # 整格/条带文本比分行多长至少 N 字则优先
+    strip_fallback_aspect_ratio: 1.8 # 高/宽>=该值且仅检出<=1行时滑动条带分行
+    suspicious_short_min_chars: 4    # 高分但过短仍跑整格/条带兜底(与 enhance_retry 无关)
+    cell_preprocess:
+      watermark:
+        enabled: true
+        method: threshold
+      denoise:
+        enabled: false   # 小格 median 易糊笔画;lab 用 --denoise 对比
+      contrast:
+        enabled: false   # Pass1 去水印后可选;lab 对比 text_restore
+        method: text_restore
+        text_black_target: 88
+      light:
+        upscale_min_side: 192  # 128, 192 用于难例日期列
+    enhance_retry:
+      enabled: false
+      # enabled: true 时 Pass2 预处理,默认见代码(cell_preprocess.enhance_retry 已废弃)
 
   # Debug 可视化配置
   debug_options:

+ 99 - 55
ocr_tools/universal_doc_parser/config/bank_statement_smart_router.yaml

@@ -21,35 +21,27 @@ preprocessor:
     model_dir: null  # 使用默认路径
   unwarping:
     enabled: false
-  # -------------------------------------------------------
-  # 水印去除配置(适用于银行流水浅色斜向文字水印)
-  # -------------------------------------------------------
+  # 页级水印(细参见 ocr_utils/watermark/presets.py PAGE_WATERMARK_PRESETS)
   watermark_removal:
-    enabled: false           # 是否启用水印去除
-    method: threshold # threshold | masked | masked_adaptive
-    threshold: 175          # 全局阈值或掩膜失败时的回退阈值(140-180)
-    morph_close_kernel: 0   # 去水印后灰度图闭运算,0 跳过
-    # 去水印后对比度增强(text_restore 将笔画拉深,比全局 gamma 更接近原图)
+    enabled: false
+    detect_before_remove: true
+    method: threshold   # threshold | masked | masked_adaptive
+    threshold: 175
     contrast_enhancement:
-      enabled: true
-      method: text_restore   # text_restore | clahe | gamma | linear
-      text_black_target: 85  # 略提高,减轻去水印后笔画被拉花(原 75 过深)
-      background_threshold: 248
-      text_lo_percentile: 1.0
-      text_hi_percentile: 99.0
-      gamma: 0.75            # method=gamma 时生效
-      clip_limit: 2.0        # method=clahe
-      tile_grid_size: 8
-      black_percentile: 2.0  # method=linear
-      white_percentile: 98.0
+      enabled: false
+      method: text_restore
+      text_black_target: 85
     debug_options:
-      enabled: false              # 由命令行 --debug / --debug-layout 统一控制
-      output_dir: null            # null 时使用 pipeline 输出目录
-      prefix: ""                  # 文件名前缀(运行时注入 page_name)
-      subdir: watermark_removal   # 输出至 debug/watermark_removal/
-      save_compare: true          # 保存左右对比图 *_watermark_compare.*
-      image_format: "png"         # jpg / png
-
+      enabled: false
+      output_dir: null
+      prefix: ""
+      subdir: watermark_removal
+      save_compare: true
+      image_format: "png"
+
+# ============================================================
+# Layout 检测配置 - 智能路由器(按场景直接选择模型)
+# ============================================================
 layout_detection:
   module: "smart_router"
   strategy: "ocr_eval"  # ocr_eval(推荐,基于OCR评估选择最佳), auto(快速模式,基于文档特征)
@@ -73,14 +65,6 @@ layout_detection:
       model_dir: null  # 使用默认路径
       device: "cpu"
     
-  # Debug 可视化配置(与 MinerUWiredTableRecognizer.DebugOptions 对齐)
-  # 默认关闭。开启后将保存:layout检测结果
-  debug_options:
-    enabled: true               # 是否开启调试可视化输出
-    output_dir: null             # 调试输出目录;null不输出
-    prefix: ""                  # 保存文件名前缀(如设置为页码)
-
-  
   # 可选:回退模型(当所有模型都失败时使用)
   fallback_model:
     module: "mineru"
@@ -90,11 +74,25 @@ layout_detection:
   # 后处理配置
   post_process:
     # 将大面积文本块转换为表格(后处理)
-    convert_large_text_to_table: true
-    min_text_area_ratio: 0.25
-    min_text_width_ratio: 0.4
-    min_text_height_ratio: 0.3
+    convert_large_text_to_table: true  # 是否启用
+    min_text_area_ratio: 0.25         # 最小面积占比(25%)
+    min_text_width_ratio: 0.4         # 最小宽度占比(40%)
+    min_text_height_ratio: 0.3        # 最小高度占比(30%)
+
+  # Debug 可视化(底图为 inference_image,与 Layout 检测输入一致)
+  debug_options:
+    enabled: false              # 由命令行 --debug / --debug-layout 控制
+    output_dir: null            # null 时由 pipeline 按页注入
+    prefix: ""
+    subdir: layout_detection    # 输出至 debug/layout_detection/
+    save_raw: true              # 后处理前
+    save_post_processed: true   # 后处理后
+    save_json: true
+    image_format: "png"
 
+# ============================================================
+# OCR 识别配置
+# ============================================================
 ocr_recognition:
   module: "mineru"
   language: "ch"
@@ -104,7 +102,6 @@ ocr_recognition:
   batch_size: 8
   device: "cpu"
 
-
   # Debug 可视化(底图为 inference_image,与整页 OCR 输入一致)
   debug_options:
     enabled: true              # 由命令行 --debug / --debug-ocr 控制
@@ -114,56 +111,100 @@ ocr_recognition:
     save_json: true
     image_format: png
 
+# ============================================================
 # 表格分类配置(自动区分有线/无线表格)
+# ============================================================
 table_classification:
   enabled: true               # 是否启用自动表格分类(默认关闭,使用手动配置)
   module: "paddle"            # 分类模型:paddle(MinerU PaddleTableClsModel)
   confidence_threshold: 0.5   # 分类置信度阈值
   batch_size: 16              # 批处理大小
 
-
-
-  # Debug 可视化(底图为 inference_image,与 Layout 检测输入一致)
+  # Debug 可视化配置
   debug_options:
-    enabled: true              # 由命令行 --debug / --debug-layout 控制
+    enabled: false              # 由命令行 --debug / --debug-table 统一控制
     output_dir: null            # null 时由 pipeline 按页注入
     prefix: ""
-    subdir: layout_detection    # 输出至 debug/layout_detection/
-    save_raw: true              # 后处理前
-    save_post_processed: true   # 后处理后
-    save_json: true
+    subdir: table_classification  # 输出至 debug/table_classification/
+    save_table_lines: true      # paddle 线条检测叠加图
     image_format: "png"
 
-# 有线表格识别专用配置
+# ============================================================
+# 有线表格识别专用配置(MinerU UNet)
+# ============================================================
 table_recognition_wired:
   use_wired_unet: true
   upscale_ratio: 3.333
   need_ocr: true
   row_threshold: 10
   col_threshold: 15
-  ocr_conf_threshold: 0.8
+  ocr_conf_threshold: 0.9       # 单元格 OCR 置信度阈值
   cell_crop_margin: 2
   use_custom_postprocess: true  # 是否使用自定义后处理(默认启用)
 
   # 是否启用倾斜矫正
   enable_deskew: true
 
+  # 🆕 启用多源单元格融合
+  use_cell_fusion: true
+  
+  # 融合引擎配置
+  cell_fusion:
+    # RT-DETR 模型路径(必需)
+    rtdetr_model_path: "/Users/zhch158/models/pytorch_models/Table/RT-DETR-L_wired_table_cell_det.onnx"
+    
+    # 融合权重
+    unet_weight: 0.6        # UNet 权重(结构性强)
+    rtdetr_weight: 0.4      # RT-DETR 权重(鲁棒性强)
+    
+    # 阈值配置
+    iou_merge_threshold: 0.7    # 高IoU合并阈值(>0.7则加权平均)
+    iou_nms_threshold: 0.5      # NMS去重阈值
+    rtdetr_conf_threshold: 0.5  # RT-DETR置信度阈值
+    
+    # 功能开关
+    enable_ocr_compensation: true      # 启用OCR边缘补偿
 
-  # 单元格二次 OCR(det 分行 + 整格兜底 + 低分块过滤)
+  # 单元格二次 OCR(det 分行 + 整格/条带兜底 + 低分笔画增强重试
   second_pass_ocr:
-    line_min_score: 0.8
+    reocr_mode: bank_statement       # 表体空单元必跑 + 同行多数非空则空格也跑
+    header_row: 0                    # 表头行号(0=首行)
+    row_peer_min_nonempty: 5         # 同行至少 N 个非空格时,本格空也触发二次 OCR
+    line_min_score: 0.8              # 低于此分的分行从文本与计分中丢弃
     drop_low_score_blocks: true
-    whole_cell_fallback: true
+    whole_cell_fallback: true        # 整格 det=False 兜底 + 条带扫描
     prefer_whole_on_tie: true
+    whole_longer_min_extra_chars: 2  # 整格/条带文本比分行多长至少 N 字则优先
+    strip_fallback_aspect_ratio: 1.8 # 高/宽>=该值且仅检出<=1行时滑动条带分行
+    suspicious_short_min_chars: 4    # 高分但过短仍跑整格/条带兜底(与 enhance_retry 无关)
+    cell_preprocess:
+      watermark:
+        enabled: true
+        method: threshold
+      denoise:
+        enabled: false   # 小格 median 易糊笔画;lab 用 --denoise 对比
+      contrast:
+        enabled: false   # Pass1 去水印后可选;lab 对比 text_restore
+        method: text_restore
+        text_black_target: 88
+      light:
+        upscale_min_side: 192  # 128, 192 用于难例日期列
+    enhance_retry:
+      enabled: false
+      # enabled: true 时 Pass2 预处理,默认见代码(cell_preprocess.enhance_retry 已废弃)
 
   # Debug 可视化配置
   debug_options:
-    enabled: true              # 由命令行 --debug / --debug-table 统一控制
+    enabled: false              # 由命令行 --debug / --debug-table 统一控制
     output_dir: null            # null 时由 pipeline 按页注入
     prefix: ""
-    subdir: table_classification  # 输出至 debug/table_classification/
-    save_table_lines: true      # paddle 线条检测叠加图
+    subdir: table_recognition_wired  # 输出至 debug/table_recognition_wired/
+    save_table_lines: true
+    save_connected_components: true
+    save_grid_structure: true
+    save_text_overlay: true
     image_format: "png"
+    # 单元格二次 OCR 裁剪图:debug/table_recognition_wired/tablecell_ocr/
 
 # VLM 表格识别配置(当分类为 'wireless' 时使用)
 vl_recognition:
@@ -187,6 +228,9 @@ vl_recognition:
   # 表格识别特定配置
   table_recognition:
 
+# ============================================================
+# 输出配置
+# ============================================================
 output:
   create_subdir: false
   save_pdf_images: true

+ 0 - 158
ocr_tools/universal_doc_parser/config/bank_statement_yusys_v2.yaml

@@ -1,158 +0,0 @@
-# 银行交易流水场景配置 v2
-# 支持完整的处理流程:PDF分类 → 方向识别 → Layout检测 → OCR/VLM并行处理 → 坐标匹配
-
-scene_name: "bank_statement"
-description: "银行交易流水、对账单等场景 - 增强版"
-
-# ============================================================
-# 输入配置
-# ============================================================
-input:
-  supported_formats: [".pdf", ".png", ".jpg", ".jpeg", ".bmp", ".tiff"]
-  dpi: 200  # PDF转图片的DPI
-  txt_pdf_watermark_removal:
-    enabled: true   # 文字型PDF渲染前去除水印XObject(保留文字可搜索性)
-    sample_pages: 3  # 扫描前N页快速预检
-
-# ============================================================
-# 预处理配置(方向识别)
-# ============================================================
-preprocessor:
-  module: "mineru"
-  orientation_classifier:
-    enabled: true  # 扫描件自动开启,数字PDF自动跳过
-    model_name: "paddle_orientation_classification"
-    model_dir: null  # 使用默认路径
-  unwarping:
-    enabled: false  # 图像矫正(可选)
-  # -------------------------------------------------------
-  # 水印去除配置(适用于银行流水浅色斜向文字水印)
-  # -------------------------------------------------------
-  watermark_removal:
-    enabled: true           # 是否启用水印去除
-    threshold: 160          # 灰度阈值(140-180):高于此值视为水印变白
-                            # 值越大保守(残留水印),值越小激进(损失浅色正文)
-    morph_close_kernel: 0   # 形态学闭运算核大小(像素),默认的 morph_kernel 改为 0(非二值图像时形态学闭运算会适得其反)
-
-# ============================================================
-# 版式检测配置
-# ============================================================
-layout_detection:
-  module: "docling"
-  model_name: "docling-layout-old"
-  model_dir: ds4sd/docling-layout-old  # 使用默认路径,自动下载 doclayout_yolo_docstructbench_imgsz1280_2501.pt
-  device: "cpu"  # 可选: "cpu", "cuda", "mps"
-  conf: 0.3
-  num_threads: 4
-  
-  # 后处理配置
-  post_process:
-    # 将大面积文本块转换为表格(后处理)
-    convert_large_text_to_table: true  # 是否启用
-    min_text_area_ratio: 0.25         # 最小面积占比(25%)
-    min_text_width_ratio: 0.4         # 最小宽度占比(40%)
-    min_text_height_ratio: 0.3        # 最小高度占比(30%)
-
-# ============================================================
-# VL识别配置(表格、公式)
-# ============================================================
-vl_recognition:
-  # 可选: "mineru" (MinerU VLM) 或 "paddle" (PaddleOCR-VL)
-  module: "paddle"
-  model_name: "PaddleOCR-VL-0.9B"
-  
-  # 后端配置
-  backend: "http-client"  # 可选: "http-client", "vllm-engine", "transformers"
-  server_url: "http://10.192.72.11:20016"  # PaddleOCR-VL 服务地址
-  
-  # 图片尺寸限制(避免序列长度超限)
-  max_image_size: 4096
-  resize_mode: 'max'  # 'max' 保持宽高比, 'fixed' 固定尺寸
-  
-  device: "cpu"
-  batch_size: 1
-  
-  model_params:
-    max_concurrency: 10
-    http_timeout: 600
-  
-  # 表格识别特定配置
-  table_recognition:
-    bank_statement_mode: true      # 银行流水优化模式
-
-# ============================================================
-# OCR识别配置(文本检测+识别)
-# ============================================================
-ocr_recognition:
-  module: "mineru"
-  language: "ch"  # 语言: ch, ch_lite, en, japan 等
-  det_threshold: 0.6  # 检测阈值
-  unclip_ratio: 1.5   # 文本框扩展比例
-  enable_merge_det_boxes: false  # 不合并框
-  batch_size: 8
-  device: "cpu"
-
-# ============================================================
-# 输出配置
-# ============================================================
-output:
-  # 基础输出
-  create_subdir: false       # 创建子目录
-  save_json: true           # 保存 middle.json(MinerU标准格式)
-  save_markdown: true       # 保存 Markdown 文件
-  save_html: true           # 保存表格 HTML 文件
-  
-  # Debug 输出(通过命令行 --debug 开启)
-  save_layout_image: true  # 保存 layout 可视化图片
-  save_ocr_image: true     # 保存 OCR 可视化图片
-  draw_type_label: true     # 在可视化图片上标注类型
-  draw_bbox_number: true    # 在可视化图片上标注序号
-  
-  # 增强输出
-  save_enhanced_json: true  # 保存增强版 JSON(包含单元格坐标)
-
-  normalize_numbers: true  # 金额数字标准化(全角→半角)
-
-# ============================================================
-# 场景特定配置
-# ============================================================
-scene_config:
-  bank_statement:
-    # 表格结构特征
-    table_structure: "single_column_list"  # 单栏列表形式
-    merged_cells: false                     # 无合并单元格
-    
-    # 预期列名(用于验证)
-    expected_columns: ["日期", "摘要", "收入", "支出", "余额"]
-    
-    # 验证规则
-    amount_validation: true   # 金额格式验证
-    date_validation: true     # 日期格式验证
-    balance_validation: true  # 余额一致性验证
-    
-  processing_rules:
-    # 表格处理规则
-    table_rules:
-      - detect_table_type: ["wired", "wireless"]  # 检测有线/无线表格
-      - extract_header_automatically: true         # 自动提取表头
-      - validate_amount_format: true               # 验证金额格式
-      - merge_continuation_rows: true              # 合并续行
-      
-    # OCR后处理规则
-    ocr_rules:
-      - filter_low_confidence: 0.7      # 过滤低置信度结果
-      - merge_adjacent_text: true       # 合并相邻文本
-      - number_format_normalization: true  # 数字格式标准化
-
-# ============================================================
-# 跨页表格合并配置
-# ============================================================
-cross_page_merge:
-  enabled: true
-  # 判断表格是否跨页的条件
-  conditions:
-    - table_at_page_bottom: true    # 表格位于页面底部
-    - table_at_page_top: true       # 下一页表格位于顶部
-    - similar_column_count: true    # 列数相似
-    - header_match: false           # 表头匹配(跨页表格通常没有重复表头)
-

+ 38 - 30
ocr_tools/universal_doc_parser/config/bank_statement_yusys_v4.yaml

@@ -21,34 +21,23 @@ preprocessor:
     model_dir: null  # 使用默认路径
   unwarping:
     enabled: false
-  # -------------------------------------------------------
-  # 水印去除配置(适用于银行流水浅色斜向文字水印)
-  # -------------------------------------------------------
+  # 页级水印(细参见 ocr_utils/watermark/presets.py PAGE_WATERMARK_PRESETS)
   watermark_removal:
-    enabled: false           # 是否启用水印去除
-    method: threshold # threshold | masked | masked_adaptive
-    threshold: 175          # 全局阈值或掩膜失败时的回退阈值(140-180)
-    morph_close_kernel: 0   # 去水印后灰度图闭运算,0 跳过
-    # 去水印后对比度增强(text_restore 将笔画拉深,比全局 gamma 更接近原图)
+    enabled: false
+    detect_before_remove: true
+    method: threshold   # threshold | masked | masked_adaptive
+    threshold: 175
     contrast_enhancement:
-      enabled: true
-      method: text_restore   # text_restore | clahe | gamma | linear
-      text_black_target: 85  # 略提高,减轻去水印后笔画被拉花(原 75 过深)
-      background_threshold: 248
-      text_lo_percentile: 1.0
-      text_hi_percentile: 99.0
-      gamma: 0.75            # method=gamma 时生效
-      clip_limit: 2.0        # method=clahe
-      tile_grid_size: 8
-      black_percentile: 2.0  # method=linear
-      white_percentile: 98.0
+      enabled: false
+      method: text_restore
+      text_black_target: 85
     debug_options:
-      enabled: false              # 由命令行 --debug / --debug-layout 统一控制
-      output_dir: null            # null 时使用 pipeline 输出目录
-      prefix: ""                  # 文件名前缀(运行时注入 page_name)
-      subdir: watermark_removal   # 输出至 debug/watermark_removal/
-      save_compare: true          # 保存左右对比图 *_watermark_compare.*
-      image_format: "png"         # jpg / png
+      enabled: false
+      output_dir: null
+      prefix: ""
+      subdir: watermark_removal
+      save_compare: true
+      image_format: "png"
 
 # ============================================================
 # Layout 检测配置 - 智能路由器(按场景直接选择模型)
@@ -115,7 +104,6 @@ ocr_recognition:
   batch_size: 8
   device: "cpu"
 
-
   # Debug 可视化(底图为 inference_image,与整页 OCR 输入一致)
   debug_options:
     enabled: false              # 由命令行 --debug / --debug-ocr 控制
@@ -179,13 +167,33 @@ table_recognition_wired:
     # 功能开关
     enable_ocr_compensation: true      # 启用OCR边缘补偿
 
-
-  # 单元格二次 OCR(det 分行 + 整格兜底 + 低分块过滤)
+  # 单元格二次 OCR(det 分行 + 整格/条带兜底 + 低分笔画增强重试)
   second_pass_ocr:
-    line_min_score: 0.8
+    reocr_mode: bank_statement       # 表体空单元必跑 + 同行多数非空则空格也跑
+    header_row: 0                    # 表头行号(0=首行)
+    row_peer_min_nonempty: 5         # 同行至少 N 个非空格时,本格空也触发二次 OCR
+    line_min_score: 0.8              # 低于此分的分行从文本与计分中丢弃
     drop_low_score_blocks: true
-    whole_cell_fallback: true
+    whole_cell_fallback: true        # 整格 det=False 兜底 + 条带扫描
     prefer_whole_on_tie: true
+    whole_longer_min_extra_chars: 2  # 整格/条带文本比分行多长至少 N 字则优先
+    strip_fallback_aspect_ratio: 1.8 # 高/宽>=该值且仅检出<=1行时滑动条带分行
+    suspicious_short_min_chars: 4    # 高分但过短仍跑整格/条带兜底(与 enhance_retry 无关)
+    cell_preprocess:
+      watermark:
+        enabled: true
+        method: threshold
+      denoise:
+        enabled: false   # 小格 median 易糊笔画;lab 用 --denoise 对比
+      contrast:
+        enabled: false   # Pass1 去水印后可选;lab 对比 text_restore
+        method: text_restore
+        text_black_target: 88
+      light:
+        upscale_min_side: 192  # 128, 192 用于难例日期列
+    enhance_retry:
+      enabled: false
+      # enabled: true 时 Pass2 预处理,默认见代码(cell_preprocess.enhance_retry 已废弃)
 
   # Debug 可视化配置
   debug_options: