Nincs leírás

zhch158_admin 7b6a80f651 feat: Add table line generator and template applier modules 4 napja
.vscode 3cf0f6e4da feat: 添加table_line_generator调试配置以支持streamlit应用 4 napja
batch_ocr c7cd1d7fe4 feat: 更新PDF列表并移除PP-StructureV3处理器的冗余配置 1 hete
comparator cc3e15d2d7 feat: 更新OCR结果比较功能,添加日期时间格式检测和解析逻辑 1 hete
config 88905951a0 feat: 添加康强_北京农村商业银行的OCR配置文件及数据源 1 hete
image 1f11c256ba Add image and markdown documentation for coordinate system explanation and conversion 2 hónapja
image_edit e129dc6ca8 Remove LocalVLMProcessor class and its associated methods for image processing and model handling 2 hónapja
merger 979d73759e feat: 调整长度比例检查逻辑,修改阈值以提高匹配准确性 1 hete
ocr_vlm_verify 6a8e5074e1 直接VLM读取原图和识别结果比对,效果很差,不可行 2 hónapja
streamlit_test 3ca33ce0d1 feat: 更新DataFrame和Plotly图表容器的宽度设置,支持自适应宽度 1 hónapja
table_line_generator 7b6a80f651 feat: Add table line generator and template applier modules 4 napja
test 3229a4cace Add unified diff and HTML diff generation functions 1 hónapja
.env.example c26adef7b0 添加示例环境配置文件 .env.example,包含多模态API的密钥和基础信息 2 hónapja
README.md 5a5e4015d6 Remove obsolete configuration file for OCR validation tool, including styles, UI settings, OCR data configurations, data sources, and pre-validation paths. 1 hete
compare_ocr_results-算法.md a6a21562a8 新增字符串相似度算法文档,详细解释四种算法及其适用场景和例子 1 hónapja
compare_use_unified_diff.py 18fbf8f769 feat: 采用difflib的统一差异比较功能,支持生成JSON和Markdown报告 1 hónapja
config_manager.py a8b6eabc3a feat: 优化数据源名称生成逻辑,使用 result_dir 提高唯一性和清晰度 1 hete
normalize_financial_numbers.py 6410af974b 添加财务数字标准化功能,支持全角字符转换为半角字符,并处理Markdown和JSON格式中的数字标准化 1 hónapja
ocr_by_vlm.py a8dab89a60 去掉生成文本中的markdown标记,优化文本处理逻辑 1 hónapja
ocr_validator_file_utils.py 72ddd4812f 新增OCR工具功能,支持HTML和Markdown内容中图片引用的处理,增强图片查找和转换为base64的能力 1 hónapja
ocr_validator_layout.py b2ff96cc83 fix: 修复图表宽度设置,使用容器宽度替代废弃参数 4 napja
ocr_validator_utils.py 4a914d9089 feat: 修改 find_available_ocr_files_multi_source 函数,简化数据源唯一标识生成逻辑 1 hete
run_streamlit_validator.py cc8a579d76 优化OCR数据检查路径,确保正确读取数据文件 2 hónapja
streamlit_ocr_validator.py ad61e0ace2 fix: 修正OCR工具统计信息的显示文本 1 hete
streamlit_validator_core.py 788e93532b feat: 添加文件路径检查,确保切换数据源时路径有效 1 hete
streamlit_validator_cross.py 28da19dca4 fix: 修复导入路径,更新compare_ocr_results模块的引用 4 hete
streamlit_validator_result.py 1b1b1acb02 fix: 修正差异数据框的样式应用方法 1 hete
streamlit_validator_table.py e8a57aba1c feat: 更新数据展示组件宽度设置,支持自适应宽度 1 hónapja
streamlit_validator_ui.py a59da04cec feat: 重构数据源选择器,优化文档和OCR工具选择逻辑,支持三列布局 1 hete
styles.css 7cd2ced3de 新增OCR验证工具样式配置文件,定义主体、侧边栏、选择框、文本及内容样式 2 hónapja
图片操作说明.md 83ad36b24d 修正图像旋转算法,优化旋转矩阵实现,新增坐标旋转说明文档 2 hónapja

README.md

🔍 OCR 可视化验证系统

一个功能强大的 OCR 识别与验证系统,集成了多种 OCR 工具支持、智能交叉验证、可视化校验和表格数据分析功能,专为财务报表、数据表格等复杂文档设计。

✨ 核心功能

🎯 多工具 OCR 支持

  • Dots OCR:专业 VLM OCR 引擎
  • PaddleOCR PPStructV3:结构化文档识别
  • PaddleOCR-VL:视觉语言模型增强版
  • Table Recognition V2:专业表格识别
  • MinerU VLM:多模态文档理解

🔄 智能交叉验证

  • 多数据源对比:支持不同 OCR 工具结果的交叉验证
  • 细粒度差异检测:精确到单元格级别的差异分析
  • 智能表格对比
    • 标准表格模式(standard
    • 流水表格模式(flow_list)- 支持表头位置智能检测
    • 资产负债表等多层表头识别:自动识别总表头和分类标题
    • 自动列类型检测(数字、日期、文本、文本型数字)
  • 差异分类统计
    • 金额差异(table_amount)- 严重度:high
    • 日期时间差异(table_datetime)- 严重度:medium
    • 文本差异(table_text)- 严重度:low/medium(根据相似度)
    • 表头差异(位置、内容、结构)
    • 段落差异
    • 列类型冲突(自动提升严重度到 high

📊 可视化校验工具

  • 交互式图像标注:点击文本高亮对应图像位置
  • 精确坐标定位:基于 bbox 的精确位置标示
  • 旋转角度处理
    • 自动检测文档旋转角度
    • 支持手动调整旋转
    • 智能坐标转换
  • 多渲染模式
    • HTML 渲染(支持横向滚动)
    • Markdown 渲染
    • DataFrame 表格
    • 原始文本

📈 表格数据分析

  • 智能表格解析:自动识别并转换 HTML 表格
  • 交互式操作
    • 过滤(按列值、关键词)
    • 排序(升序/降序)
    • 分页显示
    • 列选择显示
  • 数据导出:支持 CSV、Excel 格式
  • 统计分析:自动生成数值列统计信息

🔧 数字标准化

  • 全角/半角字符转换
  • 千分位分隔符标准化
  • 小数点格式统一
  • 支持批量标准化处理

🚀 快速开始

环境配置

# 创建 conda 环境
conda create -n py312 python=3.12 -y
conda activate py312

# 克隆项目
git clone https://gitee.com/zhch158_admin/ocr_verify.git
cd ocr_verify

# 安装依赖
pip install -r requirements.txt
# 或手动安装核心依赖
pip install streamlit plotly pandas pillow numpy opencv-python openpyxl \
    beautifulsoup4 pyyaml fuzzywuzzy python-Levenshtein

配置文件

编辑配置文件(详见 config/README.md):

1. 全局配置 (config/global.yaml)

data_sources:
  - 德_内蒙古银行照.yaml
  - 对公_招商银行图.yaml
  - A用户_单元格扫描流水.yaml
  - B用户_扫描流水.yaml
  - 至远彩色_2023年报.yaml

2. 项目配置示例 (config/B用户_扫描流水.yaml)

document:
  name: "B用户_扫描流水"
  base_dir: "/Users/zhch158/workspace/data/流水分析/B用户_扫描流水"
  
  ocr_results:
    # PPStructV3
    - tool: "ppstructv3"
      result_dir: "ppstructurev3_client_results"
      image_dir: "ppstructurev3_client_results/{{name}}"
      description: "PPStructV3 图片合成结果"
      enabled: true
    
    # PaddleOCR-VL
    - tool: "paddleocr_vl"
      result_dir: "paddleocr_vl_results"
      image_dir: "paddleocr_vl_results/{{name}}"
      description: "PaddleOCR VLM 图片合成结果"
      enabled: true
    
    # MinerU
    - tool: "mineru"
      result_dir: "mineru_vllm_results"
      image_dir: "mineru_vllm_results/{{name}}"
      description: "MinerU 图片合成结果"
      enabled: true
    
    # Dots OCR
    - tool: "dots_ocr"
      result_dir: "dotsocr_vllm_results"
      image_dir: "dotsocr_vllm_results/{{name}}"
      description: "Dots OCR 图片合成结果"
      enabled: true

配置说明

  • document.name:项目名称
  • base_dir:项目根目录(绝对路径)
  • ocr_results:OCR 工具结果配置数组
    • tool:工具标识(ppstructv3 / paddleocr_vl / mineru / dots_ocr
    • result_dir:结果目录(相对于 base_dir
    • image_dir:图像目录(支持 {{name}} 模板变量)
    • description:工具描述
    • enabled:是否启用(true / false

详细配置说明config/README.md

📖 使用指南

1️⃣ 启动可视化验证工具

# 启动 Streamlit 应用
python -m streamlit run streamlit_ocr_validator.py

# 或使用启动脚本
python run_streamlit_validator.py

功能模块:

📄 内容人工检查

  • 选择数据源和页码
  • 点击文本内容查看图像位置
  • 旋转图像调整角度
  • 显示所有文本框或仅显示选中框

🔍 交叉验证结果

  • 选择两个不同的 OCR 数据源
  • 点击「交叉验证」按钮运行批量验证
  • 查看详细的差异对比结果(支持按严重度筛选)
  • 下载验证报告(Excel、JSON)

📊 表格分析

  • 解析 HTML 表格为 DataFrame
  • 过滤、排序、搜索表格数据
  • 导出表格为 CSV 或 Excel
  • 查看统计信息

2️⃣ 命令行对比工具

使用 comparator/compare_ocr_results.py 进行命令行对比(详见 comparator/README.md):

# 基本对比
python comparator/compare_ocr_results.py file1.md file2.md

# 使用流水表格模式(智能表头检测 + 多层表头识别)
python comparator/compare_ocr_results.py file1.md file2.md \
    --table-mode flow_list \
    --similarity-algorithm ratio \
    -o output/comparison_result \
    -f both

# 资产负债表对比(自动识别多层表头)
python comparator/compare_ocr_results.py balance_sheet1.md balance_sheet2.md \
    --table-mode flow_list \
    -o balance_sheet_comparison

参数说明:

  • -o, --output:输出文件名(不含扩展名)
  • -f, --format:输出格式(jsonmarkdownboth
  • --table-mode:表格比对模式
    • standard:标准表格(结构固定)
    • flow_list:流水表格(智能表头检测、支持多层表头)
  • --similarity-algorithm:相似度算法
    • ratio:标准相似度
    • partial_ratio:部分匹配
    • token_sort_ratio:排序后匹配
    • token_set_ratio:集合匹配
  • --ignore-images:忽略图片内容对比

详细文档:参见 comparator/README.md

3️⃣ OCR 结果合并工具

合并不同 OCR 工具的识别结果,提升准确性(详见 merger/README.md):

# 合并 MinerU 和 PaddleOCR 结果
python merger/merge_mineru_paddle_ocr.py \
    --mineru-dir /path/to/mineru/output \
    --paddle-dir /path/to/paddleocr/output \
    --output-dir /path/to/merged/output

# 合并 PaddleOCR-VL 和 PaddleOCR 结果
python merger/merge_paddleocr_vl_paddleocr.py \
    --paddleocr-vl-dir /path/to/paddleocr_vl/output \
    --paddle-dir /path/to/paddleocr/output \
    --output-dir /path/to/merged/output

# 合并 Dots OCR 和 PaddleOCR 结果
python merger/merge_dotsocr_paddleocr.py \
    --dotsocr-dir /path/to/dotsocr/output \
    --paddle-dir /path/to/paddleocr/output \
    --output-dir /path/to/merged/output

合并策略:

  • 表格内容:优先使用 VLM 工具(MinerU/PaddleOCR-VL/Dots OCR)的结果
  • 表格坐标:使用 PaddleOCR 的全局 OCR 文本块坐标(更精确)
  • 文本内容:智能匹配并合并

详细文档:参见 merger/README.md

4️⃣ 批量处理工具

批量处理 PDF 文档并合并 OCR 结果(详见 batch_ocr/README.md):

# 批量处理 PDF 列表
python batch_ocr/batch_process_pdf.py \
    --config batch_ocr/processor_configs.yaml \
    --pdf-list batch_ocr/pdf_list.txt

# 批量合并 OCR 结果
python batch_ocr/batch_merge_results.py \
    --config batch_ocr/processor_configs.yaml \
    --pdf-list batch_ocr/pdf_list.txt \
    --merge-mode mineru_paddle

配置文件示例 (processor_configs.yaml):

processors:
  mineru:
    command: "magic-pdf"
    args:
      - "-p"
      - "{pdf_path}"
      - "-o"
      - "{output_dir}"
    output_structure: "auto/{pdf_name}/auto"
  
  paddleocr:
    command: "paddleocr"
    args:
      - "--image_dir"
      - "{image_dir}"

详细文档:参见 batch_ocr/README.md

5️⃣ 数字标准化工具

使用 normalize_financial_numbers.py

from normalize_financial_numbers import normalize_financial_numbers, normalize_json_file

# 标准化文本中的数字
text = "2023年净利润为28,239,305.48元"
normalized = normalize_financial_numbers(text)
# 输出: "2023年净利润为28,239,305.48元"

# 批量标准化 JSON 文件
normalize_json_file("input.json", "output.json")

📁 项目结构

ocr_verify/
├── streamlit_ocr_validator.py          # 主应用入口
├── streamlit_validator_core.py         # 核心验证器类
├── streamlit_validator_ui.py           # UI 组件
├── streamlit_validator_table.py        # 表格处理
├── streamlit_validator_cross.py        # 交叉验证
├── streamlit_validator_result.py       # 结果展示
├── ocr_validator_layout.py             # 布局管理
├── ocr_validator_utils.py              # 工具函数
├── ocr_validator_file_utils.py         # 文件处理
├── normalize_financial_numbers.py      # 数字标准化
├── styles.css                          # 样式文件
├── requirements.txt                    # 依赖列表
├── config/                             # 配置文件目录 ✨
│   ├── global.yaml                    # 全局配置
│   ├── 至远彩色_2023年报.yaml         # 年报类项目配置
│   ├── A用户_单元格扫描流水.yaml      # 流水表格配置
│   ├── B用户_扫描流水.yaml            # 流水表格配置
│   ├── 德_内蒙古银行照.yaml           # 银行流水配置
│   ├── 对公_招商银行图.yaml           # 银行流水配置
│   └── README.md                      # 配置文档 ✨
├── comparator/                         # OCR 结果对比模块
│   ├── compare_ocr_results.py         # 命令行对比工具
│   ├── ocr_comparator.py              # 核心对比器
│   ├── table_comparator.py            # 表格对比器(✨ 支持多层表头)
│   ├── paragraph_comparator.py        # 段落对比器
│   ├── similarity_calculator.py       # 相似度计算
│   ├── data_type_detector.py          # 数据类型检测
│   ├── content_extractor.py           # 内容提取器
│   ├── text_processor.py              # 文本处理器
│   ├── report_generator.py            # 报告生成器
│   └── README.md                      # 对比模块文档
├── merger/                             # OCR 结果合并模块
│   ├── merge_mineru_paddle_ocr.py     # MinerU + PaddleOCR 合并
│   ├── merge_paddleocr_vl_paddleocr.py # PaddleOCR-VL + PaddleOCR 合并
│   ├── merge_dotsocr_paddleocr.py     # Dots OCR + PaddleOCR 合并
│   ├── merger_core.py                 # 合并核心逻辑
│   ├── text_matcher.py                # 文本匹配器(fazz partial_ratio算法)
│   ├── bbox_extractor.py              # 坐标提取器
│   ├── data_processor.py              # 数据处理器
│   ├── markdown_generator.py          # Markdown 生成器
│   ├── unified_output_converter.py    # 统一输出转换器
│   └── README.md                      # 合并模块文档
├── batch_ocr/                          # 批量处理模块
│   ├── batch_process_pdf.py           # 批量 PDF 处理
│   ├── batch_merge_results.py         # 批量结果合并
│   ├── processor_configs.yaml         # 处理器配置
│   ├── pdf_list.txt                   # PDF 列表
│   └── README.md                      # 批量处理文档
├── output/                             # 输出目录
│   └── pre_validation/                # 交叉验证结果
├── .streamlit/                         # Streamlit 配置
│   └── config.toml                    # Streamlit 设置
└── README.md                          # 项目总文档(本文件)

🎯 核心功能详解

交叉验证流程

  1. 数据源选择

    • 在 Streamlit 界面选择 OCR 数据源(从配置文件加载)
    • 选择验证数据源(用于交叉对比)
  2. 批量验证

    • 自动匹配相同页码的文件
    • 逐页进行差异检测
    • 生成详细验证报告
  3. 差异分析

    • 表格差异:逐单元格对比(支持多层表头)
    • 段落差异:智能段落匹配
    • 结构差异:表头位置、行缺失等
    • 严重度分级:critical > high > medium > low
  4. 结果展示

    • 差异列表(按类型、严重程度分类)
    • 统计图表(饼图、柱状图)
    • 详细对比视图(左右对照)

表格对比算法

标准模式 (standard)

  • 适用于结构固定的表格
  • 逐行逐列对比
  • 适合财务报表、数据统计表

流水表格模式 (flow_list) ✨

智能表头检测:

# 自动检测表头位置(支持多层表头)
header_row_idx = detect_table_header_row(table)

# 检测策略:
# 1. 关键词匹配(日期、金额、余额、资产、负债等)
# 2. 下一行验证(数据行/分类行)
# 3. 多层表头识别(资产负债表等)

✨ 新增:多层表头识别

针对资产负债表等特殊表格:

# 示例表格结构:
# 第1行:['资产', '期末余额', '期初余额', '负债及所有者权益', '期末余额', '期初余额']  ← 总表头
# 第2行:['流动资产:', '', '', '流动负债:', '', '']  ← 分类标题(分类行)
# 第3行:['货币资金', '28,239,305.48', '68,162,260.60', ...]  ← 数据行

def _is_category_row(row):
    """识别分类行(如"流动资产:")"""
    patterns = [
        r'.*:$',  # 以冒号结尾
    ]
    # 返回 True 表示是分类行

# 评分调整:
# - 数据行:+0.2 分
# - 分类行:+0.1 分(新增)

列类型检测:

  • numeric:数字金额
  • datetime:日期时间
  • text_number:文本型数字(如票据号)
  • text:普通文本

✨ 差异严重度改进:

# 基础严重度(由单元格对比决定)
base_severity = {
    'table_amount': 'high',        # 金额差异
    'table_datetime': 'medium',    # 日期差异
    'table_text': 'low/medium'     # 文本差异(根据相似度)
}

# 列类型冲突自动提升
if col_idx in mismatched_columns:
    if base_severity != 'high':
        final_severity = 'high'  # 提升到 high

适用场景:

  • 银行流水表
  • 交易记录
  • 资产负债表(✨ 多层表头)
  • 利润表
  • 流水日志

表格匹配算法

智能匹配两个文件中的表格,支持:

  1. 行列数相似度 (30%)
    • 行数相似度 (15%)
    • 列数相似度 (15%) - ✨ 改进:容忍 1-2 列差异
  2. 表头相似度 (50%) - 最重要
    • 精确匹配 (40%)
    • 模糊匹配 (40%)
    • 语义匹配 (20%) - 识别常见表头关键词
  3. 内容特征相似度 (20%)

    # 表格匹配示例
    matches = find_matching_tables(tables1, tables2)
    # 输出: [(0, 0, 95.2), (1, 1, 87.3)]
    # 格式: (文件1表格索引, 文件2表格索引, 相似度%)
    

OCR 结果合并策略

1. MinerU + PaddleOCR 合并

# 表格内容:优先 MinerU(VLM 更准确)
# 表格坐标:使用 PaddleOCR 全局 OCR 坐标(更精确)
merged_result = merge_mineru_paddleocr(mineru_json, paddle_json)

2. PaddleOCR-VL + PaddleOCR 合并

# 表格内容:优先 PaddleOCR-VL
# 表格坐标:使用 PaddleOCR 全局 OCR 坐标
merged_result = merge_paddleocr_vl_paddleocr(vl_json, paddle_json)

3. Dots OCR + PaddleOCR 合并

# 表格内容:优先 Dots OCR
# 表格坐标:使用 PaddleOCR 全局 OCR 坐标
merged_result = merge_dotsocr_paddleocr(dots_json, paddle_json)

📊 输出示例

交叉验证报告

JSON 格式

{
  "differences": [
    {
      "type": "table_amount",
      "position": "第15行第5列",
      "file1_value": "15.00",
      "file2_value": "15,00",
      "description": "金额不一致: 15.00 vs 15,00",
      "severity": "high",
      "column_name": "金额",
      "column_type": "numeric",
      "row_index": 15,
      "col_index": 4
    },
    {
      "type": "table_header_position",
      "position": "表头位置",
      "file1_value": "第1行",
      "file2_value": "第2行",
      "description": "表头位置不一致: 文件1在第1行,文件2在第2行",
      "severity": "high"
    },
    {
      "type": "table_text",
      "position": "第20行第3列",
      "file1_value": "流动资产",
      "file2_value": "流动 资产",
      "description": "文本不一致: 流动资产 vs 流动 资产 [列类型冲突]",
      "severity": "high",
      "column_type_mismatch": true
    }
  ],
  "statistics": {
    "total_differences": 42,
    "table_differences": 35,
    "amount_differences": 8,
    "datetime_differences": 3,
    "text_differences": 24,
    "paragraph_differences": 7,
    "critical_severity": 2,
    "high_severity": 11,
    "medium_severity": 17,
    "low_severity": 12
  }
}

Markdown 格式

# OCR结果对比报告

## 统计信息
- 总差异数量: **42**
- 表格差异: **35**
  - 金额差异: **8** (严重度: high)
  - 日期差异: **3** (严重度: medium)
  - 文本差异: **24** (严重度: low/medium)
  - 列类型冲突: **3** (严重度提升至: high)
- 段落差异: **7**

## 差异详情(按严重度分类)

### ❌ 严重差异 (Critical)
| 序号 | 位置 | 类型 | 原OCR结果 | 验证结果 | 描述 |
|------|------|------|-----------|----------|------|
| 1 | 表格列类型 | table_header_critical | 5列类型不一致 | 共10列 | 列类型差异过大 (50%) |

### ⚠️ 高优先级差异 (High)
| 序号 | 位置 | 类型 | 原OCR结果 | 验证结果 | 描述 |
|------|------|------|-----------|----------|------|
| 1 | 第15行第5列 | table_amount | 15.00 | 15,00 | 金额不一致 |
| 2 | 第20行第3列 | table_text | 流动资产 | 流动 资产 | 文本不一致 [列类型冲突] |

### ℹ️ 中优先级差异 (Medium)
...

### 💡 低优先级差异 (Low)
...

🔧 高级配置

配置文件结构

项目使用 YAML 配置文件管理数据源和工具参数(详见 config/README.md)。

全局配置 (config/global.yaml):

data_sources:
  - 德_内蒙古银行照.yaml
  - 对公_招商银行图.yaml
  - A用户_单元格扫描流水.yaml
  - B用户_扫描流水.yaml
  - 至远彩色_2023年报.yaml

项目配置 (config/B用户_扫描流水.yaml):

document:
  name: "B用户_扫描流水"
  base_dir: "/Users/zhch158/workspace/data/流水分析/B用户_扫描流水"
  
  ocr_results:
    - tool: "ppstructv3"
      result_dir: "ppstructurev3_client_results"
      image_dir: "ppstructurev3_client_results/{{name}}"
      description: "PPStructV3 图片合成结果"
      enabled: true
    
    - tool: "mineru"
      result_dir: "mineru_vllm_results"
      image_dir: "mineru_vllm_results/{{name}}"
      description: "MinerU 图片合成结果"
      enabled: true

配置参数说明

  • document.name:项目名称(用于模板变量替换)
  • base_dir:项目根目录(绝对路径)
  • tool:OCR 工具标识(ppstructv3 / paddleocr_vl / mineru / dots_ocr
  • result_dir:结果目录(相对于 base_dir
  • image_dir:图像目录(支持 {{name}} 模板变量)
  • enabled:是否启用该数据源

批量处理配置

batch_ocr/processor_configs.yaml 中配置(详见 batch_ocr/README.md):

processors:
  mineru:
    command: "magic-pdf"
    args:
      - "-p"
      - "{pdf_path}"
      - "-o"
      - "{output_dir}"
      - "--method"
      - "auto"
    output_structure: "auto/{pdf_name}/auto"
    
  paddleocr:
    command: "paddleocr"
    args:
      - "--image_dir"
      - "{image_dir}"
      - "--type"
      - "structure"
      - "--det_model_dir"
      - "models/ch_PP-OCRv4_det_infer"
      - "--rec_model_dir"
      - "models/ch_PP-OCRv4_rec_infer"
    output_structure: "{pdf_name}/ppstructure"

merge:
  mineru_paddle:
    priority: "mineru"  # 表格内容优先级
    coordinate_source: "paddleocr"  # 坐标来源
    iou_threshold: 0.5  # IoU 匹配阈值

Streamlit 配置

编辑 .streamlit/config.toml

[theme]
primaryColor = "#0288d1"
backgroundColor = "#ffffff"
secondaryBackgroundColor = "#f5f5f5"
textColor = "#262730"
font = "sans serif"

[server]
maxUploadSize = 200
enableXsrfProtection = true
enableCORS = false

[browser]
gatherUsageStats = false

🐛 常见问题

Q1: 图像显示位置不正确?

A: 检查配置文件中的 OCR 工具坐标参数设置(不同工具的坐标处理方式可能不同)。

Q2: 交叉验证结果为空?

A:

  • 确保两个数据源包含相同页码的文件
  • 检查配置文件中的 enabled: true 设置
  • 验证 base_dirresult_dir 路径正确

Q3: 表格对比差异过多?

A:

  • 在命令行工具中使用 --table-mode flow_list(智能表头检测)
  • 调整相似度算法参数(如使用 --similarity-algorithm token_set_ratio
  • 检查表格结构是否为多层表头(如资产负债表) - 算法会自动识别

Q4: 表格坐标不准确?

A: 使用合并工具结合 PaddleOCR 的全局 OCR 坐标:

python merger/merge_mineru_paddle_ocr.py \
    --mineru-dir /path/to/mineru \
    --paddle-dir /path/to/paddleocr \
    --output-dir /path/to/output

Q5: 如何处理资产负债表等多层表头?✨

A: 使用 flow_list 模式,算法会自动检测多层表头:

python comparator/compare_ocr_results.py balance_sheet1.md balance_sheet2.md \
    --table-mode flow_list

识别逻辑:

  1. 第1行:总表头(如"资产"、"负债")
  2. 第2行:分类标题(如"流动资产:")- 识别为分类行
  3. 第3行起:数据行

调试信息:

📍 检测到表头在第 1 行 (得分: 0.87)
   行数对比: 10 vs 10, 相似度: 100.0%
   列数对比: 6 vs 6, 相似度: 100.0%
   表头位置: 文件1第1行, 文件2第1行
   表头相似度: 92.5%
      精确匹配: 83%, 模糊匹配: 100%, 语义匹配: 100%

Q6: 配置文件不生效?

A:

  • 检查 global.yaml 中是否正确引用了项目配置文件
  • 确认 YAML 语法正确(缩进必须用空格,不能用 Tab)
  • 确保配置文件在 config/ 目录下
  • 重启 Streamlit 应用

Q7: 模板变量未替换?

A:

  • 确认使用了正确的模板变量语法:{{name}}
  • 检查 document.name 是否已定义
  • 查看 Streamlit 控制台的路径解析日志

Q8: 批量处理失败?

A:

  • 检查 processor_configs.yaml 配置是否正确
  • 确保 PDF 路径正确且可访问
  • 查看日志文件定位具体错误

Q9: 列类型冲突导致差异过多?✨

A: 这是正常现象,列类型冲突会自动将差异严重度提升到 high

{
  "type": "table_text",
  "severity": "high",
  "column_type_mismatch": true,
  "description": "文本不一致 [列类型冲突]"
}

建议:

  1. 检查两个 OCR 工具的列类型检测是否准确
  2. 如果某一工具明显错误,优先使用另一工具的结果
  3. 考虑使用合并工具优化结果

📝 开发说明

扩展开发

新增 OCR 工具

  1. 在配置文件中添加工具配置
  2. merger/ 中实现合并逻辑(如需要)
  3. 更新 config/README.md 文档

自定义对比算法

from comparator.ocr_comparator import OCRResultComparator

class CustomComparator(OCRResultComparator):
    def compare_tables(self, table1, table2):
        # 自定义对比逻辑
        pass

新增渲染模式

ocr_validator_layout.py 中扩展:

def render_custom_mode(self, content):
    # 自定义渲染逻辑
    pass

📞 联系方式

🙏 致谢

感谢以下开源项目的支持:


最后更新: 2025年11月7日