网易易盾图标点选验证码识别代码

简介

网易图标点选一直都是一个大难题,如上图所示。难点之一是图标变幻莫测,很难刷出有重复的图标,所以使用传统等等方式去标注、识别具有较大的难度。

经过我们大量的数据标注,终于完成了这款验证码的识别。

目前我们提供两种识别方:原图识别、截图识别。

1.1原图识别

需要通过图片链接下载原图如下,他的点击区大图和点击顺序小图在同一张图片中。点击的顺序是最下面小图区域第一行。

1.2原图识别代码

代码识别后最终返回的是点击坐标,大家可以根据坐标自由发挥。

python 复制代码
import base64
import requests
import datetime
from io import BytesIO
from PIL import Image, ImageDraw

t1 = datetime.datetime.now()

#PIL图片保存为base64编码
def PIL_base64(img, coding='utf-8'):
    img_format = img.format
    if img_format == None:
        img_format = 'JPEG'

    format_str = 'JPEG'
    if 'png' == img_format.lower():
        format_str = 'PNG'
    if 'gif' == img_format.lower():
        format_str = 'gif'

    if img.mode == "P":
        img = img.convert('RGB')
    if img.mode == "RGBA":
        format_str = 'PNG'
        img_format = 'PNG'

    output_buffer = BytesIO()
    # img.save(output_buffer, format=format_str)
    img.save(output_buffer, quality=100, format=format_str)
    byte_data = output_buffer.getvalue()
    base64_str = 'data:image/' + img_format.lower() + ';base64,' + base64.b64encode(byte_data).decode(coding)
    # base64_str = base64.b64encode(byte_data).decode(coding)

    return base64_str

# 加载图片
img1 = Image.open(r'E:\Python\lixin_project\OpenAPI接口测试\test_img\54-3.jpg')
# 图片转base64
img1_base64 = PIL_base64(img1)

# 验证码识别接口
url = "http://www.detayun.cn/openapi/verify_code_identify/"
data = {
    # 用户的key
    "key":"78t9jTqCbAnHFO0tbBDW",
    # 验证码类型
    "verify_idf_id":"54",
    # 点击区大图
    "img1":img1_base64,
    # 点击顺序小图
    "img2":"",
}
header = {"Content-Type": "application/json"}

# 发送请求调用接口
response = requests.post(url=url, json=data, headers=header)

# 获取响应数据,识别结果
print(response.text)
print("耗时:", datetime.datetime.now() - t1)

2.1截图识别

需要截取点击区大图,点击顺序小图两张,如下图所示

2.2截图识别代码

截图识别通用性更好,可以扩展到同类型所有验证码。代码识别后最终返回的是点击坐标,大家可以根据坐标自由发挥。一定要注意两张图片的顺序,不能反。

python 复制代码
import base64
import requests
import datetime
from io import BytesIO
from PIL import Image, ImageDraw

t1 = datetime.datetime.now()

#PIL图片保存为base64编码
def PIL_base64(img, coding='utf-8'):
    img_format = img.format
    if img_format == None:
        img_format = 'JPEG'

    format_str = 'JPEG'
    if 'png' == img_format.lower():
        format_str = 'PNG'
    if 'gif' == img_format.lower():
        format_str = 'gif'

    if img.mode == "P":
        img = img.convert('RGB')
    if img.mode == "RGBA":
        format_str = 'PNG'
        img_format = 'PNG'

    output_buffer = BytesIO()
    # img.save(output_buffer, format=format_str)
    img.save(output_buffer, quality=100, format=format_str)
    byte_data = output_buffer.getvalue()
    base64_str = 'data:image/' + img_format.lower() + ';base64,' + base64.b64encode(byte_data).decode(coding)
    # base64_str = base64.b64encode(byte_data).decode(coding)

    return base64_str

# 加载点击区大图
img1 = Image.open(r'E:\Python\lixin_project\OpenAPI接口测试\test_img\54-1.jpg')
# 图片转base64
img1_base64 = PIL_base64(img1)
# 加载点击顺序小图
img2 = Image.open(r'E:\Python\lixin_project\OpenAPI接口测试\test_img\54-2.jpg')
# 图片转base64
img2_base64 = PIL_base64(img1)

# 验证码识别接口
url = "http://www.detayun.cn/openapi/verify_code_identify/"
data = {
    # 用户的key
    "key":"78t9jTqCbAnHFO0tbBDW",
    # 验证码类型
    "verify_idf_id":"54",
    # 点击区大图
    "img1":img1_base64,
    # 点击顺序小图
    "img2":img2_base64,
}
header = {"Content-Type": "application/json"}

# 发送请求调用接口
response = requests.post(url=url, json=data, headers=header)

# 获取响应数据,识别结果
print(response.text)
print("耗时:", datetime.datetime.now() - t1)

想了解更多验证码识别,请访问:得塔云

相关推荐
ZHOU_WUYI几秒前
旋转位置编码 (2)
pytorch·python·深度学习
qq_273900234 分钟前
AF3 squeeze_features函数解读
人工智能·pytorch·深度学习·生物信息学
程序员~小强20 分钟前
让知识触手可及!基于Neo4j的机械设备知识图谱问答系统
人工智能·python·django·知识图谱·neo4j
DanCheng-studio33 分钟前
智科 机器学习毕业设计题目指导
python·毕业设计·毕设
ZhuBin36538 分钟前
推测gpt4o视觉皮层建立的过程
人工智能·深度学习·计算机视觉
大数据追光猿41 分钟前
Qwen 模型与 LlamaFactory 结合训练详细步骤教程
大数据·人工智能·深度学习·计算机视觉·语言模型
何仙鸟1 小时前
深度学习网格搜索实战
人工智能·深度学习
java1234_小锋1 小时前
一周学会Flask3 Python Web开发-SQLAlchemy定义数据库模型
python·flask·sqlalchemy·flask3
Light601 小时前
CSnakes vs Python.NET:跨语言集成的巅峰对决与架构解密
python·性能优化·.net·跨语言集成·双向互操作
王国强20092 小时前
现代循环神经网络3-深度循环神经网络
深度学习