对比两个OCR识别结果:
从 bank_statement_yusys_v2/2023年度报告母公司_page_003.json 中发现的错误:
| 正确文本 | 识别结果 | 匹配分数 | 问题 |
|---|---|---|---|
| 合同资产 | 货资产 | 80.0% | 检测框不完整 |
| 其他应付款 | 税款 | 66.67% | 检测框错误 |
| 长期待摊费用 | 效用 | 66.67% | 检测框错误 |
| 其他非流动资产 | 非其非产动产 | 61.54% | 检测框合并错误 |
| 资本公积 | 资公存股 | 66.67% | 检测框合并错误 |
| 参数 | PPStructureV3 | MinerU默认 | 影响 |
|---|---|---|---|
box_thresh |
0.6 | 0.3 | 阈值过低导致检测到大量噪声框 |
unclip_ratio |
1.5 | 1.8 | 扩展比例过高,框不够精确 |
thresh |
0.3 | 0.3 | 相同 |
问题:
box_thresh=0.3 太低,会检测到很多低置信度的噪声框| 特性 | PPStructureV3 | MinerU | 影响 |
|---|---|---|---|
| 框合并 | 无(或更保守) | enable_merge_det_boxes=True |
可能错误合并相邻文本块 |
问题:
enable_merge_det_boxes=True 会合并相邻的检测框| 参数 | PPStructureV3 | MinerU | 影响 |
|---|---|---|---|
score_thresh |
0.0 | 0.5 | 丢弃低置信度结果 |
问题:
drop_score=0.5 会丢弃置信度 < 0.5 的识别结果score_thresh=0.0,保留所有结果| 特性 | PPStructureV3 | MinerU | 影响 |
|---|---|---|---|
| 文本行方向识别 | ✅ use_textline_orientation: True |
❌ 无 | 倾斜文本识别错误 |
问题:
| 组件 | PPStructureV3 | MinerU | 影响 |
|---|---|---|---|
| 检测模型 | PP-OCRv5_server_det | ch/ch_lite | 可能使用较旧版本 |
| 识别模型 | PP-OCRv5_server_rec | ch/ch_lite | 可能使用较旧版本 |
问题:
核心思路:不仅依赖一次整页 OCR 的参数调优,而是在有线表格场景对每个单元格单独裁剪、预处理、再 OCR。这是从"提升整页 OCR 质量"到"对关键区域精准重试"的策略升级。
| 问题 | 仅调参数 | 二次 OCR(单元格裁剪) |
|---|---|---|
| 检测框不完整("合同资产"→"货资产") | 调高 box_thresh 可能直接丢失该行 | 单格裁剪后文字占比更高,det 盒完整 |
| 检测框合并错误("其他非流动资产"→"非其非产动产") | 关闭 merge_det_boxes 可能引入其他问题 | 单元格天然隔离,不存在跨格合并 |
| 水印干扰("有限公司"被误识别) | 无法处理 | 斜框角度过滤(_is_bbox_slanted)+ 格级去水印 |
| 弱信号遗漏(空格、低分碎片) | 降低 drop_score 引入噪声 | 精确判定列空性(_column_empty_ratio),按需触发 |
| 纵向不全(只识别到"支行") | 无法检测 | _is_ocr_vertically_incomplete 纵向偏移+空白不对称检测 |
详见 有线表格识别技术文档 — 六、单元格 OCR,核心要点:
graph TB
A[整页 OCR] --> B[一验:中心点匹配<br/>fill_text_by_center_point]
B --> C{触发二次 OCR?<br/>_should_second_pass_cell}
C --> D[Pass1:格级预处理<br/>去水印+upscale+OCR]
C --> E[跳过,保持一验结果]
D --> F{Pass1 分数达标?}
F -->|否| G[Pass2:enhance_retry<br/>更强预处理+再OCR]
F -->|是| H[采纳结果]
G --> H
style B fill:#e1f5ff
style D fill:#fff4e1
style G fill:#fff4e1
| 能力 | 方法 | 对应问题 |
|---|---|---|
| 斜框过滤 | _is_bbox_slanted(多边形角度 > 10° → 丢弃) |
水印误识别(如"有限公司"被当成单元格文字) |
| 纵向完整性 | _is_ocr_vertically_incomplete(y_center 偏移 + 空白不对称) |
检测框截断(如只识别到"支行"而非完整户名) |
| 列空判断 | _column_empty_ratio(基于 matched_boxes_list 判空) |
区分"OCR 遗漏"和"列本来就空",仅前者触发重试 |
| Pass2 独立配置 | enhance_retry 可与 cell_preprocess 解耦(upscale_min_side 等) |
低分难例二次增强,不牺牲ปกติ格的处理效率 |
方案1-4 的整页 OCR 参数调整 仍然有价值,是与二次 OCR 互补而非替代:
bank_statement 模式二次 OCR修改 MinerUOCRRecognizer 的初始化参数,使其更接近 PPStructureV3:
# 在 mineru_adapter.py 中修改
self.ocr_model = self.atom_model_manager.get_atom_model(
atom_model_name=AtomicModel.OCR,
det_db_box_thresh=0.6, # 从 0.3 提高到 0.6
lang=self.config.get('language', 'ch'),
det_db_unclip_ratio=1.5, # 从 1.8 降低到 1.5
enable_merge_det_boxes=False, # 从 True 改为 False(表格场景)
)
优点:
缺点:
enable_merge_det_boxes=True修改 drop_score 参数,保留更多识别结果:
# 需要修改 PytorchPaddleOCR 的初始化
kwargs['drop_score'] = 0.3 # 从默认 0.5 降低到 0.3
优点:
缺点:
根据文档类型(表格/文本)和PDF类型(扫描件/数字PDF)动态调整参数:
def get_ocr_config(pdf_type: str, has_tables: bool) -> Dict[str, Any]:
"""根据场景返回OCR配置"""
if has_tables:
# 表格场景:更严格的检测,不合并框
return {
'det_db_box_thresh': 0.6,
'det_db_unclip_ratio': 1.5,
'enable_merge_det_boxes': False,
'drop_score': 0.3,
}
elif pdf_type == 'txt':
# 数字PDF:可以合并框,提高检测阈值
return {
'det_db_box_thresh': 0.5,
'det_db_unclip_ratio': 1.6,
'enable_merge_det_boxes': True,
'drop_score': 0.3,
}
else:
# 扫描件:平衡检测和合并
return {
'det_db_box_thresh': 0.4,
'det_db_unclip_ratio': 1.6,
'enable_merge_det_boxes': True,
'drop_score': 0.3,
}
优点:
缺点:
参考 PPStructureV3,添加文本行方向识别模块:
优点:
缺点:
_is_bbox_slanted:过滤斜向水印_is_ocr_vertically_incomplete:检测纵向不完全文本_column_empty_ratio:基于 matched_boxes_list 智能判空调整检测参数:
det_db_box_thresh: 0.3 → 0.6det_db_unclip_ratio: 1.8 → 1.5enable_merge_det_boxes: True → False(表格场景)降低识别阈值:
drop_score: 0.5 → 0.3ocr:
det_db_box_thresh: 0.6 # 提高检测阈值
det_db_unclip_ratio: 1.5 # 降低扩展比例
enable_merge_det_boxes: false # 不合并框
drop_score: 0.3 # 降低识别阈值
ocr:
det_db_box_thresh: 0.4 # 中等检测阈值
det_db_unclip_ratio: 1.6 # 中等扩展比例
enable_merge_det_boxes: true # 允许合并
drop_score: 0.3 # 降低识别阈值
models/adapters/mineru_adapter.py:
MinerUOCRRecognizer.__init__() - 修改初始化参数core/pipeline_manager_v2.py:
_process_single_page() - 检测是否有表格配置文件:
实施阶段0(✅ 已完成)+ 阶段1改进后:
_is_bbox_slanted 过滤斜向水印,减少误匹配_column_empty_ratio 区分"OCR遗漏"与"真空白",减少无效重试参数调优:
性能影响:
box_thresh 可能略微降低召回率向后兼容: