# coding:utf-8 from pytesser import * from PIL import Image def judge_s_or_f(path,name): # path为图片所在路径,name为图片的文件名 full = path + name img = Image.open(full) cropped = img.crop((919,518,1032,536)) #此处crop传入的参数为一个元组:需要裁剪图片的左上右下坐标,可以打开画图查看 new_Image_Path = path+"1_"+name cropped.save(new_Image_Path) im = Image.open(new_Image_Path) text = image_to_string(im) return text a = "E:\screen\screen\\" n = "100000000010.png_1.jpg" print judge_s_or_f(a,n)
此处为python2代码,python3注意下print格式,以及python3没有PIL库,需要
pip install Pillow #安装库
关于pytesser,这是一个图片识别软件,我传微云了https://share.weiyun.com/5ewVhQ3
下载解压后,复制到F:\Python27\Lib\site-packages\pytesser_v0.0.1目录下
复制一份到F:\Python27\Lib\site-packages目录下(具体哪个生效的我也没研究2333),
在F:\Python27\Lib\site-packages目录下新建一个文件pytesser_v0.0.1.pth,文件内容为pytesser_v0.0.1
然后把F:\Python27\Lib\site-packages和F:\Python27\Lib\site-packages\pytesser_v0.0.1都加入环境变量就ok了