从发票提出内容

#! bash python 2021.07.16
#  Pyhon 练习

from wand.image import Image
from PIL import Image as PI
from pyocr import pyocr
from pyocr import builders
import io
import re
import os
import sys
import shutil
from openpyxl import Workbook

#获取桌面路径包装成一个函数


def GetDesktopPath():
    return os.path.join(os.path.expanduser("~"), 'Desktop')


path = GetDesktopPath() + r'\发票.pdf'
print(path)
tool = pyocr.get_available_tools()[0]

image_pdf = Image(filename=path, resolution=300)
image_jpeg = image_pdf.convert('jpeg')

image_lst = []
for img in image_jpeg.sequence:
    img_page = Image(image=img)
    image_lst.append(img_page.make_blob('jpeg'))

new_img = PI.open(io.BytesIO(image_lst[0]))
#new_img.show()


## 解析开头码   此部分需要自己调整,显示的是四条边围成的矩形
left = 620
top = 1785
right = 1400
bottom = 1850
image_obj1 = new_img.crop((left, top, right, bottom))
#image_obj1.show()
txt1 = tool.image_to_string(image_obj1)
print(txt1)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值