外贸在哪些网站做,网站维护需要多长时间,南宁建设网站,苏州市住房和城乡建设局官方网站通常滑块验证码都是横向滑动#xff0c;今天看到一个比较特别的滑块拼图验证码#xff0c;他不仅能在横向上滑动#xff0c;还需要进行纵向滑动。如下图所示#xff1a; 他的滑块在背景图片的左上角#xff0c;需要鼠标拖动左上角的滑块#xff0c;移动到背景图的缺口位置…通常滑块验证码都是横向滑动今天看到一个比较特别的滑块拼图验证码他不仅能在横向上滑动还需要进行纵向滑动。如下图所示 他的滑块在背景图片的左上角需要鼠标拖动左上角的滑块移动到背景图的缺口位置拼好。 首先会识别滑块左上角的坐标然后识别缺口左上角的坐标。然后他们两个相减就是xy方向上的滑动距离
识别代码如下
import base64
import requests
import datetime
from io import BytesIO
from PIL import Image, ImageDrawt1 datetime.datetime.now()#PIL图片保存为base64编码
def PIL_base64(img, codingutf-8):img_format img.formatif img_format None:img_format JPEGformat_str JPEGif png img_format.lower():format_str PNGif gif img_format.lower():format_str gifif img.mode P:img img.convert(RGB)if img.mode RGBA:format_str PNGimg_format PNGoutput_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\53-1.png)
# 图片转base64
img1_base64 PIL_base64(img1)# 验证码识别接口
url http://www.detayun.cn/openapi/verify_code_identify/
data {# 用户的keykey:78t9jTqCbAnHFO0tbBDW,# 验证码类型verify_idf_id:53,# 样例图片img_base64:img1_base64,
}
header {Content-Type: application/json}# 发送请求调用接口
response requests.post(urlurl, jsondata, headersheader)# 获取响应数据识别结果
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), width2) # 线的起点和终点线宽
draw.line((0, y, img1.size[0], y), fill(255, 0, 0), width2) # 线的起点和终点线宽
img1.show()想了解更多验证码识别请访问得塔云