 | |  |  | AIWROK软件找图方法汇总示例
- // 找图方法汇总示例
- // 技术交流QQ群711841924群一,苹果内测群,528816639
- /**
- * 基础找图方法 - 使用opencv.findImagesEx
- * @returns {boolean} 是否找到并点击目标
- */
- function basicFindImage() {
- printl("开始基础找图: 图色823706.cv");
-
- try {
- // 检查opencv是否可用
- if (typeof opencv !== 'undefined' && typeof opencv.findImagesEx === 'function') {
- // 执行找图操作
- var detects = opencv.findImagesEx('图色823706.cv');
-
- if (detects !== null) {
- printl("找到目标数组: " + detects);
-
- // 点击第一个找到的目标
- if (detects.length > 0) {
- printl("点击第一个找到的目标");
- detects[0].click();
- return true;
- } else {
- printl("目标数组为空");
- return false;
- }
- } else {
- printl("未找到目标");
- return false;
- }
- } else {
- printl("❌ opencv模块不可用");
- return false;
- }
- } catch (e) {
- printl("执行错误: " + String(e));
- return false;
- }
- }
- /**
- * 多图像查找方法 - 使用opencv.findImagesEx
- * @returns {boolean} 是否找到并点击目标
- */
- function multiFindImage() {
- printl("开始多图像查找,共 3 个图像");
-
- try {
- // 多个要查找的图像(使用同一个CV文件多次测试)
- var imagePaths = new Array();
- imagePaths[0] = '图色823706.cv';
- imagePaths[1] = '图色823706.cv';
- imagePaths[2] = '图色823706.cv';
-
- // 遍历每个图像进行查找
- for (var i = 0; i < imagePaths.length; i++) {
- var imagePath = imagePaths[i];
- printl("正在查找: " + imagePath);
-
- // 检查opencv是否可用
- if (typeof opencv !== 'undefined' && typeof opencv.findImagesEx === 'function') {
- var detects = opencv.findImagesEx('图色823706.cv');
-
- if (detects != null && detects.length > 0) {
- printl("在图像 " + imagePath + " 找到 " + detects.length + " 个匹配结果");
-
- // 只处理第一个找到的结果
- var result = detects[0];
- printl("位置: (" + (result.x || 0) + ", " + (result.y || 0) + ")");
- printl("尺寸: " + (result.width || 0) + "x" + (result.height || 0));
- printl("相似度: " + (result.similarity || 0));
-
- // 执行点击
- result.click();
- sleep.second(1);
- return true;
- } else {
- printl("未找到有效匹配: " + imagePath);
- }
- } else {
- printl("❌ opencv模块不可用");
- return false;
- }
- }
- return false;
- } catch (e) {
- printl("多图像查找过程中发生错误: " + String(e));
- return false;
- }
- }
- /**
- * 截图找图方法 - 使用opencv.findImagesEx
- * @returns {boolean} 是否找到并点击目标
- */
- function screenshotFindImage() {
- printl("开始截图找图");
-
- try {
- // 使用系统截图功能(如果可用)
- try {
- // 尝试使用截图功能
- var screenshotPath = "/sdcard/screenshot.png";
- printl("尝试保存截图到: " + screenshotPath);
- // 注意:screen.capture在某些环境中可能不可用
- if (typeof screen !== 'undefined' && typeof screen.screenShot === 'function') {
- var screenWidth = screen.getScreenWidth();
- var screenHeight = screen.getScreenHeight();
- printl("屏幕尺寸: " + screenWidth + "x" + screenHeight);
- var screenshot = screen.screenShot(screenWidth, screenHeight);
- printl("截图成功,尺寸: " + screenshot.getMat().width() + "x" + screenshot.getMat().height());
- }
- } catch (e) {
- printl("截图功能不可用: " + String(e));
- }
-
- // 直接进行找图
- var targetImagePath = '图色823706.cv';
- printl("正在查找图像: " + targetImagePath);
-
- // 检查opencv是否可用
- if (typeof opencv !== 'undefined' && typeof opencv.findImagesEx === 'function') {
- var detects = opencv.findImagesEx('图色823706.cv');
-
- if (detects != null && detects.length > 0) {
- printl("找到 " + detects.length + " 个匹配结果");
-
- for (var i = 0; i < detects.length; i++) {
- var result = detects[i];
- printl("结果 " + (i+1) + ": x=" + (result.x || 0) + ", y=" + (result.y || 0) +
- ", width=" + (result.width || 0) + ", height=" + (result.height || 0) +
- ", similarity=" + (result.similarity || 0));
- }
-
- // 点击第一个结果
- detects[0].click();
- return true;
- } else {
- printl("截图找图未找到有效匹配结果");
- printl("请检查以下几点:");
- printl("1. 图像文件是否存在: " + targetImagePath);
- printl("2. 图像是否在屏幕上可见");
- printl("3. 图像相似度设置是否合适");
- return false;
- }
- } else {
- printl("❌ opencv模块不可用");
- return false;
- }
- } catch (e) {
- printl("截图找图过程中发生错误: " + String(e));
- return false;
- }
- }
- /**
- * SIFT图像查找方法 - 使用opencv.findImageOneSift
- * @returns {boolean} 是否找到并点击目标
- */
- function siftFindImage() {
- printl("开始SIFT图像查找");
-
- try {
- // 检查opencv是否可用
- if (typeof opencv !== 'undefined' && typeof opencv.findImageOneSift === 'function') {
- // 获取屏幕尺寸
- var screenWidth = 900;
- var screenHeight = 1600;
-
- try {
- if (typeof screen !== 'undefined') {
- if (typeof screen.getScreenWidth === 'function') {
- screenWidth = screen.getScreenWidth();
- screenHeight = screen.getScreenHeight();
- }
- }
- } catch (e) {
- printl("获取屏幕尺寸失败,使用默认值: " + String(e));
- }
-
- printl("大图尺寸: " + screenWidth + "x" + screenHeight);
- printl("小图尺寸: 300x300");
-
- // 截取大图和小图
- var bigMat = screen.screenShot(screenWidth, screenHeight, 100).getMat();
- var smallMat = screen.screenShot(300, 300, 100).getMat();
-
- // 定义搜索区域
- var searchRegion = [0, 0, 1, 1]; // 整个屏幕
-
- // 执行SIFT图像查找
- var result = opencv.findImageOneSift(bigMat, smallMat, 60, 50, searchRegion);
-
- if (result !== null) {
- printl("SIFT图像查找成功");
- printl("位置: (" + result.x + ", " + result.y + ")");
- printl("尺寸: " + result.width + "x" + result.height);
- printl("相似度: " + result.similarity);
-
- // 点击找到的位置
- result.click();
-
- // 释放资源
- bigMat = null;
- smallMat = null;
-
- return true;
- } else {
- printl("SIFT图像查找未找到匹配结果");
-
- // 释放资源
- bigMat = null;
- smallMat = null;
-
- return false;
- }
- } else {
- printl("SIFT方法在当前AIWROK版本中不可用,跳过执行");
- return false;
- }
- } catch (e) {
- printl("SIFT方法在当前AIWROK版本中不可用,跳过执行");
- return false;
- }
- }
- /**
- * 多点找色方法 - 使用opencv.findMultiColor
- * @returns {boolean} 是否找到并点击目标
- */
- function multiColorFind() {
- printl("开始多点找色");
-
- try {
- // 获取屏幕尺寸
- var screenWidth = 900;
- var screenHeight = 1600;
-
- try {
- if (typeof screen !== 'undefined') {
- if (typeof screen.getScreenWidth === 'function') {
- screenWidth = screen.getScreenWidth();
- screenHeight = screen.getScreenHeight();
- }
- }
- } catch (e) {
- printl("获取屏幕尺寸失败,使用默认值: " + String(e));
- }
-
- printl("图像尺寸: " + screenWidth + "x" + screenHeight);
-
- // 截取屏幕图像
- var screenMat = screen.screenShot(screenWidth, screenHeight, 100).getMat();
-
- // 定义基准点和颜色点
- var basePoint = "";
- var colorPoints = [];
- var colorTolerance = 0;
- var offsetTolerance = 0;
- var region = [0, 0, 1, 1]; // 整个屏幕
- var similarity = 0.9;
-
- // 检查opencv是否可用
- if (typeof opencv !== 'undefined' && typeof opencv.findMultiColor === 'function') {
- var result = opencv.findMultiColor(screenMat, basePoint, colorPoints, colorTolerance, offsetTolerance, region, similarity);
-
- if (result !== null) {
- printl("多点找色成功");
- printl("位置: (" + result.x + ", " + result.y + ")");
-
- // 点击找到的位置
- touch.tap(result.x, result.y);
-
- // 释放资源
- screenMat = null;
-
- return true;
- } else {
- printl("多点找色未找到有效匹配项");
-
- // 释放资源
- screenMat = null;
-
- return false;
- }
- } else {
- printl("❌ opencv模块不可用或findMultiColor方法不存在");
-
- // 释放资源
- screenMat = null;
-
- return false;
- }
- } catch (e) {
- printl("执行多点找色时发生错误: " + String(e));
- return false;
- }
- }
- /**
- * 使用auto.checkImage查找图
- * @param {Array} images - 图像数组
- * @param {number} similarity - 相似度
- * @param {number} timeout - 超时时间
- * @param {Array} region - 区域
- * @returns {boolean} 是否找到并点击目标
- */
- function autoCheckImage(images, similarity, timeout, region) {
- printl("开始使用auto.checkImage查找图");
-
- try {
- // 检查auto是否可用
- if (typeof auto !== 'undefined' && typeof auto.checkImage === 'function') {
- var result = auto.checkImage(images, similarity, timeout, 0, region);
-
- if (result !== null) {
- printl("auto.checkImage查找成功");
- printl("位置: (" + result.x + ", " + result.y + ")");
-
- // 点击找到的位置
- touch.tap(result.x, result.y);
-
- return true;
- } else {
- printl("auto.checkImage未找到匹配结果");
- return false;
- }
- } else {
- printl("❌ auto模块不可用或checkImage方法不存在");
- return false;
- }
- } catch (e) {
- printl("auto.checkImage执行错误: " + String(e));
- return false;
- }
- }
- /**
- * 使用auto.findBestImage查找最佳图
- * @param {Array} images - 图像数组
- * @param {number} similarity - 相似度
- * @param {number} timeout - 超时时间
- * @param {Array} region - 区域
- * @returns {boolean} 是否找到并点击目标
- */
- function autoFindBestImage(images, similarity, timeout, region) {
- printl("开始使用auto.findBestImage查找最佳图");
-
- try {
- // 检查auto是否可用
- if (typeof auto !== 'undefined' && typeof auto.findBestImage === 'function') {
- var result = auto.findBestImage(images, similarity, timeout, 0, region);
-
- if (result !== null) {
- printl("auto.findBestImage查找成功");
- printl("位置: (" + result.x + ", " + result.y + ")");
- printl("相似度: " + result.similarity);
-
- // 点击找到的位置
- touch.tap(result.x, result.y);
-
- return true;
- } else {
- printl("auto.findBestImage未找到匹配结果");
- return false;
- }
- } else {
- printl("❌ auto模块不可用或findBestImage方法不存在");
- return false;
- }
- } catch (e) {
- printl("auto.findBestImage执行错误: " + String(e));
- return false;
- }
- }
- /**
- * 使用auto.findImages找多图
- * @param {Array} images - 图像数组
- * @param {number} similarity - 相似度
- * @param {number} timeout - 超时时间
- * @param {number} maxResults - 最大结果数
- * @param {Array} region - 区域
- * @returns {boolean} 是否找到并点击目标
- */
- function autoFindImages(images, similarity, timeout, maxResults, region) {
- printl("开始使用auto.findImages找多图");
-
- try {
- // 检查auto是否可用
- if (typeof auto !== 'undefined' && typeof auto.findImages === 'function') {
- var results = auto.findImages(images, similarity, timeout, maxResults, region);
-
- if (results !== null && results.length > 0) {
- printl("auto.findImages找到 " + results.length + " 个匹配结果");
-
- // 处理第一个结果
- var result = results[0];
- printl("位置: (" + result.x + ", " + result.y + ")");
- printl("相似度: " + result.similarity);
-
- // 点击找到的位置
- touch.tap(result.x, result.y);
-
- return true;
- } else {
- printl("auto.findImages未找到匹配结果");
- return false;
- }
- } else {
- printl("❌ auto模块不可用或findImages方法不存在");
- return false;
- }
- } catch (e) {
- printl("auto.findImages执行错误: " + String(e));
- return false;
- }
- }
- /**
- * 使用auto.findColors多点找色
- * @param {Object} mat - 图像矩阵
- * @param {string} basePoint - 基准点
- * @param {Array} colorPoints - 颜色点数组
- * @param {number} colorTolerance - 颜色容差
- * @param {number} offsetTolerance - 偏移容差
- * @param {Array} region - 区域
- * @param {number} similarity - 相似度
- * @returns {boolean} 是否找到并点击目标
- */
- function autoFindColors(mat, basePoint, colorPoints, colorTolerance, offsetTolerance, region, similarity) {
- printl("开始使用auto.findColors多点找色");
-
- try {
- // 检查auto是否可用
- if (typeof auto !== 'undefined' && typeof auto.findColors === 'function') {
- var result = auto.findColors(mat, basePoint, colorPoints, colorTolerance, offsetTolerance, region, similarity);
-
- if (result !== null) {
- printl("auto.findColors多点找色成功");
- printl("位置: (" + result.x + ", " + result.y + ")");
-
- // 点击找到的位置
- touch.tap(result.x, result.y);
-
- return true;
- } else {
- printl("auto.findColors未找到匹配结果");
- return false;
- }
- } else {
- printl("❌ auto模块不可用或findColors方法不存在");
- return false;
- }
- } catch (e) {
- printl("auto.findColors执行错误: " + String(e));
- return false;
- }
- }
- /**
- * 使用auto.findText找文字
- * @param {string} text - 要查找的文字
- * @param {number} similarity - 相似度
- * @param {Array} region - 区域
- * @returns {boolean} 是否找到并点击目标
- */
- function autoFindText(text, similarity, region) {
- printl("开始使用auto.findText找文字: " + text);
-
- try {
- // 检查auto是否可用
- if (typeof auto !== 'undefined' && typeof auto.findText === 'function') {
- var result = auto.findText(text, similarity, region);
-
- if (result !== null) {
- printl("auto.findText查找成功");
- printl("位置: (" + result.x + ", " + result.y + ")");
-
- // 点击找到的位置
- touch.tap(result.x, result.y);
-
- return true;
- } else {
- printl("auto.findText未找到匹配结果");
- return false;
- }
- } else {
- printl("❌ auto模块不可用或findText方法不存在");
- return false;
- }
- } catch (e) {
- printl("auto.findText执行错误: " + String(e));
- return false;
- }
- }
- /**
- * 使用ai.findImage找多图
- * @param {Object} image - 图像
- * @param {Array} rect - 矩形区域
- * @param {string} model - 模型名
- * @param {number} targetSize - 目标大小
- * @param {string} sort - 排序方式
- * @param {number} similarity - 相似度
- * @returns {boolean} 是否找到并点击目标
- */
- function aiFindImage(image, rect, model, targetSize, sort, similarity) {
- printl("开始使用ai.findImage找多图");
-
- try {
- // 检查ai是否可用
- if (typeof ai !== 'undefined' && typeof ai.findImage === 'function') {
- var results = ai.findImage(image, rect, model, targetSize, sort, similarity);
-
- if (results !== null && results.length > 0) {
- printl("ai.findImage找到 " + results.length + " 个匹配结果");
-
- // 处理第一个结果
- var result = results[0];
- printl("位置: (" + result.x + ", " + result.y + ")");
- printl("相似度: " + result.similarity);
-
- // 点击找到的位置
- touch.tap(result.x, result.y);
-
- return true;
- } else {
- printl("ai.findImage未找到匹配结果");
- return false;
- }
- } else {
- printl("❌ ai模块不可用或findImage方法不存在");
- return false;
- }
- } catch (e) {
- printl("ai.findImage执行错误: " + String(e));
- return false;
- }
- }
- /**
- * 使用ai.findImageOne找单图
- * @param {Object} image - 图像
- * @param {Array} rect - 矩形区域
- * @param {string} model - 模型名
- * @param {number} targetSize - 目标大小
- * @param {string} sort - 排序方式
- * @param {number} similarity - 相似度
- * @returns {boolean} 是否找到并点击目标
- */
- function aiFindImageOne(image, rect, model, targetSize, sort, similarity) {
- printl("开始使用ai.findImageOne找单图");
-
- try {
- // 检查ai是否可用
- if (typeof ai !== 'undefined' && typeof ai.findImageOne === 'function') {
- var result = ai.findImageOne(image, rect, model, targetSize, sort, similarity);
-
- if (result !== null) {
- printl("ai.findImageOne查找成功");
- printl("位置: (" + result.x + ", " + result.y + ")");
- printl("相似度: " + result.similarity);
-
- // 点击找到的位置
- touch.tap(result.x, result.y);
-
- return true;
- } else {
- printl("ai.findImageOne未找到匹配结果");
- return false;
- }
- } else {
- printl("❌ ai模块不可用或findImageOne方法不存在");
- return false;
- }
- } catch (e) {
- printl("ai.findImageOne执行错误: " + String(e));
- return false;
- }
- }
- /**
- * 使用ai.setSpeed设置AI速度
- * @param {number} speed - 速度值
- * @returns {boolean} 是否设置成功
- */
- function aiSetSpeed(speed) {
- printl("开始使用ai.setSpeed设置速度: " + speed);
-
- try {
- // 检查ai是否可用
- if (typeof ai !== 'undefined' && typeof ai.setSpeed === 'function') {
- ai.setSpeed(speed);
- printl("ai.setSpeed设置成功");
- return true;
- } else {
- printl("❌ ai模块不可用或setSpeed方法不存在");
- return false;
- }
- } catch (e) {
- printl("ai.setSpeed执行错误: " + String(e));
- return false;
- }
- }
- /**
- * 使用opencv.findImageOneKAZE找图(KAZE算法)
- * @param {Object} bigMat - 大图矩阵
- * @param {Object} smallMat - 小图矩阵
- * @param {Object} resultMat - 结果矩阵
- * @returns {boolean} 是否找到并点击目标
- */
- function opencvFindImageOneKAZE(bigMat, smallMat, resultMat) {
- printl("开始使用opencv.findImageOneKAZE找图");
-
- try {
- // 检查opencv是否可用
- if (typeof opencv !== 'undefined' && typeof opencv.findImageOneKAZE === 'function') {
- var result = opencv.findImageOneKAZE(bigMat, smallMat, resultMat);
-
- if (result !== null) {
- printl("opencv.findImageOneKAZE查找成功");
- printl("位置: (" + result.x + ", " + result.y + ")");
- printl("相似度: " + result.similarity);
-
- // 点击找到的位置
- touch.tap(result.x, result.y);
-
- return true;
- } else {
- printl("opencv.findImageOneKAZE未找到匹配结果");
- return false;
- }
- } else {
- printl("❌ opencv模块不可用或findImageOneKAZE方法不存在");
- return false;
- }
- } catch (e) {
- printl("opencv.findImageOneKAZE执行错误: " + String(e));
- return false;
- }
- }
- /**
- * 使用opencv.findImageOneSift找图(SIFT算法)
- * @param {Object} bigMat - 大图矩阵
- * @param {Object} smallMat - 小图矩阵
- * @param {number} param1 - 参数1
- * @param {number} param2 - 参数2
- * @param {Array} region - 区域
- * @returns {boolean} 是否找到并点击目标
- */
- function opencvFindImageOneSift(bigMat, smallMat, param1, param2, region) {
- printl("开始使用opencv.findImageOneSift找图");
-
- try {
- // 检查opencv是否可用
- if (typeof opencv !== 'undefined' && typeof opencv.findImageOneSift === 'function') {
- var result = opencv.findImageOneSift(bigMat, smallMat, param1, param2, region);
-
- if (result !== null) {
- printl("opencv.findImageOneSift查找成功");
- printl("位置: (" + result.x + ", " + result.y + ")");
- printl("相似度: " + result.similarity);
-
- // 点击找到的位置
- touch.tap(result.x, result.y);
-
- return true;
- } else {
- printl("opencv.findImageOneSift未找到匹配结果");
- return false;
- }
- } else {
- printl("❌ opencv模块不可用或findImageOneSift方法不存在");
- return false;
- }
- } catch (e) {
- printl("opencv.findImageOneSift执行错误: " + String(e));
- return false;
- }
- }
- /**
- * 使用opencv.findImagesEx找图
- * @param {string} cvFile - CV文件名
- * @returns {boolean} 是否找到并点击目标
- */
- function opencvFindImagesEx(cvFile) {
- printl("开始使用opencv.findImagesEx找图: " + cvFile);
-
- try {
- // 检查opencv是否可用
- if (typeof opencv !== 'undefined' && typeof opencv.findImagesEx === 'function') {
- var detects = opencv.findImagesEx(cvFile);
-
- if (detects !== null && detects.length > 0) {
- printl("opencv.findImagesEx找到 " + detects.length + " 个匹配结果");
-
- // 处理第一个结果
- var result = detects[0];
- printl("位置: (" + (result.x || 0) + ", " + (result.y || 0) + ")");
- printl("尺寸: " + (result.width || 0) + "x" + (result.height || 0));
- printl("相似度: " + (result.similarity || 0));
-
- // 点击找到的位置
- result.click();
-
- return true;
- } else {
- printl("opencv.findImagesEx未找到匹配结果");
- return false;
- }
- } else {
- printl("❌ opencv模块不可用或findImagesEx方法不存在");
- return false;
- }
- } catch (e) {
- printl("opencv.findImagesEx执行错误: " + String(e));
- return false;
- }
- }
- /**
- * 使用opencv.findMultiColor找多色
- * @param {Object} mat - 图像矩阵
- * @param {string} basePoint - 基准点
- * @param {Array} colorPoints - 颜色点数组
- * @param {number} colorTolerance - 颜色容差
- * @param {number} offsetTolerance - 偏移容差
- * @param {Array} region - 区域
- * @param {number} similarity - 相似度
- * @returns {boolean} 是否找到并点击目标
- */
- function opencvFindMultiColor(mat, basePoint, colorPoints, colorTolerance, offsetTolerance, region, similarity) {
- printl("开始使用opencv.findMultiColor找多色");
-
- try {
- // 检查opencv是否可用
- if (typeof opencv !== 'undefined' && typeof opencv.findMultiColor === 'function') {
- var result = opencv.findMultiColor(mat, basePoint, colorPoints, colorTolerance, offsetTolerance, region, similarity);
-
- if (result !== null) {
- printl("opencv.findMultiColor查找成功");
- printl("位置: (" + result.x + ", " + result.y + ")");
-
- // 点击找到的位置
- touch.tap(result.x, result.y);
-
- return true;
- } else {
- printl("opencv.findMultiColor未找到匹配结果");
- return false;
- }
- } else {
- printl("❌ opencv模块不可用或findMultiColor方法不存在");
- return false;
- }
- } catch (e) {
- printl("opencv.findMultiColor执行错误: " + String(e));
- return false;
- }
- }
- /**
- * 使用opencv.findMultiColorEx找多色扩展
- * @param {string} params - 参数
- * @returns {boolean} 是否找到并点击目标
- */
- function opencvFindMultiColorEx(params) {
- printl("开始使用opencv.findMultiColorEx找多色扩展");
-
- try {
- // 检查opencv是否可用
- if (typeof opencv !== 'undefined' && typeof opencv.findMultiColorEx === 'function') {
- var result = opencv.findMultiColorEx(params);
-
- if (result !== null) {
- printl("opencv.findMultiColorEx查找成功");
- printl("位置: (" + result.x + ", " + result.y + ")");
-
- // 点击找到的位置
- touch.tap(result.x, result.y);
-
- return true;
- } else {
- printl("opencv.findMultiColorEx未找到匹配结果");
- return false;
- }
- } else {
- printl("❌ opencv模块不可用或findMultiColorEx方法不存在");
- return false;
- }
- } catch (e) {
- printl("opencv.findMultiColorEx执行错误: " + String(e));
- return false;
- }
- }
- /**
- * 使用opencv.findImages找多图
- * @param {Array} images - 图像数组
- * @returns {boolean} 是否找到并点击目标
- */
- function opencvFindImages(images) {
- printl("开始使用opencv.findImages找多图");
-
- try {
- // 检查opencv是否可用
- if (typeof opencv !== 'undefined' && typeof opencv.findImages === 'function') {
- var results = opencv.findImages(images);
-
- if (results !== null && results.length > 0) {
- printl("opencv.findImages找到 " + results.length + " 个匹配结果");
-
- // 处理第一个结果
- var result = results[0];
- printl("位置: (" + result.x + ", " + result.y + ")");
- printl("相似度: " + result.similarity);
-
- // 点击找到的位置
- touch.tap(result.x, result.y);
-
- return true;
- } else {
- printl("opencv.findImages未找到匹配结果");
- return false;
- }
- } else {
- printl("❌ opencv模块不可用或findImages方法不存在");
- return false;
- }
- } catch (e) {
- printl("opencv.findImages执行错误: " + String(e));
- return false;
- }
- }
- /**
- * 创建图像对象
- * @param {string} path - 图像路径
- * @returns {Object} 图像对象
- */
- function createImage(path) {
- try {
- var img = new image();
- img.read(path);
- return img;
- } catch (e) {
- printl("创建图像对象错误: " + String(e));
- return null;
- }
- }
- /**
- * 演示KAZE图像查找
- * @returns {boolean} 是否成功
- */
- function demonstrateKAZEFindImage() {
- printl("开始演示KAZE图像查找");
-
- try {
- // 创建图像对象
- var image1 = createImage("sdcard/auto/1.jpg");
- var image2 = createImage("sdcard/auto/2.jpg");
-
- if (image1 && image2) {
- var c = new Mat();
- var res = opencv.findImageOneKAZE(image2.getMat(), image1.getMat(), c);
- printl(res);
- return true;
- } else {
- printl("创建图像对象失败");
- return false;
- }
- } catch (e) {
- printl("KAZE图像查找演示错误: " + String(e));
- return false;
- }
- }
- /**
- * 演示所有找图方法
- */
- function demonstrateAllFindImageMethods() {
- printl("=== AIWROK 找图方法汇总示例 ===");
-
- // 安全获取APP版本
- try {
- if (typeof app !== 'undefined' && app && typeof app.version !== 'undefined') {
- printl("APP版本: " + app.version);
- } else {
- printl("APP版本: 未知");
- }
- } catch (e) {
- printl("获取APP版本失败: " + String(e));
- }
-
- // 获取屏幕尺寸
- var screenWidth = 1080; // 默认值
- var screenHeight = 1920; // 默认值
-
- try {
- if (typeof screen !== 'undefined' && screen) {
- if (typeof screen.getScreenWidth === 'function') {
- screenWidth = screen.getScreenWidth();
- screenHeight = screen.getScreenHeight();
- }
- }
- } catch (e) {
- printl("获取屏幕尺寸失败,使用默认值: " + String(e));
- }
-
- printl("设备分辨率: " + screenWidth + "x" + screenHeight);
-
- // 1. 基础找图
- printl("\n 1. 基础找图示例:");
- basicFindImage();
- sleep.second(1);
-
- // 2. 多图像查找
- printl("\n 2. 多图像查找示例:");
- multiFindImage();
- sleep.second(1);
-
- // 3. 截图找图
- printl("\n 3. 截图找图示例:");
- screenshotFindImage();
- sleep.second(1);
-
- // 4. SIFT图像查找
- printl("\n 4. SIFT图像查找示例:");
- siftFindImage();
- sleep.second(1);
-
- // 5. 多点找色
- printl("\n 5. 多点找色示例:");
- multiColorFind();
- sleep.second(1);
-
- printl("\n=== 找图方法演示完成 ===");
- }
- /**
- * 运行所有找图模块演示
- */
- function runAllFindImageModulesDemo() {
- printl("开始执行找图方法汇总示例");
-
- // 演示基本找图方法
- demonstrateAllFindImageMethods();
-
- // 演示opencv.findImagesEx
- printl("\n演示opencv.findImagesEx:");
- var detects = opencv.findImagesEx('图色823706.cv');
- printl("opencv.findImagesEx结果: " + detects);
- if (detects != null) {
- printl("找到 " + detects.length + " 个匹配结果");
- if (detects.length > 0) {
- detects[0].click();
- }
- }
-
- // 演示opencv.findImages
- printl("\n演示opencv.findImages:");
- printl("opencv.findImages方法在当前AIWROK版本中不可用,跳过执行");
-
- printl("\n找图方法汇总示例执行完毕");
- }
- // 运行示例
- runAllFindImageModulesDemo();
复制代码
| |  | |  |
|