Python3图像处理之识别图像中的文字

安装PIL:pip install Pillow(之前的博客中有写过)

安装pytesser3:pip install pytesser3

安装pytesseract:pip install pytesseract

安装autopy3:

先安装wheel:pip install wheel

下载autopy3-0.51.1-cp36-cp36m-win_amd64.whl【点击打开链接

执行命令:pip install E:\360安全浏览器下载\autopy3-0.51.1-cp36-cp36m-win_amd64.whl

##注意: 使用pip install autopy3时会报错如下:

所以要下载本地安装

④安装Tesseract-OCR:百度直接搜索Tesseract-OCR下载即可

这里要说明的是安装Tesseract-OCR, 选项时候使用语言库, 安装后,其不会被默认添加至环境变量path中,已导致如下报错:

解决办法有两种:(先找到Tesseract-OCR安装文件夹,再找到tesseract.exe文件)

我这里的绝对路径是:D:\python\Tesseract-OCR\tesseract.exe

①将此路径添加至环境变量path中(不过我是这么做的,但是PyCharm仍旧报错)

②找到pytesseract.py文件

我这里是C:\Users\admin\AppData\Local\Programs\Python\Python36\Lib\site-packages\pytesseract\pytesseract.py

将文件中的tesseract_cmd修改为上方的绝对路径

进入正题,如何识别图像中文字

上原图:(这句是海上钢琴师中的一句经典台词)

  

接下来我们要通过python的pytesseract来识别图片中的字符了


#   _*_ coding:utf-8 _*_
 
import pytesseract
from PIL import Image
 
__author__ = 'admin'
 
im = Image.open(r'C:\Users\admin\Desktop\example.png')
print(pytesseract.image_to_string(im))

效果图

--------------------- 
作者:FloatDreamed 
来源:CSDN 
原文:https://blog.csdn.net/FloatDreamed/article/details/79090741 
版权声明:本文为博主原创文章,转载请附上博文链接!

猜你喜欢

转载自blog.csdn.net/h330531987/article/details/87091474
今日推荐