Python2图像文本识别

原文地址:http://www.cnblogs.com/tanghuang/p/6380588.html

适用版本:python2以下

将图片中的数字通过 pytesseract.image_to_string(image)识别后将结果存入到本地的txt文件中
复制代码
 1 #-*-encoding:utf-8-*-
 2 import pytesseract
 3 from PIL import Image
 4 
 5 class GetImageDate(object):
 6     def m(self):
 7         image = Image.open(u"C:\\a.png")
 8         text = pytesseract.image_to_string(image)
 9         return text
10 
11     def SaveResultToDocument(self):
12         text = self.m()
13         f = open(u"C:\\Verification.txt","w")
14         print text
15         f.write(str(text))
16         f.close()
17 
18 g = GetImageDate()
19 g.SaveResultToDocument()
复制代码
 
 
posted @ 2017-09-05 11:18  沐风麟  阅读(548)  评论(0编辑  收藏  举报