mirror of
https://github.com/babalae/bettergi-scripts-list.git
synced 2026-03-31 05:59:51 +08:00
feat(config): 添加OCR识别UID功能
- 在配置文件中导入ocrUid工具函数 - 修复checkKey函数中参数赋值的格式问题 - 在initConfig函数中集成OCR识别获取用户UID - 将识别到的UID存储到配置对象中 - 在主程序中使用配置中的UID替代未定义变量 - 新增tool.js工具模块实现区域OCR识别功能 - 新增uid.js模块专门处理UID识别逻辑 - 实现了屏幕指定区域的文字识别功能
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import {ocrUid} from "../utils/uid";
|
||||
|
||||
const config = {
|
||||
//setting设置放在这个json
|
||||
domain: {
|
||||
@@ -116,10 +118,11 @@ async function getValueByMultiCheckboxName(name) {
|
||||
log.debug("values={key}", JSON.stringify(values))
|
||||
return values
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查密钥是否正确
|
||||
*/
|
||||
async function checkKey(key="") {
|
||||
async function checkKey(key = "") {
|
||||
if (config.info.key !== key.trim()) {
|
||||
throw new Error("密钥错误");
|
||||
}
|
||||
@@ -410,6 +413,7 @@ async function initConfig() {
|
||||
if (config.domainList.length <= 0) {
|
||||
throw new Error("配置文件缺失或读取异常!")
|
||||
}
|
||||
config.user.uid = await ocrUid()
|
||||
}
|
||||
|
||||
export {
|
||||
|
||||
@@ -46,7 +46,7 @@ function initDomainOrderList(domainConfig) {
|
||||
DomainRoundNum: undefined,//副本轮数
|
||||
} // 秘境信息对象
|
||||
}*/
|
||||
const uid = undefined
|
||||
const uid = config.user.uid
|
||||
if (uid) {
|
||||
const configAutoFightOrderMap = JSON.parse(file.readTextSync(config.path.domainConfig)) || new Map()
|
||||
const uidConfigList = configAutoFightOrderMap.get(uid) || [];
|
||||
|
||||
33
repo/js/AutoPlanDomain/utils/tool.js
Normal file
33
repo/js/AutoPlanDomain/utils/tool.js
Normal file
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* 对指定区域进行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
|
||||
}
|
||||
31
repo/js/AutoPlanDomain/utils/uid.js
Normal file
31
repo/js/AutoPlanDomain/utils/uid.js
Normal file
@@ -0,0 +1,31 @@
|
||||
import {ocrRegion} from './tool.js'
|
||||
|
||||
async function saveOnlyNumber(str) {
|
||||
str = str ? str : '';
|
||||
// 使用正则表达式匹配字符串中的所有数字
|
||||
// \d+ 匹配一个或多个数字
|
||||
// .join('') 将匹配到的数字数组连接成一个字符串
|
||||
// parseInt 将连接后的字符串转换为整数
|
||||
return parseInt(str.match(/\d+/g).join(''));
|
||||
}
|
||||
|
||||
/**
|
||||
* OCR识别UID的异步函数
|
||||
* 该函数用于通过OCR技术识别屏幕上特定位置的UID文本
|
||||
* @returns {Promise<number>} - 异步函数,没有明确的返回值
|
||||
*/
|
||||
async function ocrUid() {
|
||||
// 定义OCR识别的坐标和尺寸参数
|
||||
let uid_json = {
|
||||
x: 1683, // OCR识别区域的左上角x坐标
|
||||
y: 1051, // OCR识别区域的左上角y坐标
|
||||
width: 234, // OCR识别区域的宽度
|
||||
height: 28, // OCR识别区域的高度
|
||||
}
|
||||
let text = await ocrRegion(uid_json.x, uid_json.y, uid_json.width, uid_json.height);
|
||||
return await saveOnlyNumber(text);
|
||||
}
|
||||
|
||||
export {
|
||||
ocrUid,
|
||||
}
|
||||
Reference in New Issue
Block a user