gogozz

导航

python识别图片中的代码。

 在看并发编程网的时候,有些示例代码是以图片的形式出现的,要是此时自己想复制下来的话,只能对着图片敲了,很不爽,于是搜了一下识别图片的网站,有!

把图片上传上去解析,下来txt文本,打开一看,大部分能解析出来,少部分会乱码。

于是搜到下面俩篇博客:

https://blog.csdn.net/FloatDreamed/article/details/79090741

 

https://www.cnblogs.com/jianqingwang/p/6978724.html

 

可以用Python现成的库来解决,我电脑里已经安装了Python3环境,也有pip,开搞。

①安装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

https://www.lfd.uci.edu/~gohlke/pythonlibs/#autopy,打开该链接下载对应的amd,我是64位的

执行命令:pip install E:\360安全浏览器下载\autopy3-0.51.1-cp36-cp36m-win_amd64.whl(这个路径因人而异)

⑤安装Tesseract-OCR: https://github.com/UB-Mannheim/tesseract/wiki,打开这个链接,点击 tesseract-ocr-w64-setup-v4.0.0-beta.1.20180414.exe ,32位的选w32。

安装exe ,复制tesseract-ocr所在的文件路径,添加到环境变量的path中。

cmd  tesseract -v  有信息出来就是配置环境成功。

直接上Python代码,就几行!

import pytesseract
from PIL import Image

__author__ = 'admin'

im = Image.open(r'C:\Users\zhuang\Desktop\1111.png')
print(pytesseract.image_to_string(im))

解析一看,没有任何乱码! 

posted on 2018-04-22 21:38  stfzhuang  阅读(1037)  评论(0编辑  收藏  举报