Skip to main content

找图

from ascript.android.screen import FindImages

从屏幕中找到 局部图片位置 . 支持全分辨率

方法

找一个 混合算法

先使用 模版匹配find_template ,如果找不到再使用全分辨率算法 find_sift 查找

  • 函数
FindImages.find(part_img:str,rect:list=None,confidence:int=0.1)
  • 参数
参数类型是否必填说明
part_imglist,str局部图片名称或路径或图片路径列表 当只填写图片名称时,将在res/img下找到该名称的图片
rectlist圈定找图屏幕范围
confidenceint图片结果的可信度0-1之间, 1为100%匹配,低于该可信度的结果将被过滤掉 默认:0.1
  • 返回值

Python dict 字典

{
'rect': [915, 1761, 1076, 1899], # 子图在屏幕中的范围
'center_x': 995, # 在屏幕中的中心点坐标x
'center_y': 1830, # 在屏幕中的中心点坐标y
'confidence': 0.94925636649131775 # 图片的相似度
}

  • 示例
# 在屏幕中找到局部图片的位置 find方式,先 template 后全分辨率
# 导包
from ascript.android.screen import FindImages
# 导入上下文环境包,方便导入图片地址
from ascript.android.system import R
path = R.res("/img/a.png") # 这里替换为你的图片地址
res = FindImages.find(path)
if res:
print("中心坐标:",res["center_x"],res["center_y"])
print("相似度:",res["confidence"])
print("在屏幕中的范围:",res["rect"])
# 在屏幕指定范围内找到局部图片的位置 find方式,先 template 后全分辨率
# 导包
from ascript.android.screen import FindImages
# 导入上下文环境包,方便导入图片地址
from ascript.android.system import R
path = R.res("/img/a.png") # 这里替换为你的图片地址
res = FindImages.find(path,rect =[ 59,932,374,1207])
if res:
print("中心坐标:",res["center_x"],res["center_y"])
print("相似度:",res["confidence"])
print("在屏幕中的范围:",res["rect"])
from ascript.android.screen import FindImages
# 在全屏中找局部图片,过滤掉可信度低于0.8的
# 导包
from ascript.android.screen import FindImages
# 导入上下文环境包,方便导入图片地址
from ascript.android.system import R
path = R.res("/img/a.png") # 这里替换为你的图片地址
res = FindImages.find(path,confidence=0.8)
if res:
print("中心坐标:",res["center_x"],res["center_y"])
print("相似度:",res["confidence"])
print("在屏幕中的范围:",res["rect"])

找一个 模版匹配

opencv中的模版匹配算法, 找色速度快, 不支持全分辨率

  • 函数
FindImages.find_template(part_img:str,rect:list=None,confidence:int=0.1,rgb:bool=False)
  • 参数
参数类型是否必填说明
part_imglist,str局部图片名称或路径或图片路径列表 当只填写图片名称时,将在res/img下找到该名称的图片
rectlist圈定找图屏幕范围
confidenceint图片结果的可信度0-1之间, 1为100%匹配,低于该可信度的结果将被过滤掉 默认:0.1
rgbboolTrue:使用原色图匹配
False(默认):使用灰度图匹配 灰度图模式下,可以查找出相同图形,不同颜色的图案
  • 返回值

Python dict 字典

{
'rect': [915, 1761, 1076, 1899], # 子图在屏幕中的范围
'center_x': 995, # 在屏幕中的中心点坐标x
'center_y': 1830, # 在屏幕中的中心点坐标y
'confidence': 0.94925636649131775 # 图片的相似度
}

# 在指定屏幕范围中找局部图片,过滤掉可信度低于0.8的 (不支持全分辨率)
# 导包
from ascript.android.screen import FindImages
# 导入上下文环境包,方便导入图片地址
from ascript.android.system import R
path = R.res("/img/a.png") # 这里替换为你的图片地址
res = FindImages.find_template(path,rect=[ 59,932,374,1207],confidence=0.8)
if res:
print("中心坐标:",res["center_x"],res["center_y"])
print("相似度:",res["confidence"])
print("在屏幕中的范围:",res["rect"])


找一个 全分辨率查找

全分辨率算法, 找色速度慢, 可以在任意设备上找到图像特征匹配的图

  • 函数
FindImages.find_sift(part_img:str,rect:list=None,confidence:int=0.1)
  • 参数
参数类型是否必填说明
part_imglist,str局部图片名称或路径或图片路径列表 当只填写图片名称时,将在res/img下找到该名称的图片
rectlist圈定找图屏幕范围
confidenceint图片结果的可信度0-1之间, 1为100%匹配,低于该可信度的结果将被过滤掉 默认:0.1
  • 返回值

Python dict 字典

{
'rect': [915, 1761, 1076, 1899], # 子图在屏幕中的范围
'center_x': 995, # 在屏幕中的中心点坐标x
'center_y': 1830, # 在屏幕中的中心点坐标y
'confidence': 0.94925636649131775 # 图片的相似度
}

  • 示例
# 全分辨率找 单图
# 导包
from ascript.android.screen import FindImages
# 导入上下文环境包,方便导入图片地址
from ascript.android.system import R
path = R.res("/img/a.png") # 这里替换为你的图片地址
res = FindImages.find_sift(path,confidence=0.8)
if res:
print("中心坐标:",res["center_x"],res["center_y"])
print("相似度:",res["confidence"])
print("在屏幕中的范围:",res["rect"])


找所有 混合算法

先使用 模版匹配find_template ,如果找不到再使用全分辨率算法 find_全分辨率 查找

  • 函数
FindImages.find_all(part_img:str,rect:list=None,confidence:int=0.1)
  • 参数
参数类型是否必填说明
part_imglist,str局部图片名称或路径或图片路径列表 当只填写图片名称时,将在res/img下找到该名称的图片
rectlist圈定找图屏幕范围
confidenceint图片结果的可信度0-1之间, 1为100%匹配,低于该可信度的结果将被过滤掉 默认:0.1
  • 返回值

Python 字典数组

[{
'rect': [479, 415, 597, 529], # 子图在屏幕中的范围
'center_x': 538, # 在屏幕中的中心点坐标x
'center_y': 472, # 在屏幕中的中心点坐标y
'confidence': 0.9975726008415222 #图片相似度
}, {
'rect': [479, 983, 597, 1097],
'center_x': 538,
'center_y': 1040,
'confidence': 0.9972777962684631
},...]
  • 示例
# 全分辨率找 所有图
# 导包
from ascript.android.screen import FindImages
# 导入上下文环境包,方便导入图片地址
from ascript.android.system import R
path = R.res("/img/2.png")
res = FindImages.find_all(path,confidence=0.8)
if res:
# 遍历所有 找到的结果
for i in res:
print("中心坐标:",i["center_x"],i["center_y"])
print("相似度:",i["confidence"])
print("在屏幕中的范围:",i["rect"])

找所有 模版匹配

opencv中的模版匹配算法, 找色速度快, 不支持全分辨率

  • 函数
FindImages.find_all_template(part_img:str,rect:list=None,confidence:int=0.1,rgb:bool=False)
  • 参数
参数类型是否必填说明
part_imglist,str局部图片名称或路径或图片路径列表 当只填写图片名称时,将在res/img下找到该名称的图片
rectlist圈定找图屏幕范围
confidenceint图片结果的可信度0-1之间, 1为100%匹配,低于该可信度的结果将被过滤掉 默认:0.1
rgbboolTrue:使用原色图匹配
False(默认):使用灰度图匹配 灰度图模式下,可以查找出相同图形,不同颜色的图案
  • 返回值

Python 字典数组

[{
'rect': [479, 415, 597, 529], # 子图在屏幕中的范围
'center_x': 538, # 在屏幕中的中心点坐标x
'center_y': 472, # 在屏幕中的中心点坐标y
'confidence': 0.9975726008415222 #图片相似度
}, {
'rect': [479, 983, 597, 1097],
'center_x': 538,
'center_y': 1040,
'confidence': 0.9972777962684631
},...]
# 找所有图 模版匹配 (不支持全分辨率)
# 导包
from ascript.android.screen import FindImages
# 导入上下文环境包,方便导入图片地址
from ascript.android.system import R
path = R.res("/img/2.png") #这里替换成你的图片路径
res = FindImages.find_all_template(path,confidence=0.8)
if res:
# 遍历所有 找到的结果
for i in res:
print("中心坐标:",i["center_x"],i["center_y"])
print("相似度:",i["confidence"])
print("在屏幕中的范围:",i["rect"])

找所有 全分辨率算法

全分辨率算法, 找色速度慢, 可在所有设备上找到图像特征匹配的图像

  • 函数
FindImages.find_all_sift(part_img:str,rect:list=None,confidence:int=0.1)
  • 参数
参数类型是否必填说明
part_imglist,str局部图片名称或路径或图片路径列表 当只填写图片名称时,将在res/img下找到该名称的图片
rectlist圈定找图屏幕范围
confidenceint图片结果的可信度0-1之间, 1为100%匹配,低于该可信度的结果将被过滤掉 默认:0.1
  • 返回值

Python 字典数组

[{
'rect': [479, 415, 597, 529], # 子图在屏幕中的范围
'center_x': 538, # 在屏幕中的中心点坐标x
'center_y': 472, # 在屏幕中的中心点坐标y
'confidence': 0.9975726008415222 #图片相似度
}, {
'rect': [479, 983, 597, 1097],
'center_x': 538,
'center_y': 1040,
'confidence': 0.9972777962684631
},...]
  • 示例
# 找所有图 全分辨率算法 (全分辨率)
# 导包
from ascript.android.screen import FindImages
# 导入上下文环境包,方便导入图片地址
from ascript.android.system import R
path = R.res("/img/2.png")
res = FindImages.find_all_sift(path,confidence=0.8)
if res:
# 遍历所有 找到的结果
for i in res:
print("中心坐标:",i["center_x"],i["center_y"])
print("相似度:",i["confidence"])
print("在屏幕中的范围:",i["rect"])