问题是这样的,在 opencv 的发方法中用 matchTemplate 做模板匹配,发现一个奇怪的问题,在网上下在的图片和电脑本身截图的图片是可以精准匹配的,但使用 uiautomator 截屏 devices.screenshot 生成的图片却无法匹配出来,这两者有啥区别?
按理说前者是 jpg,screenshot 保存的是 png,但改了后缀名也没用。有没有遇到的,求解
#原图
src_image = "../saveimages/msi.jpg"
#模板
template_image = "../tmp/z11.png"
src = cv2.imread(src_image) # Load the src image
template = cv2.imread(template_image) # Load the src image
# 获取模板图片的高和宽
h, w = template.shape[:2]
# 获取大图片的高和宽
srch, srcw = src.shape[:2]
result = cv2.matchTemplate(src, template, cv2.TM_SQDIFF_NORMED) # comparision
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)
print('val', min_val, max_val)
if min_val <= 0.3:
left_top = min_loc # 左上角
# print(left_top)
bottom = (int(left_top[0] + w), int(left_top[1] + h))
cv2.rectangle(src, left_top, bottom, (0, 0, 225), 3) # 画出矩形位置
# 显示结果,并将匹配值显示在标题栏上
plt.subplot(1, 1, 1), plt.imshow(src), plt.title('Input'), plt.xticks([]), plt.yticks([])
plt.show()
cv2.imwrite("singefile.png", src)
cv2.waitKey()
cv2.destroyAllWindows()
# #找中心位置
right_bottom = (int(left_top[0] + w / 2),int(left_top[1] + h / 2))
print(right_bottom)