attempt to correct coordinates

This commit is contained in:
辉鸭蛋
2024-08-15 00:00:12 +08:00
parent d4fe1f2ab0
commit 6651ec7d9f
2 changed files with 11 additions and 79 deletions

View File

@@ -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";
}
}

View File

@@ -16,21 +16,6 @@ public class EntireMap : Singleton<EntireMap>
// 对无用部分进行裁剪左160上80下96
public static readonly Rect TemplateSizeRoi = new(20, 10, TemplateSize.Width - 20, TemplateSize.Height - 22);
/// <summary>
/// 主要地图缩小1024的模板
/// </summary>
// private readonly Mat _mainMap100BlockMat;
// /// <summary>
// /// 1024区块拼接的主要地图
// /// </summary>
// private readonly Mat _mainMap1024BlockMat;
//
// /// <summary>
// /// 2048城市区块拼接的主要地图
// /// </summary>
// private readonly Mat _cityMap2048BlockMat;
private readonly FeatureMatcher _featureMatcher;
private float _prevX = -1;
@@ -38,39 +23,9 @@ public class EntireMap : Singleton<EntireMap>
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"));
}
// /// <summary>
// /// 基于模板匹配获取地图位置(100区块缩小了10.24倍)
// /// 当前只支持大地图
// /// </summary>
// /// <param name="captureMat">彩色图像</param>
// /// <returns></returns>
// 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<object>(this, "UpdateBigMapRect", new object(),
// new System.Windows.Rect(p.X, p.Y, TemplateSizeRoi.Width, TemplateSizeRoi.Height)));
// }
private int _failCnt = 0;
/// <summary>
@@ -139,35 +94,4 @@ public class EntireMap : Singleton<EntireMap>
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<object>(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<object>(this, "UpdateBigMapRect", new object(),
// // new System.Windows.Rect(rect.X / 10.24, rect.Y / 10.24, rect.Width / 10.24, rect.Height / 10.24)));
// }
// }
}