pytesseract安装与基本使用

简介

Tesseract是一个光学字符识别引擎,支持多种操作系统。Tesseract是基于Apache许可证的自由软件,自2006 年起由Google赞助开发,被认为是最精准的开源光学字符识别引擎之一。

安装

第一步:下载软件

链接:https://digi.bib.uni-mannheim.de/tesseract/

我选的是tesseract-ocr-setup-3.05.01.exe这个版本
然后下载安装

第二步:设置环境变量

系统变量里加入tesseract-ocr的路径
pytesseract安装与基本使用_第1张图片
然后添加一个系统变量
pytesseract安装与基本使用_第2张图片

pytesseract安装与基本使用_第3张图片

第三步:安装pytesseract模块

直接pip就行了

pip  install pytesseract

注意事项

有时候设置了环境变量还是会显示找不到系统的环境变量 这时候就重启一下IDE,还有这个软件对一些有干扰的支持效果不是很好,最好识别一些白底黑字,这些比较容易识别。

基本使用

import pytesseract
from PIL import Image

pytesseract.pytesseract.tesseract_cmd = r'D:\tesseract-ocr\tesseract.exe '  # 执行的路径
image = Image.open('images/6.png')  # 识别的图片路径
text = pytesseract.image_to_string(image)  # 转换成文本
print(text)

运行结果
pytesseract安装与基本使用_第4张图片
可以看到基本能识别成功 但是有一些还是没识别出来。。

你可能感兴趣的:(python爬虫)