From 6651ec7d9f31d5569fdbe0807fcdfa176ec13060 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BE=89=E9=B8=AD=E8=9B=8B?= Date: Thu, 15 Aug 2024 00:00:12 +0800 Subject: [PATCH] attempt to correct coordinates --- .../GameTask/AutoPathing/PathExecutor.cs | 14 +++- .../GameTask/Common/Map/EntireMap.cs | 76 ------------------- 2 files changed, 11 insertions(+), 79 deletions(-) diff --git a/BetterGenshinImpact/GameTask/AutoPathing/PathExecutor.cs b/BetterGenshinImpact/GameTask/AutoPathing/PathExecutor.cs index 25edf7a1..751d6aeb 100644 --- a/BetterGenshinImpact/GameTask/AutoPathing/PathExecutor.cs +++ b/BetterGenshinImpact/GameTask/AutoPathing/PathExecutor.cs @@ -16,6 +16,7 @@ using OpenCvSharp; using BetterGenshinImpact.Core.Recognition.OCR; namespace BetterGenshinImpact.GameTask.AutoPathing; + public class PathExecutor { public static async Task Pathing(PathingTask task, CancellationTokenSource cts, bool withDelay = true) @@ -52,6 +53,16 @@ public class PathExecutor // 这里应该判断一下自动拾取是否处于工作状态,但好像没有什么方便的读取办法 + // TODO:大地图传送的时候使用游戏坐标,追踪的时候应该使用2048地图图像坐标,这里临时做转换,后续改进 + foreach (var waypoint in task.Waypoints) + { + if (waypoint.WaypointType == WaypointType.Teleport) + { + continue; + } + (waypoint.X, waypoint.Y) = MapCoordinate.GameToMain2048(waypoint.X, waypoint.Y); + } + foreach (var waypoint in task.Waypoints) { if (waypoint.WaypointType == WaypointType.Teleport) @@ -70,7 +81,6 @@ public class PathExecutor { await MoveCloseTo(waypoint); } - } } @@ -250,6 +260,4 @@ public class PathExecutor var text = OcrFactory.Paddle.OcrWithoutDetector(greyMat); return text.ToLower() == "space"; } - } - diff --git a/BetterGenshinImpact/GameTask/Common/Map/EntireMap.cs b/BetterGenshinImpact/GameTask/Common/Map/EntireMap.cs index 7fc9040d..530e8967 100644 --- a/BetterGenshinImpact/GameTask/Common/Map/EntireMap.cs +++ b/BetterGenshinImpact/GameTask/Common/Map/EntireMap.cs @@ -16,21 +16,6 @@ public class EntireMap : Singleton // 对无用部分进行裁剪(左160,上80,下96) public static readonly Rect TemplateSizeRoi = new(20, 10, TemplateSize.Width - 20, TemplateSize.Height - 22); - /// - /// 主要地图缩小1024的模板 - /// - // private readonly Mat _mainMap100BlockMat; - - // /// - // /// 1024区块拼接的主要地图 - // /// - // private readonly Mat _mainMap1024BlockMat; - // - // /// - // /// 2048城市区块拼接的主要地图 - // /// - // private readonly Mat _cityMap2048BlockMat; - private readonly FeatureMatcher _featureMatcher; private float _prevX = -1; @@ -38,39 +23,9 @@ public class EntireMap : Singleton public EntireMap() { - // 大地图模板匹配使用的模板 - // _mainMap100BlockMat = MapAssets.Instance.MainMap100BlockMat.Value; - // _mainMap1024BlockMat = MapAssets.Instance.MainMap1024BlockMat.Value; - // _cityMap2048BlockMat = new Mat(@"E:\HuiTask\更好的原神\地图匹配\有用的素材\cityMap2048Block.png", ImreadModes.Grayscale); - // Mat grey = new(); - // Cv2.CvtColor(_mainMap100BlockMat, grey, ColorConversionCodes.BGR2GRAY); - // _featureMatcher = new FeatureMatcher(MapAssets.Instance.MainMap1024BlockMat.Value, new FeatureStorage("mainMap1024Block")); - // 只从特征点加载 _featureMatcher = new FeatureMatcher(new Size(28672, 26624), new FeatureStorage("mainMap2048Block")); } - // /// - // /// 基于模板匹配获取地图位置(100区块,缩小了10.24倍) - // /// 当前只支持大地图 - // /// - // /// 彩色图像 - // /// - // public Point GetMapPositionByMatchTemplate(Mat captureMat) - // { - // Cv2.CvtColor(captureMat, captureMat, ColorConversionCodes.BGRA2BGR); - // using var tar = new Mat(captureMat.Resize(TemplateSize, 0, 0, InterpolationFlags.Cubic), TemplateSizeRoi); - // var p = MatchTemplateHelper.MatchTemplate(_mainMap100BlockMat, tar, TemplateMatchModes.CCoeffNormed, null, 0.2); - // Debug.WriteLine($"BigMap Match Template: {p}"); - // return p; - // } - // - // public void GetMapPositionAndDrawByMatchTemplate(Mat captureMat) - // { - // var p = GetMapPositionByMatchTemplate(captureMat); - // WeakReferenceMessenger.Default.Send(new PropertyChangedMessage(this, "UpdateBigMapRect", new object(), - // new System.Windows.Rect(p.X, p.Y, TemplateSizeRoi.Width, TemplateSizeRoi.Height))); - // } - private int _failCnt = 0; /// @@ -139,35 +94,4 @@ public class EntireMap : Singleton return new Point2f(); } } - - // public static Point GetIntersection(Point2f[] points) - // { - // double a1 = (points[0].Y - points[2].Y) / (double)(points[0].X - points[2].X); - // double b1 = points[0].Y - a1 * points[0].X; - // - // double a2 = (points[1].Y - points[3].Y) / (double)(points[1].X - points[3].X); - // double b2 = points[1].Y - a2 * points[1].X; - // - // if (Math.Abs(a1 - a2) < double.Epsilon) - // { - // // 不相交 - // throw new InvalidOperationException(); - // } - // - // double x = (b2 - b1) / (a1 - a2); - // double y = a1 * x + b1; - // return new Point((int)x, (int)y); - // } - - // public void GetMapPositionAndDrawByFeatureMatch(Mat captureGreyMat) - // { - // var rect = GetMiniMapPositionByFeatureMatch(captureGreyMat); - // if (rect != Rect.Empty) - // { - // WeakReferenceMessenger.Default.Send(new PropertyChangedMessage(this, "UpdateBigMapRect", new object(), - // new System.Windows.Rect(rect.X / 20.48, rect.Y / 20.48, rect.Width / 20.48, rect.Height / 20.48))); - // // WeakReferenceMessenger.Default.Send(new PropertyChangedMessage(this, "UpdateBigMapRect", new object(), - // // new System.Windows.Rect(rect.X / 10.24, rect.Y / 10.24, rect.Width / 10.24, rect.Height / 10.24))); - // } - // } }