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

滑块拼图验证码识别

通常滑块验证码都是横向滑动,今天看到一个比较特别的滑块拼图验证码,他不仅能在横向上滑动,还需要进行纵向滑动。如下图所示:

他的滑块在背景图片的左上角,需要鼠标拖动左上角的滑块,移动到背景图的缺口位置拼好。

首先会识别滑块左上角的坐标,然后识别缺口左上角的坐标。然后他们两个相减,就是x,y方向上的滑动距离

识别代码如下:

import base64
import requests
import datetime
from io import BytesIO
from PIL import Image, ImageDrawt1 = 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)# base64_str = base64.b64encode(byte_data).decode(coding)return base64_str# 加载图片
img1 = Image.open(r'E:\Python\lixin_project\OpenAPI接口测试\test_img\53-1.png')
# 图片转base64
img1_base64 = PIL_base64(img1)# 验证码识别接口
url = "http://www.detayun.cn/openapi/verify_code_identify/"
data = {# 用户的key"key":"78t9jTqCbAnHFO0tbBDW",# 验证码类型"verify_idf_id":"53",# 样例图片"img_base64":img1_base64,
}
header = {"Content-Type": "application/json"}# 发送请求调用接口
response = requests.post(url=url, json=data, headers=header)# 获取响应数据,识别结果
print(response.text)
print("耗时:", datetime.datetime.now() - t1)# 获取识别距离
point = eval(response.json()['data']['res_str'])
img1 = img1.convert("RGB")
draw = ImageDraw.Draw(img1)
x = point[0]
y = point[1]
draw.line((x, 0, x, img1.size[1]), fill=(255, 0, 0), width=2)  # 线的起点和终点,线宽
draw.line((0, y, img1.size[0], y), fill=(255, 0, 0), width=2)  # 线的起点和终点,线宽
img1.show()

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

http://www.lryc.cn/news/400121.html

相关文章:

  • Activity启动流程
  • PHP转Go系列 | ThinkPHP与Gin框架之OpenApi授权设计实践
  • 使用SOAP与TrinityCore交互(待定)
  • QQ频道导航退出
  • MySQL里的累计求和
  • Python爬虫速成之路(3):下载图片
  • 同三维T80004EA编解码器视频使用操作说明书:高清HDMI编解码器,高清SDI编解码器,4K超清HDMI编解码器,双路4K超高清编解码器
  • ChatGPT提问获取高质量答案的艺术PDF下载书籍推荐分享
  • 微信小程序中的数据通信
  • everything搜索不到任何文件-设置
  • python如何结束程序运行
  • InnoDB
  • spark运行报错:Container killed by YARN for exceeding memory limits
  • (三)大模型/人工智能/机器学习/深度学习/NLP
  • 数学基础 -- 三角学
  • 基于BitMap的工作日间隔计算
  • sqlite3 — DB-API 2.0 interface for SQLite databases
  • Spring Boot中的安全配置与实现
  • DepthAnything(2): 基于ONNXRuntime在ARM(aarch64)平台部署DepthAnything
  • JAVA简单封装UserUtil
  • 【TOOLS】Chrome扩展开发
  • 分享WPF的UI开源库
  • [ACM独立出版]2024年虚拟现实、图像和信号处理国际学术会议(ICVISP 2024)
  • JVM:类加载器
  • 支持向量机 (support vector machine,SVM)
  • 宝塔面板以www用户运行composer
  • 昇思25天打卡营-mindspore-ML- Day24-基于 MindSpore 实现 BERT 对话情绪识别
  • 【精品资料】模块化数据中心解决方案(33页PPT)
  • N6 word2vec文本分类
  • excel、word、ppt 下载安装步骤整理