#! 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)
从发票提出内容
最新推荐文章于 2025-04-10 18:04:34 发布