1 line of Python code, recognize the invoice and save it in Excel, let's know about smart office?

Hello everyone, this is the programmer Wan Feng, the whole network is called this name~

Last time I shared with you: "One line of Python code to realize value-added tax invoice recognition" . (PS: Google the title in the title of this book, and you can see the corresponding video tutorial~)

At the beginning of that video, the content of this article was also previewed: write the recognized invoice content into Excel files by category.

Let's take a look today!

1. First upload the code

To identify the invoice and write the AI ​​function, a third-party library of python is called: poocr .

Go directly to the code, see here, remind students who have not installed Python, you can take a look at the full set of free tutorials on my homepage, and follow me to download and install Python for free.

# 安装这个库
pip install poocr

(Swipe left and right to view all)

# 运行这个库
import poocr

# 1行代码,完成识别发票 + 导入Excel
poocr.ocr2excel.VatInvoiceOCR2Excel(intput_path=r'C:\程序员晚枫的文件夹\增值税发票-test.jpg',
                                    output_excel='程序员晚枫的发票信息.xlsx',
                                    configPath=r'D:\程序员晚枫的配置文件夹\py310\potencent-test\poocr-config.toml'
                                    )

The result of the operation is as follows:

2. Code Description

poocrIt is a python third-party library with ocr function, which supports text recognition in more than 100 scenarios, such as invoices, driver's licenses, ID cards, etc.

The underlying implementation is the AI ​​function provided by Tencent, and configPaththe id and key of Tencent AI need to be configured, as shown in the following code. (Swipe left and right to view all)

# 文件名:poocr-config.toml
[tencent-ai]
TENCENTCLOUD_SECRET_ID = 'AKIDX7d3CFCBlLtxIdxGWls8RmAsUCrBoP6p'     # 获取可参考 https://cloud.tencent.com/act/cps/redirect?redirect=36394&cps_key=ca76be5a2293ba3906d6d5407aea15ee
TENCENTCLOUD_SECRET_KEY = 'EUlBfBd9HPTRYfgdVPOKG7yjO2gQwgEp'   # 获取可参考 https://cloud.tencent.com/act/cps/redirect?redirect=36394&cps_key=ca76be5a2293ba3906d6d5407aea15ee


Guess you like

Origin blog.csdn.net/weixin_42321517/article/details/129775307