Python + 超级鹰 识别图形验证码

2023-07-29,,

前言:

一、下载

1.进入官网:http://www.chaojiying.com/,注册完成后,进行登录

2.点击开发文档,点击Python语言示例

3.进行示例下载

4.解压后的文件

注:关注公众号,进行账户绑定,可获得1000题分

二、简单使用

直接上代码 (*^▽^*)

#!/usr/bin/env python
# coding:utf-8 import requests
from hashlib import md5
from PIL import Image
from PIL import ImageEnhance class Chaojiying_Client(object): def __init__(self, username, password, soft_id):
self.username = username
password = password.encode('utf8')
self.password = md5(password).hexdigest()
self.soft_id = soft_id
self.base_params = {
'user': self.username,
'pass2': self.password,
'softid': self.soft_id,
}
self.headers = {
'Connection': 'Keep-Alive',
'User-Agent': 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)',
} def PostPic(self, im, codetype):
"""
im: 图片字节
codetype: 题目类型 参考 http://www.chaojiying.com/price.html
"""
params = {
'codetype': codetype,
}
params.update(self.base_params)
files = {'userfile': ('ccc.jpg', im)}
r = requests.post('http://upload.chaojiying.net/Upload/Processing.php', data=params, files=files, headers=self.headers)
return r.json() def ReportError(self, im_id):
"""
im_id:报错题目的图片ID
"""
params = {
'id': im_id,
}
params.update(self.base_params)
r = requests.post('http://upload.chaojiying.net/Upload/ReportError.php', data=params, headers=self.headers)
return r.json()

#此部分源码没有,主要是对图片进行了处理,使识别更加准确
def rangeImage(path):
img = Image.open(path)
imgry = img.convert('L')
sharpness = ImageEnhance.Contrast(imgry)
sharp_img = sharpness.enhance(2.0)
sharp_img.save(path)
im = open(path, 'rb').read()
return im if __name__ == '__main__':
chaojiying = Chaojiying_Client('你的账号', '你的密码', '96001')
path = 'a.png'
im = Chaojiying_Client.rangeImage(path)
code = chaojiying.PostPic(im, 1902)['pic_str']
print(code)

处理前的图片

处理后的图片

识别结果

三、补充

百度AI的我也做了实验,感觉,嗯???!!!!,一般吧

from aip import AipOcr
import re
#现在百度AI官网申请人工智能接口信息
# client_id 为官网获取的AK, client_secret 为官网获取的SK
APP_ID=""
API_KEY=""
SECRET_KEY=""
client=AipOcr(APP_ID,API_KEY,SECRET_KEY) with open(r"chaojiying/889.png", "rb") as f: image=f.read() data=str(client.basicGeneral(image)).replace(" ","")
pat=re.compile(r"{'words':'(.*?')}") #得到一个json格式的内容,用正则匹配想要的信息
res=pat.findall(data)[0]
print(res)

识别的图片

识别结果

也有可能是我操作不对   ̄□ ̄||

                    to be continued...

Python + 超级鹰 识别图形验证码的相关教程结束。

《Python + 超级鹰 识别图形验证码.doc》

下载本文的Word格式文档,以方便收藏与打印。