Files
bettergi-scripts-list/repo/js/AutoPlanDomain/utils/tool.js
yan f1a019ea98 feat(config): 添加OCR识别UID功能
- 在配置文件中导入ocrUid工具函数
- 修复checkKey函数中参数赋值的格式问题
- 在initConfig函数中集成OCR识别获取用户UID
- 将识别到的UID存储到配置对象中
- 在主程序中使用配置中的UID替代未定义变量
- 新增tool.js工具模块实现区域OCR识别功能
- 新增uid.js模块专门处理UID识别逻辑
- 实现了屏幕指定区域的文字识别功能
2026-02-08 14:36:44 +08:00

33 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 对指定区域进行OCR文字识别
* @param {number} x - 区域左上角x坐标默认为0
* @param {number} y - 区域左上角y坐标默认为0
* @param {number} w - 区域宽度默认为1920
* @param {number} h - 区域高度默认为1080
* @returns {Promise<string|null>} 返回识别到的文本内容如果识别失败则返回null
*/
async function ocrRegion(x = 0,
y = 0,
w = 1920,
h = 1080) {
// 创建OCR识别对象使用指定的坐标和尺寸
let recognitionObjectOcr = RecognitionObject.Ocr(x, y, w,h);
// 捕获游戏区域图像
let region3 = captureGameRegion()
try {
// 在捕获的区域中查找OCR识别对象
let res = region3.find(recognitionObjectOcr);
// 返回识别到的文本内容如果不存在则返回undefined
return res?.text
} catch (e) {
// 捕获并记录错误信息
log.error("识别异常:{1}", e.message)
return null
} finally {
// 确保释放区域资源
region3.Dispose()
}
}
export {
ocrRegion
}