From 90fdfcaa095baf0ee3679e3608a39afd33745109 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BE=89=E9=B8=AD=E8=9B=8B?= Date: Fri, 27 Jun 2025 18:10:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=96=87=E5=AD=97=E8=AF=86?= =?UTF-8?q?=E5=88=AB=E5=8A=9F=E8=83=BD=EF=BC=8C=E4=BD=BF=E7=94=A8=E6=96=B0?= =?UTF-8?q?=E7=9A=84=E6=96=87=E5=AD=97=E5=8C=BA=E5=9F=9F=E6=A3=80=E6=B5=8B?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=E5=87=8F=E5=B0=91CPU=E6=B6=88=E8=80=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Core/Recognition/ONNX/BgiOnnxFactory.cs | 2 +- .../GameTask/AutoPick/AutoPickTrigger.cs | 28 ++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/BetterGenshinImpact/Core/Recognition/ONNX/BgiOnnxFactory.cs b/BetterGenshinImpact/Core/Recognition/ONNX/BgiOnnxFactory.cs index 6ca4a764..f62ff5d6 100644 --- a/BetterGenshinImpact/Core/Recognition/ONNX/BgiOnnxFactory.cs +++ b/BetterGenshinImpact/Core/Recognition/ONNX/BgiOnnxFactory.cs @@ -234,7 +234,7 @@ public class BgiOnnxFactory /// BgiYoloPredictor public BgiYoloPredictor CreateYoloPredictor(BgiOnnxModel model) { - logger.LogDebug("[Yolo]创建yolo预测器,模型: {ModelName}", model.Name); + // logger.LogDebug("[Yolo]创建yolo预测器,模型: {ModelName}", model.Name); if (!EnableCache) return new BgiYoloPredictor(model, model.ModalPath, CreateSessionOptions(model, false)); var cached = GetCached(model); diff --git a/BetterGenshinImpact/GameTask/AutoPick/AutoPickTrigger.cs b/BetterGenshinImpact/GameTask/AutoPick/AutoPickTrigger.cs index bac9811d..51a0348b 100644 --- a/BetterGenshinImpact/GameTask/AutoPick/AutoPickTrigger.cs +++ b/BetterGenshinImpact/GameTask/AutoPick/AutoPickTrigger.cs @@ -203,7 +203,18 @@ public partial class AutoPickTrigger : ITaskTrigger else { var textMat = new Mat(content.CaptureRectArea.SrcMat, textRect); - text = OcrFactory.Paddle.Ocr(textMat); + var boundingRect = GetWhiteTextBoundingRect(textMat); + // 如果找到有效区域 + if (boundingRect.Width > 5 && boundingRect.Height > 5) + { + // 截取只包含文字的区域 + var textOnlyMat = new Mat(textMat, boundingRect); + text = OcrFactory.Paddle.OcrWithoutDetector(textOnlyMat); + } + else + { + text = OcrFactory.Paddle.Ocr(textMat); + } } speedTimer.Record("文字识别"); @@ -258,6 +269,21 @@ public partial class AutoPickTrigger : ITaskTrigger speedTimer.DebugPrint(); } + private static Rect GetWhiteTextBoundingRect(Mat textMat) + { + // 预处理提取纯白色文字 + var processedMat = new Mat(); + // 提取白色文字 (255,255,255) + Cv2.InRange(textMat, new Scalar(254, 254, 254), new Scalar(255, 255, 255), processedMat); + // 形态学操作,先腐蚀后膨胀,去除噪点并保持文字完整 + var kernel = Cv2.GetStructuringElement(MorphShapes.Rect, new Size(2, 2)); + Cv2.MorphologyEx(processedMat, processedMat, MorphTypes.Open, kernel, iterations: 1); + Cv2.Dilate(processedMat, processedMat, kernel, iterations: 1); + // 寻找非零区域,即文字区域 + Rect boundingRect = Cv2.BoundingRect(processedMat); + return boundingRect; + } + private bool HasScrollIcon(ImageRegion captureRectArea) {