ImageMagick包括许多用于处理图像的命令行实用程序。
ImageMagick的下载地址是:
https://docs.wand-py.org/en/latest/guide/install.html#install-imagemagick-on-windows
Tesseract是一款由HP实验室开发由Google维护的开源OCR(Optical Character Recognition , 光学字符识别)引擎,与Microsoft Office Document Imaging(MODI)相比,我们可以不断地训练库,使图像转换文本的能力不断增强。如果团队深度需要,还可以以它为模板,开发出符合自身需求的OCR引擎。
tesseract-OCR的下载地址是:
https://digi.bib.uni-mannheim.de/tesseract/
安装后要配置环境变量:
源代码
1. 读取发票
ocr = CnOcr()``tool = pyocr.get_available_tools()[0]`
`img_url = "pic/fp01.jpg"``with open(img_url, 'rb') as f:` `a = f.read()``new_img = PI.open(io.BytesIO(a))``new_img.show()
2. 提取发票号码
def text1(new_img):`
`left = 1530` `top