This article is from the official account of the project: “AirtestProject” Copyright notice: It is allowed to be reproduced, but the original link must be retained. Do not use it for commercial or illegal purposes
preface
In Airtest version 1.2.0, we added an image recognition algorithm: MSTPL. The algorithm can improve the accuracy of image recognition to some extent.
In addition, MSTPL algorithm also has two unique parameters, respectively scale_step and scale_max. So today we’re going to talk about how these two parameters are adjusted.
1. How to adjustscale_step
Scale_step is used to control the scale step of the search, which represents the degree of fineness of the search when matching. For image matching, the search is performed with the step of the longest edge of the screenshot * scale_step within a certain zoom range of the original screenshot. The default value is 0.01, the value range is [0.001, 0.1], and the recommended values are 0.02, 0.005, and 0.001.
In general, this value does not need to be adjusted, and you can try to reduce it when cross-resolution matches (especially small screenshots) fail to match. But reducing it dramatically increases the matching time.
For example, we perform the following image recognition:
Scale_step =0.01; scale_step=0.01;
When scale_step=0.005, success can be recognized:
2. How to adjustscale_max
Scale_max is used to adjust the maximum range of matches. The default value is 800, the value range is 700, 2000, and the recommended values are 740, 800, and 1000.
Considering the matching performance, MSTPL will set a maximum screenshot size before starting the match, for example, if the screenshot is (699, 1964) and scale_max=1000, then the screenshot will be resized to (356,1000) before the match.
Smaller scale_max is theoretically faster, but there is also the risk of not matching smaller UI. However, it is also possible to match smaller UIs faster when scale_max is larger due to the early exit mechanism.
In use, if the screenshot is too small to match, you can try to increase scale_max.
For example, we perform the following image recognition:
Scale_max =1000; scale_max=1000;
Scale_max =1100; scale_max=1100;
3. Where can I change the values of the two parameters
1) Modify through the image editor
We can double-click the image in the IDE to open the image editor. In the right parameter table, modify the scale_step and scale_max values. After the modification, don’t forget to click the OK button in the lower right corner to save the modification:
2) Modify directly in the script
We can also right-click in the script editing window of the IDE and choose Image/Code Mode toggle. After switching to code mode, we can add/modify scale_step and scale_max in the image script:
Touch (Template (r "tpl1631007320263. PNG," scale_max = 1100, scale_step = 0.005))Copy the code
3) Modify the image recognition algorithm used by Airtest
Sometimes, we want to modify the image recognition algorithm used by Airtest according to the needs of our project, such as adjusting the order in which the Airtest image recognition algorithm is used, or specifying that only one of the algorithms is used:
CVSTRATEGY = [" MSTPL "," TPL ", "Sift ","brisk"] # specify only MSTPL algorithm st. CVSTRATEGY = [" MSTPL "]Copy the code
summary
So that’s all for today’s introduction of the new algorithm “MSTPL”. If you have any questions about the new algorithm, or have any comments on Airtest’s image recognition algorithm, please feel free to send them to our issue-Helper website.
AirtestIDE download: airtest.netease.com/ Airtest tutorial website: airtest.doc.io.netease.com/ build enterprise private cloud service: airlab.163.com/b2b
Official Q group: 654700783
Ah, so serious all see here, help in the left side of the article click on the likes and favorites, give me a support, ash often thank ~