使用OCR的收据和账单解析器
项目描述
receiptparser
摘要
一个用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%,但会增加扫描时间两倍。
安装
先决条件
- Python 3
- PIP3
- tesseract
通过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)
CLI使用
示例
这是一个简单的示例,用于从目录中读取所有图像(.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 格式字符串,具体请参考这里。格式字符串中可以使用以下值
- company: 识别的公司名称
- postal: 识别的公司邮政编码
- date: 识别的账单或收据日期
- 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
项目详情
下载文件
下载适用于您的平台的文件。如果您不确定选择哪一个,请了解有关 安装包 的更多信息。
源代码分发
此版本没有可用的源代码分发文件。请参阅生成分发存档的教程。
构建分发
receiptparser-1.1-py2.py3-none-any.whl (11.0 kB 查看哈希值)
关闭
receiptparser-1.1-py2.py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | f4de7ce67f8017b7cab0ed16ada44c04b2d05440a4214c6d9dc05807c63e13e1 |
|
MD5 | fd7856c78709160d14b11995287d3373 |
|
BLAKE2b-256 | 90ac6d1a6f0626dbb66027ba9832429ddfd213d535525555808264889f594b2a |