当咱们在使用pytesseract库的时候,使用 pip install pytesseract安装完成后,发现它并不能识别出图片内容,而且会抛出异常pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it's not in your PATH. See README file for more information.
这是怎么回事呢?今天让咱们一探究竟
python
尝试
使用代码git
import pytesseract from PIL import Image image = Image.open("./NormalImg.png") text = pytesseract.image_to_string(image) print(text)
报错提示:github
raise TesseractNotFoundError() pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it's not in your PATH. See README file for more information.
官方文档
pytesseract官方文档:https://pypi.org/project/pytesseract/shell
是咱们缺乏了tesseract程序url
tesseract官方Github地址:https://github.com/UB-Mannheim/tesseractspa
tesseract官方Github说明https://github.com/UB-Mannheim/tesseract/wiki.net
安装tesseract
下载地址code
Tesseract 5.0.0 32位版本:tesseract-ocr-w32-setup-v5.0.0-alpha.20200328.exe (32 bit)orm
Tesseract 5.0.0 64位版本:tesseract-ocr-w64-setup-v5.0.0-alpha.20200328.exe (64 bit)图片
新增百度云盘连接:
连接:https://pan.baidu.com/s/1EO5tFmzn1hqY_M679eSBnw
提取码:nyw4
导入tesseract.exe执行文件地址
添加如下导入路径:
pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'
最终代码:
import pytesseract from PIL import Image pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe' image = Image.open("./NormalImg.png") text = pytesseract.image_to_string(image) print(text)
至此运行代码不会异常,并能够正常读取图片文字内容
总结
pytesseract包依赖于Tesseract执行文件,须要安装Tesseract
固然Tesseract只能识别标准的ASCII字符串,复杂的验证吗就没法使用pytesseract来读取了
欢迎来跟博主讨论Python有关的问题。