From dda0d0755a24ceb5230660e59a2de5b3a0539889 Mon Sep 17 00:00:00 2001 From: skyflag2022 <107539971+skyflag2022@users.noreply.github.com> Date: Mon, 16 Mar 2026 01:59:18 +0800 Subject: [PATCH] Update (#2997) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 增加延迟 * 修改 --- repo/js/ArtifactExpCount/main.js | 66 ++++----- repo/js/ArtifactExpCount/manifest.json | 2 +- repo/js/营养袋吃药统计/assets/背包数字/0.png | Bin 0 -> 564 bytes repo/js/营养袋吃药统计/assets/背包数字/1.png | Bin 0 -> 234 bytes repo/js/营养袋吃药统计/assets/背包数字/2.png | Bin 0 -> 539 bytes repo/js/营养袋吃药统计/assets/背包数字/3.png | Bin 0 -> 555 bytes repo/js/营养袋吃药统计/assets/背包数字/4.png | Bin 0 -> 454 bytes repo/js/营养袋吃药统计/assets/背包数字/5.png | Bin 0 -> 490 bytes repo/js/营养袋吃药统计/assets/背包数字/6.png | Bin 0 -> 608 bytes repo/js/营养袋吃药统计/assets/背包数字/7.png | Bin 0 -> 399 bytes repo/js/营养袋吃药统计/assets/背包数字/8.png | Bin 0 -> 567 bytes repo/js/营养袋吃药统计/assets/背包数字/9.png | Bin 0 -> 512 bytes repo/js/营养袋吃药统计/main.js | 146 +++++++++++++++---- repo/js/营养袋吃药统计/manifest.json | 2 +- 14 files changed, 150 insertions(+), 66 deletions(-) create mode 100644 repo/js/营养袋吃药统计/assets/背包数字/0.png create mode 100644 repo/js/营养袋吃药统计/assets/背包数字/1.png create mode 100644 repo/js/营养袋吃药统计/assets/背包数字/2.png create mode 100644 repo/js/营养袋吃药统计/assets/背包数字/3.png create mode 100644 repo/js/营养袋吃药统计/assets/背包数字/4.png create mode 100644 repo/js/营养袋吃药统计/assets/背包数字/5.png create mode 100644 repo/js/营养袋吃药统计/assets/背包数字/6.png create mode 100644 repo/js/营养袋吃药统计/assets/背包数字/7.png create mode 100644 repo/js/营养袋吃药统计/assets/背包数字/8.png create mode 100644 repo/js/营养袋吃药统计/assets/背包数字/9.png diff --git a/repo/js/ArtifactExpCount/main.js b/repo/js/ArtifactExpCount/main.js index 587a3e28e..5fff0e038 100644 --- a/repo/js/ArtifactExpCount/main.js +++ b/repo/js/ArtifactExpCount/main.js @@ -1,5 +1,5 @@ let notify = settings.notify -let account = settings.account || "默认账户"; +let account = settings.userName || "默认账户"; (async function () { // 设置分辨率和缩放 setGameMetrics(1920, 1080, 1); @@ -105,11 +105,14 @@ let account = settings.account || "默认账户"; const formattedExpBig = await formatExp(expBig); const formattedExpStock = await formatExp(expStock); const formattedTotalExp = await formatExp(totalExp); + + // 记录保存功能 + const userName = await getUserName(); + const recordPath = `assets/${userName}.txt`; // 构建通知消息 let message = `📦 圣遗物经验统计\n`; - message += `\n`; - message += `💾 已储存经验:${initialValue} 点\n`; + message += `👤 账户名:${userName}\n`;; message += `\n`; message += `📊 [狗粮数量统计]\n`; message += `📦 总数量:${totalCount} 个\n`; @@ -125,9 +128,6 @@ let account = settings.account || "默认账户"; message += `💰 库存经验合计:${formattedExpStock}(含储存${initialValue}点)\n`; message += `\n`; message += `✨ 总经验:${formattedTotalExp}\n`; - // 记录保存功能 - const userName = await getUserName(); - const recordPath = `assets/${userName}.txt`; // 获取本地保存的数据 const localData = await getLocalData(recordPath); @@ -248,32 +248,33 @@ let account = settings.account || "默认账户"; const gameRegion = captureGameRegion(); const allCandidates = []; - /* 1. splitCount 次等间隔阈值递减 */ - for (let k = 0; k < splitCount; k++) { - const curThr = maxThreshold - (maxThreshold - minThreshold) * k / Math.max(splitCount - 1, 1); - setThreshold(ros, curThr); + try{ + /* 1. splitCount 次等间隔阈值递减 */ + for (let k = 0; k < splitCount; k++) { + const curThr = maxThreshold - (maxThreshold - minThreshold) * k / Math.max(splitCount - 1, 1); + setThreshold(ros, curThr); - /* 2. 0-9 每个模板跑一遍,所有框都收 */ - for (let digit = 0; digit <= 9; digit++) { - const res = gameRegion.findMulti(ros[digit]); - if (res.count === 0) continue; + /* 2. 0-9 每个模板跑一遍,所有框都收 */ + for (let digit = 0; digit <= 9; digit++) { + const res = gameRegion.findMulti(ros[digit]); + if (res.count === 0) continue; - for (let i = 0; i < res.count; i++) { - const box = res[i]; - allCandidates.push({ - digit: digit, - x: box.x, - y: box.y, - w: box.width, - h: box.height, - thr: curThr - }); + for (let i = 0; i < res.count; i++) { + const box = res[i]; + allCandidates.push({ + digit: digit, + x: box.x, + y: box.y, + w: box.width, + h: box.height, + thr: curThr + }); + } } } - + }catch{ + gameRegion.dispose(); } - gameRegion.dispose(); - /* 3. 无结果提前返回 -1 */ if (allCandidates.length === 0) { return -1; @@ -325,17 +326,6 @@ let account = settings.account || "默认账户"; return false; } - // 检验账户名 - async function getUserName() { - userName = userName.trim(); - // 账户名规则:数字、中英文,长度1-20字符 - if (!userName || !/^[\u4e00-\u9fa5A-Za-z0-9]{1,20}$/.test(userName)) { - log.error(`账户名${userName}违规,暂时使用默认账户名,请查看readme后修改`) - userName = "默认账户"; - } - return userName; - } - async function close_expired_stuff_popup_window() { const game_region = captureGameRegion(); const text_x = 850; diff --git a/repo/js/ArtifactExpCount/manifest.json b/repo/js/ArtifactExpCount/manifest.json index 99ed86c62..90a329eb7 100644 --- a/repo/js/ArtifactExpCount/manifest.json +++ b/repo/js/ArtifactExpCount/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 1, "name": "圣遗物经验统计", - "version": "1.0", + "version": "1.1", "bgi_version": "0.55", "description": "识别可分解的1-4星圣遗物和经验瓶数量", "authors": [ diff --git a/repo/js/营养袋吃药统计/assets/背包数字/0.png b/repo/js/营养袋吃药统计/assets/背包数字/0.png new file mode 100644 index 0000000000000000000000000000000000000000..da4d074628bfb4356fb0864da7c10ed2169106ff GIT binary patch literal 564 zcmV-40?Yl0P)JP00001b5ch_0Itp) z=>Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D0m(^3K~yMHby90f zVo?-bp8L>SW@ef8(DXwyQq2?$4KqC;3c`>5+&;uWR8$l}Gi4|hcFXiinvX>9F}>}3 z%LoQ#$YpVsHcL3qZ0Gz5~7lzm4Ml>80dBfyL zB-3DeCQnII2m=104{;Y`qdutboULWgrK)({hPz)Awm!q{?r}xZGLtu9wJkv?iVWr; z!=IqYJoWYKwTpHwYF92cWrBK^RZZsMk%hCQ^aNTmdHMB92Z4!NN3I`>6EcQuzhRn|m}G zrVwO}0@8X`SoI9_W9G{gWS3LL>aTC2Wq0=m_KyCcO(nb}xJ=z4OG8y@pOzM95D5h! zme2NRkN)&L3H>22x+O^xwUJ|xrX8COiIwpWd+`PaOv8>}Uv20B0000O>_4AgKKgc*)gmcHf$9 zup#G8Vb8;N&FMVx`|6T^{GZRr@z2Uu7#J8EJMI){IMvLwi^Is!a3NPw(I(>$Ma51mGbJP?fBf7b+4D6-Qsjw> a1Viy8#eRXiPOE@UVeoYIb6Mw<&;$T|_)(|; literal 0 HcmV?d00001 diff --git a/repo/js/营养袋吃药统计/assets/背包数字/2.png b/repo/js/营养袋吃药统计/assets/背包数字/2.png new file mode 100644 index 0000000000000000000000000000000000000000..1b4ebe3639035583e45b56a02919df4e768ad5fc GIT binary patch literal 539 zcmV+$0_6RPP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D0kBC#K~yMHb&$q2%U#tkmK0ThrJ5V30Vc-I zac6RZuH=Q(v-w<+NI1leYZpnUM$jW+wzl_JTd!g_90IHI;kqu9=}Syy(j1Q-V{hEV zt~=zGO01MN(02crghD|E2l^D?t0x{M9@Eh@4a;tz_4mdYKAq?QzUuOX<21p8E(r!6 zJ;)G}W`_n(D4^A9Q~puI*xaGjZjyn@BIrJVQj z?IH_{-*Kgf^pz3r%PP)FPza%HXm92Ve99L&IJ6lXO)_=wI>|Ew9l*Du6^a!Ot-AU= zmFQLJei^^j{FGDKs3E3jo_Ma?lEn%7dSd8$SZ(m-wLMIEK|Fl?v{S*q002ovPDHLkV1jL>_7eaA literal 0 HcmV?d00001 diff --git a/repo/js/营养袋吃药统计/assets/背包数字/3.png b/repo/js/营养袋吃药统计/assets/背包数字/3.png new file mode 100644 index 0000000000000000000000000000000000000000..b37488276c653aa0e9ff5758026bc16b59a9b6b1 GIT binary patch literal 555 zcmV+`0@VG9P)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D0l-N_K~yMHJ(62b z6Hyd}zqz!4ZD~Oe3N*A5tpP$XF?hikpM3K_@pp_dF_DBPpBh8(hC$O%Dbm}tov}As zT1sJNJm);Pl9O}Wd!4oRKHBN;pMIfiQ?5F6y8~R$Wh@vV7LAZh%&{1sL3{J|ouAo1 z!m2k31WYju`u!n>p|g@);N|uvMtpg7M>5?@E%NNqDr@N^vB@yaPM2cEW^j3hX*+Fo z`26uYTMr*#ng*>-kN#lD7cuA0EcE%gX*SmGl318k0TNTuFp=;Cnx-)t-JrjI^^_M+ zHki2`Qvts3W7Qh`ZJy(K9@A41G~3Gi^75=yQ{soi5&1%uY_2GnV0&vFQ>6>!@)h>K zW@(=bJ;I$USfqU^<3CgGv`neuC^yx5L+mSDU*C{kNucGjKm4F5-uPG$T^IZUb*IJq zy-$2QI>B{ajMV+j9hn`AhE$+LI5dIX=!iNw46jD$A2Wx1K0Kz??x_F?=}Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D0b5B#K~yMHg^|rm z0znwYpZ(BWcGI=8@*@i*=un3w>QF?`$E9O*>JR9T>e{taSeHDQw2&PnA|k1zQvATJ zlp+n?ZDw3or9%%4v->{3d1mGvu9SZ;(WB?r5)KYy$QLUxiLYW8PSSY!8be@w1fnQd4uQ#FAl>qW zY)R+M)hN8GLd#4h!w6^?Ca%)=$UNq-Ob#6i_#g`1G>ZdYuDm0jOk+qL#8PwyiY&Dq zOLpREJcWC=5!D(9ZPu$V*IWkWPx#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D0e?wEK~yMHZIR6{ z13?(ZpWW%U^ix$;h1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)fz;B%VHJJ-52n}MHz-+!lSyd_%SV?nREini_@5zh{3XK zw4OTPZ+!zIOv^&&xhLNuY}-cPc>f15@Wfb1e)f8=$ZJ>F&!3@G`HRB&HHz1F)Dpu7 z-ym2nm$kQl?4f*917{3@VJ~8%Av`o%xUbdaa9>syz*C8c?8~h>rL10W;rR3qZtipv zWO6?i4T6`-_oz@cM%8>?59a44keQ6bJLG|3nyB9D$o)Km5**EJot&4TIvrAC?eh}S z<70Ga5N#UnvDHDN*@hCJM1>e8sfF(w-w+88BNX%_6_1b#$Jtc{eImmJ2Ci@^C8qly zDsi1o$H^t9TyuqzEYp%u^?FloiZF=bL*q%BArL9+8=G4q;pMe2t?Clbn%=|(StpnZ zM1J28*v?MQ{Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D0hLKaK~yMHO_5tq z8c`I5zhQs@(V`?oK*UiXDbb+lgT^+gZPO^r=6j#-xo&eX(t9qD{Swwh;&j zI0aF>z%V`MkX}}Da&q?GYwx|*(bnI*b$9nHnyo9wqhkaNKh?U8>$+s7CsO} z`h8xmJGX4_eB-{`V>lGV7DA3rOWfUe2Su|FO^!}V?Cc&;so4w#4Z1ytvr>(oxaB6= z_Qx&v`*D$m-NF&UfY?Psk}lgFBBMf(G%Rf<)DDtq7(O;We8v^3WS7N!_Mf`YP(WA_ zqFib4b>C8?sbq|mrQD$C4=U#uY;JuKw@rLJ!ppTKlEN=l)N>rHA7$RX|HOe+#7xC_ z^?aGaTt*qIotG`QDpbim>K9Ft@u>Qq=~NtP55R9SzoZQzbE)6}0000= 0) console.log(`当前摩拉:${mora}`); + */ + async function numberTemplateMatch( + numberPngFilePath, + x = 0, y = 0, w = 1920, h = 1080, + maxThreshold = 0.95, + minThreshold = 0.8, + splitCount = 3, + maxOverlap = 2 + ) { + let ros = []; + for (let i = 0; i <= 9; i++) { + ros[i] = RecognitionObject.TemplateMatch( + file.ReadImageMatSync(`${numberPngFilePath}/${i}.png`), x, y, w, h); + } - if (!resList || resList.length === 0) { - log.warn("OCR未识别到任何文本"); - return null; + function setThreshold(roArr, newThreshold) { + for (let i = 0; i < roArr.length; i++) { + roArr[i].Threshold = newThreshold; + roArr[i].InitTemplate(); } + } - for (const res of resList) { - if (!res || !res.text) { - continue; - } - const numberMatch = res.text.match(pattern); - if (numberMatch) { - const number = parseInt(numberMatch[1] || numberMatch[0]); - if (!isNaN(number)) { - return number; + const gameRegion = captureGameRegion(); + const allCandidates = []; + + /* 1. splitCount 次等间隔阈值递减 */ + try{ + for (let k = 0; k < splitCount; k++) { + const curThr = maxThreshold - (maxThreshold - minThreshold) * k / Math.max(splitCount - 1, 1); + setThreshold(ros, curThr); + /* 2. 0-9 每个模板跑一遍,所有框都收 */ + for (let digit = 0; digit <= 9; digit++) { + const res = gameRegion.findMulti(ros[digit]); + if (res.count === 0) continue; + for (let i = 0; i < res.count; i++) { + const box = res[i]; + allCandidates.push({ + digit: digit, + x: box.x, + y: box.y, + w: box.width, + h: box.height, + thr: curThr + }); } } } + }finally { + gameRegion.dispose(); } - catch (error) { - log.error(`OCR识别时发生异常: ${error.message}`); + + /* 3. 无结果提前返回 -1 */ + if (allCandidates.length === 0) { + return -1; } - finally { - if (captureRegion) { - captureRegion.dispose(); + + /* 4. 非极大抑制(必须 x、y 两个方向重叠都 > maxOverlap 才视为重复) */ + const adopted = []; + for (const c of allCandidates) { + let overlap = false; + for (const a of adopted) { + const xOverlap = Math.max(0, Math.min(c.x + c.w, a.x + a.w) - Math.max(c.x, a.x)); + const yOverlap = Math.max(0, Math.min(c.y + c.h, a.y + a.h) - Math.max(c.y, a.y)); + if (xOverlap > maxOverlap && yOverlap > maxOverlap) { + overlap = true; + break; + } + } + if (!overlap) { + adopted.push(c); + //log.info(`在 [${c.x},${c.y},${c.w},${c.h}] 找到数字 ${c.digit},匹配阈值=${c.thr}`); } } - return null; + + /* 5. 按 x 排序,拼整数;仍无有效框时返回 -1 */ + if (adopted.length === 0) return -1; + adopted.sort((a, b) => a.x - b.x); + + return adopted.reduce((num, item) => num * 10 + item.digit, 0); + } + + /** + * 识别背包中指定物品的数量 + * @param {string} itemName - 物品名称(仅用于日志) + * @param {number} x - 数字区域左上角x坐标 + * @param {number} y - 数字区域左上角y坐标 + * @param {number} width - 数字区域宽度 + * @param {number} height - 数字区域高度 + * @returns {Promise} 识别到的数字字符串(可能为空) + */ + async function getFoodCount(itemName, ocrRegion) { + for (let i = 0; i < 5; i++) { + try { + // 使用numberTemplateMatch函数识别数字 + const count = await numberTemplateMatch( + 'assets/背包数字', // 数字模板文件夹路径 + ocrRegion.x, ocrRegion.y, ocrRegion.width, ocrRegion.height + ); + const digits = count === -1 ? '' : count.toString(); + log.info(`识别到${itemName}数量为${digits}`); + //log.info(`识别到${itemName}识别区域为${x}, ${y}, ${width}, ${height}`) + return digits; // 成功识别即返回 + } catch (error) { + log.error(`识别${itemName}数量时发生错误: ${error.message}`); + } + if (i < 5 - 1) await sleep(50); + } + return ''; // 未找到时返回空字符串 } async function recognizeFoodItemByOCR(ocrRegion, pattern) { @@ -490,7 +583,7 @@ function escapeRegExp(string) { } async function clickPNG(png, maxAttempts = 20, doClick=true) { -// log.info(`调试-点击目标${png},重试次数${maxAttempts}`); + //log.info(`调试-点击目标${png},重试次数${maxAttempts}`); const pngRo = RecognitionObject.TemplateMatch(file.ReadImageMatSync(`assets/${png}.png`)); pngRo.Threshold = 0.95; pngRo.InitTemplate(); @@ -583,7 +676,8 @@ function escapeRegExp(string) { inputText(drugName); await clickPNG('确认筛选'); await sleep(loadDelay); - const count = await recognizeNumberByOCR(ocrRegion2, /\d+/) || 0; + const countStr = await getFoodCount(drugName, ocrRegion2); + const count = Number(countStr || 0); if (count === 0) { notification.send(`【营养袋吃药统计】\n未识别到${drugType}数量\n药品名:${drugName}\n设置数量为:0`); diff --git a/repo/js/营养袋吃药统计/manifest.json b/repo/js/营养袋吃药统计/manifest.json index 2a727e275..faaa86522 100644 --- a/repo/js/营养袋吃药统计/manifest.json +++ b/repo/js/营养袋吃药统计/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 1, "name": "吃药统计", - "version": "1.8", + "version": "1.9", "bgi_version": "0.51", "description": "用于查询指定多个食物的消耗,推荐锄地前后使用", "authors": [