阿里图像复原验证码识别 一、简介这个就是阿里的图像还原验证码他是从一个图片中任意抠出一个物品可能是蜡烛、车轮、盘子、瓶子、盖子、扣子等等。然后让你通过鼠标拖动的方式把物品拖到对应的位置上完成图像复原验证。这个验证码还有一个非常变态的地方就是他的滑动轨迹的变速的。在x方向上的速度并不是匀速滑动是忽快忽慢难以捉摸。所有导致滑动100像素距离实际上滑块并不一定滑动100像素距离有可能大于100像素也有可能小于100像素的任意值。因为上面两个原因导致这款验证码的识别难度非常大上升到了一个新的阶段。经过我们不断努力这块验证码也被我们成功攻克识别正确率能到几乎100%二、识别代码1、原图识别简介原图需要获取下面背景图片img1滑块图片img2图1 背景图片图2 滑块图片2、原图识别代码import base64 import requests import datetime from io import BytesIO from PIL import Image, ImageDraw, ImageFont t1 datetime.datetime.now() #PIL图片保存为base64编码 def PIL_base64(img, codingutf-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, formatformat_str) img.save(output_buffer, quality100, formatformat_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(rE:\Python\lixin_project\OpenAPI接口测试\test_img\76-1.png) # 背景大图 img2 Image.open(rE:\Python\lixin_project\OpenAPI接口测试\test_img\76-2.png) # 滑动小图 # 图片转base64 img1_base64 PIL_base64(img1) img2_base64 PIL_base64(img2) # 验证码识别接口 url http://220.167.181.200:9009/openapi/verify_code_identify/ data { # 用户的key key: nHaAjgg5q1znn6tRUstY, # 验证码类型 verify_idf_id: 76, # 背景大图 img1: img1_base64, # 滑动小图 img2: img2_base64, } header {Content-Type: application/json} # 发送请求调用接口 response requests.post(urlurl, jsondata, headersheader) # 获取响应数据识别结果 print(response.text) # 因为这款验证码是变速滑动建议使用px_distance参数进行滑动 print(建议滑动距离, response.json()[data][px_distance]) print(耗时, datetime.datetime.now() - t1)3、截图识别简介需要根据下图的要求进行截图根据红框所示切边截图截图越准确识别效果越好。截图的大小可能跟设备有关图片大小各不相同。我们会统一缩放到宽度300像素来进行计算。4、截图识别代码import base64 import requests import datetime from io import BytesIO from PIL import Image, ImageDraw, ImageFont t1 datetime.datetime.now() #PIL图片保存为base64编码 def PIL_base64(img, codingutf-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, formatformat_str) img.save(output_buffer, quality100, formatformat_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(rE:\Python\lixin_project\OpenAPI接口测试\test_img\76-3.jpg) # 背景大图 # 图片转base64 img1_base64 PIL_base64(img1) # 验证码识别接口 url http://bq1gpmr8.xiaomy.net/openapi/verify_code_identify/ data { # 用户的key key: 0AAahdF39yYIX2Qy1iAE, # 验证码类型 verify_idf_id: 76, # 背景大图 img1: img1_base64, # 滑动小图 img2: , } header {Content-Type: application/json} # 发送请求调用接口 response requests.post(urlurl, jsondata, headersheader) # 获取响应数据识别结果 print(response.text) # 因为这款验证码是变速滑动建议使用px_distance参数进行滑动 print(建议滑动距离, response.json()[data][px_distance]) print(耗时, datetime.datetime.now() - t1)想了解更多验证码识别请访问http://bq1gpmr8.xiaomy.net/tool/verifyCodeHomePage2/?_1779073343947