用的图鉴的接口
缺口图+背景图的接口识别很准,但要传2张图
背景图带滑块,需要裁调滑块部分
# x,y:426x248
from PIL import Image as image
img = image.open("D:\lpt_img\\img_bgk.png")
# 按缩放比例 算出要裁剪的距离左边的x值
x_1=int(27/(340/426))
x=x_1+85
cropped = img.crop((x,0,426,248)) # (left, upper, right, lower)
cropped.save("D:\lpt_img\\img_bgk1.png")
调接口取x轴位移数
import json
import requests
import base64
from io import BytesIO
from PIL import Image as image
from sys import version_info
def get_x(uname, pwd, img_bgk):
#
# img = img.convert('RGB')
img_bgk = img_bgk.convert('RGB')
# buffered_img = BytesIO()
# img.save(buffered_img, format="JPEG")
buffered_img_bgk = BytesIO()
img_bgk.save(buffered_img_bgk, format("JPEG"))
# if version_info.major >= 3:
# b64_img = str(base64.b64encode(buffered_img.getvalue()), encoding='utf-8')
# else:
# b64_img = str(base64.b64encode(buffered_img.getvalue()))
if version_info.major >= 3:
b64_img_bgk = str(base64.b64encode(buffered_img_bgk.getvalue()), encoding='utf-8')
else:
b64_img_bgk = str(base64.b64encode(buffered_img_bgk.getvalue()))
data = {"username": uname, "password": pwd, "image": b64_img_bgk, "typeid": 33}
result = json.loads(requests.post("http://api.ttshitu.com/base64", json=data).text)
if result['success']:
return result["data"]["result"]
else:
return result["message"]
return ""
def get_img(img_bgk_path):
# img = image.open(img_path)
# 裁剪bgk_img
img_bgk1 = image.open(img_bgk_path)
# 按缩放比例 算出要裁剪的距离左边的x值
x_1 = int(27 / (340 / 426))
#
x = x_1 + 85
img_bgk = img_bgk1.crop((x, 0, 426, 248)) # (left, upper, right, lower)
# img_bgk=image.open(img_bgk)
# return img,img_bgk
return img_bgk
if __name__ == "__main__":
# img_path = "D:\\lpt_img\\img.png"
img_bgk_path = "D:\lpt_img\\img_bgk.png"
# img,img_bgk=get_img(img_path,img_bgk_path)
img_bgk = get_img(img_bgk_path)
# print(img,img_bgk)
result = get_x(uname='', pwd='', img_bgk=img_bgk)
# print(result)
# move_x=int(result.split(",")[0])
# x轴位移量
x = int((int(result) + 85) * (340 / 426))
print(x) # 221
测试位移量(多测几遍 误差不大就行了)
起始值+位移值=缺口值
后边就用selenium拖动滑块