 | |  |  | AIWROK软件用图找图示例templateMat方法
- //🍎交流 QQ 群 711841924 群一,苹果内测群,528816639
- //适用本文档ES5系统安卓 JavaScript引擎Rhino
- //图找图示例templateMat方法
- function safeImageMatching() {
- printl("图找图示例");
-
- // 只截取一次屏幕作为基础图像
- var screenshot = screen.screenShot(1080, 1920, 100);
- var mat = screenshot.getMat();
- printl("基础图像: " + mat.width() + "x" + mat.height());
-
- // 从基础图像中提取模板区域 (左上角200x200区域)
- var templateMat = mat.submat(0, 200, 0, 200);
- printl("模板图像: " + templateMat.width() + "x" + templateMat.height());
-
- // 转换模板为Base64
- var templateBase64 = templateMat.ToBase64();
- printl("模板Base64长度: " + ('' + templateBase64).length);
-
- // 使用整个基础图像作为搜索图像
- var searchMat = mat;
- printl("搜索图像: " + searchMat.width() + "x" + searchMat.height());
-
- // 图像匹配
- var results = opencv.templateMatch(searchMat, [templateBase64], 0.9, [0, 0, 1, 1], true);
-
- if (results && results.length > 0) {
- printl("匹配成功!");
- // 安全地访问匹配结果属性
- var result = results[0];
- // 尝试访问各种属性
- if (result.x !== undefined) {
- printl("位置X: " + result.x);
- }
- if (result.y !== undefined) {
- printl("位置Y: " + result.y);
- }
- if (result.score !== undefined) {
- printl("相似度: " + result.score);
- }
- // 尝试调用click方法
- if (typeof result.click === 'function') {
- printl("支持点击操作");
- }
- } else {
- printl("未找到匹配");
- }
-
- // 释放资源
- templateMat = null;
- mat = null;
- screenshot = null;
-
- printl("示例结束");
- }
- safeImageMatching();
复制代码
| |  | |  |
|