zoukankan      html  css  js  c++  java
  • airtest局部识图|局部找图

    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("
    
    
    === 开始 ===
    
    
    ")
    
    touch(FindSubImg(Template(r"tpl1623399241628.png", target_pos=5, record_pos=(-0.426, -0.904), resolution=(1080, 2340)), [350, 340]))

     本文地址:

    https://www.cnblogs.com/stumpx/p/14888698.html

  • 相关阅读:
    将Mat类型坐标数据生成pts文件
    DelaunayTriangulation_VoronoiDiagram_using_OpenCV的实现
    安装python第三方库
    安装wordcloud第三方库Unable to find vcvarsall.bat
    Vec3b类型数据确定颜色通道
    使用Inno Setup Compiler制作安装软件包
    QT-This application failed to start because it could not find or load the Qt platform plugin "windows"
    m函数与m文件的命名
    当前目录如何打开cmd
    [Machine Learning & Algorithm] 随机森林(Random Forest)-转载
  • 原文地址:https://www.cnblogs.com/stumpx/p/14888698.html
Copyright © 2011-2022 走看看