使用 OCR 的收据和账单解析器
项目描述
收据解析器
概括
用 Python 编写的收据和账单解析器。可用作 Python 模块或 CLI 工具。
它最初基于receipt-parser,但实际上已被完全重写/替换。
到目前为止,仅支持德国收据,但可以使用简单的YAML 配置文件添加其他国家/地区。
识别率
为了开发这个工具,我使用了一组 182 张不同质量的收据。一些被弄皱了,大部分被折叠了,等等。这组收据的结果是:
Total: 182
Company found: 171
Postal code found: 158
Date found: 159
Amount found: 114
如果您的收据清晰、平整且对比度良好,我预计成功率将达到 97%-99%,但总金额除外,这很难正确识别。这可能接近 75%。
在适用的情况下,我选择了自动化和质量而不是性能。例如,receiptparser 对每张图像扫描两次,一次不锐化,一次锐化,这将识别率提高了 6% 左右,但扫描时间增加了一倍。
安装
先决条件
- 蟒蛇 3
- 画中画
- 正方体
通过 PIP 安装
pip3 install receiptparser
通过 Git 安装
pip3 install -r requirements.txt
pip3 install .
Python 用法
from receiptparser.config import read_config
from receiptparser.parser import process_receipt
config = read_config('my_config.yml')
receipt = process_receipt(config, "my_receipt.jpg", out_dir=None, verbosity=0)
print("Filename: ", receipt.filename)
print("Company: ", receipt.company)
print("Postal code:", receipt.postal)
print("Date: ", receipt.date)
print("Amount: ", receipt.sum)
命令行使用
例子
从目录中读取所有图像 (.jpg) 并将识别的数据打印到标准输出的简单示例:
receiptparser tests/data/germany/img/
您可以按如下方式自定义输出:
receiptparser -v0 --format "{date:%Y-%m-%d} - {company} - {postal} - {sum}.jpg" tests/data/germany/img/
在这种情况下,-v0禁止任何输出,除了您在--format FORMAT
参数中指定的内容。FORMAT 是此处指定的 Python 格式字符串。可以在格式字符串中使用以下值:
- 公司:公司的公认名称
- 邮政:公司认可的邮政编码
- 日期:票据或收据的确认日期
- sum:账单或收据的美元(或欧元,或其他货币)金额
句法
usage: receiptparser [-h] [-c CONFIG] [--config-file CONFIG_FILE] [-t TESSERACT] [-f FORMAT] [-v {0,1,2}] input
positional arguments:
input file or directory from which images will be read
optional arguments:
-h, --help show this help message and exit
-c CONFIG, --config CONFIG
built-in config to use
--config-file CONFIG_FILE
like -c, but point to a file instead
-t TESSERACT, --tesseract TESSERACT
output directory for OCR recognized text (default is to discard)
-f FORMAT, --format FORMAT
format of the recognized output. default is pretty-printing
-v {0,1,2}, --verbosity {0,1,2}
increase output verbosity
项目详情
关
收据parser-1.1- py2.py3 -none-any.whl 的哈希值
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | f4de7ce67f8017b7cab0ed16ada44c04b2d05440a4214c6d9dc05807c63e13e1 |
|
| MD5 | fd7856c78709160d14b11995287d3373 |
|
| 布莱克2-256 | 90ac6d1a6f0626dbb66027ba9832429ddfd213d535525555808264889f594b2a |