New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

图片对不同分辨率的手机适应性欠佳,希望加入SIFT算法 #4

Closed
stayhungryYu opened this Issue Mar 9, 2018 · 7 comments

Comments

Projects
None yet
4 participants
@stayhungryYu

stayhungryYu commented Mar 9, 2018

No description provided.

@Meteorix

This comment has been minimized.

Member

Meteorix commented Mar 9, 2018

你好,这里已经有使用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)

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

@adolli

This comment has been minimized.

Member

adolli commented Mar 13, 2018

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

@stayhungryYu

This comment has been minimized.

stayhungryYu commented Mar 14, 2018

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

@stayhungryYu

This comment has been minimized.

stayhungryYu commented Mar 14, 2018

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

@rockywhisper

This comment has been minimized.

Contributor

rockywhisper commented Mar 29, 2018

@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

@stayhungryYu stayhungryYu reopened this Apr 10, 2018

@Meteorix Meteorix assigned Meteorix and unassigned rockywhisper Apr 11, 2018

@Meteorix

This comment has been minimized.

Member

Meteorix commented Apr 11, 2018

@rockywhisper 写的基本看不懂。。

@Meteorix

This comment has been minimized.

Member

Meteorix commented Apr 11, 2018

@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图片宽高,简单的数学 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment