python识别图片1

操作系统win7 64位为例  python 3.5.4

一、安装

pip install Pillow

pip install pytesseract

官网下载tesseract-ocr(4.0),支持语言包搁:D:\worksoftware\Tesseract-OCR\tessdata目录下。

ps:tesseract --list-langs  查看支持语言包。

二、环境配置

Path                                            D:\worksoftware\Tesseract-OCR;

TESSDATA_PREFIX                     D:\worksoftware\Tesseract-OCR\tessdata

修改D:\worksoftware\python3.5.4\Lib\site-packages\pytesseract下pytesseract.py文件,指定tesseract.exe安装路径:

tesseract_cmd ='D:/worksoftware/Tesseract-OCR/tesseract.exe'

三、利用python识别简单图片

1、数字识别

# coding = utf-8
#作者:陆四爷
#创建时间:20180822

from PIL import Image
import pytesseract
img = Image.open('1.png')
text = pytesseract.image_to_string(img)
print (text)

2、中文识别

# coding = utf-8
#作者:陆四爷
#创建时间:20180822
from PIL import Image
import pytesseract
img = Image.open('5.png')
text = pytesseract.image_to_string((img),lang='chi_sim')
print (text)

识别结果:

总结:利用python图像扩展库可以识别简单的图片。这里只作简单识别,遇到复杂点的图像还是会识别不出或者识别错误,优化识别效率在:python识别图片2再做讨论。

猜你喜欢

转载自blog.csdn.net/lusainan_testgirl/article/details/81946643