请问找图功能有多个一样的图能否一次找出来?获取数量以及各自标记位置? · 问答 · hamibot 安卓自动化工具-九游会

已存档

请问找图功能有多个一样的图能否一次找出来?获取数量以及各自标记位置??有没有技术交流群啥的,很多功能代码感觉介绍的不是很全面啊!

· 1 年前

回答

batu1579
455
· 1 年前

hi!

如果想在一个图片中寻找图片并获得多个结果,可以使用 images 模块中的 matchtemplate() 方法,使用方式可以参考下面的示例:

if (!images.requestscreencapture(false)) {
    throw new error("dont have permission to capture screen");
}
const current_screen = images.capturescreen();
const template_image = images.read("template.png");
if (!template_image) {
    throw new error("cannot read template image");
}
const header_height = 100;
let results = images.matchtemplate(current_screen, template_image, {
    "max": 10,          // 最多匹配 10 张图片
    "threshold": 0.8,   // 相似度阈值
    "region": [
        0,
        header_height,
        current_screen.getwidth(),
        current_screen.getheight() - header_height,
    ]
})
console.log("find "   results.matches.length   " matches");

详细使用方式请见开发文档中 一节

技术交流群可以加我v(和我的 id一样),备注上你的 id 我看看能不能拉你 😃

等你回复~

已选为答案
0
网站地图