From a960ef40e90e2fc93b35ccc45fd6d64cdd23c517 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BE=89=E9=B8=AD=E8=9B=8B?= Date: Sun, 14 Dec 2025 23:59:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=87=BA=E6=88=98=E8=A7=92=E8=89=B2=E7=BC=96?= =?UTF-8?q?=E5=8F=B7=E8=AF=86=E5=88=AB=EF=BC=8C=E5=A4=84=E7=90=86=E8=83=8C?= =?UTF-8?q?=E6=99=AF=E5=85=A8=E7=99=BD=E7=9A=84=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GameTask/AutoFight/Model/CombatScenes.cs | 2 +- .../Model/PartyAvatarSideIndexHelper.cs | 33 ++++++++++++++++--- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/BetterGenshinImpact/GameTask/AutoFight/Model/CombatScenes.cs b/BetterGenshinImpact/GameTask/AutoFight/Model/CombatScenes.cs index f608ec70..3122438e 100644 --- a/BetterGenshinImpact/GameTask/AutoFight/Model/CombatScenes.cs +++ b/BetterGenshinImpact/GameTask/AutoFight/Model/CombatScenes.cs @@ -466,7 +466,7 @@ public class CombatScenes : IDisposable if (PartyAvatarSideIndexHelper.CountIndexRect(imageRegion) == Avatars.Length) { bool res = RefreshTeamAvatarIndexRectList(imageRegion); - _logger.LogWarning("多次识别出战角色失败,尝试刷新角色编号位置(处理草露问题),刷新结果:{Result}", res ? "成功" : "失败"); + _logger.LogWarning("多次识别出战角色失败,尝试刷新角色编号位置,刷新结果:{Result}", res ? "成功" : "失败"); imageRegion.SrcMat.SaveImage(Global.Absolute("log\\refresh_avatar_index_rect.png")); if (res) { diff --git a/BetterGenshinImpact/GameTask/AutoFight/Model/PartyAvatarSideIndexHelper.cs b/BetterGenshinImpact/GameTask/AutoFight/Model/PartyAvatarSideIndexHelper.cs index 2e30b6bf..122a56ac 100644 --- a/BetterGenshinImpact/GameTask/AutoFight/Model/PartyAvatarSideIndexHelper.cs +++ b/BetterGenshinImpact/GameTask/AutoFight/Model/PartyAvatarSideIndexHelper.cs @@ -403,7 +403,7 @@ public class PartyAvatarSideIndexHelper { return m2; } - + // 方法3:使用更加靠谱的差值识别(-1是未识别),但是不支持非满队 if (mats.Length == 4) { @@ -494,6 +494,29 @@ public class PartyAvatarSideIndexHelper { return notWhiteRectNum; } + else if (whiteCount == mats.Length) + { + // 如果四个都是白色,那就找内部有没有黑色 + int blackCount = 0, notBlackRectNum = -1; + for (int i = 0; i < mats.Length; i++) + { + var count = OpenCvCommonHelper.CountGrayMatColorC1(mats[i], 50, 50); // 黑字 + if (count > 0) + { + blackCount++; + } + else + { + notBlackRectNum = i + 1; + } + } + + if (notBlackRectNum >= 1) + { + TaskControl.Logger.LogDebug("当前所有编号边缘均为白色(背景过白),通过内部黑色像素识别出战编号为{Index},存在黑色数字的角色编号有{C1}个,总角色数量{C2}", notBlackRectNum, blackCount, mats.Length); + return notBlackRectNum; + } + } else { return -1; @@ -530,13 +553,13 @@ public class PartyAvatarSideIndexHelper for (int x = 0; x < width; x++) { // 顶边 - if (image.At(0, x) >= 251) + if (image.At(0, x) == 255) { whiteCount++; } // 底边(避免只有一行时重复计数) - if (height > 1 && image.At(height - 1, x) >= 251) + if (height > 1 && image.At(height - 1, x) == 255) { whiteCount++; } @@ -546,13 +569,13 @@ public class PartyAvatarSideIndexHelper for (int y = 1; y < height - 1; y++) { // 左边 - if (image.At(y, 0) >= 251) + if (image.At(y, 0) == 255) { whiteCount++; } // 右边(避免只有一列时重复计数) - if (width > 1 && image.At(y, width - 1) >= 251) + if (width > 1 && image.At(y, width - 1) == 255) { whiteCount++; }