根据现成的开源项目 http://code.google.com/p/pytesser/改写
在window上用easy_install安装不上 看了下源码发现代码很少 于是就想自己改写一下
添加支持网络图片的直接解析
#coding:utf-8
#import sys
#reload(sys)
#sys.setdefaultencoding('utf-8')
import subprocess,urllib2,tempfile
import os,time
tesseract_exe_name = 'tesseract' # Name of executable to be called at command line
temp_dir_name = tempfile.gettempdir() # Name of executable to be called at command line
def call_tesseract(input_filename, output_filename):
args = [tesseract_exe_name, input_filename, output_filename]
proc = subprocess.Popen(args)
retcode = proc.wait()
def image_file_to_string(filename):
image_file_path = filename
text_file_path = '%s%s%sout' %(temp_dir_name,os.path.sep,time.time())
try:
call_tesseract(image_file_path,text_file_path);
text = file(text_file_path+'.txt').read()
if text.find("Error") != -1:
text = None
return text
finally:
if(os.path.exists(text_file_path+'.txt')):
os.remove(text_file_path+'.txt')
def image_url_to_string(url):
image_file_path = '%s%s%sin' %(temp_dir_name,os.path.sep,time.time())
try:
urlinfo = urllib2.urlopen(url, None,3);
if not urlinfo.headers['Content-Type'].startswith('image'):
return None
f = open(image_file_path,'wb')
f.write(urlinfo.read())
f.close()
return image_file_to_string(image_file_path);
finally:
if(os.path.exists(image_file_path)):
os.remove(image_file_path);
print image_file_to_string('D:\\pytesser_v0.0.1\\fonts_test.png')
分享到:
相关推荐
# 打开文件夹中的图片 image=Image.open('./Img/'+str(i)+'.jpg') # 灰度图 lim=image.convert('L') # 灰度阈值设为165,低于这个值的点全部填白色 threshold=165 table=[] for j in range(256): if j<
python生成图片验证码,这里的是中文验证码,要生字母只需自己改改就可以了
python实现图片验证码及html源代码,前端从python后台获取图片base64及guid,然后通过guid与验证码到后台进行验证码,后台从sqlite数据库表中进行查找,判断验证码是否正确。
该资源为小编原创的使用Python生成随机验证码的源文件,可供学习制作python验证码的小伙伴们下载
python自动创建字符验证码,python创建验证码! python自动创建字符验证码,python创建验证码! python自动创建字符验证码,python创建验证码! python自动创建字符验证码,python创建验证码 !python自动创建字符...
python制作图片验证码(加噪)
使用python+robot framework识别图片验证码 前提:安装PIL
python识别字符验证码
python+selenium自动获取验证码,可实现自动登录功能!
利用Python生成验证码图片 代码和字体文件压缩包
(一)python爬虫验证码识别(去除干扰线)https://blog.csdn.net/weixin_40267472/article/details/81384624
python安装包-验证码识别(图片识别)包muggle-ocr的安装文件,可以直接使用pip安装。 下载之后解压缩,然后使用命令“pip install muggle-ocr-1.0.3.tar.gz -i https://pypi.douban.com/simple”,因为使用豆瓣下载...
使用Python分析图片验证码并登录
python生成汉字验证码python生成汉字验证码python生成汉字验证码python生成汉字验证码python生成汉字验证码
主要介绍了python自动化实现登录获取图片验证码功能,本文通过实例截图的形式给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下
很多小伙伴们反馈,在web自动化的过程中,经常会被登录的验证码给卡住,不知道如何去通过验证码的验证。今天专门给大家来聊聊验证码的问题,一般的情况下遇到验证码我们可以都可以找开发去帮忙解决,关闭验证码,...
网页旋转验证码识别 Python
主要介绍了使用python实现滑动验证码功能,本文通过示例代码给大家介绍的非常详细,具有一定的参考借鉴价值 ,需要的朋友可以参考下
关于Python实现短信验证码注册登录的Python - http.client.py、Python - Requests.py文件.zip
用Python编写的一个登陆验证码识别,主要用于登录时输入的验证码,需要安装类库。