Airtest 点击按钮前后两张图片的相似度,判断按钮是否可以被点击
Airtest 点击按钮后两张图片的相似度大于90%
__author__ = "xiaoyun461"
from airtest.core.api import *
from airtest.aircv.aircv import *
from airtest.core.cv import *
from airtest.aircv.template import *
#获得屏幕宽高
def height_width():
global width
global height
if G.DEVICE.display_info['orientation'] in [1,3]:
height = G.DEVICE.display_info['width']
width = G.DEVICE.display_info['height']
else:
height = G.DEVICE.display_info['height']
width = G.DEVICE.display_info['width']
global half_num
half_num = (0.5*width,0.5*height)
return [height,width]
#每隔多少秒截图 对比相似度
def search_equal(sleep_num):
x_min =width/4
y_min =height/4
x_max = width/4*3
y_max = height/4*3
#截图到内存
screen_01 = G.DEVICE.snapshot()
sleep(sleep_num)
screen_02 = G.DEVICE.snapshot()
#裁剪图片
predict_screen_01 = aircv.crop_image(screen_01, (x_min, y_min, x_max, y_max))
predict_screen_02 = aircv.crop_image(screen_02, (x_min, y_min, x_max, y_max))
like_num = find_template(screen_01,screen_02,-1)['confidence']
print("当前相似度:" , like_num)
if like_num >0.9:
return True
else:
return False
#战斗业务逻辑
def win_exists():
#开始战斗
sleep(10)
#永动机,每隔5秒对比,当相似度大于90%退出当前循环
while True:
if search_equal(5):
break
#执行下接下来的业务逻辑
#初始化长宽
height_width()
#战斗
win_exists()