v.2.0版本 自动幽境危战 20250830 (#1770)

### v.2.0版本:20250830

- **优化**:
1. 改用模板匹配进行浓缩树脂识别,使用颜色遮罩模板,全脚本要求BGI版本提高到0.47.1。
2. 针对2K和4K分辨率,降低匹配度要求,提高识别精度。
This commit is contained in:
kaedelcb
2025-08-30 12:03:43 +08:00
committed by GitHub
parent 47e3a238c7
commit 8148819108
13 changed files with 106 additions and 90 deletions

View File

@@ -41,6 +41,12 @@
## 三、更新说明
### v.2.0版本20250830
- **优化**
1. 改用模板匹配进行浓缩树脂识别使用颜色遮罩模板全脚本要求BGI版本提高到0.47.1。
2. 针对2K和4K分辨率降低匹配度要求提高识别精度。
### v.1.9版本20250828
- **新功能**

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.0 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@@ -1,26 +1,26 @@
{
"info": {
"name": "全自动幽境危战",
"type": "collect",
"author": "LCB-茶包",
"version": "1.0",
"description": "",
"bgi_version": "0.44.8"
},
"positions": [
{
"id": 1,
"x": -194.198,
"y": 984.095,
"move_mode": "walk",
"type": "teleport"
},
{
"id": 2,
"x": -194.25293,
"y": 980.6616,
"move_mode": "walk",
"type": "target"
}
]
{
"info": {
"name": "全自动幽境危战",
"type": "collect",
"author": "LCB-茶包",
"version": "1.0",
"description": "",
"bgi_version": "0.44.8"
},
"positions": [
{
"id": 1,
"x": -194.198,
"y": 984.095,
"move_mode": "walk",
"type": "teleport"
},
{
"id": 2,
"x": -194.25293,
"y": 980.6616,
"move_mode": "walk",
"type": "target"
}
]
}

View File

@@ -1,5 +1,10 @@
(async function () {
var Threshold = genshin.width > 2560 ? 0.65
: genshin.width > 1920 ? 0.7
: 0.8;
log.warn(`屏幕分辨率${genshin.width},识别阈值调整为${Threshold}...`);
let challengeNum = settings.challengeNum;//挑战次数
if (challengeNum === undefined || challengeNum === ""){challengeNum = 15; }//挑战次数
let challengeName = settings.challengeName;//挑战BOSS
@@ -63,10 +68,17 @@
var originalResin = "assets/original_resin_count.png";
var fragileResin = "assets/fragile_resin_count.png";
var momentResin = "assets/moment_resin_count.png";
var oneResin = "assets/one.png";
var enterButton = "assets/enter.png";
var rewardsButton = "assets/rewards.png";
var resinImages = [
"assets/model/one.png",
"assets/model/two.png",
"assets/model/three.png",
"assets/model/four.png",
"assets/model/five.png"
];
//文字识别封装函数
async function Textocr(wenzi="空参数",chaotime=10,clickocr=0,debugcode=0,x=0,y=0,w=1920,h=1080) {
const startTime = new Date();
@@ -107,9 +119,15 @@
}
// 图片识别封装函数
async function imageRecognition(imagefilePath="空参数",timeout=10,afterBehavior=0,debugmodel=0,xa=0,ya=0,wa=1920,ha=1080) {
async function imageRecognition(imagefilePath="空参数",timeout=10,afterBehavior=0,debugmodel=0,xa=0,ya=0,wa=1920,ha=1080,tt=0.8) {
const startTime = new Date();
const Imagidentify = RecognitionObject.TemplateMatch(file.ReadImageMatSync(imagefilePath));
const Imagidentify = RecognitionObject.TemplateMatch(file.ReadImageMatSync(imagefilePath),true);
if (tt !== 0.8){
Imagidentify.Threshold=tt;
Imagidentify.InitTemplate();
}
for (let ii = 0; ii < 10; ii++) {
captureRegion = captureGameRegion(); // 获取一张截图
res = captureRegion.DeriveCrop(xa, ya, wa, ha).Find(Imagidentify);
@@ -135,13 +153,30 @@
async function getRemainResinStatus() {
var condensedResinCount = 0; // 浓缩树脂
var originalResinCount = 0; // 原粹树脂
var fragileResinCount = 0; // 脆弱树脂
var momentResinCount = 0; // 须臾树脂
var fragileResinCount = 0; // 脆弱树脂
var momentResinCount = 0; //须臾树脂
var originalResinCountRa = await imageRecognition(originalResin,0.3, 0, 0,1500,0,200,90);
// 浓缩树脂
var condensedResinCountRa = await imageRecognition(condensedResin,0.2, 0, 0,800,15,700,70,Threshold);
if (condensedResinCountRa.found) {
for (let i = 0; i < resinImages.length; i++) {
if(i==0){await sleep(1000);}
let countArea = await imageRecognition(resinImages[i],0.2, 0, 0,condensedResinCountRa.x+condensedResinCountRa.w*0.9,condensedResinCountRa.y,condensedResinCountRa.w*2,condensedResinCountRa.h,Threshold);
if (countArea.found){
condensedResinCount =i+1;
break;
}
if (i==4){log.info("未检测到浓缩数量强制为1"); condensedResinCount=1;}
}
}else{
log.info("未检测到浓缩树脂图标");
}
var originalResinCountRa = await imageRecognition(originalResin,0.1, 0, 0,1555,0,100,100,Threshold);
if (originalResinCountRa.found) {
// await moveMouseTo(originalResinCountRa.x,originalResinCountRa.y);
let countArea = await Textocr("",1, 0, 2,originalResinCountRa.x+originalResinCountRa.w,originalResinCountRa.y,originalResinCountRa.w*3,originalResinCountRa.h);//
let countArea = await Textocr("",0.5, 0, 2,originalResinCountRa.x+originalResinCountRa.w,originalResinCountRa.y,originalResinCountRa.w*3,originalResinCountRa.h,Threshold);//
if (countArea.found){
log.info("原粹树脂识别数量结果:"+ countArea.text);
let match = countArea.text.match(/(\d+)\s*[/17]\s*(2|20|200)/);
@@ -149,11 +184,13 @@
originalResinCount = match[1];
// log.info("脆弱树脂识别数量提取:"+ originalResinCount);
}
else{
else
{
log.info("原粹树脂识别数量提取失败");
}
}
else{
else
{
log.info("原粹树脂识别数量结果::无");
}
@@ -161,81 +198,51 @@
log.info("未检测到原粹树脂图标");
}
// 浓缩树脂
var condensedResinCountRa = await imageRecognition(condensedResin,0.1, 0, 0,960,0,800,100);
if (condensedResinCountRa.found) {
// await moveMouseTo(condensedResinCountRa.x,condensedResinCountRa.y);
let countArea = await Textocr("",0.5, 0, 2,condensedResinCountRa.x+condensedResinCountRa.w,condensedResinCountRa.y,condensedResinCountRa.w,condensedResinCountRa.h);//
if (countArea.found){
// log.info("浓缩树脂识别数量结果: "+ countArea.text);
condensedResinCount = countArea.text
if (countArea.text == "")
{
log.info("浓缩树脂识别强制为: 1");//
condensedResinCount = "1";
var momentResinCountRa = await imageRecognition(momentResin,0.2, 0, 1,1170,0,500,100,0.7,Threshold);
if (momentResinCountRa.found) {
for (let i = 0; i < resinImages.length; i++) {
let countArea = await imageRecognition(resinImages[i],0.2, 0, 0,momentResinCountRa.x+momentResinCountRa.w,momentResinCountRa.y,momentResinCountRa.w*2,momentResinCountRa.h,Threshold);
if (countArea.found){
momentResinCount =i+1;
break;
}
}
else{
condensedResinCount = "1";
log.info("浓缩树脂识别数量结果1");//不知道为什么1无法识别0是不显示图标的所以就当时1了反正也没啥影响
}
} else {
log.info("未检测到浓缩树脂图标");
}
var momentResinCountRa = await imageRecognition(momentResin,0.1, 0, 1,1170,0,300,100);
if (momentResinCountRa.found) {
// await moveMouseTo(momentResinCountRa.x,momentResinCountRa.y);
let countArea = await Textocr("",0.5, 0, 2,momentResinCountRa.x+momentResinCountRa.w+20,momentResinCountRa.y-15,60,40);//
if (countArea.found){
//log.info("须臾树脂识别数量结果:"+ countArea.text);
momentResinCount = countArea.text
}
else{
var oneRa = await imageRecognition(oneResin,0.1, 0, 1,momentResinCountRa.x+momentResinCountRa.w+20,momentResinCountRa.y-15,60,40);
if (oneRa.found){
momentResinCount = "1";
}else{
log.info("须臾树脂强制为 1 ");
momentResinCount = "1";
}
}
log.info("脆弱树脂强制为 1 ");//须臾树脂出现脆弱树脂不显示强制设置为1情况非常少大不了打多一次
if (i==4){log.info("未检测到须臾图标强制为1"); momentResinCount=1;}
}
fragileResinCount = "1";
log.info("未检测到脆弱树脂图标,可能被须臾图标覆盖,脆弱树脂强制为 1 ");//有图标说明至少为1
}else
{
var fragileResinCountRa = await imageRecognition(fragileResin,0.1, 0, 1,1170,0,300,100);
log.info("未检测到须臾树脂图标");
var fragileResinCountRa = await imageRecognition(fragileResin,0.1, 0, 1,1170,0,300,100,Threshold);
if (fragileResinCountRa.found) {
// await moveMouseTo(fragileResinCountRa.x+fragileResinCountRa.w+20,fragileResinCountRa.y-15);
let countArea = await Textocr("",0.5, 0, 2,fragileResinCountRa.x+fragileResinCountRa.w+20,fragileResinCountRa.y-15,60,40);//
// await moveMouseTo(fragileResinCountRa.x+fragileResinCountRa.w+20,fragileResinCountRa.y-15);
let countArea = await Textocr("",0.5, 0, 2,fragileResinCountRa.x+fragileResinCountRa.w,fragileResinCountRa.y,fragileResinCountRa.w*2,fragileResinCountRa.h,Threshold);//
if (countArea.found){
// log.info("脆弱树脂识别数量结果:"+ countArea.text);
fragileResinCount = countArea.text
if (countArea.text == "")
{
log.info("脆弱树脂识别强制为: 1");//
fragileResinCount = "1";
}
}
else{
var oneRa = await imageRecognition(oneResin,0.1, 0, 1,fragileResinCountRa.x+fragileResinCountRa.w+20,fragileResinCountRa.y-15,60,40);
var oneRa = await imageRecognition(resinImages[0],0.1, 0, 1,fragileResinCountRa.x+fragileResinCountRa.w,fragileResinCountRa.y,60,40,Threshold);
if (oneRa.found){
fragileResinCount = "1";
}else{
fragileResinCount = "1";
log.info("脆弱树脂识别强制为 1 ");//有图标说明至少为1
}
}
}
else {
log.info("未检测到脆弱树脂图标");
fragileResinCount = "1";
log.info("未检测到脆弱树脂图标,脆弱树脂识别强制为 1 ");//有图标说明至少为1
}
}
log.info("树脂状态:浓缩{0} 原粹{1} 脆弱{2} 须臾{3}", condensedResinCount, originalResinCount, fragileResinCount,momentResinCount)
return {condensedResinCount,originalResinCount,fragileResinCount,momentResinCount}
}
}
//征讨之花领奖寻找函数
@@ -505,6 +512,9 @@
log.info(`${resinTypeMap[rewards[i]]} 获取奖励...`);
await Textocr("锁定辅助",10,0,0,1768,0,115,90);
await sleep(500);
let { condensedResinCount, originalResinCount, fragileResinCount , momentResinCount} = await getRemainResinStatus();
let shouldExit = true;
@@ -591,7 +601,7 @@
}
log.warn("自动幽境危战版本v1.9");
log.warn("自动幽境危战版本v2.0");
log.warn("请保证队伍战斗实力,战斗失败或执行错误,会重试两次...");
log.warn("使用前请在 <<幽境危战>> 中配置好战斗队伍...");
log.info("使用树脂类型数量:{0} ", rewards.length)

View File

@@ -1,11 +1,11 @@
{
"manifest_version": 1,
"name": "自动幽境危战",
"version": "1.9",
"version": "2.0",
"tags": [
"幽境危战"
],
"bgi_version": "0.44.8",
"bgi_version": "0.47.1",
"description": "请先配置好秘境内的队伍,幽境危战战斗失败或执行错误会重试一次,请保证队伍实力",
"authors": [
{