|
|
1 周之前 | |
|---|---|---|
| .vscode | 2 月之前 | |
| batch_ocr | 1 周之前 | |
| comparator | 1 周之前 | |
| config | 1 周之前 | |
| image | 2 月之前 | |
| image_edit | 2 月之前 | |
| merger | 1 周之前 | |
| ocr_vlm_verify | 2 月之前 | |
| streamlit_test | 1 月之前 | |
| test | 1 月之前 | |
| .env.example | 2 月之前 | |
| README.md | 4 周之前 | |
| compare_ocr_results-算法.md | 1 月之前 | |
| compare_use_unified_diff.py | 1 月之前 | |
| config.yaml | 3 周之前 | |
| config_manager.py | 1 周之前 | |
| normalize_financial_numbers.py | 1 月之前 | |
| ocr_by_vlm.py | 1 月之前 | |
| ocr_validator_file_utils.py | 1 月之前 | |
| ocr_validator_layout.py | 1 月之前 | |
| ocr_validator_utils.py | 1 周之前 | |
| run_streamlit_validator.py | 2 月之前 | |
| streamlit_ocr_validator.py | 1 周之前 | |
| streamlit_validator_core.py | 1 周之前 | |
| streamlit_validator_cross.py | 4 周之前 | |
| streamlit_validator_result.py | 1 月之前 | |
| streamlit_validator_table.py | 1 月之前 | |
| streamlit_validator_ui.py | 1 周之前 | |
| styles.css | 2 月之前 | |
| 图片操作说明.md | 2 月之前 |
一个功能强大的 OCR 识别与验证系统,集成了多种 OCR 工具支持、智能交叉验证、可视化校验和表格数据分析功能,专为财务报表、数据表格等复杂文档设计。
table_amount)table_datetime)table_text)# 创建 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.yaml 配置数据源:
data_sources:
- name: "至远彩色_2023年报"
ocr_tool: "ppstructv3"
ocr_out_dir: "/path/to/ppstructv3/output"
src_img_dir: "/path/to/source/images"
description: "使用 PPStructV3 的识别结果"
- name: "至远彩色_2023年报"
ocr_tool: "mineru"
ocr_out_dir: "/path/to/mineru/output"
src_img_dir: "/path/to/source/images"
description: "使用 MinerU 的识别结果"
# 启动 Streamlit 应用
python -m streamlit run streamlit_ocr_validator.py
# 或使用启动脚本
python run_streamlit_validator.py
功能模块:
使用 comparator/compare_ocr_results.py 进行命令行对比:
# 基本对比
python compare_ocr_results.py file1.md file2.md
# 使用流水表格模式
python compare_ocr_results.py file1.md file2.md \
--table-mode flow_list \
--similarity-algorithm ratio \
-o output/comparison_result \
-f both
# 仅生成 JSON 报告
python compare_ocr_results.py file1.md file2.md \
-f json -o report
参数说明:
-o, --output:输出文件名(不含扩展名)-f, --format:输出格式(json、markdown、both)--table-mode:表格比对模式(standard、flow_list)--similarity-algorithm:相似度算法(ratio、partial_ratio、token_sort_ratio、token_set_ratio)--ignore-images:忽略图片内容对比使用 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 # 文件处理
├── compare_ocr_results.py # OCR 结果对比
├── normalize_financial_numbers.py # 数字标准化
├── merge_mineru_paddle_ocr.py # 合并 MinerU 和 Paddle OCR 结果
├── config.yaml # 配置文件
├── styles.css # 样式文件
├── output/ # 输出目录
│ └── pre_validation/ # 交叉验证结果
├── .streamlit/ # Streamlit 配置
│ └── config.toml # Streamlit 设置
└── README.md # 项目文档
数据源选择
批量验证
差异分析
结果展示
standard)flow_list)# 自动检测旋转角度
detection_result = detect_image_orientation_by_opencv(image_path)
# 手动调整旋转
validator.layout_manager.rotated_angle = 90 # 顺时针 90 度
# 坐标自动转换
rotated_image, rotated_bboxes = rotate_image_and_coordinates(
image, angle, coordinates_list, rotate_coordinates=True
)
{
"differences": [
{
"type": "table_amount",
"position": "第15行第5列",
"file1_value": "15.00",
"file2_value": "15,00",
"description": "金额不一致: 15.00 vs 15,00",
"severity": "medium",
"column_name": "金额",
"column_type": "numeric"
}
],
"statistics": {
"total_differences": 42,
"table_differences": 35,
"amount_differences": 8,
"datetime_differences": 3,
"text_differences": 24,
"paragraph_differences": 7,
"high_severity": 8,
"medium_severity": 20,
"low_severity": 14
}
}
# OCR结果对比报告
## 统计信息
- 总差异数量: **42**
- 表格差异: **35**
- 金额差异: **8**
- 日期差异: **3**
- 文本差异: **24**
- 段落差异: **7**
## 差异详情
| 序号 | 位置 | 类型 | 原OCR结果 | 验证结果 | 描述 |
|------|------|------|-----------|----------|------|
| 1 | 第15行第5列 | table_amount | 15.00 | 15,00 | 金额不一致 |
在 config.yaml 中配置工具参数:
ocr:
tools:
ppstructv3:
name: "PPStructV3"
json_structure: "object"
rotation:
coordinates_are_pre_rotated: true
mineru:
name: "MinerU"
json_structure: "array"
rotation:
coordinates_are_pre_rotated: false
[theme]
primaryColor = "#0288d1"
backgroundColor = "#ffffff"
secondaryBackgroundColor = "#f5f5f5"
[server]
maxUploadSize = 200
enableXsrfProtection = true
A: 检查 OCR 工具的坐标是否已预旋转,在 config.yaml 中调整 coordinates_are_pre_rotated 设置。
A: 确保两个数据源包含相同页码的文件,且文件名格式为 *_page_XXX.json。
A: 尝试切换到 flow_list 模式,或调整相似度算法参数。
ocr_validator_utils.py 中添加解析函数OCRResultComparator 类ocr_validator_layout.py 中扩展欢迎提交 Issue 和 Pull Request!
git checkout -b feature/AmazingFeature)git commit -m 'Add some AmazingFeature')git push origin feature/AmazingFeature)本项目采用 MIT 许可证。详见 LICENSE 文件。
最后更新: 2025年10月10日