Giter Club home page Giter Club logo

Comments (11)

Meteorix avatar Meteorix commented on August 15, 2024 5

@stayhungryYu

airtest里面实现了默认的分辨率适配规则,我们采用的是Cocos引擎的默认缩放规则,代码在这里

想要提高2d游戏的识别精度,最好的办法就是明确指定你的游戏的分辨率适配规则!

你可以在airtest脚本中自定义你的游戏的分辨率适配规则,直接写到.air文件的开头

from airtest.core.settings import Settings as ST

def custom_resize_method(w, h, sch_resolution, src_resolution):
    print(w, h, sch_resolution, src_resolution)
    return int(w), int(h)

ST.RESIZE_METHOD = custom_resize_method

向上面这样就指定了你自定义的缩放规则,但是直接return原来的值,就是不管屏幕分辨率,所有UI都不进行缩放(有的游戏就是这种策略)。那么你需要知道你测试的游戏的缩放规则,然后在custom_resize_method中代码实现。

这里的输入参数:

w, h  # 录制下来的UI图片的宽高
sch_resolution  # 录制时的屏幕分辨率
src_resolution  # 回放时的屏幕分辨率

所以你要输出的就是回放时的UI图片宽高,简单的数学 :)

from airtest.

Meteorix avatar Meteorix commented on August 15, 2024

你好,这里已经有使用SIFT算法,但是SIFT在特征点较少的时候识别效果并不好。

Airtest/airtest/core/cv.py

Lines 125 to 131 in 9f81526

for method in ST.CVSTRATEGY:
if method == "tpl":
ret = self._try_match(self._find_template, image, screen)
elif method == "sift":
ret = self._try_match(self._find_sift_in_predict_area, image, screen)
if not ret:
ret = self._try_match(self._find_sift, image, screen)

实际上我们有针对游戏的分辨率适配提供了更多优化,需要自行配置,这方面的文档会在稍后放出。

from airtest.

adolli avatar adolli commented on August 15, 2024

@stayhungryYu 原生应用推荐使用Poco进行控件识别,不同手机的文字渲染差异较大,非常容易认为是不同的两个图。 AndroidUiautomationPoco

from airtest.

stayhungryYu avatar stayhungryYu commented on August 15, 2024

@Meteorix 可以分享一下么,怎么配置 跪谢.gif

from airtest.

stayhungryYu avatar stayhungryYu commented on August 15, 2024

@adolli 谢谢,不过我目前在测试2D游戏 :)

from airtest.

rockywhisper avatar rockywhisper commented on August 15, 2024

@stayhungryYu 你好,目前框架内已经集成了SIFT,在使用IDE运行脚本时,会有SIFT识别方法的调用,但某些情况下SIFT识别不够稳定。

针对你的测试情形,建议配置自己游戏的适配规则。

配置代码:

from airtest.core.settings import Settings as ST

def custom_resize_method(w_a, h_a, resolution_a, resolution_b):
    # 本函数根据传入的resolution_a分辨率下UI截图的宽、高,分别为w_a和h_a,
    # 返回该UI元素在resolution_b下的宽w_b和高w_b
    w_b, h_b = ....  # 根据游戏的跨分辨率适配逻辑进行计算w_b, h_b:
    return int(w_b), int(w_b)

ST.RESIZE_METHOD = staticmethod(custom_resize_method)

以上代码的有两种设置方式:
①如果就只有单个脚本,可以直接放在脚本开头;
②如果有较多脚本,可以在自定义脚本启动器内实现,详细请查阅: 自定义脚本启动器&配置游戏适配规则RESIZE_METHOD

from airtest.

Meteorix avatar Meteorix commented on August 15, 2024

@rockywhisper 写的基本看不懂。。

from airtest.

niuniuprice avatar niuniuprice commented on August 15, 2024

@Meteorix 你好,我使用了你所说的分辨率适配方法对脚本进行了适配,但是有时候19201080分辨率下生产的图片放到12801024的运行环境中识别精度就大幅降低了,请问这种情况的原因是什么呢?我推测是因为接近2:1的分辨率到4:3的分辨率下图片的失真?如果项目组有对于这种问题的解决方案,请不吝赐教。

from airtest.

rockywhisper avatar rockywhisper commented on August 15, 2024

@niuniuprice
Hi,你好。

针对图像识别不够理想的情况,我们有以下几种解决思路:

1、部分特征较少的图片脚本情形,可以改用poco脚本替换掉图像脚本:

  • 对于普通app可以直接使用,
  • 游戏应用则需要接入SDK才能使用。

2、图像脚本的兼容性改进:

  • ① 截图时,尽量不要包含过多变化的背景元素,消除影响识别的负面因素。
  • ② 静态背景的话,可以通过多截取背景特征,然后target_pos指定操作点位置
  • ③ 封装自定义兼容性图片操作函数(略微麻烦,最有效)
picList = [pic1,pic2,pic3]  # 截图的图片对象列表
for pic in picList:
     pos = exists(pic)
     if pos:
         touch(pos)
         break  # 只要找到图片列表中的任何一张图片,就执行touch

image

3、图像脚本调试器:(比较精细,一般在小规模测试集群上使用)

  • 双击脚本内图片打开图片调试器,然后查看识别结果,调整至合适的阈值。
    image

from airtest.

yuzhujiutian avatar yuzhujiutian commented on August 15, 2024

火钳留言,关注本bug解决方案讨论

from airtest.

smartcal1995 avatar smartcal1995 commented on August 15, 2024

关注

from airtest.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.