概述
这是一篇硬广告软文了,首先我们来康康这个验证码:
特点: 字体多,干扰线,小字符干扰,旋转,不少文字和背景颜色接近
生成样本
我生成的:
真实切割:
就这样生成了30w左右:
大概使用了8种字体,部分字体通过手动修改加粗样式,字符集无脑采用5.7k汉字。
然后无脑使用(https://github.com/kerlomz/captcha_trainer)训练
得到模型,部署
效果
通过对接官网实测75左右识别率,单字识别率在90+。
验证码校验源码,基于(https://github.com/kerlomz/captcha_spider)
from utils import Project, ServiceType
from constants import ProxyType
class BaiduKuaiZhao(Project):
def __init__(self):
super().__init__()
self.service_type = ServiceType.OD
self.delay = 2
# self.need_identify = False
self.feedback_url = "http://help.baidu.com/toususubmit"
self.before_url = "http://help.baidu.com/newadd?prod_id=1&category=1"
self.captcha_url = "http://help.baidu.com/getcodeimage?{}"
self.captcha_text_url = "http://help.baidu.com/getcodetext"
def before_process(self) -> dict:
r = self.session.get(self.before_url, timeout=30)
r.encoding = "utf8"
html = Project.Parser(r.text)
submit_token = html.input("submit_token")
if not submit_token:
print('error')
return {"submit_token": submit_token}
def captcha_process(self) -> bytes:
# self.session.headers.update({"Referer": "http://help.baidu.com/webmaster/"})
r = self.session.get(self.captcha_url)
need_text = self.session.get(self.captcha_text_url.format(self.random), timeout=30)
if not need_text.text.strip():
print('标题获取失败')
return b''
need_text = need_text.json()
self.before_params.update({"param_key": "".join(need_text)})
return r.content
def feedback_process(self, captcha_text: dict) -> bool:
items = captcha_text.get('items')
coord0 = items[0]['coord']
coord1 = items[1]['coord']
coord2 = items[2]['coord']
payload = {
"submit_token": self.before_params['submit_token'],
"os_info": "Windows NT 4.0",
"browser_info": "chrome 84",
"pid": "1",
"category_id": "1",
"title": "u5febu7167u5220u9664u4e0eu66f4u65b0",
"content": "u5febu7167u5220u9664u4e0eu66f4u65b0",
"webmaster_type": "u641cu7d22u5185u5bb9u548cu5b9eu9645u4e0du4e00u81f4",
"links[]": "http://cache.baiducontent.com/c?m=9f65cb4a8c8507ed19fa950d100b8738440197634b86914323c3933fcf331d5c0425f4bc5324130ed8c27f6c03b21a1cacab672c601e76e0dd9bd3149ca6912a2d8b2030731c8255578e59f9c45154c537e75efedf68f0c9f12592dec5a5dc4324c144737e97838d4d0164dd1ef0034693&p=cb759a46d7c159fc57efcd605753c1&newp=836cc54ad5c243e019bac7710f528d231610db2151d7d4106b82c825d7331b001c3bbfb423281704d7c27a630bad4e5fe0fb31703d0923a3dda5c91d9fb4c57479c76663&s=8f14e45fceea167a&user=baidu&fm=sc&query=%C6%E6%BC%A3%D1%E9%D6%A4%C2%EB&qid=813a5910002b39e5&p1=1",
"verify_code[0][x]": coord0[0],
"verify_code[0][y]": coord0[1],
"verify_code[1][x]": coord1[0],
"verify_code[1][y]": coord1[1],
"verify_code[2][x]": coord2[0],
"verify_code[2][y]": coord2[1]
}
r = self.session.post(self.feedback_url, data=payload, timeout=30)
result = r.json().get('errmsg')
if "反馈成功" in result or "请不要针对同一问题重复进行举报" in result:
return True
else:
return False
服务端截图:
CPU识别总耗时在40-50ms左右,目标检测10ms左右。
作者QQ:27009583
顺便提一句,要Pytorch版识别的可以去 lengyue.video 学习