rapidocr-invoice
Installation
Review the source and dependencies with a prompt. A package is available to download.
Install with an AI assistant
Copy the prompt so your assistant can review the pinned revision and dependencies first.
View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "rapidocr-invoice" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-e91328f7b6dfdcbb5ecc4b0cabbd83661c6365d3545a564ea6e959067ae4cbce. Verify the upstream source and version against https://skillhub.cn/skills/user_535eed5d/rapidocr-invoice before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.
Source and setup
skillhub.cn
Setup guidance pending
See the original source for supported tools, dependencies, and permissions.
Installation test pending
Invoice OCR: A pure-CPU OCR skill based on RapidOCR (ONNX Runtime) for recognizing electronic invoices and scanned paper VAT special/regular invoices, extracting key fields (total amount including tax, invoice number, issue date, etc.). Suitable for batch extraction of invoice amounts from docx/pdf, digitizing receipts, and automating bookkeeping or expense audit workflows. Use when you need OCR on invoice/receipt images and field extraction.
Introduction source: third_party · user_535eed5d · 1.0.0 Reference
SkillPi interpretation
- Tasks
- Translation pending; see source documentation.
- Audience
- Translation pending; see source documentation.
- Inputs and outputs
- Not specified in the source documentation.
- Software, accounts and paid services
- Not specified in the source documentation.
- Limits and differences
- Not specified in the source documentation.
- Testing
- Not tested
Browse files
Frontmatter
name: rapidocr-invoice
slug: rapidocr-invoice
version: 1.0.0
displayName: "RapidOCR 发票票据识别"
summary: "基于 RapidOCR 引擎,纯 CPU 批量识别发票图片金额,支持从 Word 文档提取发票并按客户汇总生成 Excel 报表。"
description: "OCR 识别发票/票据图片并提取关键字段(价税合计金额、发票号码、开票日期等)。基于 RapidOCR (ONNX Runtime) 引擎,纯 CPU 运行,支持电子发票(数电票)和纸质增值税专用/普通发票扫描件。适用于从 docx/pdf 文档批量提取发票金额、记账凭证数字化、票据信息自动录入、财务报销审核等场景。This skill should be used when users need to OCR invoice or receipt images, extract amounts from invoices, batch process invoice images embedded in Word/PDF documents, digitize paper invoices, or automate bookkeeping and accounting data entry."
tags:
- OCR
- 发票识别
- 金额提取
- RapidOCR
- 财务自动化
- 票据数字化
- 发票汇总
- 增值税发票
- 电子发票
license: MIT
agent_created: trueRapidOCR 发票票据识别技能
概述
使用 RapidOCR (rapidocr-onnxruntime) 引擎对发票/票据图片进行 OCR 识别,提取关键字段:价税合计金额、发票号码、开票日期、销售方/购买方名称等。支持电子发票(数电票 PNG)和纸质增值税专用/普通发票扫描件(JPEG/PNG),纯 CPU 运行,无需 GPU。
核心能力
- 批量 OCR 识别:支持单张或目录批量处理发票图片
- 智能金额提取:自动定位"价税合计(小写)"行,提取金额并交叉验证
- 文档图片提取:从 docx 文档中提取嵌入的发票图片,按段落上下文建立客户-发票对应关系
- 重复引用检测:检测同一图片在文档中被多次引用的情况,按实际引用次数累计金额
- 交叉验证机制:通过"金额 + 税额 = 价税合计"和大写金额双重校验,自动发现 OCR 丢字问题
- Excel 报表生成:一键生成包含汇总表和明细表的标准 Excel 报表
技术特性
| 特性 | 说明 |
|---|---|
| OCR 引擎 | RapidOCR (ONNX Runtime),中文识别准确率高 |
| 运行环境 | 纯 CPU,无需 GPU,普通 2 核服务器即可运行 |
| 模型体积 | 约 15MB,首次加载后毫秒级响应 |
| 支持发票类型 | 电子发票(数电票)、增值税专用发票、增值税普通发票 |
| 提取字段 | 价税合计金额、发票号码、开票日期、销售方/购买方、税额等 |
| 输出格式 | JSON 结构化数据、Excel 汇总报表 |
适用场景
- 企业财务:从合同文档中批量提取发票金额,按客户/供应商汇总统计
- 记账软件:发票图片自动识别并录入金额、发票号等字段,替代手工录入
- 报销审核:批量扫描报销发票,自动提取金额并校验合理性
- 税务合规:发票信息数字化归档,便于查询和审计
- 数据分析:将纸质票据转化为结构化数据,支持后续财务分析
环境安装
前置条件
- Python 3.10+
- 操作系统:Windows / Linux / macOS
创建独立 OCR 虚拟环境
建议在独立 venv 中安装,避免依赖冲突:
# 创建 venv
python -m venv ocr_env
# 激活(Windows)
ocr_env\Scripts\activate
# 激活(Linux/macOS)
source ocr_env/bin/activate
# 安装依赖
pip install rapidocr-onnxruntime Pillow openpyxl
验证安装:
python -c "from rapidocr_onnxruntime import RapidOCR; engine = RapidOCR(); print('OCR engine ready')"
使用流程
第一步:从 docx 文档提取发票图片(可选)
当发票图片嵌入在 Word 文档中时,使用 scripts/extract_docx_images.py 提取图片并建立上下文对应关系:
python scripts/extract_docx_images.py <docx文件路径> [--output <输出目录>]
该脚本会:
- 解压 docx(本质为 ZIP),提取
word/media/下所有图片 - 解析
word/document.xml和word/_rels/document.xml.rels - 按文档段落顺序建立图片与上下文文字(如客户名称)的对应关系
- 自动区分 JPEG(通常为合同/证明材料)和 PNG(通常为电子发票)
- 检测同一图片在文档中被多次引用的情况(同一 rId 出现多次 blip 引用),不去重
第二步:OCR 识别并提取金额
使用 scripts/ocr_invoices.py 进行批量 OCR 识别和金额提取:
python scripts/ocr_invoices.py <图片目录或文件> [--output <结果JSON路径>] [--scale 1.5] [--contrast 1.5]
参数说明:
--scale:图片放大倍数(默认 1.5,提高小字识别率)--contrast:对比度增强系数(默认 1.5)--output:结果输出 JSON 文件路径
输出 JSON 格式:
[
{
"image": "image5.png",
"amount": 131741.27,
"invoice_number": "25442000000012345678",
"date": "2024-03-15",
"raw_text": "..."
}
]
第三步:金额交叉验证(可选)
使用 scripts/verify_amounts.py 验证 OCR 结果准确性:
python scripts/verify_amounts.py <OCR结果JSON路径> [--output <验证报告路径>]
验证逻辑:
- 金额(不含税)+ 税额 = 价税合计 → 等式成立则通过
- 大写金额反推数字金额 → 与 OCR 识别金额比对
- 标记验证失败的记录,提示人工复核
金额提取规则
中国发票的"价税合计(小写)"金额提取遵循以下优先级规则:
- 首选规则:查找包含"价税合计"且包含"小写"的行,在其后 3 行范围内匹配
(小写)¥XXX,XXX.XX格式 - 备选规则 1:匹配
¥后跟数字(含千分位逗号)的金额 - 备选规则 2:取文本中所有 ¥ 金额的最大值(适用于发票总额最大的场景)
- 交叉验证:当金额 + 税额可计算时,验证等式
金额(不含税) + 税额 = 价税合计,用于发现 OCR 丢字问题
常见问题与处理
OCR 识别金额丢失首位数字
电子发票中"(小写)"后的金额可能因字体渲染问题导致首位数字丢失(如 66854.00 识别为 6854.00)。
解决方案:
- 交叉验证:
金额(不含税) + 税额 = 价税合计,若等式不成立则 OCR 结果可能有误 - 大写金额验证:OCR 同时识别"价税合计(大写)"行,通过大写金额反推数字金额
- 图片放大:使用
--scale 2.0放大图片后重新 OCR
文档中同一图片被多次引用
Word 文档中同一张图片可能被插入多次(document.xml 中同一 rId 出现多次 blip 引用)。处理时需注意:
- 解析 XML 时不要去重 blip 引用,按实际出现次数计数
- 同一图片文件出现 N 次,金额应累计 N 次
电子发票 vs 纸质发票金额行位置不同
- 电子发票(PNG,如数电票):"价税合计"行通常在图片高度的 52%-66% 区域
- 纸质发票扫描件(JPEG/PNG):"价税合计"行通常在图片高度的 70%-82% 区域
批量处理时可采用双区域裁剪策略,同时截取两个候选区域拼接后 OCR。
参考文档
references/invoice_formats.md:中国发票格式说明、OCR 金额提取正则表达式、常见字段定位参考references/integration_guide.md:将 RapidOCR 嵌入到应用(小程序后端、桌面工具、Web 服务)的集成方案
脚本清单
| 脚本 | 功能 |
|---|---|
scripts/extract_docx_images.py |
从 docx 文档提取图片并建立客户-发票映射 |
scripts/ocr_invoices.py |
批量 OCR 识别发票图片,提取金额等关键字段 |
scripts/verify_amounts.py |
金额交叉验证(金额+税额=价税合计) |
Current listing version
1.0.0
Safety and assessment details
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Highlights
- 解决企业财务、记账、报销审核等高频刚需场景
- 支持批量处理发票图片和从 Word 文档提取发票
- 提供完整的 OCR 识别、金额提取、交叉验证和 Excel 报表生成闭环
Highlights
- 触发场景描述完整,覆盖 OCR 发票、提取金额、批量处理、数字化等多种变体
- 中英文双语描述,边界清晰,不易误触或漏触
Areas to improve
-
缺少显式 When to Use 章节 Reported severity: Minor
文档结构完整,但缺少显式的 'When to Use' 章节标题,尽管 description 中已包含使用场景描述。
Recommendation: 建议在概述部分增加显式的 'When to Use' 章节,提升用户查找效率。
Highlights
- 文档结构清晰,包含概述、核心能力、技术特性、适用场景、环境安装、使用流程等完整章节
- 提供端到端使用示例和参数说明,frontmatter 完整规范
Areas to improve
-
脚本错误处理说明不足 Reported severity: Minor
脚本功能描述详细,但缺少对文件不存在、权限问题、依赖安装失败等常见运行时异常的处理说明。
Recommendation: 建议在脚本使用说明中增加错误处理建议,如文件路径校验、依赖安装验证等。
Highlights
- 工具来源明确(rapidocr-onnxruntime、Pillow、openpyxl),参数说明清晰
- 具备交叉验证机制(金额+税额=价税合计)和重复引用检测,提升结果可靠性
The arithmetic mean of the first four original scores, rounded to a whole number.
Static text checks
100 / 100 · skillpi-20261123-no-r3-v1
No current rules matched the text.
This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.
Permissions and checks before use
Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.
-
Install or fetch external dependencies
Use official sources and pin versions. Check install scripts in an isolated environment. This document check does not cover code downloaded later.
Mentioned in main document · lines 77
Security rating and access scope
safe · Static evidence review; not a runtime safety guarantee.
Not specified in the source documentation.
Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.
User discussion
No verified reviews yet.