当前位置: 首页 > news >正文

京东图标点选验证码识别代码

 

如上图所示,京东会让你根据小图中的图案,在大图中点击对应的图标。

识别代码如下:

需要两张图片,可以是原图2张,或者是截图2张。运行下面代码可以看到点击的位置。

import base64
import requests
import datetime
import numpy as np
from io import BytesIO
from PIL import Image,ImageDraw,ImageFontt1 = datetime.datetime.now()#PIL图片保存为base64编码
def PIL_base64(img, coding='utf-8'):img_format = img.formatif 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)return base64_str# 旋转图片
def rotate_img(img, angle):# 转换为有alpha层temp_img2 = img.convert('RGBA')# 旋转rot = temp_img2.rotate(-angle)# 创建一个与旋转图像大小相同的白色图像fff = Image.new('RGBA', rot.size, (255, 255, 255, 0))# 使用alpha层的rot作为掩码创建一个复合图像out = Image.composite(rot, fff, rot)# 将临时图片转换为元素图片颜色模式temp_img2 = out.convert(img.mode)return temp_img2# 加载外圈大图
img1 = Image.open(r'E:\Python\lixin_project\OpenAPI接口测试\test_img\59-1.jpg')
# 图片转base64
img1_base64 = PIL_base64(img1)
# 加载内圈小图
img2 = Image.open(r'E:\Python\lixin_project\OpenAPI接口测试\test_img\59-2.jpg')
# 图片转base64
img2_base64 = PIL_base64(img2)# 验证码识别接口
url = "https://www.detayun.cn/openapi/verify_code_identify/"
data = {# 用户的key"key":"EI4vT8UGFTXRE4hZR7cE",# 验证码类型"verify_idf_id":"59",# 外圈大图"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)# 标记识别结果
draw = ImageDraw.Draw(img1)
# 字体设置
font_type = "./msyhl.ttc"
font_size = 20
font = ImageFont.truetype(font_type, font_size)
# 获取结果列表
y = response.json()['data']['res_str']
point_list = eval(y)
# 标记点击序号
for i, point in enumerate(point_list):draw.ellipse((point[0] - 15, point[1] - 15,point[0] + 15, point[1] + 15), fill=(255, 0, 0))draw.text((point[0] - 5, point[1] - 15), str(i + 1), fill=(255, 255, 255), font=font)img1.show()

识别效果图

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


http://www.mrgr.cn/news/22775.html

相关文章:

  • JDK 家族成员 OpenKona 介绍
  • 19_单片机开发常用工具的使用
  • 技术风口 Spring Al+ChatGPT Java接入AI大模型
  • AWK进阶教程:学习如何使用AWK index函数查找子字符串!
  • vscode---snippets配置全局代码片段,快捷开发!
  • 三国地理揭秘:为何北伐之路如此艰难,为何诸葛亮无法攻克陇右小城?
  • 开敞式屋脊通风天窗,“0”差评厂房通风换气设备!
  • 祝福在茶礼丨酒茶香充满东方古韵特色的中秋礼盒,太惊艳了
  • 【进阶】Stable Diffusion 插件 Controlnet 安装使用教程(图像精准控制)
  • SpringCloud-03 LoadBalancer服务调用与负载均衡
  • Python发邮箱:如何配置SMTP服务器发邮件?
  • 网页版聊天室--自动化测试项目实战
  • 系统架构师考试学习笔记第三篇——架构设计高级知识(20)通信系统架构设计理论与实践
  • 视频加密软件哪个最好用?怎么对视频文件设置加密?公司视频文件加密的最佳选择!
  • C语言实现普通二叉树的数据结构
  • Java 设计模式-状态模式
  • 【C++】windwos下vscode多文件项目创建、编译、运行
  • 论文学习:常用的遥感参数
  • 沃尔玛活跃卖家一年内增长50%,突破15万!沃尔玛新店铺如何快速出单?
  • 攻防世界--->点燃我