airtest區域性識圖|區域性找圖
阿新 • • 發佈:2021-06-16
airtest區域性識圖|區域性找圖
# -*- encoding=utf8 -*- __author__ = "Administrator" from airtest.core.api import * from airtest.cli.parser import cli_setup from airtest.aircv import * import time def FindSubImg(temp, endPos, startPos=[0, 0]): """ 區域性找圖 :param startPos: 找圖範圍開始點 :param endPos: 找圖範圍結束點 :param temp: 目標圖片 :return: [posX,posY] | None 座標""" startTime = int(round(time.time() * 1000)) endTime = int(round(time.time() * 1000)) print('Log SubTime', endTime - startTime) loopFlag = 0 while endTime - startTime < 5000: loopFlag += 1 print('Log loopFlag', loopFlag) # 全屏截圖 screen = G.DEVICE.snapshot()# 獲取裝置螢幕解析度(豎屏) height = G.DEVICE.display_info['height'] width = G.DEVICE.display_info['width'] print('Log height', height) print('Log width', width) # 區域性截圖 local_screen = aircv.crop_image(screen, (startPos[0], startPos[1], endPos[0], endPos[1]))# 將我們的目標截圖設定為一個Template物件 tempalte = temp # 在區域性截圖裡面查詢指定的圖片物件 pos = tempalte.match_in(local_screen) print('Log pos', pos) if not pos: endTime = int(round(time.time() * 1000)) print('Log SubTime, continue', endTime - startTime) continue # 返回找到的圖片物件的座標(該座標是相對於區域性截圖的座標) # print(pos) # 若要返回目標在整個螢幕中的座標,則x,y都需要加上區域性截圖時設定的最小x、y resPos = [pos[0] + startPos[0], pos[1] + startPos[1]] print('Log resPos', resPos) endTime = int(round(time.time() * 1000)) print('Log SubTime, Ok Res', endTime - startTime) return resPos print('Log Err, Func FindSubImg None Return') endTime = int(round(time.time() * 1000)) print('Log SubTime, None Res', endTime - startTime) print('Log Start exists') return exists(temp) if not cli_setup(): auto_setup(__file__, logdir=None, devices=["android://127.0.0.1:5037/610e8756?cap_method=MINICAP_STREAM&&ori_method=MINICAPORI&&touch_method=MINITOUCH", ]) # script content print("\n\n\n=== 開始 ===\n\n\n") touch(FindSubImg(Template(r"tpl1623399241628.png", target_pos=5, record_pos=(-0.426, -0.904), resolution=(1080, 2340)), [350, 340]))
本文地址: