mirror of
https://github.com/babalae/better-genshin-impact.git
synced 2026-05-25 10:05:49 +08:00
图标识别应用两则 (#2154)
This commit is contained in:
@@ -3,6 +3,7 @@ using BetterGenshinImpact.Core.Simulator;
|
||||
using BetterGenshinImpact.GameTask.AutoArtifactSalvage;
|
||||
using BetterGenshinImpact.GameTask.Common;
|
||||
using BetterGenshinImpact.GameTask.Common.Job;
|
||||
using BetterGenshinImpact.GameTask.Model;
|
||||
using BetterGenshinImpact.GameTask.Model.Area;
|
||||
using BetterGenshinImpact.GameTask.Model.GameUI;
|
||||
using BetterGenshinImpact.Helpers.Extensions;
|
||||
@@ -198,13 +199,8 @@ public class GetGridIconsTask : ISoloTask
|
||||
{
|
||||
using (FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None))
|
||||
{
|
||||
double scale = TaskContext.Instance().SystemInfo.AssetScale;
|
||||
double width = 60;
|
||||
double height = 60; // 宽高缩放似乎不一致,似乎在2.05:2.15之间,但不知道怎么测定
|
||||
Rect iconRect = new Rect((int)(itemRegion.Width / 2 - 237 * scale - width / 2), (int)(itemRegion.Height / 2 - height / 2), (int)width, (int)height);
|
||||
Mat crop = itemRegion.SrcMat.SubMat(iconRect);
|
||||
using Mat resize = crop.Resize(new Size(125, 125));
|
||||
resize.ToBitmap().Save(fs, System.Drawing.Imaging.ImageFormat.Png);
|
||||
using Mat img125 = CropResizeArtifactSetFilterGridIcon(itemRegion);
|
||||
img125.ToBitmap().Save(fs, System.Drawing.Imaging.ImageFormat.Png);
|
||||
}
|
||||
logger.LogInformation("图片保存成功:{Text}", fileName);
|
||||
}
|
||||
@@ -230,6 +226,16 @@ public class GetGridIconsTask : ISoloTask
|
||||
}
|
||||
}
|
||||
|
||||
internal static Mat CropResizeArtifactSetFilterGridIcon(ImageRegion itemRegion, ISystemInfo? systemInfo = null)
|
||||
{
|
||||
double scale = (systemInfo ?? TaskContext.Instance().SystemInfo).AssetScale;
|
||||
double width = 60;
|
||||
double height = 60; // 宽高缩放似乎不一致,似乎在2.05:2.15之间,但不知道怎么测定
|
||||
Rect iconRect = new Rect((int)(itemRegion.Width / 2 - 237 * scale - width / 2), (int)(itemRegion.Height / 2 - height / 2), (int)width, (int)height);
|
||||
Mat crop = itemRegion.SrcMat.SubMat(iconRect);
|
||||
return crop.Resize(new Size(125, 125));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OCR检测★字符很不稳定,因此用cv
|
||||
/// 非常简陋的色彩检测,请传入聚焦的图像,勿带入可能的干扰
|
||||
|
||||
@@ -111,7 +111,6 @@ public class GridIconsAccuracyTestTask : ISoloTask
|
||||
{
|
||||
itemRegion.Click();
|
||||
Task task1 = Delay(300, ct);
|
||||
var sadf = task1.Status;
|
||||
|
||||
// 用模型推理得到的结果
|
||||
Task<(string, int)> task2 = Task.Run(() =>
|
||||
@@ -161,7 +160,7 @@ public class GridIconsAccuracyTestTask : ISoloTask
|
||||
/// <param name="mat"></param>
|
||||
/// <param name="session"></param>
|
||||
/// <param name="prototypes"></param>
|
||||
/// <returns></returns>
|
||||
/// <returns>(预测名称, 预测星级)</returns>
|
||||
/// <exception cref="Exception"></exception>
|
||||
public static (string, int) Infer(Mat mat, InferenceSession session, Dictionary<string, float[]> prototypes)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user