Python学习笔记--Python 爬虫入门 -17-11 tesseract-OCR

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u013985879/article/details/82598127

一.Tesseract 安装教程请参考:

https://jingyan.baidu.com/article/219f4bf788addfde442d38fe.html

这里说明两点关于配置环境变量的地方:

1.1在环境变量PATH,把tesseract-ocr的安装路径添加进去。

D:\softWare\tesseract\Tesseract-OCR

注意,添加时候开头用“;”跟之前的变量隔开,结尾以“;”结尾。

2.在环境变量中,增加一个TESSDATA_PREFIX变量名,

变量值tessdata的安装路径

D:\softWare\tesseract\Tesseract-OCR\tessdata

然后DOS 窗口下,输入 tesseract 显示如下表明安装成功

扫描二维码关注公众号,回复: 3352765 查看本文章

二.安装Pillow   pip install Pillow

三.安装pytesseract  pip install pytesseract

四.使用:

注意:改变环境变量需要重新打开powershell

输入: 

tesseract bigdata.jpg 2 -l chi_sim

bigdata.jpg是当前目录中的bigdata.jpg图片

2 是指定结果输出到文本文件,默认txt后缀

-l是指定使用的包

chi_sim是中文识别包

五.代码

import  pytesseract as pt
from  PIL import  Image
#指定tesseract 地址
pt.pytesseract.tesseract_cmd=r"D:\softWare\tesseract\Tesseract-OCR\tesseract.exe"
image = Image.open(r"C:\Users\Dream\Pictures\wyy1.png")
print(type(image))
print(image)

text = pt.image_to_string(image)
# text = pt.image_to_data(image)
print(text)

猜你喜欢

转载自blog.csdn.net/u013985879/article/details/82598127