Airtest手机屏幕上查找多张相同图片坐标
一、问题
有时候在应用层上的开发会遇到奇奇怪怪的问题,就会让人难以解决,自己就遇到这个问题了,正好把资料整理一下,分享给大家。
二、解决思路
# -*- encoding=utf8 -*-
__author__ = "AirtestProject"
from airtest.core.api import *
auto_setup(__file__)
results= find_all(Template(r"tpl1662624311911.png", record_pos=(-0.002, -0.178), resolution=(1080, 2520)))
print("--------------------------------")
print(results)
for i in range(0,4):
touch(results[i]['result'])
sleep(1.0)
三、运行结果
[{'result': (538, 1423), 'rectangle': ((490, 1363), (490, 1483), (587, 1483), (587, 1363)), 'confidence': 0.9852163195610046},
{'result': (301, 1186), 'rectangle': ((253, 1126), (253, 1246), (350, 1246), (350, 1126)), 'confidence': 0.9825006723403931},
{'result': (775, 1186), 'rectangle': ((727, 1126), (727, 1246), (824, 1246), (824, 1126)), 'confidence': 0.9197724461555481},
{'result': (249, 1894), 'rectangle': ((201, 1834), (201, 1954), (298, 1954), (298, 1834)), 'confidence': 0.7261688709259033}]
四、扩展两张图片相似度对比
# -*- encoding=utf8 -*-
__author__ = "AirtestProject"
from airtest.core.api import *
from airtest.aircv.cal_confidence import *
auto_setup(__file__)
img1 = cv2.resize(cv2.imread(r"frog.png"),(85,100))
img2 = cv2.resize(cv2.imread(r"chick.png"),(85,100))
confidence = cal_ccoeff_confidence(img1,img2)
print("----------------")
print(confidence)
代码中:
- cv2.resize 用于统一图片尺寸,上图中的(85,100)为我们指定的目标尺寸
- cv2.imread用于读取本地路径下的图片
- cal_ccoeff_confidence用于对比两张图片的相似度,返回可信度的值