paddleocr识别电子发票,输出到Excel, 并用tkinter显示识别后的图片及结果
Python —paddleocr Demo
#paddleocr识别电子发票,输出到Excel, 并用tkinter显示识别后的图片及结果
#由于发票数据比较机密,先随便找个新闻内容截图,识别文字看看效果,具体效果图如下!

#python -m pip install paddlepaddle -i https://mirror.baidu.com/pypi/simple
from paddleocr import PaddleOCR, draw_ocr
ocr = PaddleOCR(use_angle_cls=True,use_gpu=False)
img_path = '1.png'
result = ocr.ocr(img_path, cls=True)
# for line in result:
# print(line[1])
# 显示结果
from PIL import Image
image = Image.open(img_path).convert('RGB')
boxes = [detection[0] for line in result for detection in line]
txts = [detection[1][0] for line in result for detection in line]
scores = [detection[1][1] for line in result for detection in line]
# txts_scores = [detection[1] for line in result for detection in line]
# print(txts_scores)
im_show = draw_ocr(image, boxes, txts, scores, font_path='./fonts/simfang.ttf')
im_show = Image.fromarray(im_show)
im_show.save(img_result+'_result.jpg')
#结果图片保存在代码同级文件夹中。
import datetime
dt = datetime.datetime.now()
img_result = dt.strftime("%Y%m%d%H%M%S")
print(img_result)
#输出到Excel
import pandas as pd
df = pd.DataFrame(txts)
df.to_excel(img_result+'_result.xlsx')

#显示识别后的图片及结果
import tkinter
from PIL import Image, ImageTk
root = tkinter.Tk()
img_open = Image.open(img_result+'_result.jpg')
img_png = ImageTk.PhotoImage(img_open)
label_img = tkinter.Label(root, image = img_png)
label_img.pack()
root.mainloop()

【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 提示词工程——AI应用必不可少的技术
· 地球OL攻略 —— 某应届生求职总结
· 字符编码:从基础到乱码解决
· SpringCloud带你走进微服务的世界