随笔 - 2  文章 - 0  评论 - 0  阅读 - 8396

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()
 

 

posted on   FTD_chen  阅读(1388)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 提示词工程——AI应用必不可少的技术
· 地球OL攻略 —— 某应届生求职总结
· 字符编码:从基础到乱码解决
· SpringCloud带你走进微服务的世界
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示