Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
49faf756a1 |
No files matched your search
@@ -1,22 +0,0 @@
|
||||
---
|
||||
name: Bug report / 错误报告
|
||||
about: Create a report to help us improve / 创建报告以帮助我们改进
|
||||
title: "[bug] "
|
||||
labels: bug
|
||||
---
|
||||
|
||||
<!--
|
||||
请提供下述完整信息以便快速定位问题 / Please provide the following information to quickly locate the problem
|
||||
-->
|
||||
|
||||
- 系统环境 / System Environment:
|
||||
|
||||
|
||||
- BetterGI版本号 / BetterGI Version:
|
||||
|
||||
|
||||
- 问题描述 / Description of the issue:
|
||||
|
||||
|
||||
- 复现步骤 / Reproduction steps:
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
blank_issues_enabled: false
|
||||
contact_links:
|
||||
- name: 官方文档 / Document
|
||||
url: https://bgi.huiyadan.com/doc.html
|
||||
about: 请在提出问题前阅读文档 / Read the document before submit the issue
|
||||
|
||||
- name: 常见问题 / FAQ
|
||||
url: https://bgi.huiyadan.com/faq.html
|
||||
about: 常见的用户提出的问题 / Common questions asked by users
|
||||
@@ -1,5 +0,0 @@
|
||||
---
|
||||
name: Feel free to express / 随便写写
|
||||
about: Record something / 简单写写记录记录
|
||||
---
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
---
|
||||
name: I have a question / 我有疑问
|
||||
about: Solve your problem / 解决你的疑问
|
||||
title: "[question] "
|
||||
labels: question
|
||||
---
|
||||
|
||||
- Problem Description / 问题描述
|
||||
- 请尽量提供问题相关的截图/日志等内容
|
||||
@@ -1,9 +0,0 @@
|
||||
---
|
||||
name: I have suggestions / 我有建议
|
||||
about: Your suggestions may benefit everyone / 你的建议可能让所有人受益
|
||||
title: "[suggestion] "
|
||||
labels: suggestion
|
||||
---
|
||||
|
||||
- Your suggestions / 你的建议
|
||||
|
||||
@@ -23,9 +23,4 @@ bld/
|
||||
# Mine
|
||||
Tmp/
|
||||
/packages/
|
||||
node_modules/
|
||||
|
||||
*.zip
|
||||
|
||||
# Rider
|
||||
.idea
|
||||
node_modules/
|
||||
@@ -1,7 +0,0 @@
|
||||
<Application x:Class="BetterGenshinImpact.Test.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:BetterGenshinImpact.Test"
|
||||
StartupUri="MainWindow.xaml">
|
||||
<Application.Resources />
|
||||
</Application>
|
||||
@@ -1,14 +0,0 @@
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Windows;
|
||||
|
||||
namespace BetterGenshinImpact.Test
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for App.xaml
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
using System.Windows;
|
||||
|
||||
[assembly: ThemeInfo(
|
||||
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
|
||||
//(used if a resource is not found in the page,
|
||||
// or application resource dictionaries)
|
||||
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
|
||||
//(used if a resource is not found in the page,
|
||||
// app, or any theme specific resource dictionaries)
|
||||
)]
|
||||
@@ -1,19 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net7.0-windows10.0.22621.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UseWPF>true</UseWPF>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="OxyPlot.Wpf" Version="2.1.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BetterGenshinImpact\BetterGenshinImpact.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -1,146 +0,0 @@
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using OpenCvSharp;
|
||||
|
||||
namespace BetterGenshinImpact.Test.Dataset;
|
||||
|
||||
public class AvatarClassifyGen
|
||||
{
|
||||
// 基础图像文件夹
|
||||
private const string BaseDir = @"E:\HuiTask\更好的原神\自动秘境\自动战斗\队伍识别\分类器\";
|
||||
|
||||
// 背景图像文件夹
|
||||
private static readonly string BackgroundDir = Path.Combine(BaseDir, "background");
|
||||
|
||||
private static readonly Random Rd = new Random();
|
||||
|
||||
public static void GenAll()
|
||||
{
|
||||
// 读取基础图像
|
||||
// List<string> sideImageFiles = Directory.GetFiles(Path.Combine(BaseDir, "side_src"), "*.png", SearchOption.TopDirectoryOnly).ToList();
|
||||
// 只用一个图像
|
||||
List<string> sideImageFiles = Directory.GetFiles(Path.Combine(BaseDir, "side_src"), "UI_AvatarIcon_Side_Arlecchino.png", SearchOption.TopDirectoryOnly).ToList();
|
||||
|
||||
// 生成训练集
|
||||
GenTo(sideImageFiles, Path.Combine(BaseDir, @"dateset\train"), 200);
|
||||
// 生成测试集
|
||||
GenTo(sideImageFiles, Path.Combine(BaseDir, @"dateset\test"), 40);
|
||||
// GenTo(new List<string> { sideImageFiles[1] }, Path.Combine(BaseDir, @"dateset\test"), 1);
|
||||
}
|
||||
|
||||
static void GenTo(List<string> sideImageFiles, string dataFolder, int count)
|
||||
{
|
||||
// 保留区域 从底边中心为固定点
|
||||
var reservedSize = new Size(60, 80);
|
||||
|
||||
Directory.CreateDirectory(dataFolder);
|
||||
// 循环生成每个基础图像对应的数据集
|
||||
foreach (string sideImageFile in sideImageFiles)
|
||||
{
|
||||
// 获取基础图像文件名
|
||||
string sideImageFileName = Path.GetFileNameWithoutExtension(sideImageFile);
|
||||
sideImageFileName = sideImageFileName.Replace("UI_AvatarIcon_Side_", "");
|
||||
// 创建基础图像对应的数据集文件夹
|
||||
string sideDataFolder = Path.Combine(dataFolder, sideImageFileName);
|
||||
Directory.CreateDirectory(sideDataFolder);
|
||||
|
||||
// 读取基础图像
|
||||
Mat sideImageSrc = Cv2.ImRead(sideImageFile, ImreadModes.Unchanged);
|
||||
var channels = sideImageSrc.Split();
|
||||
var alphaChannel = channels[3]; // 透明通道
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
Cv2.Multiply(channels[i], alphaChannel, channels[i], 1 / 255.0);
|
||||
}
|
||||
|
||||
var sideImage = new Mat();
|
||||
Cv2.Merge(channels[..3], sideImage);
|
||||
|
||||
// Cv2.ImShow("avatar", sideImage);
|
||||
|
||||
// 循环生成图像
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
// 随机挑选一张背景图像
|
||||
string backgroundImageFile = Path.Combine(BackgroundDir, Directory.GetFiles(BackgroundDir, "*.png")[Rd.Next(Directory.GetFiles(BackgroundDir, "*.png").Length)]);
|
||||
|
||||
// 从背景图像中随机取一块 128x128 的区域
|
||||
Mat backgroundImage = Cv2.ImRead(backgroundImageFile, ImreadModes.Color);
|
||||
Rect backgroundRect = new Rect(Rd.Next(backgroundImage.Width - 128), new Random().Next(backgroundImage.Height - 128), 128, 128);
|
||||
Mat backgroundImageRegion = backgroundImage[backgroundRect];
|
||||
|
||||
// 随机平移、缩放保留区域
|
||||
float scale = (float)(Rd.NextDouble() * (1.6 - 0.7) + 0.7);
|
||||
int w = (int)(sideImage.Width * scale);
|
||||
int h = (int)(sideImage.Height * scale);
|
||||
|
||||
Debug.WriteLine($"{sideImageFileName} 生成随机缩放{scale}");
|
||||
|
||||
// 把保留区域合成到背景图像上
|
||||
Mat backgroundImageRegionClone = backgroundImageRegion.Clone();
|
||||
var resizedSideImage = new Mat();
|
||||
Cv2.Resize(sideImage, resizedSideImage, new Size(128 * scale, 128 * scale));
|
||||
// Cv2.ImShow("resizedSideImage", resizedSideImage);
|
||||
var resizedMaskImage = new Mat();
|
||||
// Cv2.Threshold(alphaChannel, alphaChannel, 200, 255, ThresholdTypes.Otsu);
|
||||
Cv2.Resize(255 - alphaChannel, resizedMaskImage, new Size(128 * scale, 128 * scale), 0, 0, InterpolationFlags.Cubic);
|
||||
var resizedAlphaChannel = new Mat();
|
||||
Cv2.Resize(alphaChannel, resizedAlphaChannel, new Size(128 * scale, 128 * scale), 0, 0, InterpolationFlags.Cubic);
|
||||
|
||||
// Cv2.ImShow("resizedMaskImage", resizedMaskImage);
|
||||
// generatedImage[transformedRect] = resizedSideImage;
|
||||
Mat result;
|
||||
if (scale > 1)
|
||||
{
|
||||
int xSpace1 = (int)((128 - reservedSize.Width * scale) / 2.0);
|
||||
int ySpace1 = (int)(128 - reservedSize.Height * scale);
|
||||
int xSpace2 = (int)((resizedSideImage.Width - 128) / 2.0);
|
||||
int ySpace2 = resizedSideImage.Height - 128;
|
||||
int xSpace = Math.Min(xSpace1, xSpace2);
|
||||
int ySpace = Math.Min(ySpace1, ySpace2);
|
||||
int offsetX = Rd.Next(-xSpace, xSpace);
|
||||
int offsetY = Rd.Next(-ySpace, 0);
|
||||
Debug.WriteLine($"{sideImageFileName} 缩放{scale}大于1 偏移 ({offsetX},{offsetY})");
|
||||
|
||||
var roi = new Rect((resizedSideImage.Width - 128) / 2 + offsetX, (resizedSideImage.Height - 128) + offsetY, 128, 128);
|
||||
// result = new Mat();
|
||||
// Cv2.BitwiseAnd(backgroundImageRegionClone, backgroundImageRegionClone, result, resizedMaskImage[roi]);
|
||||
result = Mul(backgroundImageRegionClone, resizedAlphaChannel[roi]);
|
||||
Cv2.Add(result, resizedSideImage[roi], result);
|
||||
}
|
||||
else
|
||||
{
|
||||
int xSpace = (128 - w) / 2;
|
||||
int ySpace = 128 - h;
|
||||
int offsetX = Rd.Next(-xSpace, xSpace);
|
||||
int offsetY = Rd.Next(-ySpace, 0);
|
||||
Debug.WriteLine($"{sideImageFileName} 缩放{scale}小于等于1 偏移 ({offsetX},{offsetY})");
|
||||
|
||||
var roi = new Rect((128 - resizedSideImage.Width) / 2 + offsetX, (128 - resizedSideImage.Height) + offsetY, resizedSideImage.Width, resizedSideImage.Height);
|
||||
var res = new Mat();
|
||||
// Cv2.BitwiseAnd(backgroundImageRegionClone[roi], backgroundImageRegionClone[roi], res, resizedMaskImage);
|
||||
res = Mul(backgroundImageRegionClone[roi], resizedAlphaChannel);
|
||||
Cv2.Add(res, resizedSideImage, res);
|
||||
backgroundImageRegionClone[roi] = res;
|
||||
result = backgroundImageRegionClone.Clone();
|
||||
}
|
||||
|
||||
// Cv2.ImShow("avatarR", result);
|
||||
// 保存生成的图像
|
||||
Cv2.ImWrite(Path.Combine(sideDataFolder, $"{sideImageFileName}_{i}.png"), result);
|
||||
}
|
||||
}
|
||||
|
||||
static Mat Mul(Mat background, Mat alphaChannel)
|
||||
{
|
||||
var channels = background.Split();
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
Cv2.Multiply(channels[i], 255 - alphaChannel, channels[i], 1 / 255.0);
|
||||
}
|
||||
Mat result = new Mat();
|
||||
Cv2.Merge(channels[..3], result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
<Window x:Class="BetterGenshinImpact.Test.MainWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
Title="Test"
|
||||
Width="120"
|
||||
Height="450"
|
||||
mc:Ignorable="d">
|
||||
<Canvas>
|
||||
<Button Canvas.Left="10"
|
||||
Canvas.Top="10"
|
||||
Width="100"
|
||||
Height="23"
|
||||
Click="ShowCameraRecWindow"
|
||||
Content="视角识别测试" />
|
||||
<Button Canvas.Left="10"
|
||||
Canvas.Top="40"
|
||||
Width="100"
|
||||
Height="23"
|
||||
Click="ShowHsvTestWindow"
|
||||
Content="Hsv拉条" />
|
||||
<Button Canvas.Left="10"
|
||||
Canvas.Top="70"
|
||||
Width="100"
|
||||
Height="23"
|
||||
Click="DoMapPuzzle"
|
||||
Content="拼接超大地图" />
|
||||
<Button Canvas.Left="10"
|
||||
Canvas.Top="100"
|
||||
Width="100"
|
||||
Height="23"
|
||||
Click="DoMatchTest"
|
||||
Content="特征匹配测试" />
|
||||
<Button Canvas.Left="10"
|
||||
Canvas.Top="130"
|
||||
Width="100"
|
||||
Height="23"
|
||||
Click="DoMatchTemplateTest"
|
||||
Content="模板匹配测试" />
|
||||
<Button Canvas.Left="10"
|
||||
Canvas.Top="160"
|
||||
Width="100"
|
||||
Height="23"
|
||||
Click="MapDrawTeleportPoint"
|
||||
Content="超大地图标点" />
|
||||
<Button Canvas.Left="10"
|
||||
Canvas.Top="190"
|
||||
Width="100"
|
||||
Height="23"
|
||||
Click="GenAvatarData"
|
||||
Content="生成侧面头像数据集" />
|
||||
<Button Canvas.Left="10"
|
||||
Canvas.Top="190"
|
||||
Width="100"
|
||||
Height="23"
|
||||
Click="AutoCookTestCase"
|
||||
Content="自动烹饪图像测试" />
|
||||
</Canvas>
|
||||
</Window>
|
||||
@@ -1,68 +0,0 @@
|
||||
using System.Windows;
|
||||
using BetterGenshinImpact.Core.Config;
|
||||
using BetterGenshinImpact.GameTask.Common.Map;
|
||||
using BetterGenshinImpact.Test.Dataset;
|
||||
using BetterGenshinImpact.Test.Simple;
|
||||
using BetterGenshinImpact.Test.Simple.AllMap;
|
||||
using BetterGenshinImpact.Test.View;
|
||||
|
||||
namespace BetterGenshinImpact.Test;
|
||||
|
||||
/// <summary>
|
||||
/// MainWindow.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
Global.StartUpPath = @"D:\HuiPrograming\Projects\CSharp\MiHoYo\BetterGenshinImpact\BetterGenshinImpact\bin\x64\Debug\net7.0-windows10.0.22621.0";
|
||||
}
|
||||
|
||||
private void ShowCameraRecWindow(object sender, System.Windows.RoutedEventArgs e)
|
||||
{
|
||||
new CameraRecWindow().Show();
|
||||
}
|
||||
|
||||
private void ShowHsvTestWindow(object sender, System.Windows.RoutedEventArgs e)
|
||||
{
|
||||
new HsvTestWindow().Run();
|
||||
}
|
||||
|
||||
private void DoMapPuzzle(object sender, System.Windows.RoutedEventArgs e)
|
||||
{
|
||||
MapPuzzle.Put();
|
||||
}
|
||||
|
||||
private void DoOcrTest(object sender, System.Windows.RoutedEventArgs e)
|
||||
{
|
||||
OcrTest.TestYap();
|
||||
}
|
||||
|
||||
private void DoMatchTemplateTest(object sender, System.Windows.RoutedEventArgs e)
|
||||
{
|
||||
MatchTemplateTest.Test();
|
||||
}
|
||||
|
||||
private void DoMatchTest(object sender, System.Windows.RoutedEventArgs e)
|
||||
{
|
||||
// KeyPointMatchTest.Test();
|
||||
// EntireMapTest.Test();
|
||||
EntireMapTest.Storage();
|
||||
}
|
||||
|
||||
private void MapDrawTeleportPoint(object sender, RoutedEventArgs e)
|
||||
{
|
||||
MapTeleportPointDraw.Draw();
|
||||
}
|
||||
|
||||
private void GenAvatarData(object sender, RoutedEventArgs e)
|
||||
{
|
||||
AvatarClassifyGen.GenAll();
|
||||
}
|
||||
|
||||
private void AutoCookTestCase(object sender, RoutedEventArgs e)
|
||||
{
|
||||
AutoCookTest.Test();
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
using BetterGenshinImpact.Core.Recognition.OpenCv.FeatureMatch;
|
||||
using BetterGenshinImpact.GameTask.Common.Element.Assets;
|
||||
using BetterGenshinImpact.Helpers;
|
||||
using OpenCvSharp;
|
||||
using OpenCvSharp.Detail;
|
||||
using System.Diagnostics;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace BetterGenshinImpact.Test.Simple.AllMap;
|
||||
|
||||
public class EntireMapTest
|
||||
{
|
||||
public static void Test()
|
||||
{
|
||||
SpeedTimer speedTimer = new();
|
||||
var mainMap1024BlockMat = new Mat(@"E:\HuiTask\更好的原神\地图匹配\有用的素材\mainMap1024Block.png", ImreadModes.Grayscale);
|
||||
var surfMatcher = new FeatureMatcher(mainMap1024BlockMat);
|
||||
var queryMat = new Mat(@"E:\HuiTask\更好的原神\地图匹配\比较\小地图\Clip_20240323_183119.png", ImreadModes.Grayscale);
|
||||
|
||||
speedTimer.Record("初始化特征");
|
||||
|
||||
var pArray = surfMatcher.Match(queryMat);
|
||||
speedTimer.Record("匹配1");
|
||||
if (pArray != null)
|
||||
{
|
||||
var rect = Cv2.BoundingRect(pArray);
|
||||
Debug.WriteLine($"Matched rect 1: {rect}");
|
||||
Cv2.Rectangle(mainMap1024BlockMat, rect, Scalar.Red, 2);
|
||||
// Cv2.ImWrite(@"E:\HuiTask\更好的原神\地图匹配\b1.png", mainMap1024BlockMat);
|
||||
|
||||
var pArray2 = surfMatcher.Match(queryMat, rect.X + rect.Width / 2, rect.Y + rect.Height / 2);
|
||||
speedTimer.Record("匹配2");
|
||||
if (pArray2 != null)
|
||||
{
|
||||
var rect2 = Cv2.BoundingRect(pArray2);
|
||||
Debug.WriteLine($"Matched rect 2: {rect2}");
|
||||
Cv2.Rectangle(mainMap1024BlockMat, rect2, Scalar.Yellow, 1);
|
||||
// Cv2.ImWrite(@"E:\HuiTask\更好的原神\地图匹配\b2.png", mainMap1024BlockMat);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.WriteLine("No match 2");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.WriteLine("No match 1");
|
||||
}
|
||||
speedTimer.DebugPrint();
|
||||
}
|
||||
|
||||
public static void Storage()
|
||||
{
|
||||
var featureMatcher = new FeatureMatcher(MapAssets.Instance.MainMap2048BlockMat.Value, new FeatureStorage("mainMap2048Block"));
|
||||
MessageBox.Show("特征点生成完成");
|
||||
}
|
||||
}
|
||||
@@ -1,328 +0,0 @@
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using System.Xml;
|
||||
using OpenCvSharp;
|
||||
|
||||
namespace BetterGenshinImpact.Test.Simple.AllMap;
|
||||
|
||||
public class KeyPointMatchTest
|
||||
{
|
||||
public static void Test()
|
||||
{
|
||||
// var trainMat = new Mat(@"E:\HuiTask\更好的原神\地图匹配\比较\叠图\无法匹配2.png", ImreadModes.Color);
|
||||
var trainMat = new Mat(@"E:\HuiTask\更好的原神\地图匹配\比较\小地图\Clip_20240323_152015.png", ImreadModes.Grayscale);
|
||||
|
||||
// tar = tar.Resize(new Size(tar.Width * 2, tar.Height * 2), 0, 0, InterpolationFlags.Nearest);
|
||||
|
||||
// var queryMat = new Mat(@"E:\HuiTask\更好的原神\地图匹配\combined_image_lim[quick].png", ImreadModes.Color);
|
||||
var queryMat = new Mat(@"E:\HuiTask\更好的原神\地图匹配\combined_image_2048_lim[quick].png", ImreadModes.Grayscale);
|
||||
var res = MatchPicBySurf(trainMat, queryMat);
|
||||
|
||||
Cv2.ImWrite(@"E:\HuiTask\更好的原神\地图匹配\s1.png", res);
|
||||
}
|
||||
|
||||
/*public static Mat MatchPicBySift(Mat matSrc, Mat matTo)
|
||||
{
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
|
||||
Mat matSrcRet = new Mat();
|
||||
using Mat matToRet = new Mat();
|
||||
KeyPoint[] keyPointsSrc, keyPointsTo;
|
||||
using (var sift = SIFT.Create())
|
||||
{
|
||||
var kpPath = @"E:\HuiTask\更好的原神\地图匹配\sift.kp";
|
||||
var kpMatPath = @"E:\HuiTask\更好的原神\地图匹配\sift.mat";
|
||||
if (File.Exists(kpPath) && File.Exists(kpMatPath))
|
||||
{
|
||||
keyPointsSrc = (KeyPoint[])DeserializeObject(File.ReadAllBytes(kpPath));
|
||||
GCHandle pinnedArray = GCHandle.Alloc(DeserializeObject(File.ReadAllBytes(kpMatPath)), GCHandleType.Pinned);
|
||||
IntPtr pointer = pinnedArray.AddrOfPinnedObject();
|
||||
matSrcRet = new Mat(166767, 128, MatType.CV_32FC1, pointer);
|
||||
}
|
||||
else
|
||||
{
|
||||
sift.DetectAndCompute(matSrc, null, out keyPointsSrc, matSrcRet);
|
||||
byte[] arr = new byte[matSrcRet.Step(0) * matSrcRet.Rows]; // matSrcRet.Total() * matSrcRet.ElemSize()
|
||||
Marshal.Copy(matSrcRet.Data, arr, 0, arr.Length);
|
||||
File.WriteAllBytes(kpMatPath, SerializeObject(arr));
|
||||
File.WriteAllBytes(kpPath, SerializeObject(keyPointsSrc));
|
||||
}
|
||||
|
||||
sw.Stop();
|
||||
Debug.WriteLine($"大地图kp耗时:{sw.ElapsedMilliseconds}ms.");
|
||||
sw.Restart();
|
||||
sift.DetectAndCompute(matTo, null, out keyPointsTo, matToRet);
|
||||
sw.Stop();
|
||||
Debug.WriteLine($"模板kp耗时:{sw.ElapsedMilliseconds}ms.");
|
||||
sw.Restart();
|
||||
}
|
||||
|
||||
using (var bfMatcher = new OpenCvSharp.BFMatcher())
|
||||
{
|
||||
var matches = bfMatcher.KnnMatch(matSrcRet, matToRet, k: 2);
|
||||
|
||||
var pointsSrc = new List<Point2f>();
|
||||
var pointsDst = new List<Point2f>();
|
||||
var goodMatches = new List<DMatch>();
|
||||
foreach (DMatch[] items in matches.Where(x => x.Length > 1))
|
||||
{
|
||||
if (items[0].Distance < 0.5 * items[1].Distance)
|
||||
{
|
||||
pointsSrc.Add(keyPointsSrc[items[0].QueryIdx].Pt);
|
||||
pointsDst.Add(keyPointsTo[items[0].TrainIdx].Pt);
|
||||
goodMatches.Add(items[0]);
|
||||
Debug.WriteLine($"{keyPointsSrc[items[0].QueryIdx].Pt.X}, {keyPointsSrc[items[0].QueryIdx].Pt.Y}");
|
||||
}
|
||||
}
|
||||
|
||||
sw.Stop();
|
||||
Debug.WriteLine($"bfMatcher耗时:{sw.ElapsedMilliseconds}ms.");
|
||||
sw.Restart();
|
||||
|
||||
var outMat = new Mat();
|
||||
|
||||
// algorithm RANSAC Filter the matched results
|
||||
var pSrc = pointsSrc.ConvertAll(Point2fToPoint2d);
|
||||
var pDst = pointsDst.ConvertAll(Point2fToPoint2d);
|
||||
var outMask = new Mat();
|
||||
// If the original matching result is null, Skip the filtering step
|
||||
if (pSrc.Count > 0 && pDst.Count > 0)
|
||||
Cv2.FindHomography(pSrc, pDst, HomographyMethods.Ransac, mask: outMask);
|
||||
|
||||
sw.Stop();
|
||||
Debug.WriteLine($"FindHomography耗时:{sw.ElapsedMilliseconds}ms.");
|
||||
sw.Restart();
|
||||
// If passed RANSAC After processing, the matching points are more than 10.,Only filters are used. Otherwise, use the original matching point result(When the matching point is too small, it passes through RANSAC After treatment,It is possible to get the result of 0 matching points.).
|
||||
if (outMask.Rows > 10)
|
||||
{
|
||||
byte[] maskBytes = new byte[outMask.Rows * outMask.Cols];
|
||||
outMask.GetArray(out maskBytes);
|
||||
Cv2.DrawMatches(matSrc, keyPointsSrc, matTo, keyPointsTo, goodMatches, outMat, matchesMask: maskBytes, flags: DrawMatchesFlags.NotDrawSinglePoints);
|
||||
}
|
||||
else
|
||||
Cv2.DrawMatches(matSrc, keyPointsSrc, matTo, keyPointsTo, goodMatches, outMat, flags: DrawMatchesFlags.NotDrawSinglePoints);
|
||||
|
||||
sw.Stop();
|
||||
Debug.WriteLine($"绘图耗时:{sw.ElapsedMilliseconds}ms.");
|
||||
sw.Restart();
|
||||
return outMat;
|
||||
}
|
||||
}*/
|
||||
|
||||
//This method may be missed, you may read a lot of blogs, but none of them wrote
|
||||
private static Point2d Point2fToPoint2d(Point2f input)
|
||||
{
|
||||
Point2d p2 = new Point2d(input.X, input.Y);
|
||||
return p2;
|
||||
}
|
||||
|
||||
public static Mat MatchPicBySurf(Mat matSrc, Mat matTo, double threshold = 400)
|
||||
{
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
|
||||
using Mat matSrcRet = new Mat();
|
||||
using Mat matToRet = new Mat();
|
||||
KeyPoint[] keyPointsSrc, keyPointsTo;
|
||||
using (var surf = OpenCvSharp.XFeatures2D.SURF.Create(threshold, 4, 3, false, true))
|
||||
{
|
||||
surf.DetectAndCompute(matSrc, null, out keyPointsSrc, matSrcRet);
|
||||
sw.Stop();
|
||||
Debug.WriteLine($"模板kp耗时:{sw.ElapsedMilliseconds}ms.");
|
||||
sw.Restart();
|
||||
|
||||
surf.DetectAndCompute(matTo, null, out keyPointsTo, matToRet);
|
||||
sw.Stop();
|
||||
Debug.WriteLine($"大地图kp耗时:{sw.ElapsedMilliseconds}ms.");
|
||||
sw.Restart();
|
||||
}
|
||||
|
||||
using (var flnMatcher = new FlannBasedMatcher())
|
||||
{
|
||||
var matches = flnMatcher.Match(matSrcRet, matToRet);
|
||||
//Finding the Minimum and Maximum Distance
|
||||
double minDistance = 1000; //Backward approximation
|
||||
double maxDistance = 0;
|
||||
for (int i = 0; i < matSrcRet.Rows; i++)
|
||||
{
|
||||
double distance = matches[i].Distance;
|
||||
if (distance > maxDistance)
|
||||
{
|
||||
maxDistance = distance;
|
||||
}
|
||||
|
||||
if (distance < minDistance)
|
||||
{
|
||||
minDistance = distance;
|
||||
}
|
||||
}
|
||||
|
||||
Debug.WriteLine($"max distance : {maxDistance}");
|
||||
Debug.WriteLine($"min distance : {minDistance}");
|
||||
|
||||
var pointsSrc = new List<Point2f>();
|
||||
var pointsDst = new List<Point2f>();
|
||||
//Screening better matching points
|
||||
var goodMatches = new List<DMatch>();
|
||||
for (int i = 0; i < matSrcRet.Rows; i++)
|
||||
{
|
||||
double distance = matches[i].Distance;
|
||||
if (distance < Math.Max(minDistance * 2, 0.02))
|
||||
{
|
||||
pointsSrc.Add(keyPointsSrc[matches[i].QueryIdx].Pt);
|
||||
pointsDst.Add(keyPointsTo[matches[i].TrainIdx].Pt);
|
||||
//Compression of new ones with distances less than ranges DMatch
|
||||
goodMatches.Add(matches[i]);
|
||||
}
|
||||
}
|
||||
|
||||
sw.Stop();
|
||||
Debug.WriteLine($"flnMatcher耗时:{sw.ElapsedMilliseconds}ms.");
|
||||
sw.Restart();
|
||||
|
||||
var outMat = new Mat();
|
||||
|
||||
// algorithm RANSAC Filter the matched results
|
||||
var pSrc = pointsSrc.ConvertAll(Point2fToPoint2d);
|
||||
var pDst = pointsDst.ConvertAll(Point2fToPoint2d);
|
||||
var outMask = new Mat();
|
||||
// If the original matching result is null, Skip the filtering step
|
||||
if (pSrc.Count > 0 && pDst.Count > 0)
|
||||
{
|
||||
var hMat = Cv2.FindHomography(pSrc, pDst, HomographyMethods.Ransac, mask: outMask);
|
||||
|
||||
var objCorners = new Point2f[4];
|
||||
objCorners[0] = new Point2f(0, 0);
|
||||
objCorners[1] = new Point2f(0, matSrc.Rows);
|
||||
objCorners[2] = new Point2f(matSrc.Cols, matSrc.Rows);
|
||||
objCorners[3] = new Point2f(matSrc.Cols, 0);
|
||||
|
||||
var sceneCorners = Cv2.PerspectiveTransform(objCorners, hMat);
|
||||
|
||||
// for (int i = 0; i < 4; i++)
|
||||
// {
|
||||
// /* 作用和perspectiveTransform一样
|
||||
// double x = obj_corners[i].x;
|
||||
// double y = obj_corners[i].y;
|
||||
// double Z = 1. / (H.At<double>(2, 0) * x + H.At<double>(2, 1) * y + H.At<double>(2, 2));
|
||||
// double X = (H.At<double>(0, 0) * x + H.At<double>(0, 1) * y + H.At<double>(0, 2)) * Z;
|
||||
// double Y = (H.At<double>(1, 0) * x + H.At<double>(1, 1) * y + H.At<double>(1, 2)) * Z;
|
||||
// scene_corners[i] = new Point(cv.Round(X) + img_1.Cols, cv.Round(Y));*/
|
||||
// sceneCorners[i].X += matSrc.Cols;
|
||||
// }
|
||||
|
||||
Cv2.Line(matTo, sceneCorners[0].ToPoint(), sceneCorners[1].ToPoint(), Scalar.Red, 2);
|
||||
Cv2.Line(matTo, sceneCorners[1].ToPoint(), sceneCorners[2].ToPoint(), Scalar.Red, 2);
|
||||
Cv2.Line(matTo, sceneCorners[2].ToPoint(), sceneCorners[3].ToPoint(), Scalar.Red, 2);
|
||||
Cv2.Line(matTo, sceneCorners[3].ToPoint(), sceneCorners[0].ToPoint(), Scalar.Red, 2);
|
||||
}
|
||||
sw.Stop();
|
||||
Debug.WriteLine($"FindHomography耗时:{sw.ElapsedMilliseconds}ms.");
|
||||
sw.Restart();
|
||||
|
||||
// If passed RANSAC After processing, the matching points are more than 10.,Only filters are used. Otherwise, use the original matching point result(When the matching point is too small, it passes through RANSAC After treatment,It's possible to get the result of 0 matching points.).
|
||||
if (outMask.Rows > 10)
|
||||
{
|
||||
Debug.WriteLine($"使用了Ransac的结果");
|
||||
byte[] maskBytes = new byte[outMask.Rows * outMask.Cols];
|
||||
outMask.GetArray(out maskBytes);
|
||||
Cv2.DrawMatches(matSrc, keyPointsSrc, matTo, keyPointsTo, goodMatches, outMat, matchesMask: maskBytes, flags: DrawMatchesFlags.NotDrawSinglePoints);
|
||||
}
|
||||
else
|
||||
Cv2.DrawMatches(matSrc, keyPointsSrc, matTo, keyPointsTo, goodMatches, outMat, flags: DrawMatchesFlags.NotDrawSinglePoints);
|
||||
|
||||
sw.Stop();
|
||||
Debug.WriteLine($"绘图耗时:{sw.ElapsedMilliseconds}ms.");
|
||||
return outMat;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 序列化
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
/// <returns></returns>
|
||||
private static byte[] Serialize(object obj)
|
||||
{
|
||||
using var memoryStream = new MemoryStream();
|
||||
DataContractSerializer ser = new DataContractSerializer(typeof(object));
|
||||
ser.WriteObject(memoryStream, obj);
|
||||
var data = memoryStream.ToArray();
|
||||
return data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 反序列化
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
private static T Deserialize<T>(byte[] data)
|
||||
{
|
||||
using var memoryStream = new MemoryStream(data);
|
||||
XmlDictionaryReader reader = XmlDictionaryReader.CreateTextReader(memoryStream, new XmlDictionaryReaderQuotas());
|
||||
DataContractSerializer ser = new DataContractSerializer(typeof(T));
|
||||
var result = (T)ser.ReadObject(reader, true);
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool WriteRawImage(Mat image, string filename)
|
||||
{
|
||||
using (FileStream file = new FileStream(filename, FileMode.Create))
|
||||
{
|
||||
if (file == null || !file.CanWrite)
|
||||
return false;
|
||||
|
||||
BinaryWriter writer = new BinaryWriter(file);
|
||||
writer.Write(image.Rows);
|
||||
writer.Write(image.Cols);
|
||||
int depth = image.Depth();
|
||||
int type = image.Type();
|
||||
int channels = image.Channels();
|
||||
writer.Write(depth);
|
||||
writer.Write(type);
|
||||
writer.Write(channels);
|
||||
int sizeInBytes = (int)image.Step() * image.Rows;
|
||||
writer.Write(sizeInBytes);
|
||||
byte[] arr = new byte[sizeInBytes];
|
||||
Marshal.Copy(image.Data, arr, 0, arr.Length);
|
||||
writer.Write(arr, 0, sizeInBytes);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool ReadRawImage(out Mat image, string filename)
|
||||
{
|
||||
int rows, cols, data, depth, type, channels;
|
||||
image = null;
|
||||
|
||||
using (FileStream file = new FileStream(filename, FileMode.Open))
|
||||
{
|
||||
if (file == null || !file.CanRead)
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
BinaryReader reader = new BinaryReader(file);
|
||||
rows = reader.ReadInt32();
|
||||
cols = reader.ReadInt32();
|
||||
depth = reader.ReadInt32();
|
||||
type = reader.ReadInt32();
|
||||
channels = reader.ReadInt32();
|
||||
data = reader.ReadInt32();
|
||||
image = new Mat(rows, cols, (MatType)type);
|
||||
// reader.Read(image.Data, 0, data);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,194 +0,0 @@
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text.RegularExpressions;
|
||||
using OpenCvSharp;
|
||||
|
||||
namespace BetterGenshinImpact.Test.Simple.AllMap;
|
||||
|
||||
public class MapPuzzle
|
||||
{
|
||||
public static readonly int block = 2048;
|
||||
|
||||
public static List<string> PicWhiteHashList = new List<string>
|
||||
{
|
||||
"25E23B0D18C2CBEA19D28E5E399D42FA",
|
||||
"3B4847FEA7D506EAF3B75D4F4541E867",
|
||||
"CCCAF02768432A46AA0001E51DC5991B",
|
||||
"F80C609208063B289A05B8A1E0351226",
|
||||
"06767779699056515930D0597072AB7D",
|
||||
"04F757BD57FBB5FA74A6C9C0634BB122",
|
||||
"04C1EDFCD89249209D1DD885DD2F2129",
|
||||
"01B8641F5F58BBDE6E10F53D56EA7288",
|
||||
"AF56BDE27BDF534317A9FB34E08165C0",
|
||||
"05F4EAB8C6BFBADD60B8A5CCDD614F83"
|
||||
};
|
||||
|
||||
public static MD5 Md5Service = MD5.Create();
|
||||
|
||||
public static void Put()
|
||||
{
|
||||
string folderPath = @"E:\HuiTask\更好的原神\地图匹配\UI_Map"; // 图片文件夹路径
|
||||
string pattern = @"UI_MapBack_([-+]?\d+)_([-+]?\d+)(.*)";
|
||||
var images = Directory.GetFiles(folderPath, "*.png", SearchOption.TopDirectoryOnly); // 获取所有图片文件路径
|
||||
|
||||
// 解析图片位置信息并存储到字典中
|
||||
var imageLocations = new Dictionary<(int row, int col), ImgInfo>();
|
||||
foreach (var imagePath in images)
|
||||
{
|
||||
// 获取文件大小
|
||||
var fileInfo = new FileInfo(imagePath);
|
||||
|
||||
// 解析图片名称中的行列信息
|
||||
var name = Path.GetFileNameWithoutExtension(imagePath);
|
||||
var match = Regex.Match(name, pattern);
|
||||
int row, col;
|
||||
if (match.Success)
|
||||
{
|
||||
// Debug.WriteLine($"已匹配 ({match.Groups[1].Value}, {match.Groups[2].Value}) {name}");
|
||||
row = int.Parse(match.Groups[1].Value);
|
||||
col = int.Parse(match.Groups[2].Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Debug.WriteLine($"未匹配 {name}");
|
||||
continue;
|
||||
}
|
||||
|
||||
// 排除指定行列的图片
|
||||
if ((row, col) == (4, 6) || (row, col) == (5, 6) || (row, col) == (5, 5) || (row, col) == (5, 2) || (row, col) == (5, 1) || (row, col) == (4, 1))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// 读取图片并计算hash值
|
||||
Mat img = Cv2.ImRead(imagePath);
|
||||
var hashBytes = Md5Service.ComputeHash(File.ReadAllBytes(imagePath));
|
||||
var hash = BitConverter.ToString(hashBytes).Replace("-", "").ToUpperInvariant();
|
||||
|
||||
if (img.Width < 8)
|
||||
{
|
||||
Debug.WriteLine($"太小的不要 ({row}, {col}) {img.Width} {img.Height} {name}");
|
||||
continue;
|
||||
}
|
||||
|
||||
// 如果只要城市拼接,取消注释这段
|
||||
// if (block == 2048 && img.Width != 2048)
|
||||
// {
|
||||
// Debug.WriteLine($"不是2048的不要 ({row}, {col}) {img.Width} {img.Height} {name}");
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// 如果当前位置已经有图片了,保留尺寸较大的图片
|
||||
if (imageLocations.ContainsKey((row, col)))
|
||||
{
|
||||
// 如果当前位置的图片已经被hash锁定,跳过
|
||||
if (imageLocations[(row, col)].Locked)
|
||||
{
|
||||
Debug.WriteLine($"已锁定 ({row}, {col}) {name}");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (img.Width > imageLocations[(row, col)].Img.Width || fileInfo.Length > imageLocations[(row, col)].FileLength || PicWhiteHashList.Contains(hash))
|
||||
{
|
||||
imageLocations[(row, col)] = new ImgInfo(img, name, fileInfo.Length, PicWhiteHashList.Contains(hash));
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.WriteLine($"重复 ({row}, {col}) {img.Width} {img.Height} {name}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
imageLocations[(row, col)] = new ImgInfo(img, name, fileInfo.Length, PicWhiteHashList.Contains(hash));
|
||||
}
|
||||
}
|
||||
|
||||
int minRow = imageLocations.Keys.Min(key => key.row);
|
||||
int minCol = imageLocations.Keys.Min(key => key.col);
|
||||
|
||||
// 确定大图的行数和列数
|
||||
int maxRow = imageLocations.Keys.Max(key => key.row);
|
||||
int maxCol = imageLocations.Keys.Max(key => key.col);
|
||||
|
||||
// 计算大图的总宽度和高度
|
||||
var lenCol = maxCol - minCol;
|
||||
var lenRow = maxRow - minRow;
|
||||
int totalWidth = (lenCol + 1) * block;
|
||||
int totalHeight = (lenRow + 1) * block;
|
||||
|
||||
// 创建空白大图
|
||||
Mat largeImage = new Mat(totalHeight, totalWidth, MatType.CV_8UC3, new Scalar(0, 0, 0));
|
||||
|
||||
// 拼接图片
|
||||
int[,] arr = new int[lenRow + 1, lenCol + 1];
|
||||
foreach (var location in imageLocations)
|
||||
{
|
||||
int row = location.Key.row - minRow;
|
||||
int col = location.Key.col - minCol;
|
||||
Mat img = location.Value.Img;
|
||||
|
||||
arr[row, col] = 1;
|
||||
|
||||
// 计算当前图片在大图中的左上角位置
|
||||
int x = (lenCol - col) * block; // 顺序倒过来了,屮
|
||||
int y = (lenRow - row) * block; // 顺序倒过来了,屮
|
||||
|
||||
// 将图片粘贴到大图上
|
||||
if (img.Width != block || img.Height != block)
|
||||
{
|
||||
img = img.Resize(new Size(block, block), 0, 0, InterpolationFlags.Nearest);
|
||||
}
|
||||
|
||||
// 添加位置标识
|
||||
// img.PutText($"{location.Key.row} , {location.Key.col}", new Point(50, 50), HersheyFonts.HersheyComplex, 2, Scalar.Red, 2, LineTypes.Link8);
|
||||
|
||||
img.CopyTo(new Mat(largeImage, new Rect(x, y, img.Width, img.Height)));
|
||||
}
|
||||
|
||||
// 康康二维数组的拼接结果
|
||||
for (int i = 0; i < arr.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < arr.GetLength(1); j++)
|
||||
{
|
||||
Debug.Write(arr[i, j] + " ");
|
||||
}
|
||||
|
||||
Debug.WriteLine("");
|
||||
}
|
||||
|
||||
// 保存大图
|
||||
Cv2.ImWrite(@"E:\HuiTask\更好的原神\地图匹配\map_46_2048.png", largeImage);
|
||||
// Cv2.ImWrite(@"E:\HuiTask\更好的原神\地图匹配\combined_image_sd4x.png", largeImage.Resize(new Size(largeImage.Width / 4, largeImage.Height / 4), 0, 0, InterpolationFlags.Cubic));
|
||||
// Cv2.ImWrite(@"E:\HuiTask\更好的原神\地图匹配\combined_image_small.png", largeImage.Resize(new Size(1400, 1300), 0, 0, InterpolationFlags.Cubic));
|
||||
|
||||
// 释放资源
|
||||
largeImage.Dispose();
|
||||
foreach (var img in imageLocations.Values)
|
||||
{
|
||||
img.Img.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public class ImgInfo
|
||||
{
|
||||
public Mat Img { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 文件大小
|
||||
/// </summary>
|
||||
public long FileLength { get; set; }
|
||||
|
||||
public bool Locked { get; set; }
|
||||
|
||||
public ImgInfo(Mat mat, string name, long fileLength, bool locked = false)
|
||||
{
|
||||
Img = mat;
|
||||
Name = name;
|
||||
FileLength = fileLength;
|
||||
Locked = locked;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
using BetterGenshinImpact.Service;
|
||||
using OpenCvSharp;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace BetterGenshinImpact.Test.Simple.AllMap;
|
||||
|
||||
public class MapTeleportPointDraw
|
||||
{
|
||||
public static void Draw()
|
||||
{
|
||||
var pList = LoadTeleportPoint(@"E:\HuiTask\更好的原神\地图匹配\地图点位\Json_Integration\锚点&神像\");
|
||||
var map = new Mat(@"E:\HuiTask\更好的原神\地图匹配\genshin_map_带标记.png");
|
||||
DrawTeleportPoint(map, pList.ToArray());
|
||||
Cv2.ImWrite(@"E:\HuiTask\更好的原神\地图匹配\genshin_map_带标记_传送点.png", map);
|
||||
}
|
||||
|
||||
public static void DrawTeleportPoint(Mat map, Point[] points)
|
||||
{
|
||||
foreach (var point in points)
|
||||
{
|
||||
Cv2.Circle(map, new Point(point.X, point.Y), 10, Scalar.Red, 2);
|
||||
}
|
||||
}
|
||||
|
||||
public static List<Point> LoadTeleportPoint(string folderPath)
|
||||
{
|
||||
string[] files = Directory.GetFiles(folderPath, "*.*", SearchOption.AllDirectories);
|
||||
List<Point> points = new();
|
||||
foreach (var file in files)
|
||||
{
|
||||
var gamePoint = JsonSerializer.Deserialize<GamePoint>(File.ReadAllText(file), ConfigService.JsonOptions);
|
||||
if (gamePoint == null)
|
||||
{
|
||||
Debug.WriteLine($"{file} json is null");
|
||||
continue;
|
||||
}
|
||||
|
||||
points.Add(Transform(gamePoint.Position));
|
||||
}
|
||||
|
||||
return points;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 坐标系转换
|
||||
/// </summary>
|
||||
/// <param name="position">[a,b,c]</param>
|
||||
/// <returns></returns>
|
||||
public static Point Transform(decimal[] position)
|
||||
{
|
||||
// 四舍六入五取偶
|
||||
var a = (int)Math.Round(position[0]); // 上
|
||||
var c = (int)Math.Round(position[2]); // 左
|
||||
|
||||
// 转换1024区块坐标,大地图坐标系正轴是往左上方向的
|
||||
// 这里写最左上角的区块坐标(m,n)/(上,左),截止4.5版本,最左上角的区块坐标是(5,7)
|
||||
|
||||
int m = 5, n = 7;
|
||||
return new Point((n + 1) * 1024 - c, (m + 1) * 1024 - a);
|
||||
}
|
||||
|
||||
class GamePoint
|
||||
{
|
||||
public string Description { get; set; } = string.Empty;
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public decimal[] Position { get; set; } = new decimal[3];
|
||||
}
|
||||
}
|
||||
@@ -1,117 +0,0 @@
|
||||
using BetterGenshinImpact.Core.Recognition.OpenCv;
|
||||
using OpenCvSharp;
|
||||
|
||||
namespace BetterGenshinImpact.Test.Simple.AllMap;
|
||||
|
||||
public class MatchTemplateTest
|
||||
{
|
||||
public static readonly Size TemplateSize = new(240, 135);
|
||||
|
||||
// 对无用部分进行裁剪(左160,上80,下96)
|
||||
public static readonly Rect TemplateSizeRoi = new Rect(20, 10, TemplateSize.Width - 20, TemplateSize.Height - 22);
|
||||
|
||||
public static void Test()
|
||||
{
|
||||
var tar = new Mat(@"E:\HuiTask\更好的原神\地图匹配\比较\叠图\无法匹配.png", ImreadModes.Grayscale);
|
||||
var sTar = tar.Resize(new Size(240, 135), 0, 0, InterpolationFlags.Cubic);
|
||||
// sTar = new Mat(sTar, TemplateSizeRoi);
|
||||
Cv2.ImShow("sTar", sTar);
|
||||
var src = new Mat(@"E:\HuiTask\更好的原神\地图匹配\combined_image_small.png", ImreadModes.Grayscale);
|
||||
var src2 = src.Clone();
|
||||
var p = MatchTemplateWithGaussianBlur(src, sTar, TemplateMatchModes.CCoeffNormed, null, 0.1);
|
||||
|
||||
Cv2.Rectangle(src2, new Rect(p.X, p.Y, sTar.Width, sTar.Height), new Scalar(0, 0, 255));
|
||||
|
||||
Cv2.ImWrite(@"E:\HuiTask\更好的原神\地图匹配\x1.png", src2);
|
||||
}
|
||||
|
||||
public static void TestTrack()
|
||||
{
|
||||
var tar = new Mat(@"E:\HuiTask\更好的原神\自动剧情\任务剧情与地图追踪\blue_task_point_28x.png", ImreadModes.Grayscale);
|
||||
var src = new Mat(@"E:\HuiTask\更好的原神\自动剧情\任务剧情与地图追踪\202404050232291883.png", ImreadModes.Grayscale);
|
||||
var src2 = src.Clone();
|
||||
var p = MatchTemplateHelper.MatchTemplate(src, tar, TemplateMatchModes.CCoeffNormed, null, 0.2);
|
||||
Cv2.Rectangle(src2, new Rect(p.X, p.Y, tar.Width, tar.Height), new Scalar(0, 0, 255), 1);
|
||||
Cv2.ImWrite(@"E:\HuiTask\更好的原神\自动剧情\任务剧情与地图追踪\rec_b1.png", src2);
|
||||
}
|
||||
|
||||
public static void TestMenu()
|
||||
{
|
||||
var tar = new Mat(@"D:\HuiPrograming\Projects\CSharp\MiHoYo\BetterGenshinImpact\BetterGenshinImpact\GameTask\Common\Element\Assets\1920x1080\paimon_menu.png", ImreadModes.Color);
|
||||
var src = new Mat(@"E:\HuiTask\更好的原神\地图匹配\比较\菜单\Clip_20240331_155210.png", ImreadModes.Color);
|
||||
var src2 = src.Clone();
|
||||
var p = MatchTemplateHelper.MatchTemplate(src, tar, TemplateMatchModes.CCoeffNormed, null, 0.1);
|
||||
Cv2.Rectangle(src2, new Rect(p.X, p.Y, tar.Width, tar.Height), new Scalar(0, 0, 255), 1);
|
||||
// 画出小地图的位置
|
||||
// 此图38x40 小地图210x210 小地图左上角位置 24,-15
|
||||
Cv2.Rectangle(src2, new Rect(p.X + 24, p.Y - 15, 210, 210), Scalar.Blue, 1);
|
||||
Cv2.ImWrite(@"E:\HuiTask\更好的原神\地图匹配\比较\菜单\rec2.png", src2);
|
||||
}
|
||||
|
||||
public static void TestTeamAvatar()
|
||||
{
|
||||
var tar = new Mat(@"E:\HuiTask\更好的原神\自动秘境\自动战斗\队伍识别\识别头像素材\UI_AvatarIcon_Side_Zhongli_2.png", ImreadModes.Unchanged);
|
||||
// tar = tar.Resize(new Size(108, 108), 0, 0, InterpolationFlags.Cubic);
|
||||
var channels = tar.Split();
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
channels[i] &= channels[3];
|
||||
}
|
||||
Cv2.Merge(channels[..3], tar);
|
||||
Cv2.ImShow("tar.png", tar);
|
||||
var src = new Mat(@"E:\HuiTask\更好的原神\自动秘境\自动战斗\队伍识别\1.png", ImreadModes.Color);
|
||||
var src2 = src.Clone();
|
||||
var p = MatchTemplateWithGaussianBlur(src, tar, TemplateMatchModes.CCoeffNormed, null, 0.1);
|
||||
Cv2.Rectangle(src2, new Rect(p.X, p.Y, tar.Width, tar.Height), new Scalar(0, 0, 255), 1);
|
||||
// Cv2.ImWrite(@"E:\HuiTask\更好的原神\自动秘境\自动战斗\队伍识别\rec_1.png", src2);
|
||||
Cv2.ImShow("src2", src2);
|
||||
}
|
||||
|
||||
public static Point MatchTemplateWithGaussianBlur(Mat srcMat, Mat dstMat, TemplateMatchModes matchMode, Mat? maskMat = null, double threshold = 0.8)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = new Mat();
|
||||
if (maskMat == null)
|
||||
{
|
||||
Cv2.MatchTemplate(srcMat, dstMat, result, matchMode);
|
||||
}
|
||||
else
|
||||
{
|
||||
Cv2.MatchTemplate(srcMat, dstMat, result, matchMode, maskMat);
|
||||
}
|
||||
|
||||
if (matchMode is TemplateMatchModes.SqDiff or TemplateMatchModes.CCoeff or TemplateMatchModes.CCorr)
|
||||
{
|
||||
Cv2.Normalize(result, result, 0, 1, NormTypes.MinMax, -1, null);
|
||||
}
|
||||
using var blurResult = new Mat();
|
||||
Cv2.GaussianBlur(result, blurResult, new Size(1, 1), 0);
|
||||
Cv2.ImShow("blurResult", blurResult);
|
||||
Cv2.Subtract(result, blurResult, result);
|
||||
|
||||
Cv2.MinMaxLoc(result, out var minValue, out var maxValue, out var minLoc, out var maxLoc);
|
||||
Cv2.ImShow("result", result);
|
||||
if (matchMode is TemplateMatchModes.SqDiff or TemplateMatchModes.SqDiffNormed)
|
||||
{
|
||||
if (minValue <= 1 - threshold)
|
||||
{
|
||||
return minLoc;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (maxValue >= threshold)
|
||||
{
|
||||
return maxLoc;
|
||||
}
|
||||
}
|
||||
|
||||
return new Point();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new Point();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
using OpenCvSharp;
|
||||
|
||||
namespace BetterGenshinImpact.Test.Simple;
|
||||
|
||||
internal class AutoCookTest
|
||||
{
|
||||
public static void Test()
|
||||
{
|
||||
var img = new Mat(@"E:\HuiTask\更好的原神\自动烹饪\2.png");
|
||||
Cv2.CvtColor(img, img, ColorConversionCodes.BGR2RGB);
|
||||
var img2 = new Mat();
|
||||
// Cv2.InRange(img, new Scalar(255, 192, 64), new Scalar(255, 192, 64), img2);
|
||||
Cv2.InRange(img, new Scalar(255, 255, 192), new Scalar(255, 255, 192), img2);
|
||||
|
||||
Cv2.ImShow("img", img2);
|
||||
}
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
using OpenCvSharp;
|
||||
|
||||
namespace BetterGenshinImpact.Test.Simple;
|
||||
|
||||
internal class HsvTestWindow
|
||||
{
|
||||
private const int MaxValueH = 360 / 2;
|
||||
private static readonly int MaxValue = 255;
|
||||
|
||||
//private const string WindowCaptureName = "Video Capture";
|
||||
private const string _windowDetectionName = "Object Detection";
|
||||
|
||||
private static int _lowH = 0, _lowS = 0, _lowV = 0;
|
||||
private static int _highH = MaxValueH, _highS = MaxValue, _highV = MaxValue;
|
||||
|
||||
static void on_low_H_thresh_trackbar(int pos, nint userdata)
|
||||
{
|
||||
_lowH = Math.Min(_highH - 1, _lowH);
|
||||
Cv2.SetTrackbarPos("Low H", _windowDetectionName, _lowH);
|
||||
}
|
||||
|
||||
static void on_high_H_thresh_trackbar(int pos, nint userdata)
|
||||
{
|
||||
_highH = Math.Max(_highH, _lowH + 1);
|
||||
Cv2.SetTrackbarPos("High H", _windowDetectionName, _highH);
|
||||
}
|
||||
|
||||
static void on_low_S_thresh_trackbar(int pos, nint userdata)
|
||||
{
|
||||
_lowS = Math.Min(_highS - 1, _lowS);
|
||||
Cv2.SetTrackbarPos("Low S", _windowDetectionName, _lowS);
|
||||
}
|
||||
|
||||
static void on_high_S_thresh_trackbar(int pos, nint userdata)
|
||||
{
|
||||
_highS = Math.Max(_highS, _lowS + 1);
|
||||
Cv2.SetTrackbarPos("High S", _windowDetectionName, _highS);
|
||||
}
|
||||
|
||||
static void on_low_V_thresh_trackbar(int pos, nint userdata)
|
||||
{
|
||||
_lowV = Math.Min(_highV - 1, _lowV);
|
||||
Cv2.SetTrackbarPos("Low V", _windowDetectionName, _lowV);
|
||||
}
|
||||
|
||||
static void on_high_V_thresh_trackbar(int pos, nint userdata)
|
||||
{
|
||||
_highV = Math.Max(_highV, _lowV + 1);
|
||||
Cv2.SetTrackbarPos("High V", _windowDetectionName, _highV);
|
||||
}
|
||||
|
||||
public void Run()
|
||||
{
|
||||
//Cv2.NamedWindow(WindowCaptureName);
|
||||
Cv2.NamedWindow(_windowDetectionName);
|
||||
Cv2.ResizeWindow(_windowDetectionName, 900, 900);
|
||||
// Trackbars to set thresholds for HSV values
|
||||
Cv2.CreateTrackbar("Low H", _windowDetectionName, ref _lowH, MaxValueH, on_low_H_thresh_trackbar);
|
||||
Cv2.CreateTrackbar("High H", _windowDetectionName, ref _highH, MaxValueH, on_high_H_thresh_trackbar);
|
||||
Cv2.CreateTrackbar("Low S", _windowDetectionName, ref _lowS, MaxValue, on_low_S_thresh_trackbar);
|
||||
Cv2.CreateTrackbar("High S", _windowDetectionName, ref _highS, MaxValue, on_high_S_thresh_trackbar);
|
||||
Cv2.CreateTrackbar("Low V", _windowDetectionName, ref _lowV, MaxValue, on_low_V_thresh_trackbar);
|
||||
Cv2.CreateTrackbar("High V", _windowDetectionName, ref _highV, MaxValue, on_high_V_thresh_trackbar);
|
||||
var frame = Cv2.ImRead(@"E:\HuiTask\更好的原神\自动秘境\自动战斗\队伍识别\bsz1.png", ImreadModes.Color);
|
||||
Mat frameHsv = new Mat();
|
||||
// Convert from BGR to HSV colorspace
|
||||
Cv2.CvtColor(frame, frameHsv, ColorConversionCodes.BGR2HSV);
|
||||
Mat frameThreshold = new Mat();
|
||||
|
||||
while (true)
|
||||
{
|
||||
// Detect the object based on HSV Range Values
|
||||
Cv2.InRange(frameHsv, new Scalar(_lowH, _lowS, _lowV), new Scalar(_highH, _highS, _highV), frameThreshold);
|
||||
// Show the frames
|
||||
// Cv2.ImShow(WindowCaptureName, frame);
|
||||
Cv2.ImShow(_windowDetectionName, frameThreshold);
|
||||
|
||||
char key = (char)Cv2.WaitKey(30);
|
||||
if (key == 'q' || key == 27)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,164 +0,0 @@
|
||||
using OpenCvSharp;
|
||||
|
||||
namespace BetterGenshinImpact.Test.Simple.MiniMap;
|
||||
|
||||
public class CameraOrientationTest
|
||||
{
|
||||
public static (int[], int[], int[]) Test1()
|
||||
{
|
||||
var mat = Cv2.ImRead(@"E:\HuiTask\更好的原神\自动秘境\视角朝向识别\3.png", ImreadModes.Grayscale);
|
||||
Cv2.GaussianBlur(mat, mat, new Size(3, 3), 0);
|
||||
// 极坐标展开
|
||||
var centerPoint = new Point2f(mat.Width / 2f, mat.Height / 2f);
|
||||
var polarMat = new Mat();
|
||||
Cv2.WarpPolar(mat, polarMat, new Size(360, 360), centerPoint, 360d, InterpolationFlags.Linear, WarpPolarMode.Linear);
|
||||
// Cv2.ImShow("polarMat", polarMat);
|
||||
var polarRoiMat = new Mat(polarMat, new Rect(10, 0, 70, polarMat.Height));
|
||||
Cv2.Rotate(polarRoiMat, polarRoiMat, RotateFlags.Rotate90Counterclockwise);
|
||||
Cv2.ImShow("极坐标转换后", polarRoiMat);
|
||||
//Cv2.ImWrite(@"E:\HuiTask\更好的原神\自动秘境\视角朝向识别\2_p.png", polarRoiMat);
|
||||
|
||||
var scharrResult = new Mat();
|
||||
Cv2.Scharr(polarRoiMat, scharrResult, MatType.CV_32F, 1, 0);
|
||||
|
||||
var scharrResultDisplay = new Mat();
|
||||
Cv2.ConvertScaleAbs(scharrResult, scharrResultDisplay);
|
||||
Cv2.ImShow("Scharr", scharrResultDisplay);
|
||||
|
||||
// 求波峰
|
||||
var left = new int[360];
|
||||
var right = new int[360];
|
||||
|
||||
scharrResult.GetArray<float>(out var array);
|
||||
var leftPeaks = FindPeaks(array);
|
||||
leftPeaks.ForEach(i => left[i % 360]++);
|
||||
|
||||
var reversedArray = array.Select(x => -x).ToArray();
|
||||
var rightPeaks = FindPeaks(reversedArray);
|
||||
rightPeaks.ForEach(i => right[i % 360]++);
|
||||
|
||||
// 优化
|
||||
var left2 = left.Zip(right, (x, y) => Math.Max(x - y, 0)).ToArray();
|
||||
var right2 = right.Zip(left, (x, y) => Math.Max(x - y, 0)).ToArray();
|
||||
|
||||
// 左移后相乘
|
||||
var rightAfterShift = Shift(right2, -90);
|
||||
//var all = left2.Zip(rightAfterShift, (x, y) => x * y).ToArray();
|
||||
|
||||
// for (var i = 0; i < all.Length; i++)
|
||||
// {
|
||||
// if (i < 270)
|
||||
// {
|
||||
// all[i] = left[i] * right[i + 90];
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// all[i] = left[i] * right[i - 270];
|
||||
// }
|
||||
// }
|
||||
|
||||
// 左移后相乘 在附近2°内寻找最大值
|
||||
var sum = new int[360];
|
||||
for (var i = -2; i <= 2; i++)
|
||||
{
|
||||
var all = left2.Zip(Shift(right2, -90 + i), (x, y) => x * y * (3 - Math.Abs(i)) / 3).ToArray();
|
||||
sum = sum.Zip(all, (x, y) => x + y).ToArray();
|
||||
}
|
||||
|
||||
// 卷积
|
||||
var result = new int[360];
|
||||
for (var i = -2; i <= 2; i++)
|
||||
{
|
||||
var all = Shift(sum, i);
|
||||
for (var j = 0; j < all.Length; j++)
|
||||
{
|
||||
all[j] = all[j] * (3 - Math.Abs(i)) / 3;
|
||||
}
|
||||
|
||||
result = result.Zip(all, (x, y) => x + y).ToArray();
|
||||
}
|
||||
|
||||
return (left2, rightAfterShift, result);
|
||||
}
|
||||
|
||||
//static List<int> FindPeaks(double[] data)
|
||||
//{
|
||||
// List<int> peakIndices = new List<int>();
|
||||
|
||||
// for (int i = 1; i < data.Length - 1; i++)
|
||||
// {
|
||||
// if (data[i] > data[i - 1] && data[i] > data[i + 1])
|
||||
// {
|
||||
// peakIndices.Add(i);
|
||||
// }
|
||||
// }
|
||||
|
||||
// return peakIndices;
|
||||
//}
|
||||
|
||||
static List<int> FindPeaks(float[] data)
|
||||
{
|
||||
List<int> peakIndices = new List<int>();
|
||||
|
||||
for (int i = 1; i < data.Length - 1; i++)
|
||||
{
|
||||
if (data[i] > data[i - 1] && data[i] > data[i + 1])
|
||||
{
|
||||
peakIndices.Add(i);
|
||||
}
|
||||
}
|
||||
|
||||
return peakIndices;
|
||||
}
|
||||
|
||||
public static int[] RightShift(int[] array, int k)
|
||||
{
|
||||
return array.Skip(array.Length - k)
|
||||
.Concat(array.Take(array.Length - k))
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
public static int[] LeftShift(int[] array, int k)
|
||||
{
|
||||
return array.Skip(k)
|
||||
.Concat(array.Take(k))
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
public static int[] Shift(int[] array, int k)
|
||||
{
|
||||
if (k > 0)
|
||||
{
|
||||
return RightShift(array, k);
|
||||
}
|
||||
else
|
||||
{
|
||||
return LeftShift(array, -k);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Test2()
|
||||
{
|
||||
var mat = Cv2.ImRead(@"E:\HuiTask\更好的原神\自动秘境\视角朝向识别\1.png", ImreadModes.Color);
|
||||
|
||||
// 极坐标展开
|
||||
var centerPoint = new Point2f(mat.Width / 2f, mat.Height / 2f);
|
||||
var polarMat = new Mat();
|
||||
Cv2.WarpPolar(mat, polarMat, new Size(360, 360), centerPoint, 360d, InterpolationFlags.Linear, WarpPolarMode.Linear);
|
||||
var polarRoiMat = new Mat(polarMat, new Rect(20, 0, 70, polarMat.Height));
|
||||
Cv2.Rotate(polarRoiMat, polarRoiMat, RotateFlags.Rotate90Counterclockwise);
|
||||
Cv2.CvtColor(polarRoiMat, polarRoiMat, ColorConversionCodes.BGR2Lab);
|
||||
Cv2.ImShow("极坐标转换后", polarRoiMat);
|
||||
|
||||
var splitMat = polarRoiMat.Split();
|
||||
|
||||
for (int i = 0; i < splitMat.Length; i++)
|
||||
{
|
||||
Cv2.ImShow($"splitMat{i}", splitMat[i]);
|
||||
}
|
||||
|
||||
var andMat = new Mat();
|
||||
Cv2.Scharr(splitMat[0], andMat, MatType.CV_8UC1, 1, 0);
|
||||
Cv2.ImShow("Scharr", andMat);
|
||||
}
|
||||
}
|
||||
@@ -1,362 +0,0 @@
|
||||
using System.Diagnostics;
|
||||
using BetterGenshinImpact.Core.Recognition.OpenCv;
|
||||
using OpenCvSharp;
|
||||
|
||||
namespace BetterGenshinImpact.Test.Simple.MiniMap;
|
||||
|
||||
public class CharacterOrientationTest
|
||||
{
|
||||
public static void TestArrow()
|
||||
{
|
||||
var mat = Cv2.ImRead(@"E:\HuiTask\更好的原神\自动秘境\箭头识别\3.png", ImreadModes.Color);
|
||||
var lowScalar = new Scalar(0, 207, 255);
|
||||
var highScalar = new Scalar(0, 208, 255);
|
||||
var gray = OpenCvCommonHelper.Threshold(mat, lowScalar, highScalar);
|
||||
Cv2.ImShow("gray", gray);
|
||||
}
|
||||
|
||||
static double Distance(Point pt1, Point pt2)
|
||||
{
|
||||
int deltaX = Math.Abs(pt2.X - pt1.X);
|
||||
int deltaY = Math.Abs(pt2.Y - pt1.Y);
|
||||
|
||||
return Math.Sqrt(deltaX * deltaX + deltaY * deltaY);
|
||||
}
|
||||
|
||||
static double Distance(Point2f pt1, Point2f pt2)
|
||||
{
|
||||
var deltaX = Math.Abs(pt2.X - pt1.X);
|
||||
var deltaY = Math.Abs(pt2.Y - pt1.Y);
|
||||
|
||||
return Math.Sqrt(deltaX * deltaX + deltaY * deltaY);
|
||||
}
|
||||
|
||||
// static Point2f Midpoint(Point2f p1, Point2f p2)
|
||||
// {
|
||||
// var midX = (p1.X + p2.X) / 2;
|
||||
// var midY = (p1.Y + p2.Y) / 2;
|
||||
// return new Point2f(midX, midY);
|
||||
// }
|
||||
|
||||
static Point Midpoint(Point p1, Point p2)
|
||||
{
|
||||
var midX = (p1.X + p2.X) / 2;
|
||||
var midY = (p1.Y + p2.Y) / 2;
|
||||
return new Point(midX, midY);
|
||||
}
|
||||
|
||||
public static void Triangle(Mat src, Mat gray)
|
||||
{
|
||||
Cv2.FindContours(gray, out var contours, out var hierarchy, RetrievalModes.External, ContourApproximationModes.ApproxNone);
|
||||
Mat dst = Mat.Zeros(gray.Size(), MatType.CV_8UC3);
|
||||
for (int i = 0; i < contours.Length; i++)
|
||||
{
|
||||
Cv2.DrawContours(src, contours, i, Scalar.Red, 1, LineTypes.Link4, hierarchy);
|
||||
}
|
||||
// Cv2.ImShow("目标", dst);
|
||||
|
||||
Mat dst2 = Mat.Zeros(gray.Size(), MatType.CV_8UC3);
|
||||
// 遍历轮廓
|
||||
for (int i = 0; i < contours.Length; i++)
|
||||
{
|
||||
// 计算轮廓的周长
|
||||
double perimeter = Cv2.ArcLength(contours[i], true);
|
||||
|
||||
// 近似多边形拟合
|
||||
Point[] approx = Cv2.ApproxPolyDP(contours[i], 0.04 * perimeter, true);
|
||||
|
||||
// 如果拟合的多边形有三个顶点,认为是三角形
|
||||
if (approx.Length == 3)
|
||||
{
|
||||
// 在图像上绘制三角形的轮廓
|
||||
Cv2.DrawContours(src, new Point[][] { approx }, -1, Scalar.Green, 1);
|
||||
// 计算三条边的长度
|
||||
var sideLengths = new double[3];
|
||||
sideLengths[0] = Distance(approx[1], approx[2]);
|
||||
sideLengths[1] = Distance(approx[2], approx[0]);
|
||||
sideLengths[2] = Distance(approx[0], approx[1]);
|
||||
|
||||
var result = sideLengths
|
||||
.Select((value, index) => new { Value = value, Index = index })
|
||||
.OrderBy(item => item.Value)
|
||||
.First();
|
||||
|
||||
// 计算最短线的中点
|
||||
var residue = approx.ToList();
|
||||
residue.RemoveAt(result.Index);
|
||||
var midPoint = new Point((residue[0].X + residue[1].X) / 2, (residue[0].Y + residue[1].Y) / 2);
|
||||
|
||||
// 在图像上绘制直线
|
||||
Cv2.Line(src, midPoint, approx[result.Index] + (approx[result.Index] - midPoint) * 3, Scalar.Red, 1);
|
||||
|
||||
Debug.WriteLine(CalculateAngle(midPoint, approx[result.Index]));
|
||||
}
|
||||
}
|
||||
|
||||
Cv2.ImShow("目标2", src);
|
||||
}
|
||||
|
||||
public static void TestArrow2()
|
||||
{
|
||||
var mat = Cv2.ImRead(@"E:\HuiTask\更好的原神\自动秘境\箭头识别\s1.png", ImreadModes.Color);
|
||||
Cv2.GaussianBlur(mat, mat, new Size(3, 3), 0);
|
||||
var splitMat = mat.Split();
|
||||
|
||||
//for (int i = 0; i < splitMat.Length; i++)
|
||||
//{
|
||||
// Cv2.ImShow($"splitMat{i}", splitMat[i]);
|
||||
//}
|
||||
|
||||
// 红蓝通道按位与
|
||||
var red = new Mat(mat.Size(), MatType.CV_8UC1);
|
||||
Cv2.InRange(splitMat[0], new Scalar(250), new Scalar(255), red);
|
||||
//Cv2.ImShow("red", red);
|
||||
var blue = new Mat(mat.Size(), MatType.CV_8UC1);
|
||||
Cv2.InRange(splitMat[2], new Scalar(0), new Scalar(10), blue);
|
||||
//Cv2.ImShow("blue", blue);
|
||||
var andMat = red & blue;
|
||||
Cv2.ImShow("andMat2", andMat);
|
||||
Triangle(mat, andMat);
|
||||
}
|
||||
|
||||
public static void TestArrow3()
|
||||
{
|
||||
var mat = Cv2.ImRead(@"E:\HuiTask\更好的原神\自动秘境\箭头识别\s1.png", ImreadModes.Color);
|
||||
Cv2.GaussianBlur(mat, mat, new Size(3, 3), 0);
|
||||
var splitMat = mat.Split();
|
||||
|
||||
//for (int i = 0; i < splitMat.Length; i++)
|
||||
//{
|
||||
// Cv2.ImShow($"splitMat{i}", splitMat[i]);
|
||||
//}
|
||||
|
||||
// 红蓝通道按位与
|
||||
var red = new Mat(mat.Size(), MatType.CV_8UC1);
|
||||
Cv2.InRange(splitMat[0], new Scalar(255), new Scalar(255), red);
|
||||
//Cv2.ImShow("red", red);
|
||||
var blue = new Mat(mat.Size(), MatType.CV_8UC1);
|
||||
Cv2.InRange(splitMat[2], new Scalar(0), new Scalar(0), blue);
|
||||
//Cv2.ImShow("blue", blue);
|
||||
var andMat = red & blue;
|
||||
// Cv2.ImShow("andMat", andMat);
|
||||
|
||||
//腐蚀
|
||||
var kernel = Cv2.GetStructuringElement(MorphShapes.Rect, new Size(3, 3));
|
||||
var res = new Mat(mat.Size(), MatType.CV_8UC1);
|
||||
Cv2.Erode(andMat.ToMat(), res, kernel);
|
||||
Cv2.ImShow("erode", res);
|
||||
|
||||
// 膨胀
|
||||
// var res2 = new Mat(mat.Size(), MatType.CV_8UC1);
|
||||
// Cv2.Dilate(res, res2, kernel);
|
||||
// Cv2.ImShow("dilate", res2);
|
||||
|
||||
// 矩形检测
|
||||
Cv2.FindContours(res, out var contours, out var hierarchy, RetrievalModes.External, ContourApproximationModes.ApproxNone);
|
||||
Mat dst = Mat.Zeros(res.Size(), MatType.CV_8UC3);
|
||||
for (int i = 0; i < contours.Length; i++)
|
||||
{
|
||||
// 最小外接矩形
|
||||
var rect = Cv2.MinAreaRect(contours[i]);
|
||||
// 矩形的四个顶点
|
||||
var points = Cv2.BoxPoints(rect);
|
||||
// 绘制矩形
|
||||
for (int j = 0; j < 4; ++j)
|
||||
{
|
||||
Cv2.Line(mat, (Point)points[j], (Point)points[(j + 1) % 4], Scalar.Red, 1);
|
||||
}
|
||||
|
||||
if (Distance(points[0], points[1]) > Distance(points[1], points[2]))
|
||||
{
|
||||
Debug.WriteLine(CalculateAngle(points[0], points[1]));
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.WriteLine(CalculateAngle(points[1], points[2]));
|
||||
}
|
||||
}
|
||||
|
||||
Cv2.ImShow("目标", mat);
|
||||
|
||||
TestArrow2();
|
||||
}
|
||||
|
||||
static double CalculateAngle(Point2f point1, Point2f point2)
|
||||
{
|
||||
var angleRadians = Math.Atan2(point2.Y - point1.Y, point2.X - point1.X);
|
||||
var angleDegrees = angleRadians * (180 / Math.PI);
|
||||
|
||||
// 将角度调整为正值
|
||||
if (angleDegrees < 0)
|
||||
{
|
||||
angleDegrees += 360;
|
||||
}
|
||||
|
||||
return angleDegrees;
|
||||
}
|
||||
|
||||
public static void FloodFill()
|
||||
{
|
||||
var mat = Cv2.ImRead(@"E:\HuiTask\更好的原神\自动秘境\箭头识别\s1.png", ImreadModes.Color);
|
||||
Cv2.GaussianBlur(mat, mat, new Size(3, 3), 0);
|
||||
var splitMat = mat.Split();
|
||||
|
||||
//for (int i = 0; i < splitMat.Length; i++)
|
||||
//{
|
||||
// Cv2.ImShow($"splitMat{i}", splitMat[i]);
|
||||
//}
|
||||
|
||||
// 1. 红蓝通道按位与
|
||||
var red = new Mat(mat.Size(), MatType.CV_8UC1);
|
||||
Cv2.InRange(splitMat[0], new Scalar(250), new Scalar(255), red);
|
||||
//Cv2.ImShow("red", red);
|
||||
var blue = new Mat(mat.Size(), MatType.CV_8UC1);
|
||||
Cv2.InRange(splitMat[2], new Scalar(0), new Scalar(10), blue);
|
||||
//Cv2.ImShow("blue", blue);
|
||||
var andMat = new Mat(mat.Size(), MatType.CV_8UC1);
|
||||
|
||||
Cv2.BitwiseAnd(red, blue, andMat);
|
||||
Cv2.ImShow("andMat2", andMat);
|
||||
|
||||
// 寻找轮廓
|
||||
Cv2.FindContours(andMat, out var contours, out var hierarchy, RetrievalModes.External, ContourApproximationModes.ApproxSimple);
|
||||
Mat dst = Mat.Zeros(andMat.Size(), MatType.CV_8UC3);
|
||||
for (int i = 0; i < contours.Length; i++)
|
||||
{
|
||||
Cv2.DrawContours(dst, contours, i, Scalar.Red, 1, LineTypes.Link4, hierarchy);
|
||||
}
|
||||
|
||||
Cv2.ImShow("寻找轮廓", dst);
|
||||
|
||||
// 计算最大外接矩形
|
||||
if (contours.Length > 0)
|
||||
{
|
||||
var boxes = contours.Select(Cv2.BoundingRect).Where(w => w.Height >= 2);
|
||||
var boxArray = boxes as Rect[] ?? boxes.ToArray();
|
||||
if (boxArray.Count() != 1)
|
||||
{
|
||||
throw new Exception("找到多个外接矩形");
|
||||
}
|
||||
|
||||
var box = boxArray.First();
|
||||
|
||||
// 剪裁出准备泛洪的区域(放大4倍的区域)
|
||||
var newSrcMat = new Mat(mat, new Rect(box.X - box.Width / 2, box.Y - box.Height / 2, box.Width * 2, box.Height * 2));
|
||||
Cv2.ImShow("剪裁出准备泛洪的区域", newSrcMat);
|
||||
|
||||
// 中心点作为种子点
|
||||
var seedPoint = new Point(newSrcMat.Width / 2, newSrcMat.Height / 2);
|
||||
|
||||
// 泛洪填充
|
||||
Cv2.FloodFill(newSrcMat, seedPoint, Scalar.White, out _, new Scalar());
|
||||
}
|
||||
}
|
||||
|
||||
public static void Hsv()
|
||||
{
|
||||
var mat = Cv2.ImRead(@"E:\HuiTask\更好的原神\自动秘境\箭头识别\e1.png", ImreadModes.Color);
|
||||
// Cv2.GaussianBlur(mat, mat, new Size(3, 3), 0);
|
||||
var splitMat = mat.Split();
|
||||
|
||||
// 1. 红蓝通道按位与
|
||||
var red = new Mat(mat.Size(), MatType.CV_8UC1);
|
||||
Cv2.InRange(splitMat[0], new Scalar(250), new Scalar(255), red);
|
||||
var blue = new Mat(mat.Size(), MatType.CV_8UC1);
|
||||
Cv2.InRange(splitMat[2], new Scalar(0), new Scalar(10), blue);
|
||||
var andMat = new Mat(mat.Size(), MatType.CV_8UC1);
|
||||
|
||||
Cv2.BitwiseAnd(red, blue, andMat);
|
||||
Cv2.ImShow("andMat2", andMat);
|
||||
|
||||
// 寻找轮廓
|
||||
Cv2.FindContours(andMat, out var contours, out var hierarchy, RetrievalModes.External, ContourApproximationModes.ApproxSimple);
|
||||
Mat dst = Mat.Zeros(andMat.Size(), MatType.CV_8UC3);
|
||||
for (int i = 0; i < contours.Length; i++)
|
||||
{
|
||||
Cv2.DrawContours(dst, contours, i, Scalar.Red, 1, LineTypes.Link4, hierarchy);
|
||||
}
|
||||
|
||||
Cv2.ImShow("寻找轮廓", dst);
|
||||
|
||||
// 计算最大外接矩形
|
||||
|
||||
if (contours.Length > 0)
|
||||
{
|
||||
var maxRect = Rect.Empty;
|
||||
var maxIndex = 0;
|
||||
for (int i = 0; i < contours.Length; i++)
|
||||
{
|
||||
var box = Cv2.BoundingRect(contours[i]);
|
||||
if (box.Width * box.Height > maxRect.Width * maxRect.Height)
|
||||
{
|
||||
maxRect = box;
|
||||
maxIndex = i;
|
||||
}
|
||||
}
|
||||
|
||||
var maxContour = contours[maxIndex];
|
||||
|
||||
// 计算轮廓的周长
|
||||
var perimeter = Cv2.ArcLength(maxContour, true);
|
||||
|
||||
// 近似多边形拟合
|
||||
var approx = Cv2.ApproxPolyDP(maxContour, 0.08 * perimeter, true);
|
||||
|
||||
// 如果拟合的多边形有三个顶点,认为是三角形
|
||||
if (approx.Length == 3)
|
||||
{
|
||||
// 在图像上绘制三角形的轮廓
|
||||
Cv2.DrawContours(mat, new Point[][] { approx }, -1, Scalar.Green, 1);
|
||||
|
||||
// 剪裁出三角形所在区域
|
||||
var newSrcMat = new Mat(mat, maxRect);
|
||||
|
||||
// HSV 阈值取出中心飞镖
|
||||
var hsvMat = new Mat();
|
||||
Cv2.CvtColor(newSrcMat, hsvMat, ColorConversionCodes.BGR2HSV);
|
||||
// var lowScalar = new Scalar(95, 255, 255);
|
||||
// var highScalar = new Scalar(255, 255, 255);
|
||||
var lowScalar = new Scalar(93, 155, 170);
|
||||
var highScalar = new Scalar(255, 255, 255);
|
||||
var hsvThresholdMat = new Mat();
|
||||
Cv2.InRange(hsvMat, lowScalar, highScalar, hsvThresholdMat);
|
||||
Cv2.ImShow("剪裁出三角形所在区域", hsvMat);
|
||||
Cv2.ImShow("HSV 阈值取出中心飞镖", hsvThresholdMat);
|
||||
|
||||
// 循环计算三条边的中点,并计算中点到顶点的所有点中连续黑色像素的个数
|
||||
var maxBlackCount = 0;
|
||||
Point correctP1 = new(), correctP2 = new();
|
||||
var offset = new Point(maxRect.X, maxRect.Y);
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
var midPoint = Midpoint(approx[i], approx[(i + 1) % 3]);
|
||||
var targetPoint = approx[(i + 2) % 3];
|
||||
|
||||
// 中点到顶点的所有点
|
||||
var lineIterator = new LineIterator(hsvThresholdMat, midPoint - offset, targetPoint - offset, PixelConnectivity.Connectivity8);
|
||||
|
||||
// 计算连续黑色像素的个数
|
||||
var blackCount = 0;
|
||||
foreach (var item in lineIterator)
|
||||
{
|
||||
if (item.GetValue<Vec2b>().Item0 == 255)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
blackCount++;
|
||||
}
|
||||
|
||||
if (blackCount > maxBlackCount)
|
||||
{
|
||||
maxBlackCount = blackCount;
|
||||
correctP1 = midPoint;
|
||||
correctP2 = targetPoint;
|
||||
}
|
||||
}
|
||||
Cv2.Line(mat, correctP1, correctP2 + (correctP2 - correctP1) * 3, Scalar.Red, 1);
|
||||
Cv2.ImShow("最终结果", mat);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
using System.Diagnostics;
|
||||
using BetterGenshinImpact.Core.Recognition.OCR;
|
||||
using BetterGenshinImpact.Core.Recognition.ONNX.SVTR;
|
||||
using BetterGenshinImpact.Core.Recognition.OpenCv;
|
||||
using OpenCvSharp;
|
||||
|
||||
namespace BetterGenshinImpact.Test.Simple;
|
||||
|
||||
public class OcrTest
|
||||
{
|
||||
public static void TestYap()
|
||||
{
|
||||
Mat mat = Cv2.ImRead(@"E:\HuiTask\更好的原神\临时文件\fuben_jueyuan.png", ImreadModes.Grayscale);
|
||||
var text = TextInferenceFactory.Pick.Inference(PreProcessForInference(mat));
|
||||
Debug.WriteLine(text);
|
||||
|
||||
Mat mat2 = Cv2.ImRead(@"E:\HuiTask\更好的原神\临时文件\fuben_jueyuan.png", ImreadModes.Grayscale);
|
||||
var text2 = OcrFactory.Paddle.Ocr(mat2);
|
||||
Debug.WriteLine(text2);
|
||||
}
|
||||
|
||||
private static Mat PreProcessForInference(Mat mat)
|
||||
{
|
||||
// Yap 已经改用灰度图了 https://github.com/Alex-Beng/Yap/commit/c2ad1e7b1442aaf2d80782a032e00876cd1c6c84
|
||||
// 二值化
|
||||
// Cv2.Threshold(mat, mat, 0, 255, ThresholdTypes.Otsu | ThresholdTypes.Binary);
|
||||
//Cv2.AdaptiveThreshold(mat, mat, 255, AdaptiveThresholdTypes.GaussianC, ThresholdTypes.Binary, 31, 3); // 效果不错 但是和模型不搭
|
||||
//mat = OpenCvCommonHelper.Threshold(mat, Scalar.FromRgb(235, 235, 235), Scalar.FromRgb(255, 255, 255)); // 识别物品不太行
|
||||
// 不知道为什么要强制拉伸到 221x32
|
||||
mat = ResizeHelper.ResizeTo(mat, 221, 32);
|
||||
// 填充到 384x32
|
||||
var padded = new Mat(new Size(384, 32), MatType.CV_8UC1, Scalar.Black);
|
||||
padded[new Rect(0, 0, mat.Width, mat.Height)] = mat;
|
||||
//Cv2.ImWrite(Global.Absolute("padded.png"), padded);
|
||||
return padded;
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
using BetterGenshinImpact.Test.Simple.MiniMap;
|
||||
using OxyPlot;
|
||||
using OxyPlot.Series;
|
||||
|
||||
namespace BetterGenshinImpact.Test.View;
|
||||
|
||||
internal class CameraRecViewModel
|
||||
{
|
||||
public PlotModel LeftModel { get; private set; }
|
||||
public PlotModel RightModel { get; private set; }
|
||||
public PlotModel AllModel { get; private set; }
|
||||
|
||||
public CameraRecViewModel()
|
||||
{
|
||||
var data = CameraOrientationTest.Test1();
|
||||
|
||||
LeftModel = BuildModel(data.Item1, "左");
|
||||
RightModel = BuildModel(data.Item2, "右(左移90度后)");
|
||||
AllModel = BuildModel(data.Item3, "乘积");
|
||||
}
|
||||
|
||||
public PlotModel BuildModel(int[] data, string name)
|
||||
{
|
||||
// 创建折线图
|
||||
var series = new LineSeries();
|
||||
for (int i = 0; i < data.Length; i++)
|
||||
{
|
||||
series.Points.Add(new DataPoint(i, data[i]));
|
||||
}
|
||||
|
||||
// 创建绘图模型并添加折线图
|
||||
var plotModel = new PlotModel();
|
||||
plotModel.Series.Add(series);
|
||||
|
||||
// 设置图表标题
|
||||
plotModel.Title = name;
|
||||
return plotModel;
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
<Window x:Class="BetterGenshinImpact.Test.View.CameraRecWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:BetterGenshinImpact.Test"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:oxy="http://oxyplot.org/wpf"
|
||||
xmlns:view="clr-namespace:BetterGenshinImpact.Test.View"
|
||||
Title="MainWindow"
|
||||
Width="400"
|
||||
Height="800"
|
||||
mc:Ignorable="d">
|
||||
<Window.DataContext>
|
||||
<view:CameraRecViewModel />
|
||||
</Window.DataContext>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
<oxy:PlotView Grid.Row="0" Model="{Binding LeftModel}" />
|
||||
<oxy:PlotView Grid.Row="1" Model="{Binding RightModel}" />
|
||||
<oxy:PlotView Grid.Row="2" Model="{Binding AllModel}" />
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -1,12 +0,0 @@
|
||||
namespace BetterGenshinImpact.Test.View;
|
||||
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml
|
||||
/// </summary>
|
||||
public partial class CameraRecWindow : System.Windows.Window
|
||||
{
|
||||
public CameraRecWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<Platforms>x64</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
"emitSingleFile": true,
|
||||
"public": true,
|
||||
"comInterop": {
|
||||
"useIntPtrForComOutPointers": true
|
||||
"useIntPtrForComOutPointers": true,
|
||||
"preserveSigMethods": [
|
||||
"ID3D11Device.GetDeviceRemovedReason"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -21,18 +21,16 @@ GetWindowThreadProcessId
|
||||
mouse_event
|
||||
PostMessage
|
||||
ReleaseDC
|
||||
EnumWindows
|
||||
GetWindowText
|
||||
IsWindowVisible
|
||||
GetWindowTextLength
|
||||
|
||||
// COM & WinRT
|
||||
D3D11CreateDevice
|
||||
ID3D11Device3
|
||||
IDirect3DDxgiInterfaceAccess
|
||||
IGraphicsCaptureItemInterop
|
||||
|
||||
// Constants
|
||||
D3D11_SDK_VERSION
|
||||
DXGI_ERROR_UNSUPPORTED
|
||||
WM_LBUTTONDOWN
|
||||
WM_LBUTTONUP
|
||||
WM_LBUTTONUP
|
||||
|
||||
DXGI_ERROR
|
||||
@@ -7,130 +7,36 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BetterGenshinImpact", "Bett
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vision.WindowCapture", "Vision.WindowCapture\Vision.WindowCapture.csproj", "{C9080C1D-1B26-46CB-A494-A5E7FE3FCEBA}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vision.Recognition", "Vision.Recognition\Vision.Recognition.csproj", "{97A12A37-613B-4BE3-B01B-BF3411503711}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BetterGenshinImpact.Win32", "BetterGenshinImpact.Win32\BetterGenshinImpact.Win32.csproj", "{75F4541B-9624-4AFB-BAEA-3EAFD3300EE1}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fischless.GameCapture", "Fischless.GameCapture\Fischless.GameCapture.csproj", "{6B0A3D96-D88D-48DD-8112-4CD5BA5D27CE}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vision.WindowCapture.Test", "Vision.WindowCapture.Test\Vision.WindowCapture.Test.csproj", "{D35CB953-C666-4E57-9A9A-3AAE5BF78402}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fischless.HotkeyCapture", "Fischless.HotkeyCapture\Fischless.HotkeyCapture.csproj", "{08152E44-2564-46C5-B5B2-54DD43C01A79}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fischless.KeyboardCapture", "Fischless.KeyboardCapture\Fischless.KeyboardCapture.csproj", "{10A48327-7E58-4B51-B1FC-55506C703C8F}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Deploy", "Deploy", "{458E1106-43A4-47E6-B11B-D243035D4C76}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MicaSetup", "Build\MicaSetup\MicaSetup.csproj", "{AB85DA23-EB8F-4FBF-A7FA-35CE05B23C15}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MicaSetup.Uninst", "Build\MicaSetup\MicaSetup.Uninst.csproj", "{673344BC-B860-44AE-AD88-D33465BDE25B}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BetterGenshinImpact.Test", "BetterGenshinImpact.Test\BetterGenshinImpact.Test.csproj", "{27AF227E-BE44-450F-8E95-C1AD4FDE14BE}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fischless.WindowsInput", "Fischless.WindowsInput\Fischless.WindowsInput.csproj", "{9D00BC7A-9280-4AC9-8951-4502EDB71B76}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Debug|x64 = Debug|x64
|
||||
Release|Any CPU = Release|Any CPU
|
||||
Release|x64 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{75EC89E2-413D-4725-BCEA-AFAC57708F07}.Debug|Any CPU.ActiveCfg = Debug|x64
|
||||
{75EC89E2-413D-4725-BCEA-AFAC57708F07}.Debug|Any CPU.Build.0 = Debug|x64
|
||||
{75EC89E2-413D-4725-BCEA-AFAC57708F07}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{75EC89E2-413D-4725-BCEA-AFAC57708F07}.Debug|x64.Build.0 = Debug|x64
|
||||
{75EC89E2-413D-4725-BCEA-AFAC57708F07}.Release|Any CPU.ActiveCfg = Release|x64
|
||||
{75EC89E2-413D-4725-BCEA-AFAC57708F07}.Release|Any CPU.Build.0 = Release|x64
|
||||
{75EC89E2-413D-4725-BCEA-AFAC57708F07}.Release|x64.ActiveCfg = Release|x64
|
||||
{75EC89E2-413D-4725-BCEA-AFAC57708F07}.Release|x64.Build.0 = Release|x64
|
||||
{C9080C1D-1B26-46CB-A494-A5E7FE3FCEBA}.Debug|Any CPU.ActiveCfg = Debug|x64
|
||||
{C9080C1D-1B26-46CB-A494-A5E7FE3FCEBA}.Debug|Any CPU.Build.0 = Debug|x64
|
||||
{C9080C1D-1B26-46CB-A494-A5E7FE3FCEBA}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{C9080C1D-1B26-46CB-A494-A5E7FE3FCEBA}.Debug|x64.Build.0 = Debug|x64
|
||||
{C9080C1D-1B26-46CB-A494-A5E7FE3FCEBA}.Release|Any CPU.ActiveCfg = Release|x64
|
||||
{C9080C1D-1B26-46CB-A494-A5E7FE3FCEBA}.Release|Any CPU.Build.0 = Release|x64
|
||||
{C9080C1D-1B26-46CB-A494-A5E7FE3FCEBA}.Release|x64.ActiveCfg = Release|x64
|
||||
{C9080C1D-1B26-46CB-A494-A5E7FE3FCEBA}.Release|x64.Build.0 = Release|x64
|
||||
{75F4541B-9624-4AFB-BAEA-3EAFD3300EE1}.Debug|Any CPU.ActiveCfg = Debug|x64
|
||||
{75F4541B-9624-4AFB-BAEA-3EAFD3300EE1}.Debug|Any CPU.Build.0 = Debug|x64
|
||||
{75F4541B-9624-4AFB-BAEA-3EAFD3300EE1}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{75F4541B-9624-4AFB-BAEA-3EAFD3300EE1}.Debug|x64.Build.0 = Debug|x64
|
||||
{75F4541B-9624-4AFB-BAEA-3EAFD3300EE1}.Release|Any CPU.ActiveCfg = Release|x64
|
||||
{75F4541B-9624-4AFB-BAEA-3EAFD3300EE1}.Release|Any CPU.Build.0 = Release|x64
|
||||
{75F4541B-9624-4AFB-BAEA-3EAFD3300EE1}.Release|x64.ActiveCfg = Release|x64
|
||||
{75F4541B-9624-4AFB-BAEA-3EAFD3300EE1}.Release|x64.Build.0 = Release|x64
|
||||
{6B0A3D96-D88D-48DD-8112-4CD5BA5D27CE}.Debug|Any CPU.ActiveCfg = Debug|x64
|
||||
{6B0A3D96-D88D-48DD-8112-4CD5BA5D27CE}.Debug|Any CPU.Build.0 = Debug|x64
|
||||
{6B0A3D96-D88D-48DD-8112-4CD5BA5D27CE}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{6B0A3D96-D88D-48DD-8112-4CD5BA5D27CE}.Debug|x64.Build.0 = Debug|x64
|
||||
{6B0A3D96-D88D-48DD-8112-4CD5BA5D27CE}.Release|Any CPU.ActiveCfg = Release|x64
|
||||
{6B0A3D96-D88D-48DD-8112-4CD5BA5D27CE}.Release|Any CPU.Build.0 = Release|x64
|
||||
{6B0A3D96-D88D-48DD-8112-4CD5BA5D27CE}.Release|x64.ActiveCfg = Release|x64
|
||||
{6B0A3D96-D88D-48DD-8112-4CD5BA5D27CE}.Release|x64.Build.0 = Release|x64
|
||||
{D35CB953-C666-4E57-9A9A-3AAE5BF78402}.Debug|Any CPU.ActiveCfg = Debug|x64
|
||||
{D35CB953-C666-4E57-9A9A-3AAE5BF78402}.Debug|Any CPU.Build.0 = Debug|x64
|
||||
{D35CB953-C666-4E57-9A9A-3AAE5BF78402}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{D35CB953-C666-4E57-9A9A-3AAE5BF78402}.Debug|x64.Build.0 = Debug|x64
|
||||
{D35CB953-C666-4E57-9A9A-3AAE5BF78402}.Release|Any CPU.ActiveCfg = Release|x64
|
||||
{D35CB953-C666-4E57-9A9A-3AAE5BF78402}.Release|Any CPU.Build.0 = Release|x64
|
||||
{D35CB953-C666-4E57-9A9A-3AAE5BF78402}.Release|x64.ActiveCfg = Release|x64
|
||||
{D35CB953-C666-4E57-9A9A-3AAE5BF78402}.Release|x64.Build.0 = Release|x64
|
||||
{08152E44-2564-46C5-B5B2-54DD43C01A79}.Debug|Any CPU.ActiveCfg = Debug|x64
|
||||
{08152E44-2564-46C5-B5B2-54DD43C01A79}.Debug|Any CPU.Build.0 = Debug|x64
|
||||
{08152E44-2564-46C5-B5B2-54DD43C01A79}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{08152E44-2564-46C5-B5B2-54DD43C01A79}.Debug|x64.Build.0 = Debug|x64
|
||||
{08152E44-2564-46C5-B5B2-54DD43C01A79}.Release|Any CPU.ActiveCfg = Release|x64
|
||||
{08152E44-2564-46C5-B5B2-54DD43C01A79}.Release|Any CPU.Build.0 = Release|x64
|
||||
{08152E44-2564-46C5-B5B2-54DD43C01A79}.Release|x64.ActiveCfg = Release|x64
|
||||
{08152E44-2564-46C5-B5B2-54DD43C01A79}.Release|x64.Build.0 = Release|x64
|
||||
{10A48327-7E58-4B51-B1FC-55506C703C8F}.Debug|Any CPU.ActiveCfg = Debug|x64
|
||||
{10A48327-7E58-4B51-B1FC-55506C703C8F}.Debug|Any CPU.Build.0 = Debug|x64
|
||||
{10A48327-7E58-4B51-B1FC-55506C703C8F}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{10A48327-7E58-4B51-B1FC-55506C703C8F}.Debug|x64.Build.0 = Debug|x64
|
||||
{10A48327-7E58-4B51-B1FC-55506C703C8F}.Release|Any CPU.ActiveCfg = Release|x64
|
||||
{10A48327-7E58-4B51-B1FC-55506C703C8F}.Release|Any CPU.Build.0 = Release|x64
|
||||
{10A48327-7E58-4B51-B1FC-55506C703C8F}.Release|x64.ActiveCfg = Release|x64
|
||||
{10A48327-7E58-4B51-B1FC-55506C703C8F}.Release|x64.Build.0 = Release|x64
|
||||
{AB85DA23-EB8F-4FBF-A7FA-35CE05B23C15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{AB85DA23-EB8F-4FBF-A7FA-35CE05B23C15}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{AB85DA23-EB8F-4FBF-A7FA-35CE05B23C15}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{AB85DA23-EB8F-4FBF-A7FA-35CE05B23C15}.Debug|x64.Build.0 = Debug|x64
|
||||
{AB85DA23-EB8F-4FBF-A7FA-35CE05B23C15}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{AB85DA23-EB8F-4FBF-A7FA-35CE05B23C15}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{AB85DA23-EB8F-4FBF-A7FA-35CE05B23C15}.Release|x64.ActiveCfg = Release|x64
|
||||
{AB85DA23-EB8F-4FBF-A7FA-35CE05B23C15}.Release|x64.Build.0 = Release|x64
|
||||
{673344BC-B860-44AE-AD88-D33465BDE25B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{673344BC-B860-44AE-AD88-D33465BDE25B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{673344BC-B860-44AE-AD88-D33465BDE25B}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{673344BC-B860-44AE-AD88-D33465BDE25B}.Debug|x64.Build.0 = Debug|x64
|
||||
{673344BC-B860-44AE-AD88-D33465BDE25B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{673344BC-B860-44AE-AD88-D33465BDE25B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{673344BC-B860-44AE-AD88-D33465BDE25B}.Release|x64.ActiveCfg = Release|x64
|
||||
{673344BC-B860-44AE-AD88-D33465BDE25B}.Release|x64.Build.0 = Release|x64
|
||||
{27AF227E-BE44-450F-8E95-C1AD4FDE14BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{27AF227E-BE44-450F-8E95-C1AD4FDE14BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{27AF227E-BE44-450F-8E95-C1AD4FDE14BE}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{27AF227E-BE44-450F-8E95-C1AD4FDE14BE}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{27AF227E-BE44-450F-8E95-C1AD4FDE14BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{27AF227E-BE44-450F-8E95-C1AD4FDE14BE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{27AF227E-BE44-450F-8E95-C1AD4FDE14BE}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{27AF227E-BE44-450F-8E95-C1AD4FDE14BE}.Release|x64.Build.0 = Release|Any CPU
|
||||
{9D00BC7A-9280-4AC9-8951-4502EDB71B76}.Debug|Any CPU.ActiveCfg = Debug|x64
|
||||
{9D00BC7A-9280-4AC9-8951-4502EDB71B76}.Debug|Any CPU.Build.0 = Debug|x64
|
||||
{9D00BC7A-9280-4AC9-8951-4502EDB71B76}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{9D00BC7A-9280-4AC9-8951-4502EDB71B76}.Debug|x64.Build.0 = Debug|x64
|
||||
{9D00BC7A-9280-4AC9-8951-4502EDB71B76}.Release|Any CPU.ActiveCfg = Release|x64
|
||||
{9D00BC7A-9280-4AC9-8951-4502EDB71B76}.Release|Any CPU.Build.0 = Release|x64
|
||||
{9D00BC7A-9280-4AC9-8951-4502EDB71B76}.Release|x64.ActiveCfg = Release|x64
|
||||
{9D00BC7A-9280-4AC9-8951-4502EDB71B76}.Release|x64.Build.0 = Release|x64
|
||||
{75EC89E2-413D-4725-BCEA-AFAC57708F07}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{75EC89E2-413D-4725-BCEA-AFAC57708F07}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{75EC89E2-413D-4725-BCEA-AFAC57708F07}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{75EC89E2-413D-4725-BCEA-AFAC57708F07}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C9080C1D-1B26-46CB-A494-A5E7FE3FCEBA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C9080C1D-1B26-46CB-A494-A5E7FE3FCEBA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C9080C1D-1B26-46CB-A494-A5E7FE3FCEBA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C9080C1D-1B26-46CB-A494-A5E7FE3FCEBA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{97A12A37-613B-4BE3-B01B-BF3411503711}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{97A12A37-613B-4BE3-B01B-BF3411503711}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{97A12A37-613B-4BE3-B01B-BF3411503711}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{97A12A37-613B-4BE3-B01B-BF3411503711}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{75F4541B-9624-4AFB-BAEA-3EAFD3300EE1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{75F4541B-9624-4AFB-BAEA-3EAFD3300EE1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{75F4541B-9624-4AFB-BAEA-3EAFD3300EE1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{75F4541B-9624-4AFB-BAEA-3EAFD3300EE1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{AB85DA23-EB8F-4FBF-A7FA-35CE05B23C15} = {458E1106-43A4-47E6-B11B-D243035D4C76}
|
||||
{673344BC-B860-44AE-AD88-D33465BDE25B} = {458E1106-43A4-47E6-B11B-D243035D4C76}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {352D8B78-9DE3-4E58-985F-FADD22594DB4}
|
||||
EndGlobalSection
|
||||
|
||||
@@ -1,19 +1,9 @@
|
||||
<Application x:Class="BetterGenshinImpact.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:bgivc="clr-namespace:BetterGenshinImpact.View.Converters"
|
||||
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml">
|
||||
xmlns:local="clr-namespace:BetterGenshinImpact"
|
||||
StartupUri="/View/MainWindow.xaml">
|
||||
<Application.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ui:ThemesDictionary Theme="Dark" />
|
||||
<ui:ControlsDictionary />
|
||||
<ResourceDictionary Source="/View/Controls/WpfUi/FaFontIconStyle.xaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<FontFamily x:Key="TextThemeFontFamily">/Assets/Fonts/MiSans-Regular.ttf#MiSans</FontFamily>
|
||||
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
|
||||
<bgivc:BooleanToVisibilityRevertConverter x:Key="BooleanToVisibilityRevertConverter" />
|
||||
<bgivc:InverseBooleanConverter x:Key="InverseBooleanConverter" />
|
||||
</ResourceDictionary>
|
||||
|
||||
</Application.Resources>
|
||||
</Application>
|
||||
@@ -1,241 +1,63 @@
|
||||
using BetterGenshinImpact.GameTask;
|
||||
using BetterGenshinImpact.Helpers;
|
||||
using BetterGenshinImpact.Helpers.Extensions;
|
||||
using BetterGenshinImpact.Service;
|
||||
using BetterGenshinImpact.Service.Interface;
|
||||
using BetterGenshinImpact.Service.Notification;
|
||||
using BetterGenshinImpact.Service.Notifier;
|
||||
using BetterGenshinImpact.View;
|
||||
using BetterGenshinImpact.View.Pages;
|
||||
using BetterGenshinImpact.ViewModel;
|
||||
using BetterGenshinImpact.ViewModel.Pages;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Serilog;
|
||||
using Serilog.Events;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using Wpf.Ui;
|
||||
using Vision.Recognition;
|
||||
using WinRT;
|
||||
|
||||
namespace BetterGenshinImpact;
|
||||
|
||||
public partial class App : Application
|
||||
namespace BetterGenshinImpact
|
||||
{
|
||||
// The.NET Generic Host provides dependency injection, configuration, logging, and other services.
|
||||
// https://docs.microsoft.com/dotnet/core/extensions/generic-host
|
||||
// https://docs.microsoft.com/dotnet/core/extensions/dependency-injection
|
||||
// https://docs.microsoft.com/dotnet/core/extensions/configuration
|
||||
// https://docs.microsoft.com/dotnet/core/extensions/logging
|
||||
private static readonly IHost _host = Host.CreateDefaultBuilder()
|
||||
.UseElevated()
|
||||
.UseSingleInstance("BetterGI")
|
||||
.ConfigureServices(
|
||||
(context, services) =>
|
||||
{
|
||||
// 提前初始化配置
|
||||
var configService = new ConfigService();
|
||||
services.AddSingleton<IConfigService>(sp => configService);
|
||||
var all = configService.Get();
|
||||
|
||||
var logFolder = Path.Combine(AppContext.BaseDirectory, "log");
|
||||
Directory.CreateDirectory(logFolder);
|
||||
var logFile = Path.Combine(logFolder, "better-genshin-impact.log");
|
||||
|
||||
var maskWindow = new MaskWindow();
|
||||
services.AddSingleton(maskWindow);
|
||||
|
||||
var loggerConfiguration = new LoggerConfiguration()
|
||||
.WriteTo.File(path: logFile, outputTemplate: "[{Timestamp:HH:mm:ss.fff}] [{Level:u3}] {SourceContext}{NewLine}{Message}{NewLine}{Exception}{NewLine}", rollingInterval: RollingInterval.Day)
|
||||
.MinimumLevel.Debug()
|
||||
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
|
||||
.MinimumLevel.Override("Microsoft.Hosting.Lifetime", LogEventLevel.Warning);
|
||||
if (all.MaskWindowConfig.MaskEnabled)
|
||||
{
|
||||
loggerConfiguration.WriteTo.RichTextBox(maskWindow.LogBox, LogEventLevel.Information, outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}");
|
||||
}
|
||||
|
||||
Log.Logger = loggerConfiguration.CreateLogger();
|
||||
services.AddLogging(c => c.AddSerilog());
|
||||
|
||||
// App Host
|
||||
services.AddHostedService<ApplicationHostService>();
|
||||
|
||||
// Page resolver service
|
||||
services.AddSingleton<IPageService, PageService>();
|
||||
|
||||
// Service containing navigation, same as INavigationWindow... but without window
|
||||
services.AddSingleton<INavigationService, NavigationService>();
|
||||
|
||||
// Main window with navigation
|
||||
services.AddView<INavigationWindow, MainWindow, MainWindowViewModel>();
|
||||
services.AddSingleton<NotifyIconViewModel>();
|
||||
|
||||
// Views
|
||||
services.AddView<HomePage, HomePageViewModel>();
|
||||
services.AddView<ScriptControlPage, ScriptControlViewModel>();
|
||||
services.AddView<TriggerSettingsPage, TriggerSettingsPageViewModel>();
|
||||
services.AddView<MacroSettingsPage, MacroSettingsPageViewModel>();
|
||||
services.AddView<CommonSettingsPage, CommonSettingsPageViewModel>();
|
||||
services.AddView<TaskSettingsPage, TaskSettingsPageViewModel>();
|
||||
services.AddView<HotKeyPage, HotKeyPageViewModel>();
|
||||
services.AddView<NotificationSettingsPage, NotificationSettingsPageViewModel>();
|
||||
|
||||
// My Services
|
||||
services.AddSingleton<TaskTriggerDispatcher>();
|
||||
services.AddSingleton<NotificationService>();
|
||||
services.AddHostedService(sp => sp.GetRequiredService<NotificationService>());
|
||||
services.AddSingleton<NotifierManager>();
|
||||
|
||||
// Configuration
|
||||
//services.Configure<AppConfig>(context.Configuration.GetSection(nameof(AppConfig)));
|
||||
}
|
||||
)
|
||||
.Build();
|
||||
|
||||
public static ILogger<T> GetLogger<T>()
|
||||
{
|
||||
return _host.Services.GetService<ILogger<T>>()!;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets registered service.
|
||||
/// Interaction logic for App.xaml
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of the service to get.</typeparam>
|
||||
/// <returns>Instance of the service or <see langword="null"/>.</returns>
|
||||
public static T? GetService<T>() where T : class
|
||||
public partial class App : Application
|
||||
{
|
||||
return _host.Services.GetService(typeof(T)) as T;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets registered service.
|
||||
/// </summary>
|
||||
/// <returns>Instance of the service or <see langword="null"/>.</returns>
|
||||
/// <returns></returns>
|
||||
public static object? GetService(Type type)
|
||||
{
|
||||
return _host.Services.GetService(type);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the application is loading.
|
||||
/// </summary>
|
||||
protected override async void OnStartup(StartupEventArgs e)
|
||||
{
|
||||
base.OnStartup(e);
|
||||
|
||||
try
|
||||
public App()
|
||||
{
|
||||
RegisterEvents();
|
||||
await _host.StartAsync();
|
||||
await UrlProtocolHelper.RegisterAsync();
|
||||
Services = ConfigureServices();
|
||||
|
||||
this.InitializeComponent();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// DEBUG only, no overhead
|
||||
Debug.WriteLine(ex);
|
||||
|
||||
if (Debugger.IsAttached)
|
||||
{
|
||||
Debugger.Break();
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the current <see cref="App"/> instance in use
|
||||
/// </summary>
|
||||
public new static App Current => (App)Application.Current;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="IServiceProvider"/> instance to resolve application services.
|
||||
/// </summary>
|
||||
public IServiceProvider Services { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Configures the services for the application.W
|
||||
/// </summary>
|
||||
private static IServiceProvider ConfigureServices()
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
|
||||
|
||||
var logFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"log");
|
||||
Directory.CreateDirectory(logFolder);
|
||||
var logFile = Path.Combine(logFolder, $"better-genshin-impact.log");
|
||||
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.WriteTo.File(path: logFile, outputTemplate: "[{Timestamp:HH:mm:ss.fff}] [{Level:u3}] {SourceContext}{NewLine}{Message}{NewLine}{Exception}{NewLine}", rollingInterval: RollingInterval.Day)
|
||||
.WriteTo.RichTextBox(MaskWindow.Instance().LogBox, outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}")
|
||||
.CreateLogger();
|
||||
services.AddLogging(c => c.AddSerilog());
|
||||
|
||||
|
||||
//services.AddSingleton<ISettingsService, SettingsService>();
|
||||
|
||||
return services.BuildServiceProvider();
|
||||
}
|
||||
|
||||
public static ILogger<T> GetLogger<T>()
|
||||
{
|
||||
return Current.Services.GetService<ILogger<T>>()!;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the application is closing.
|
||||
/// </summary>
|
||||
protected override async void OnExit(ExitEventArgs e)
|
||||
{
|
||||
base.OnExit(e);
|
||||
|
||||
await _host.StopAsync();
|
||||
_host.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 注册事件
|
||||
/// </summary>
|
||||
private void RegisterEvents()
|
||||
{
|
||||
//Task线程内未捕获异常处理事件
|
||||
TaskScheduler.UnobservedTaskException += TaskSchedulerUnobservedTaskException;
|
||||
|
||||
//UI线程未捕获异常处理事件(UI主线程)
|
||||
this.DispatcherUnhandledException += AppDispatcherUnhandledException;
|
||||
|
||||
//非UI线程未捕获异常处理事件(例如自己创建的一个子线程)
|
||||
AppDomain.CurrentDomain.UnhandledException += CurrentDomainUnhandledException;
|
||||
}
|
||||
|
||||
private static void TaskSchedulerUnobservedTaskException(object? sender, UnobservedTaskExceptionEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
HandleException(e.Exception);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
HandleException(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
e.SetObserved();
|
||||
}
|
||||
}
|
||||
|
||||
//非UI线程未捕获异常处理事件(例如自己创建的一个子线程)
|
||||
private static void CurrentDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (e.ExceptionObject is Exception exception)
|
||||
{
|
||||
HandleException(exception);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
HandleException(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
//ignore
|
||||
}
|
||||
}
|
||||
|
||||
//UI线程未捕获异常处理事件(UI主线程)
|
||||
private static void AppDispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
HandleException(e.Exception);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
HandleException(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
//处理完后,我们需要将Handler=true表示已此异常已处理过
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private static void HandleException(Exception e)
|
||||
{
|
||||
if (e.InnerException != null)
|
||||
{
|
||||
e = e.InnerException;
|
||||
}
|
||||
|
||||
MessageBox.Show("程序异常:" + e.Source + "\r\n--" + Environment.NewLine + e.StackTrace + "\r\n---" + Environment.NewLine + e.Message);
|
||||
|
||||
// log
|
||||
GetLogger<App>().LogDebug(e, "UnHandle Exception");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,10 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
|
||||
[assembly: DisableDpiAwareness]
|
||||
[assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)]
|
||||
[assembly: ThemeInfo(
|
||||
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
|
||||
//(used if a resource is not found in the page,
|
||||
// or application resource dictionaries)
|
||||
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
|
||||
//(used if a resource is not found in the page,
|
||||
// app, or any theme specific resource dictionaries)
|
||||
)]
|
||||
@@ -1,72 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<SyntaxDefinition name="Json" extensions=".json" xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008">
|
||||
<Color name="Bool" foreground="#569CD6" exampleText="true | false" />
|
||||
<Color name="Number" foreground="#B5CEA8" exampleText="3.14" />
|
||||
<Color name="String" foreground="#CE9178" exampleText="" />
|
||||
<Color name="Null" foreground="#569CD6" exampleText="" />
|
||||
<Color name="FieldName" foreground="#9CDCF0" />
|
||||
<Color name="Punctuation1" foreground="#DA66BE" />
|
||||
<Color name="Punctuation2" foreground="#FFD710" />
|
||||
<Color name="Punctuation3" foreground="#FFFFFF" />
|
||||
|
||||
<RuleSet name="String">
|
||||
<Span begin="\\" end="."/>
|
||||
</RuleSet>
|
||||
|
||||
<RuleSet name="Object">
|
||||
<Span color="FieldName" ruleSet="String">
|
||||
<Begin>"</Begin>
|
||||
<End>"</End>
|
||||
</Span>
|
||||
<Span color="FieldName" ruleSet="String">
|
||||
<Begin>'</Begin>
|
||||
<End>'</End>
|
||||
</Span>
|
||||
<Span color="Punctuation3" ruleSet="Expression">
|
||||
<Begin>:</Begin>
|
||||
</Span>
|
||||
<Span color="Punctuation3">
|
||||
<Begin>,</Begin>
|
||||
</Span>
|
||||
</RuleSet>
|
||||
|
||||
<RuleSet name="Array">
|
||||
<Import ruleSet="Expression"/>
|
||||
<Span color="Punctuation3">
|
||||
<Begin>,</Begin>
|
||||
</Span>
|
||||
</RuleSet>
|
||||
|
||||
<RuleSet name="Expression">
|
||||
<Keywords color="Bool" >
|
||||
<Word>true</Word>
|
||||
<Word>false</Word>
|
||||
</Keywords>
|
||||
<Keywords color="Null" >
|
||||
<Word>null</Word>
|
||||
</Keywords>
|
||||
<Span color="String" ruleSet="String">
|
||||
<Begin>"</Begin>
|
||||
<End>"</End>
|
||||
</Span>
|
||||
<Span color="String" ruleSet="String">
|
||||
<Begin>'</Begin>
|
||||
<End>'</End>
|
||||
</Span>
|
||||
<Span color="Punctuation1" ruleSet="Object" multiline="true">
|
||||
<Begin>\{</Begin>
|
||||
<End>\}</End>
|
||||
</Span>
|
||||
<Span color="Punctuation2" ruleSet="Array" multiline="true">
|
||||
<Begin>\[</Begin>
|
||||
<End>\]</End>
|
||||
</Span>
|
||||
<Rule color="Number">
|
||||
\b0[xX][0-9a-fA-F]+|(\b\d+(\.[0-9]+)?|\.[0-9]+)([eE][+-]?[0-9]+)?
|
||||
</Rule>
|
||||
</RuleSet>
|
||||
|
||||
<RuleSet>
|
||||
<Import ruleSet="Expression"/>
|
||||
</RuleSet>
|
||||
</SyntaxDefinition>
|
||||
|
Before Width: | Height: | Size: 46 KiB |
|
Before Width: | Height: | Size: 1.4 MiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 117 KiB |
|
Before Width: | Height: | Size: 166 KiB |
|
Before Width: | Height: | Size: 76 KiB |
|
Before Width: | Height: | Size: 229 KiB |
@@ -1,599 +1,53 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net7.0-windows10.0.22621.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWPF>true</UseWPF>
|
||||
<UseWindowsForms>True</UseWindowsForms>
|
||||
<LangVersion>12.0</LangVersion>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<ApplicationIcon>Assets\logo.ico</ApplicationIcon>
|
||||
<AssemblyName>BetterGI</AssemblyName>
|
||||
<Platforms>x64</Platforms>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net7.0-windows10.0.22000.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWPF>true</UseWPF>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="Assets\*.jpg" />
|
||||
<None Remove="Assets\*.png" />
|
||||
<None Remove="Assets\*.ico" />
|
||||
<None Remove="Assets\Fonts\*.ttf" />
|
||||
<None Remove="Assets\Highlighting\*.xshd" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1" />
|
||||
<PackageReference Include="Config.Net" Version="5.1.5" />
|
||||
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.46-beta">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.39" />
|
||||
<PackageReference Include="MouseKeyHook" Version="5.7.1" />
|
||||
<PackageReference Include="Serilog.Extensions.Logging" Version="7.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.RichTextBox.Wpf" Version="1.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Resource Include="Assets\*.jpg" />
|
||||
<Resource Include="Assets\*.png" />
|
||||
<Resource Include="Assets\*.ico" />
|
||||
<Resource Include="Assets\Fonts\*.ttf" />
|
||||
<Resource Include="Assets\Highlighting\*.xshd" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Vision.Recognition\Vision.Recognition.csproj" />
|
||||
<ProjectReference Include="..\Vision.WindowCapture\Vision.WindowCapture.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AvalonEdit" Version="6.3.0.90" />
|
||||
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.ML.OnnxRuntime.Gpu" Version="1.17.1" />
|
||||
<PackageReference Include="Microsoft.ML.OnnxRuntime.Managed" Version="1.17.1" />
|
||||
<PackageReference Include="Ookii.Dialogs.Wpf" Version="5.0.1" />
|
||||
<PackageReference Include="OpenCvSharp4.Extensions" Version="4.8.0.20230708" />
|
||||
<PackageReference Include="OpenCvSharp4.Windows" Version="4.8.0.20230708" />
|
||||
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.77" />
|
||||
<PackageReference Include="MouseKeyHook" Version="5.7.1" />
|
||||
<PackageReference Include="Sdcb.PaddleInference" Version="2.5.0.1" />
|
||||
<PackageReference Include="Sdcb.PaddleInference.runtime.win64.cuda118_cudnn86_tr85_sm86_89" Version="2.5.1" />
|
||||
<PackageReference Include="Sdcb.PaddleInference.runtime.win64.openblas" Version="2.5.1" />
|
||||
<PackageReference Include="Sdcb.PaddleOCR" Version="2.7.0" />
|
||||
<PackageReference Include="Sdcb.PaddleOCR.Models.Online" Version="2.7.0.1" />
|
||||
<PackageReference Include="Serilog.Extensions.Logging" Version="7.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.RichTextBox.Wpf" Version="1.1.0" />
|
||||
<PackageReference Include="Vanara.PInvoke.NtDll" Version="3.4.17" />
|
||||
<PackageReference Include="Vanara.PInvoke.SHCore" Version="3.4.17" />
|
||||
<PackageReference Include="Vanara.PInvoke.User32" Version="3.4.17" />
|
||||
<PackageReference Include="WPF-UI" Version="3.0.0-preview.7" />
|
||||
<PackageReference Include="WPF-UI.Tray" Version="3.0.0-preview.7" />
|
||||
<PackageReference Include="YoloV8.Gpu" Version="2.0.1" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="GameTask\AutoGeniusInvokation\" />
|
||||
<Folder Include="GameTask\UseActiveCode\" />
|
||||
<Folder Include="Service\Interface\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition=" '$(Configuration)' == 'Debug'">
|
||||
<PackageReference Include="Microsoft.ClearScript.V8" Version="7.4.4" />
|
||||
<PackageReference Include="Microsoft.ClearScript.V8.Native.win-x64" Version="7.4.4" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Update="GameTask\AutoFishing\Assets\1920x1080\Space.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoPick\Assets\1920x1080\F.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoSkip\Assets\1920x1080\menu.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoSkip\Assets\1920x1080\option.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoSkip\Assets\1920x1080\stop_auto.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Fischless.GameCapture\Fischless.GameCapture.csproj" />
|
||||
<ProjectReference Include="..\Fischless.HotkeyCapture\Fischless.HotkeyCapture.csproj" />
|
||||
<ProjectReference Include="..\Fischless.WindowsInput\Fischless.WindowsInput.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="GameTask\TaskContext.cs">
|
||||
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
|
||||
</Compile>
|
||||
<Compile Update="View\MaskWindow.xaml.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Update="View\Pages\HotkeyPage.xaml.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Update="View\Pages\TriggerSettingsPage.xaml.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Update="View\PickerWindow.xaml.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Update="View\Windows\MapViewer.xaml.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="Assets\Map\cityMap2048Block.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Assets\Map\combined_image_2048_lim[quick].png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Assets\Map\combined_image_lim[quick].png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Assets\Map\mainMap100Block.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Assets\Map\mainMap1024Block.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Assets\Map\mainMapZoomOut1024.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Assets\Map\map_sd1024.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Assets\Model\Common\avatar_side_classify_sim.onnx">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Assets\Model\Domain\bgi_tree.onnx">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Assets\Model\Domain\bgi_tree.pt">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Assets\Model\Fish\bgi_fish.onnx">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Assets\Model\PaddleOCR\ch_PP-OCRv4_det\inference.pdiparams">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Assets\Model\PaddleOCR\ch_PP-OCRv4_det\inference.pdiparams.info">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Assets\Model\PaddleOCR\ch_PP-OCRv4_det\inference.pdmodel">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Assets\Model\PaddleOCR\ch_PP-OCRv4_rec\inference.pdiparams">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Assets\Model\PaddleOCR\ch_PP-OCRv4_rec\inference.pdiparams.info">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Assets\Model\PaddleOCR\ch_PP-OCRv4_rec\inference.pdmodel">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Assets\Model\PaddleOCR\ch_ppocr_mobile_v2.0_cls\._inference.pdmodel">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Assets\Model\PaddleOCR\ch_ppocr_mobile_v2.0_cls\inference.pdiparams">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Assets\Model\PaddleOCR\ch_ppocr_mobile_v2.0_cls\inference.pdiparams.info">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Assets\Model\PaddleOCR\ch_ppocr_mobile_v2.0_cls\inference.pdmodel">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Assets\Model\PaddleOCR\ppocr_keys_v1.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Assets\Model\PaddleOCR\test_ocr.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Assets\Model\Yap\all_list.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Assets\Model\Yap\index_2_word.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Assets\Model\Yap\model_training.onnx">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoFight\Assets\1920x1080\click_any_close_tip.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoFight\Assets\1920x1080\condensed_resin_count.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoFight\Assets\1920x1080\confirm.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoFight\Assets\1920x1080\exit.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoFight\Assets\1920x1080\fragile_resin_count.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoFight\Assets\1920x1080\use_condensed_resin.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoFight\Assets\1920x1080\wanderer_icon.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoFight\Assets\1920x1080\wanderer_icon_no_active.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoFight\Assets\combat_avatar.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoFishing\Assets\1920x1080\bait\flashing maintenance mek bait.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoFishing\Assets\1920x1080\bait\sour bait.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoFishing\Assets\1920x1080\bait\sugardew bait.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoFishing\Assets\1920x1080\lift_rod.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoFishing\Assets\1920x1080\switch_bait.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoFishing\Assets\1920x1080\bait\fake fly bait.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoFishing\Assets\1920x1080\bait\false worm bait.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoFishing\Assets\1920x1080\bait\fruit paste bait.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoFishing\Assets\1920x1080\bait\redrot bait.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoFishing\Assets\1920x1080\exit_fishing.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoFishing\Assets\1920x1080\space.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoFishing\Assets\1920x1080\wait_bite.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoGeniusInvokation\Assets\1920x1080\dice\action_anemo.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoGeniusInvokation\Assets\1920x1080\dice\action_cryo.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoGeniusInvokation\Assets\1920x1080\dice\action_dendro.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoGeniusInvokation\Assets\1920x1080\dice\action_electro.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoGeniusInvokation\Assets\1920x1080\dice\action_geo.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoGeniusInvokation\Assets\1920x1080\dice\action_hydro.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoGeniusInvokation\Assets\1920x1080\dice\action_omni.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoGeniusInvokation\Assets\1920x1080\dice\action_pyro.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoGeniusInvokation\Assets\1920x1080\dice\roll_anemo.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoGeniusInvokation\Assets\1920x1080\dice\roll_cryo.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoGeniusInvokation\Assets\1920x1080\dice\roll_dendro.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoGeniusInvokation\Assets\1920x1080\dice\roll_electro.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoGeniusInvokation\Assets\1920x1080\dice\roll_geo.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoGeniusInvokation\Assets\1920x1080\dice\roll_hydro.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoGeniusInvokation\Assets\1920x1080\dice\roll_omni.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoGeniusInvokation\Assets\1920x1080\dice\roll_pyro.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoGeniusInvokation\Assets\1920x1080\other\元素调和.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoGeniusInvokation\Assets\1920x1080\other\元素骰子不足.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoGeniusInvokation\Assets\1920x1080\other\冻结.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoGeniusInvokation\Assets\1920x1080\other\出战角色.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoGeniusInvokation\Assets\1920x1080\other\回合结束.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoGeniusInvokation\Assets\1920x1080\other\回合结算阶段.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoGeniusInvokation\Assets\1920x1080\other\对方行动中.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoGeniusInvokation\Assets\1920x1080\other\满能量.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoGeniusInvokation\Assets\1920x1080\other\确定.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoGeniusInvokation\Assets\1920x1080\other\空能量.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoGeniusInvokation\Assets\1920x1080\other\角色死亡.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoGeniusInvokation\Assets\1920x1080\other\角色状态_冻结.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoGeniusInvokation\Assets\1920x1080\other\角色状态_冻结2.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoGeniusInvokation\Assets\1920x1080\other\角色状态_水泡.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoGeniusInvokation\Assets\1920x1080\other\角色血量上方.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoGeniusInvokation\Assets\1920x1080\other\角色被打败.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoGeniusInvokation\Assets\1920x1080\other\退出挑战.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoGeniusInvokation\Assets\tcg_character_card.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoPick\Assets\1920x1080\F.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoPick\Assets\1920x1080\icon_settings.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoSkip\Assets\1920x1080\collect.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoSkip\Assets\1920x1080\comfirm_btn1.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoSkip\Assets\1920x1080\comfirm_btn2.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoSkip\Assets\1920x1080\hangout_selected.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoSkip\Assets\1920x1080\hangout_unselected.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoSkip\Assets\1920x1080\icon_exclamation.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoSkip\Assets\1920x1080\primogem.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoSkip\Assets\1920x1080\re.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoSkip\Assets\1920x1080\icon_daily_reward.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoSkip\Assets\1920x1080\icon_explore.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoSkip\Assets\hangout.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\Common\Element\Assets\1920x1080\blue_track_point_28x.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\Common\Element\Assets\1920x1080\btn_black_cancel.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\Common\Element\Assets\1920x1080\btn_online_no.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\Common\Element\Assets\1920x1080\btn_online_yes.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\Common\Element\Assets\1920x1080\paimon_menu.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoSkip\Assets\1920x1080\icon_option.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoSkip\Assets\1920x1080\page_close.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoSkip\Assets\1920x1080\stop_auto.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoSkip\Assets\1920x1080\submit_goods.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoSkip\Assets\1920x1080\submit_icon_exclamation.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoWood\Assets\1920x1080\character_guide.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoWood\Assets\1920x1080\confirm.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoWood\Assets\1920x1080\enter_game.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoWood\Assets\1920x1080\exit_welcome.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoWood\Assets\1920x1080\menu_bag.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoWood\Assets\1920x1080\TheBoonOfTheElderTree.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\Common\Element\Assets\1920x1080\btn_black_confirm.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\Common\Element\Assets\1920x1080\btn_white_cancel.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\Common\Element\Assets\1920x1080\btn_white_confirm.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\Common\Element\Assets\1920x1080\collect.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\Common\Element\Assets\1920x1080\comfirm_btn1.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\Common\Element\Assets\1920x1080\comfirm_btn2.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\Common\Element\Assets\1920x1080\icon_daily_reward.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\Common\Element\Assets\1920x1080\icon_exclamation.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\Common\Element\Assets\1920x1080\icon_explore.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\Common\Element\Assets\1920x1080\icon_option.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\Common\Element\Assets\1920x1080\paimon_menu.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\Common\Element\Assets\1920x1080\page_close.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\Common\Element\Assets\1920x1080\primogem.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\Common\Element\Assets\1920x1080\re.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\Common\Element\Assets\1920x1080\stop_auto.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\Common\Element\Assets\1920x1080\submit_icon_exclamation.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\Common\Element\Assets\1920x1080\ui_left_top_cook_icon.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\Common\Element\Assets\1920x1080\ui_lt_cook_icon.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\Common\Element\Assets\1920x1080\yellow_track_point_28x.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\GameLoading\Assets\1920x1080\welkin_moon_logo.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\QuickTeleport\Assets\1920x1080\Domain.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\QuickTeleport\Assets\1920x1080\Domain2.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\QuickTeleport\Assets\1920x1080\GoTeleport.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\QuickTeleport\Assets\1920x1080\Mansion.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\QuickTeleport\Assets\1920x1080\MapChoose.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\QuickTeleport\Assets\1920x1080\MapCloseButton.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\QuickTeleport\Assets\1920x1080\MapScaleButton.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\QuickTeleport\Assets\1920x1080\MapUndergroundSwitchButton.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\QuickTeleport\Assets\1920x1080\PortableWaypoint.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\QuickTeleport\Assets\1920x1080\ScaleWithMask.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\QuickTeleport\Assets\1920x1080\StatueOfTheSeven.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\QuickTeleport\Assets\1920x1080\SubSpaceWaypoint.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\QuickTeleport\Assets\1920x1080\TeleportWaypoint.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\QuickSereniteaPot\Assets\1920x1080\SereniteaPotIcon.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="User\AutoFight\1.四神挂机[推荐].txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="User\AutoFight\2.宵宫夜兰班行秋.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="User\AutoFight\2.宵宫队[请看文件内说明].txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="User\AutoFight\群友分享\*.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="User\AutoGeniusInvokation\1.莫娜砂糖琴.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="User\AutoGeniusInvokation\2.刻晴雷神甘雨.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="User\AutoGeniusInvokation\3.雷神阿贝多丘丘王.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="User\AutoGeniusInvokation\4.重云雷神申鹤.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="User\AutoGeniusInvokation\5.迪希雅白术皇女.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="User\AutoGeniusInvokation\6.皇女科莱莫娜.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="User\AutoGeniusInvokation\7.莫娜白术皇女.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="User\AutoGeniusInvokation\8.雷神柯莱刻晴[推荐].txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="User\AutoGeniusInvokation\a.[惊喜牌组]东东.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="User\AutoGeniusInvokation\a.[惊喜牌组]巴哈拉克.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="User\AutoGeniusInvokation\a.[惊喜牌组]马鲁夫.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="User\AutoGeniusInvokation\a.[惊喜牌组]黄衫.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="User\AutoSkip\default_pause_options.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="User\AutoSkip\select_options.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="User\AutoSkip\pause_options.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="User\avatar_macro.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="User\pick_black_lists.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="User\pick_white_lists.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="GameTask\Common\Element\Assets\MapPoint\" />
|
||||
<Folder Include="View\Controls\WpfUi\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
</Project>
|
||||
@@ -1,173 +0,0 @@
|
||||
using BetterGenshinImpact.GameTask;
|
||||
using BetterGenshinImpact.GameTask.AutoDomain;
|
||||
using BetterGenshinImpact.GameTask.AutoFight;
|
||||
using BetterGenshinImpact.GameTask.AutoFishing;
|
||||
using BetterGenshinImpact.GameTask.AutoGeniusInvokation;
|
||||
using BetterGenshinImpact.GameTask.AutoPick;
|
||||
using BetterGenshinImpact.GameTask.AutoSkip;
|
||||
using BetterGenshinImpact.GameTask.AutoWood;
|
||||
using BetterGenshinImpact.GameTask.QuickTeleport;
|
||||
using BetterGenshinImpact.Service.Notification;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Fischless.GameCapture;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Text.Json.Serialization;
|
||||
using BetterGenshinImpact.GameTask.AutoCook;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Config;
|
||||
|
||||
/// <summary>
|
||||
/// 更好的原神配置
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public partial class AllConfig : ObservableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// 窗口捕获的方式
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private string _captureMode = CaptureModes.BitBlt.ToString();
|
||||
|
||||
/// <summary>
|
||||
/// 详细的错误日志
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private bool _detailedErrorLogs;
|
||||
|
||||
/// <summary>
|
||||
/// 不展示新版本提示的最新版本
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private string _notShowNewVersionNoticeEndVersion = "";
|
||||
|
||||
/// <summary>
|
||||
/// 触发器触发频率(ms)
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private int _triggerInterval = 50;
|
||||
|
||||
/// <summary>
|
||||
/// WGC使用位图缓存
|
||||
/// 高帧率情况下,可能会导致卡顿
|
||||
/// 云原神可能会出现黑屏
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private bool _wgcUseBitmapCache = true;
|
||||
|
||||
/// <summary>
|
||||
/// 推理使用的设备
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private string _inferenceDevice = "CPU";
|
||||
|
||||
/// <summary>
|
||||
/// 遮罩窗口配置
|
||||
/// </summary>
|
||||
public MaskWindowConfig MaskWindowConfig { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// 通用配置
|
||||
/// </summary>
|
||||
public CommonConfig CommonConfig { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// 原神启动配置
|
||||
/// </summary>
|
||||
public GenshinStartConfig GenshinStartConfig { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// 自动拾取配置
|
||||
/// </summary>
|
||||
public AutoPickConfig AutoPickConfig { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// 自动剧情配置
|
||||
/// </summary>
|
||||
public AutoSkipConfig AutoSkipConfig { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// 自动钓鱼配置
|
||||
/// </summary>
|
||||
public AutoFishingConfig AutoFishingConfig { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// 快速传送配置
|
||||
/// </summary>
|
||||
public QuickTeleportConfig QuickTeleportConfig { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// 自动烹饪配置
|
||||
/// </summary>
|
||||
public AutoCookConfig AutoCookConfig { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// 自动打牌配置
|
||||
/// </summary>
|
||||
public AutoGeniusInvokationConfig AutoGeniusInvokationConfig { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// 自动伐木配置
|
||||
/// </summary>
|
||||
public AutoWoodConfig AutoWoodConfig { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// 自动战斗配置
|
||||
/// </summary>
|
||||
public AutoFightConfig AutoFightConfig { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// 自动秘境配置
|
||||
/// </summary>
|
||||
public AutoDomainConfig AutoDomainConfig { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// 脚本类配置
|
||||
/// </summary>
|
||||
public MacroConfig MacroConfig { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// 快捷键配置
|
||||
/// </summary>
|
||||
public HotKeyConfig HotKeyConfig { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// 通知配置
|
||||
/// </summary>
|
||||
public NotificationConfig NotificationConfig { get; set; } = new();
|
||||
|
||||
[JsonIgnore]
|
||||
public Action? OnAnyChangedAction { get; set; }
|
||||
|
||||
public void InitEvent()
|
||||
{
|
||||
PropertyChanged += OnAnyPropertyChanged;
|
||||
MaskWindowConfig.PropertyChanged += OnAnyPropertyChanged;
|
||||
CommonConfig.PropertyChanged += OnAnyPropertyChanged;
|
||||
GenshinStartConfig.PropertyChanged += OnAnyPropertyChanged;
|
||||
NotificationConfig.PropertyChanged += OnAnyPropertyChanged;
|
||||
NotificationConfig.PropertyChanged += OnNotificationPropertyChanged;
|
||||
|
||||
AutoPickConfig.PropertyChanged += OnAnyPropertyChanged;
|
||||
AutoSkipConfig.PropertyChanged += OnAnyPropertyChanged;
|
||||
AutoFishingConfig.PropertyChanged += OnAnyPropertyChanged;
|
||||
QuickTeleportConfig.PropertyChanged += OnAnyPropertyChanged;
|
||||
AutoCookConfig.PropertyChanged += OnAnyPropertyChanged;
|
||||
MacroConfig.PropertyChanged += OnAnyPropertyChanged;
|
||||
HotKeyConfig.PropertyChanged += OnAnyPropertyChanged;
|
||||
AutoWoodConfig.PropertyChanged += OnAnyPropertyChanged;
|
||||
AutoFightConfig.PropertyChanged += OnAnyPropertyChanged;
|
||||
AutoDomainConfig.PropertyChanged += OnAnyPropertyChanged;
|
||||
}
|
||||
|
||||
public void OnAnyPropertyChanged(object? sender, EventArgs args)
|
||||
{
|
||||
GameTaskManager.RefreshTriggerConfigs();
|
||||
OnAnyChangedAction?.Invoke();
|
||||
}
|
||||
|
||||
public void OnNotificationPropertyChanged(object? sender, PropertyChangedEventArgs args)
|
||||
{
|
||||
NotificationService.Instance().RefreshNotifiers();
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using System;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Config;
|
||||
|
||||
/// <summary>
|
||||
/// 遮罩窗口配置
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public partial class CommonConfig : ObservableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否启用遮罩窗口
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private bool _screenshotEnabled;
|
||||
|
||||
/// <summary>
|
||||
/// UID遮盖是否启用
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private bool _screenshotUidCoverEnabled;
|
||||
|
||||
/// <summary>
|
||||
/// 退出时最小化至托盘
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private bool _exitToTray;
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using System;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Config;
|
||||
|
||||
/// <summary>
|
||||
/// 原神启动配置
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public partial class GenshinStartConfig : ObservableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// 自动点击月卡
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private bool _autoClickBlessingOfTheWelkinMoonEnabled;
|
||||
|
||||
/// <summary>
|
||||
/// 自动进入游戏(开门)
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private bool _autoEnterGameEnabled = true;
|
||||
|
||||
/// <summary>
|
||||
/// 原神启动参数
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private string _genshinStartArgs = "";
|
||||
|
||||
/// <summary>
|
||||
/// 原神安装路径
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private string _installPath = "";
|
||||
|
||||
/// <summary>
|
||||
/// 联动启动原神本体
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private bool _linkedStartEnabled = true;
|
||||
}
|
||||
@@ -1,65 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Config;
|
||||
|
||||
public class Global
|
||||
namespace BetterGenshinImpact.Core.Config
|
||||
{
|
||||
public static string Version { get; } = "0.30.2";
|
||||
|
||||
public static string StartUpPath { get; set; } = AppContext.BaseDirectory;
|
||||
|
||||
public static string Absolute(string relativePath)
|
||||
public class Global
|
||||
{
|
||||
return Path.Combine(StartUpPath, relativePath);
|
||||
}
|
||||
public static string StartUpPath { get; private set; } = AppDomain.CurrentDomain.BaseDirectory;
|
||||
|
||||
public static string? ReadAllTextIfExist(string relativePath)
|
||||
{
|
||||
var path = Absolute(relativePath);
|
||||
if (File.Exists(path)) return File.ReadAllText(path);
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 新获取到的版本号与当前版本号比较,判断是否为新版本
|
||||
/// </summary>
|
||||
/// <param name="currentVersion">新获取到的版本</param>
|
||||
/// <returns></returns>
|
||||
public static bool IsNewVersion(string currentVersion)
|
||||
{
|
||||
return IsNewVersion(Version, currentVersion);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 新获取到的版本号与当前版本号比较,判断是否为新版本
|
||||
/// </summary>
|
||||
/// <param name="oldVersion">老版本</param>
|
||||
/// <param name="currentVersion">新获取到的版本</param>
|
||||
/// <returns>是否需要更新</returns>
|
||||
public static bool IsNewVersion(string oldVersion, string currentVersion)
|
||||
{
|
||||
try
|
||||
public static string Absolute(string relativePath)
|
||||
{
|
||||
Version oldVersionX = new(oldVersion);
|
||||
Version currentVersionX = new(currentVersion);
|
||||
|
||||
if (currentVersionX > oldVersionX)
|
||||
// 需要更新
|
||||
return true;
|
||||
return Path.Combine(StartUpPath, relativePath);
|
||||
}
|
||||
catch
|
||||
{
|
||||
///
|
||||
}
|
||||
|
||||
// 不需要更新
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void WriteAllText(string relativePath, string blackListJson)
|
||||
{
|
||||
var path = Absolute(relativePath);
|
||||
File.WriteAllText(path, blackListJson);
|
||||
}
|
||||
}
|
||||
@@ -1,165 +0,0 @@
|
||||
using BetterGenshinImpact.Model;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using System;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Config;
|
||||
|
||||
/// <summary>
|
||||
/// 格式必须是 快捷键 与 快捷键Type
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public partial class HotKeyConfig : ObservableObject
|
||||
{
|
||||
[ObservableProperty]
|
||||
private string _autoTrackHotkey = "";
|
||||
|
||||
[ObservableProperty]
|
||||
private string _autoTrackHotkeyType = HotKeyTypeEnum.KeyboardMonitor.ToString();
|
||||
|
||||
[ObservableProperty]
|
||||
private string _autoDomainHotkey = "";
|
||||
|
||||
[ObservableProperty]
|
||||
private string _autoDomainHotkeyType = HotKeyTypeEnum.KeyboardMonitor.ToString();
|
||||
|
||||
[ObservableProperty]
|
||||
private string _autoFightHotkey = "";
|
||||
|
||||
[ObservableProperty]
|
||||
private string _autoFightHotkeyType = HotKeyTypeEnum.KeyboardMonitor.ToString();
|
||||
|
||||
[ObservableProperty]
|
||||
private string _autoFishingEnabledHotkey = "";
|
||||
|
||||
[ObservableProperty]
|
||||
private string _autoFishingEnabledHotkeyType = HotKeyTypeEnum.KeyboardMonitor.ToString();
|
||||
|
||||
[ObservableProperty]
|
||||
private string _autoGeniusInvokationHotkey = "";
|
||||
|
||||
[ObservableProperty]
|
||||
private string _autoGeniusInvokationHotkeyType = HotKeyTypeEnum.KeyboardMonitor.ToString();
|
||||
|
||||
[ObservableProperty]
|
||||
private string _autoPickEnabledHotkey = "";
|
||||
|
||||
[ObservableProperty]
|
||||
private string _autoPickEnabledHotkeyType = HotKeyTypeEnum.KeyboardMonitor.ToString();
|
||||
|
||||
[ObservableProperty]
|
||||
private string _autoSkipEnabledHotkey = "";
|
||||
|
||||
[ObservableProperty]
|
||||
private string _autoSkipEnabledHotkeyType = HotKeyTypeEnum.KeyboardMonitor.ToString();
|
||||
|
||||
[ObservableProperty]
|
||||
private string _autoSkipHangoutEnabledHotkey = "";
|
||||
|
||||
[ObservableProperty]
|
||||
private string _autoSkipHangoutEnabledHotkeyType = HotKeyTypeEnum.KeyboardMonitor.ToString();
|
||||
|
||||
[ObservableProperty]
|
||||
private string _autoWoodHotkey = "";
|
||||
|
||||
[ObservableProperty]
|
||||
private string _autoWoodHotkeyType = HotKeyTypeEnum.KeyboardMonitor.ToString();
|
||||
|
||||
[ObservableProperty]
|
||||
private string _bgiEnabledHotkey = "F11";
|
||||
|
||||
[ObservableProperty]
|
||||
private string _bgiEnabledHotkeyType = HotKeyTypeEnum.GlobalRegister.ToString();
|
||||
|
||||
[ObservableProperty]
|
||||
private string _enhanceArtifactHotkey = "";
|
||||
|
||||
[ObservableProperty]
|
||||
private string _enhanceArtifactHotkeyType = HotKeyTypeEnum.KeyboardMonitor.ToString();
|
||||
|
||||
[ObservableProperty]
|
||||
private string _quickBuyHotkey = "";
|
||||
|
||||
[ObservableProperty]
|
||||
private string _quickBuyHotkeyType = HotKeyTypeEnum.KeyboardMonitor.ToString();
|
||||
|
||||
[ObservableProperty]
|
||||
private string _quickSereniteaPotHotkey = "";
|
||||
|
||||
[ObservableProperty]
|
||||
private string _quickSereniteaPotHotkeyType = HotKeyTypeEnum.KeyboardMonitor.ToString();
|
||||
|
||||
[ObservableProperty]
|
||||
private string _quickTeleportEnabledHotkey = "";
|
||||
|
||||
[ObservableProperty]
|
||||
private string _quickTeleportEnabledHotkeyType = HotKeyTypeEnum.KeyboardMonitor.ToString();
|
||||
|
||||
// 快捷传送触发
|
||||
[ObservableProperty]
|
||||
private string _quickTeleportTickHotkey = "";
|
||||
|
||||
[ObservableProperty]
|
||||
private string _quickTeleportTickHotkeyType = HotKeyTypeEnum.KeyboardMonitor.ToString();
|
||||
|
||||
// 截图
|
||||
[ObservableProperty]
|
||||
private string _takeScreenshotHotkey = "";
|
||||
|
||||
[ObservableProperty]
|
||||
private string _takeScreenshotHotkeyType = HotKeyTypeEnum.KeyboardMonitor.ToString();
|
||||
|
||||
[ObservableProperty]
|
||||
private string _turnAroundHotkey = "";
|
||||
|
||||
[ObservableProperty]
|
||||
private string _turnAroundHotkeyType = HotKeyTypeEnum.KeyboardMonitor.ToString();
|
||||
|
||||
// 点击确认按钮
|
||||
[ObservableProperty]
|
||||
private string _clickGenshinConfirmButtonHotkey = "";
|
||||
|
||||
[ObservableProperty]
|
||||
private string _clickGenshinConfirmButtonHotkeyType = HotKeyTypeEnum.KeyboardMonitor.ToString();
|
||||
|
||||
// 点击取消按钮
|
||||
[ObservableProperty]
|
||||
private string _clickGenshinCancelButtonHotkey = "";
|
||||
|
||||
[ObservableProperty]
|
||||
private string _clickGenshinCancelButtonHotkeyType = HotKeyTypeEnum.KeyboardMonitor.ToString();
|
||||
|
||||
// 一键战斗宏
|
||||
[ObservableProperty]
|
||||
private string _oneKeyFightHotkey = "";
|
||||
|
||||
[ObservableProperty]
|
||||
private string _oneKeyFightHotkeyType = HotKeyTypeEnum.KeyboardMonitor.ToString();
|
||||
|
||||
// 地图路线录制开始/停止
|
||||
[ObservableProperty]
|
||||
private string _mapPosRecordHotkey = "";
|
||||
|
||||
[ObservableProperty]
|
||||
private string _mapPosRecordHotkeyType = HotKeyTypeEnum.KeyboardMonitor.ToString();
|
||||
|
||||
// 活动音游开始/停止
|
||||
[ObservableProperty]
|
||||
private string _autoMusicGameHotkey = "";
|
||||
|
||||
[ObservableProperty]
|
||||
private string _autoMusicGameHotkeyType = HotKeyTypeEnum.KeyboardMonitor.ToString();
|
||||
|
||||
// 自动寻路
|
||||
[ObservableProperty]
|
||||
private string _autoTrackPathHotkey = "";
|
||||
|
||||
[ObservableProperty]
|
||||
private string _autoTrackPathHotkeyType = HotKeyTypeEnum.KeyboardMonitor.ToString();
|
||||
|
||||
// 测试
|
||||
[ObservableProperty]
|
||||
private string _test1Hotkey = "";
|
||||
|
||||
[ObservableProperty]
|
||||
private string _test1HotkeyType = HotKeyTypeEnum.KeyboardMonitor.ToString();
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
using BetterGenshinImpact.GameTask.AutoFight;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using System;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Config;
|
||||
|
||||
[Serializable]
|
||||
public partial class MacroConfig : ObservableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// 高延迟下强化的额外等待时间
|
||||
/// https://github.com/babalae/better-genshin-impact/issues/9
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private int _enhanceWaitDelay;
|
||||
|
||||
/// <summary>
|
||||
/// F连发时间间隔
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private int _fFireInterval = 100;
|
||||
|
||||
/// <summary>
|
||||
/// 长按F变F连发
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private bool _fPressHoldToContinuationEnabled;
|
||||
|
||||
/// <summary>
|
||||
/// 转圈圈时间间隔
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private int _runaroundInterval;
|
||||
|
||||
/// <summary>
|
||||
/// 转圈圈鼠标右移长度
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private int _runaroundMouseXInterval = 500;
|
||||
|
||||
/// <summary>
|
||||
/// 空格连发时间间隔
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private int _spaceFireInterval = 100;
|
||||
|
||||
/// <summary>
|
||||
/// 长按空格变空格连发
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private bool _spacePressHoldToContinuationEnabled;
|
||||
|
||||
/// <summary>
|
||||
/// 一键战斗宏启用状态
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private bool _combatMacroEnabled;
|
||||
|
||||
/// <summary>
|
||||
/// 一键战斗宏快捷键模式
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private string _combatMacroHotkeyMode = OneKeyFightTask.HoldOnMode;
|
||||
|
||||
/// <summary>
|
||||
/// 一键战斗宏优先级
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private int _combatMacroPriority = 1;
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using OpenCvSharp;
|
||||
using System;
|
||||
using Point = System.Windows.Point;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Config;
|
||||
|
||||
/// <summary>
|
||||
/// 遮罩窗口配置
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public partial class MaskWindowConfig : ObservableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// 控件是否锁定(拖拽移动等)
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private bool _controlLocked = true;
|
||||
|
||||
/// <summary>
|
||||
/// 方位提示是否启用
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private bool _directionsEnabled;
|
||||
|
||||
/// <summary>
|
||||
/// 是否在遮罩窗口上显示识别结果
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private bool _displayRecognitionResultsOnMask = true;
|
||||
|
||||
/// <summary>
|
||||
/// 日志窗口位置与大小
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private Rect _logBoxLocation;
|
||||
|
||||
/// <summary>
|
||||
/// 是否启用遮罩窗口
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private bool _maskEnabled = true;
|
||||
|
||||
///// <summary>
|
||||
///// 显示遮罩窗口边框
|
||||
///// </summary>
|
||||
//[ObservableProperty] private bool _showMaskBorder = false;
|
||||
|
||||
/// <summary>
|
||||
/// 显示日志窗口
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private bool _showLogBox = true;
|
||||
|
||||
/// <summary>
|
||||
/// 显示状态指示
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private bool _showStatus = true;
|
||||
|
||||
/// <summary>
|
||||
/// UID遮盖是否启用
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private bool _uidCoverEnabled;
|
||||
|
||||
/// <summary>
|
||||
/// 1080p下UID遮盖的位置与大小
|
||||
/// </summary>
|
||||
public Rect UidCoverRect { get; set; } = new(1690, 1052, 173, 22);
|
||||
|
||||
/// <summary>
|
||||
/// 1080p下UID遮盖的位置与大小
|
||||
/// </summary>
|
||||
public Rect UidCoverRightBottomRect { get; set; } = new(1920 - 1690, 1080 - 1052, 173, 22);
|
||||
|
||||
public Point EastPoint { get; set; } = new(274, 109);
|
||||
public Point SouthPoint { get; set; } = new(150, 233);
|
||||
public Point WestPoint { get; set; } = new(32, 109);
|
||||
public Point NorthPoint { get; set; } = new(150, -9);
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
using OpenCvSharp;
|
||||
using System;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Config;
|
||||
|
||||
[Obsolete("Replace with original OpenCvSharp.Rect")]
|
||||
public class RectConfig
|
||||
{
|
||||
public RectConfig()
|
||||
{
|
||||
}
|
||||
|
||||
public RectConfig(int x, int y, int width, int height)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
Width = width;
|
||||
Height = height;
|
||||
}
|
||||
|
||||
public int X { get; set; }
|
||||
public int Y { get; set; }
|
||||
public int Width { get; set; }
|
||||
public int Height { get; set; }
|
||||
|
||||
public Rect ToRect()
|
||||
{
|
||||
return new Rect(X, Y, Width, Height);
|
||||
}
|
||||
}
|
||||
@@ -1,170 +0,0 @@
|
||||
using BetterGenshinImpact.Core.Simulator;
|
||||
using BetterGenshinImpact.GameTask;
|
||||
using BetterGenshinImpact.Model;
|
||||
using Gma.System.MouseKeyHook;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Windows.Forms;
|
||||
using Vanara.PInvoke;
|
||||
using Timer = System.Timers.Timer;
|
||||
|
||||
namespace BetterGenshinImpact.Core;
|
||||
|
||||
public class MouseKeyMonitor
|
||||
{
|
||||
/// <summary>
|
||||
/// 长按F变F连发
|
||||
/// </summary>
|
||||
private readonly Timer _fTimer = new();
|
||||
|
||||
//private readonly Random _random = new();
|
||||
|
||||
/// <summary>
|
||||
/// 长按空格变空格连发
|
||||
/// </summary>
|
||||
private readonly Timer _spaceTimer = new();
|
||||
|
||||
private DateTime _firstFKeyDownTime = DateTime.MaxValue;
|
||||
|
||||
/// <summary>
|
||||
/// DateTime.MaxValue 代表没有按下
|
||||
/// </summary>
|
||||
private DateTime _firstSpaceKeyDownTime = DateTime.MaxValue;
|
||||
|
||||
private IKeyboardMouseEvents? _globalHook;
|
||||
private IntPtr _hWnd;
|
||||
|
||||
public void Subscribe(IntPtr gameHandle)
|
||||
{
|
||||
_hWnd = gameHandle;
|
||||
// Note: for the application hook, use the Hook.AppEvents() instead
|
||||
_globalHook = Hook.GlobalEvents();
|
||||
|
||||
_globalHook.KeyDown += GlobalHookKeyDown;
|
||||
_globalHook.KeyUp += GlobalHookKeyUp;
|
||||
_globalHook.MouseDownExt += GlobalHookMouseDownExt;
|
||||
_globalHook.MouseUpExt += GlobalHookMouseUpExt;
|
||||
//_globalHook.KeyPress += GlobalHookKeyPress;
|
||||
|
||||
_firstSpaceKeyDownTime = DateTime.MaxValue;
|
||||
var si = TaskContext.Instance().Config.MacroConfig.SpaceFireInterval;
|
||||
_spaceTimer.Interval = si;
|
||||
_spaceTimer.Elapsed += (sender, args) => { Simulation.PostMessage(_hWnd).KeyPress(User32.VK.VK_SPACE); };
|
||||
|
||||
var fi = TaskContext.Instance().Config.MacroConfig.FFireInterval;
|
||||
_fTimer.Interval = fi;
|
||||
_fTimer.Elapsed += (sender, args) => { Simulation.PostMessage(_hWnd).KeyPress(User32.VK.VK_F); };
|
||||
}
|
||||
|
||||
private void GlobalHookKeyDown(object? sender, KeyEventArgs e)
|
||||
{
|
||||
// Debug.WriteLine("KeyDown: \t{0}", e.KeyCode);
|
||||
|
||||
// 热键按下事件
|
||||
HotKeyDown(sender, e);
|
||||
|
||||
if (e.KeyCode == Keys.Space)
|
||||
{
|
||||
if (_firstSpaceKeyDownTime == DateTime.MaxValue)
|
||||
{
|
||||
_firstSpaceKeyDownTime = DateTime.Now;
|
||||
}
|
||||
else
|
||||
{
|
||||
var timeSpan = DateTime.Now - _firstSpaceKeyDownTime;
|
||||
if (timeSpan.TotalMilliseconds > 300 && TaskContext.Instance().Config.MacroConfig.SpacePressHoldToContinuationEnabled)
|
||||
if (!_spaceTimer.Enabled)
|
||||
_spaceTimer.Start();
|
||||
}
|
||||
}
|
||||
else if (e.KeyCode == Keys.F)
|
||||
{
|
||||
if (_firstFKeyDownTime == DateTime.MaxValue)
|
||||
{
|
||||
_firstFKeyDownTime = DateTime.Now;
|
||||
}
|
||||
else
|
||||
{
|
||||
var timeSpan = DateTime.Now - _firstFKeyDownTime;
|
||||
if (timeSpan.TotalMilliseconds > 200 && TaskContext.Instance().Config.MacroConfig.FPressHoldToContinuationEnabled)
|
||||
if (!_fTimer.Enabled)
|
||||
_fTimer.Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void GlobalHookKeyUp(object? sender, KeyEventArgs e)
|
||||
{
|
||||
// Debug.WriteLine("KeyUp: \t{0}", e.KeyCode);
|
||||
|
||||
// 热键松开事件
|
||||
HotKeyUp(sender, e);
|
||||
|
||||
if (e.KeyCode == Keys.Space)
|
||||
{
|
||||
if (_firstSpaceKeyDownTime != DateTime.MaxValue)
|
||||
{
|
||||
var timeSpan = DateTime.Now - _firstSpaceKeyDownTime;
|
||||
Debug.WriteLine($"Space按下时间:{timeSpan.TotalMilliseconds}ms");
|
||||
_firstSpaceKeyDownTime = DateTime.MaxValue;
|
||||
_spaceTimer.Stop();
|
||||
}
|
||||
}
|
||||
else if (e.KeyCode == Keys.F)
|
||||
{
|
||||
if (_firstFKeyDownTime != DateTime.MaxValue)
|
||||
{
|
||||
var timeSpan = DateTime.Now - _firstFKeyDownTime;
|
||||
Debug.WriteLine($"F按下时间:{timeSpan.TotalMilliseconds}ms");
|
||||
_firstFKeyDownTime = DateTime.MaxValue;
|
||||
_fTimer.Stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void HotKeyDown(object? sender, KeyEventArgs e)
|
||||
{
|
||||
if (KeyboardHook.AllKeyboardHooks.TryGetValue(e.KeyCode, out var hook)) hook.KeyDown(sender, e);
|
||||
}
|
||||
|
||||
private void HotKeyUp(object? sender, KeyEventArgs e)
|
||||
{
|
||||
if (KeyboardHook.AllKeyboardHooks.TryGetValue(e.KeyCode, out var hook)) hook.KeyUp(sender, e);
|
||||
}
|
||||
|
||||
//private void GlobalHookKeyPress(object? sender, KeyPressEventArgs e)
|
||||
//{
|
||||
// Debug.WriteLine("KeyPress: \t{0}", e.KeyChar);
|
||||
//}
|
||||
|
||||
private void GlobalHookMouseDownExt(object? sender, MouseEventExtArgs e)
|
||||
{
|
||||
// Debug.WriteLine("MouseDown: {0}; \t Location: {1};\t System Timestamp: {2}", e.Button, e.Location, e.Timestamp);
|
||||
|
||||
if (e.Button != MouseButtons.Left)
|
||||
if (MouseHook.AllMouseHooks.TryGetValue(e.Button, out var hook))
|
||||
hook.MouseDown(sender, e);
|
||||
}
|
||||
|
||||
private void GlobalHookMouseUpExt(object? sender, MouseEventExtArgs e)
|
||||
{
|
||||
// Debug.WriteLine("MouseUp: {0}; \t Location: {1};\t System Timestamp: {2}", e.Button, e.Location, e.Timestamp);
|
||||
|
||||
if (e.Button != MouseButtons.Left)
|
||||
if (MouseHook.AllMouseHooks.TryGetValue(e.Button, out var hook))
|
||||
hook.MouseUp(sender, e);
|
||||
}
|
||||
|
||||
public void Unsubscribe()
|
||||
{
|
||||
if (_globalHook != null)
|
||||
{
|
||||
_globalHook.KeyDown -= GlobalHookKeyDown;
|
||||
_globalHook.KeyUp -= GlobalHookKeyUp;
|
||||
_globalHook.MouseDownExt -= GlobalHookMouseDownExt;
|
||||
_globalHook.MouseUpExt -= GlobalHookMouseUpExt;
|
||||
//_globalHook.KeyPress -= GlobalHookKeyPress;
|
||||
_globalHook.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using OpenCvSharp;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Recognition
|
||||
{
|
||||
public class CommonRecognition
|
||||
{
|
||||
/// <summary>
|
||||
/// 寻找游戏内按钮
|
||||
/// </summary>
|
||||
/// <param name="srcMat"></param>
|
||||
/// <returns></returns>
|
||||
public static List<Rect> FindGameButton(Mat srcMat)
|
||||
{
|
||||
try
|
||||
{
|
||||
var src = srcMat.Clone();
|
||||
Cv2.CvtColor(src, src, ColorConversionCodes.BGR2RGB);
|
||||
var lowPurple = new Scalar(236, 229, 216);
|
||||
var highPurple = new Scalar(236, 229, 216);
|
||||
Cv2.InRange(src, lowPurple, highPurple, src);
|
||||
Cv2.Threshold(src, src, 0, 255, ThresholdTypes.Binary);
|
||||
//var kernel = Cv2.GetStructuringElement(MorphShapes.Rect, new OpenCvSharp.Size(20, 20),
|
||||
// new OpenCvSharp.Point(-1, -1));
|
||||
//Cv2.Dilate(src, src, kernel); //膨胀
|
||||
|
||||
Cv2.FindContours(src, out var contours, out _, RetrievalModes.External,
|
||||
ContourApproximationModes.ApproxSimple, null);
|
||||
if (contours.Length > 0)
|
||||
{
|
||||
var boxes = contours.Select(Cv2.BoundingRect).Where(r => r.Width > 50);
|
||||
return boxes.ToList();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.WriteLine(e);
|
||||
}
|
||||
|
||||
return new List<Rect>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
using OpenCvSharp;
|
||||
using Sdcb.PaddleOCR;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Recognition.OCR;
|
||||
|
||||
public interface IOcrService
|
||||
{
|
||||
public string Ocr(Mat mat);
|
||||
|
||||
public string OcrWithoutDetector(Mat mat);
|
||||
|
||||
public PaddleOcrResult OcrResult(Mat mat);
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Recognition.OCR;
|
||||
|
||||
public class OcrFactory
|
||||
{
|
||||
// public static IOcrService Media = Create(OcrEngineTypes.Media);
|
||||
public static IOcrService Paddle { get; } = Create(OcrEngineTypes.Paddle);
|
||||
|
||||
public static IOcrService Create(OcrEngineTypes type)
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
OcrEngineTypes.Paddle => new PaddleOcrService(),
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
using BetterGenshinImpact.GameTask.AutoSkip.Model;
|
||||
using BetterGenshinImpact.View.Drawable;
|
||||
using OpenCvSharp;
|
||||
using Sdcb.PaddleOCR;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Recognition.OCR;
|
||||
|
||||
public static class PaddleOcrResultExtension
|
||||
{
|
||||
public static bool RegionHasText(this PaddleOcrResult result, ReadOnlySpan<char> text)
|
||||
{
|
||||
foreach (ref readonly PaddleOcrResultRegion item in result.Regions.AsSpan())
|
||||
{
|
||||
if (item.Text.AsSpan().Contains(text, StringComparison.InvariantCulture))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static PaddleOcrResultRegion FindRegionByText(this PaddleOcrResult result, ReadOnlySpan<char> text)
|
||||
{
|
||||
foreach (ref readonly PaddleOcrResultRegion item in result.Regions.AsSpan())
|
||||
{
|
||||
if (item.Text.AsSpan().Contains(text, StringComparison.InvariantCulture))
|
||||
{
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
|
||||
public static Rect FindRectByText(this PaddleOcrResult result, string text)
|
||||
{
|
||||
foreach (ref PaddleOcrResultRegion item in result.Regions.AsSpan())
|
||||
{
|
||||
if (item.Text.Contains(text))
|
||||
{
|
||||
return item.Rect.BoundingRect();
|
||||
}
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
|
||||
public static List<RectDrawable> ToRectDrawableList(this PaddleOcrResult result, Pen? pen = null)
|
||||
{
|
||||
return result.Regions.Select(item => item.Rect.BoundingRect().ToRectDrawable(pen)).ToList();
|
||||
}
|
||||
|
||||
public static List<RectDrawable> ToRectDrawableListOffset(this PaddleOcrResult result, int offsetX, int offsetY, Pen? pen = null)
|
||||
{
|
||||
return result.Regions.Select(item => item.Rect.BoundingRect().ToRectDrawable(offsetX, offsetY, pen)).ToList();
|
||||
}
|
||||
|
||||
public static PaddleOcrResultRect ToOcrResultRect(this PaddleOcrResultRegion region)
|
||||
{
|
||||
return new PaddleOcrResultRect(region.Rect.BoundingRect(), region.Text, region.Score);
|
||||
}
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
using BetterGenshinImpact.Core.Config;
|
||||
using OpenCvSharp;
|
||||
using Sdcb.PaddleInference;
|
||||
using Sdcb.PaddleOCR;
|
||||
using Sdcb.PaddleOCR.Models;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using BetterGenshinImpact.GameTask;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Recognition.OCR;
|
||||
|
||||
public class PaddleOcrService : IOcrService
|
||||
{
|
||||
private static readonly object locker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Usage:
|
||||
/// https://github.com/sdcb/PaddleSharp/blob/master/docs/ocr.md
|
||||
/// 模型列表:
|
||||
/// https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.5/doc/doc_ch/models_list.md
|
||||
/// </summary>
|
||||
private readonly PaddleOcrAll _paddleOcrAll;
|
||||
|
||||
public PaddleOcrService()
|
||||
{
|
||||
var path = Global.Absolute("Assets\\Model\\PaddleOcr");
|
||||
var localDetModel = DetectionModel.FromDirectory(Path.Combine(path, "ch_PP-OCRv4_det"), ModelVersion.V4);
|
||||
var localClsModel = ClassificationModel.FromDirectory(Path.Combine(path, "ch_ppocr_mobile_v2.0_cls"));
|
||||
var localRecModel = RecognizationModel.FromDirectory(Path.Combine(path, "ch_PP-OCRv4_rec"), Path.Combine(path, "ppocr_keys_v1.txt"), ModelVersion.V4);
|
||||
var model = new FullOcrModel(localDetModel, localClsModel, localRecModel);
|
||||
Action<PaddleConfig> device = TaskContext.Instance().Config.InferenceDevice switch
|
||||
{
|
||||
"CPU" => PaddleDevice.Onnx(),
|
||||
"GPU" => PaddleDevice.Gpu(),
|
||||
_ => throw new InvalidEnumArgumentException("无效的推理设备")
|
||||
};
|
||||
_paddleOcrAll = new PaddleOcrAll(model, device)
|
||||
{
|
||||
AllowRotateDetection = false, /* 允许识别有角度的文字 */
|
||||
Enable180Classification = false /* 允许识别旋转角度大于90度的文字 */
|
||||
};
|
||||
|
||||
// System.AccessViolationException
|
||||
// https://github.com/babalae/better-genshin-impact/releases/latest
|
||||
// 下载并解压到相同目录下
|
||||
}
|
||||
|
||||
public string Ocr(Mat mat)
|
||||
{
|
||||
return OcrResult(mat).Text;
|
||||
}
|
||||
|
||||
public PaddleOcrResult OcrResult(Mat mat)
|
||||
{
|
||||
lock (locker)
|
||||
{
|
||||
long startTime = Stopwatch.GetTimestamp();
|
||||
var result = _paddleOcrAll.Run(mat);
|
||||
TimeSpan time = Stopwatch.GetElapsedTime(startTime);
|
||||
Debug.WriteLine($"PaddleOcr 耗时 {time.TotalMilliseconds}ms 结果: {result.Text}");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public string OcrWithoutDetector(Mat mat)
|
||||
{
|
||||
lock (locker)
|
||||
{
|
||||
var str = _paddleOcrAll.Recognizer.Run(mat).Text;
|
||||
Debug.WriteLine($"PaddleOcrWithoutDetector 结果: {str}");
|
||||
return str;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
using BetterGenshinImpact.GameTask;
|
||||
using BetterGenshinImpact.Model;
|
||||
using Microsoft.ML.OnnxRuntime;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Recognition.ONNX;
|
||||
|
||||
public class BgiSessionOption : Singleton<BgiSessionOption>
|
||||
{
|
||||
public SessionOptions Options { get; set; } = TaskContext.Instance().Config.InferenceDevice switch
|
||||
{
|
||||
"CPU" => new SessionOptions(),
|
||||
"GPU" => SessionOptions.MakeSessionOptionWithCudaProvider(),
|
||||
_ => throw new InvalidEnumArgumentException("无效的推理设备")
|
||||
};
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
using OpenCvSharp;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Recognition.ONNX.SVTR;
|
||||
|
||||
/// <summary>
|
||||
/// 文字识别推理(SVTR网络)
|
||||
/// </summary>
|
||||
public interface ITextInference
|
||||
{
|
||||
public string Inference(Mat mat);
|
||||
}
|
||||
@@ -1,121 +0,0 @@
|
||||
using BetterGenshinImpact.Core.Config;
|
||||
using BetterGenshinImpact.GameTask;
|
||||
using Microsoft.ML.OnnxRuntime;
|
||||
using Microsoft.ML.OnnxRuntime.Tensors;
|
||||
using OpenCvSharp;
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Recognition.ONNX.SVTR;
|
||||
|
||||
/// <summary>
|
||||
/// 来自于 Yap 的拾取文字识别
|
||||
/// https://github.com/Alex-Beng/Yap
|
||||
/// </summary>
|
||||
public class PickTextInference : ITextInference
|
||||
{
|
||||
private readonly InferenceSession _session;
|
||||
private readonly Dictionary<int, string> _wordDictionary;
|
||||
|
||||
public PickTextInference()
|
||||
{
|
||||
var modelPath = Global.Absolute("Assets\\Model\\Yap\\model_training.onnx");
|
||||
if (!File.Exists(modelPath)) throw new FileNotFoundException("Yap模型文件不存在", modelPath);
|
||||
|
||||
_session = new InferenceSession(modelPath, BgiSessionOption.Instance.Options);
|
||||
|
||||
var wordJsonPath = Global.Absolute("Assets\\Model\\Yap\\index_2_word.json");
|
||||
if (!File.Exists(wordJsonPath)) throw new FileNotFoundException("Yap字典文件不存在", wordJsonPath);
|
||||
|
||||
var json = File.ReadAllText(wordJsonPath);
|
||||
_wordDictionary = JsonSerializer.Deserialize<Dictionary<int, string>>(json) ?? throw new Exception("index_2_word.json deserialize failed");
|
||||
}
|
||||
|
||||
public string Inference(Mat mat)
|
||||
{
|
||||
long startTime = Stopwatch.GetTimestamp();
|
||||
// 将输入数据调整为 (1, 1, 32, 384) 形状的张量
|
||||
var reshapedInputData = ToTensorUnsafe(mat, out var owner);
|
||||
|
||||
IDisposableReadOnlyCollection<DisposableNamedOnnxValue> results;
|
||||
|
||||
using (owner)
|
||||
{
|
||||
// 创建输入 NamedOnnxValue, 运行模型推理
|
||||
results = _session.Run([NamedOnnxValue.CreateFromTensor("input", reshapedInputData)]);
|
||||
}
|
||||
|
||||
using (results)
|
||||
{
|
||||
// 获取输出数据
|
||||
var boxes = results[0].AsTensor<float>();
|
||||
|
||||
var ans = new StringBuilder();
|
||||
var lastWord = default(string);
|
||||
for (var i = 0; i < boxes.Dimensions[0]; i++)
|
||||
{
|
||||
var maxIndex = 0;
|
||||
var maxValue = -1.0;
|
||||
for (var j = 0; j < _wordDictionary.Count; j++)
|
||||
{
|
||||
var value = boxes[[i, 0, j]];
|
||||
if (value > maxValue)
|
||||
{
|
||||
maxValue = value;
|
||||
maxIndex = j;
|
||||
}
|
||||
}
|
||||
|
||||
var word = _wordDictionary[maxIndex];
|
||||
if (word != lastWord && word != "|")
|
||||
{
|
||||
ans.Append(word);
|
||||
}
|
||||
|
||||
lastWord = word;
|
||||
}
|
||||
|
||||
TimeSpan time = Stopwatch.GetElapsedTime(startTime);
|
||||
string result = ans.ToString();
|
||||
Debug.WriteLine($"Yap模型识别 耗时{time.TotalMilliseconds}ms 结果: {result}");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public static Tensor<float> ToTensorUnsafe(Mat src, out IMemoryOwner<float> tensorMemoryOwnser)
|
||||
{
|
||||
var channels = src.Channels();
|
||||
var nRows = src.Rows;
|
||||
var nCols = src.Cols * channels;
|
||||
if (src.IsContinuous())
|
||||
{
|
||||
nCols *= nRows;
|
||||
nRows = 1;
|
||||
}
|
||||
|
||||
//var inputData = new float[nCols];
|
||||
tensorMemoryOwnser = MemoryPool<float>.Shared.Rent(nCols);
|
||||
var memory = tensorMemoryOwnser.Memory[..nCols];
|
||||
unsafe
|
||||
{
|
||||
for (var i = 0; i < nRows; i++)
|
||||
{
|
||||
var b = (byte*)src.Ptr(i);
|
||||
for (var j = 0; j < nCols; j++)
|
||||
{
|
||||
memory.Span[j] = b[j] / 255f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new DenseTensor<float>(memory, [1, 1, 32, 384]);
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Recognition.ONNX.SVTR;
|
||||
|
||||
public class TextInferenceFactory
|
||||
{
|
||||
public static ITextInference Pick { get; } = Create(OcrEngineTypes.YapModel);
|
||||
|
||||
public static ITextInference Create(OcrEngineTypes type)
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
OcrEngineTypes.YapModel => new PickTextInference(),
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
using BetterGenshinImpact.Core.Config;
|
||||
using Microsoft.ML.OnnxRuntime;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Recognition.ONNX.YOLO;
|
||||
|
||||
[Obsolete]
|
||||
public class Predictor
|
||||
{
|
||||
private readonly InferenceSession _session;
|
||||
private readonly string[] labels;
|
||||
|
||||
public Predictor()
|
||||
{
|
||||
var options = new SessionOptions();
|
||||
var modelPath = Global.Absolute("Assets\\Model\\Fish\\bgi_fish.onnx");
|
||||
if (!File.Exists(modelPath)) throw new FileNotFoundException("自动钓鱼模型文件不存在", modelPath);
|
||||
|
||||
_session = new InferenceSession(modelPath, options);
|
||||
|
||||
var wordJsonPath = Global.Absolute("Assets\\Model\\Fish\\label.json");
|
||||
if (!File.Exists(wordJsonPath)) throw new FileNotFoundException("自动钓鱼模型分类文件不存在", wordJsonPath);
|
||||
|
||||
var json = File.ReadAllText(wordJsonPath);
|
||||
labels = JsonSerializer.Deserialize<string[]>(json) ?? throw new Exception("label.json deserialize failed");
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
namespace BetterGenshinImpact.Core.Recognition;
|
||||
|
||||
public enum OcrEngineTypes
|
||||
{
|
||||
// 通用
|
||||
//Media,
|
||||
Paddle,
|
||||
|
||||
// 特定模型
|
||||
YasModel,
|
||||
|
||||
YapModel
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
using OpenCvSharp;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Recognition.OpenCv;
|
||||
|
||||
public class ArithmeticHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 水平投影
|
||||
/// </summary>
|
||||
/// <param name="gray"></param>
|
||||
/// <returns></returns>
|
||||
public static int[] HorizontalProjection(Mat gray)
|
||||
{
|
||||
var projection = new int[gray.Height];
|
||||
//对每一行计算投影值
|
||||
for (var y = 0; y < gray.Height; ++y)
|
||||
//遍历这一行的每一个像素,如果是有效的,累加投影值
|
||||
for (var x = 0; x < gray.Width; ++x)
|
||||
{
|
||||
var s = gray.Get<Vec2b>(y, x);
|
||||
if (s.Item0 == 255) projection[y]++;
|
||||
}
|
||||
|
||||
return projection;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 垂直投影
|
||||
/// </summary>
|
||||
/// <param name="gray"></param>
|
||||
/// <returns></returns>
|
||||
public static int[] VerticalProjection(Mat gray)
|
||||
{
|
||||
var projection = new int[gray.Width];
|
||||
//遍历每一列计算投影值
|
||||
for (var x = 0; x < gray.Width; ++x)
|
||||
for (var y = 0; y < gray.Height; ++y)
|
||||
{
|
||||
var s = gray.Get<Vec2b>(y, x);
|
||||
if (s.Item0 == 255) projection[x]++;
|
||||
}
|
||||
|
||||
return projection;
|
||||
}
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
using OpenCvSharp;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using Vanara.PInvoke;
|
||||
using Color = System.Windows.Media.Color;
|
||||
using Point = OpenCvSharp.Point;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Recognition.OpenCv;
|
||||
|
||||
public static class CommonExtension
|
||||
{
|
||||
public static unsafe Point AsCvPoint(this System.Drawing.Point point)
|
||||
{
|
||||
return *(Point*)&point;
|
||||
}
|
||||
|
||||
public static unsafe System.Drawing.Point AsDrawingPoint(this Point point)
|
||||
{
|
||||
return *(System.Drawing.Point*)&point;
|
||||
}
|
||||
|
||||
public static System.Windows.Point ToWindowsPoint(this Point point)
|
||||
{
|
||||
return new System.Windows.Point(point.X, point.Y);
|
||||
}
|
||||
|
||||
public static unsafe Rect AsCvRect(this Rectangle rectangle)
|
||||
{
|
||||
return *(Rect*)&rectangle;
|
||||
}
|
||||
|
||||
public static System.Windows.Rect ToWindowsRectangle(this Rect rect)
|
||||
{
|
||||
return new System.Windows.Rect(rect.X, rect.Y, rect.Width, rect.Height);
|
||||
}
|
||||
|
||||
public static System.Windows.Rect ToWindowsRectangleOffset(this Rect rect, int offsetX, int offsetY)
|
||||
{
|
||||
return new System.Windows.Rect(rect.X + offsetX, rect.Y + offsetY, rect.Width, rect.Height);
|
||||
}
|
||||
|
||||
public static unsafe Rectangle AsDrawingRectangle(this Rect rect)
|
||||
{
|
||||
return *(Rectangle*)▭
|
||||
}
|
||||
|
||||
public static System.Drawing.Point GetCenterPoint(this Rectangle rectangle)
|
||||
{
|
||||
if (rectangle.IsEmpty) throw new ArgumentException("rectangle is empty");
|
||||
|
||||
return new System.Drawing.Point(rectangle.X + rectangle.Width / 2, rectangle.Y + rectangle.Height / 2);
|
||||
}
|
||||
|
||||
public static Point GetCenterPoint(this RECT rectangle)
|
||||
{
|
||||
if (rectangle.IsEmpty) throw new ArgumentException("rectangle is empty");
|
||||
|
||||
return new Point(rectangle.X + rectangle.Width / 2, rectangle.Y + rectangle.Height / 2);
|
||||
}
|
||||
|
||||
public static Point GetCenterPoint(this Rect rectangle)
|
||||
{
|
||||
if (rectangle == Rect.Empty) throw new ArgumentException("rectangle is empty");
|
||||
|
||||
return new Point(rectangle.X + rectangle.Width / 2, rectangle.Y + rectangle.Height / 2);
|
||||
}
|
||||
|
||||
public static Rect Multiply(this Rect rect, double assetScale)
|
||||
{
|
||||
if (rect == Rect.Empty) throw new ArgumentException("rect is empty");
|
||||
|
||||
return new Rect((int)(rect.X * assetScale), (int)(rect.Y * assetScale), (int)(rect.Width * assetScale), (int)(rect.Height * assetScale));
|
||||
}
|
||||
|
||||
public static Color ToWindowsColor(this System.Drawing.Color color)
|
||||
{
|
||||
return Color.FromArgb(color.A, color.R, color.G, color.B);
|
||||
}
|
||||
|
||||
public static Point2d ToPoint2d(this Point2f p)
|
||||
{
|
||||
return new Point2d(p.X, p.Y);
|
||||
}
|
||||
|
||||
public static List<Point2d> ToPoint2d(this List<Point2f> list)
|
||||
{
|
||||
return list.ConvertAll(ToPoint2d);
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
using OpenCvSharp;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Recognition.OpenCv;
|
||||
|
||||
public class CommonRecognition
|
||||
{
|
||||
/// <summary>
|
||||
/// 寻找游戏内按钮
|
||||
/// </summary>
|
||||
/// <param name="srcMat"></param>
|
||||
/// <returns></returns>
|
||||
public static List<Rect> FindGameButton(Mat srcMat)
|
||||
{
|
||||
try
|
||||
{
|
||||
var src = srcMat.Clone();
|
||||
Cv2.CvtColor(src, src, ColorConversionCodes.BGR2RGB);
|
||||
var lowPurple = new Scalar(236, 229, 216);
|
||||
var highPurple = new Scalar(236, 229, 216);
|
||||
Cv2.InRange(src, lowPurple, highPurple, src);
|
||||
Cv2.Threshold(src, src, 0, 255, ThresholdTypes.Binary);
|
||||
//var kernel = Cv2.GetStructuringElement(MorphShapes.Rect, new OpenCvSharp.Size(20, 20),
|
||||
// new OpenCvSharp.Point(-1, -1));
|
||||
//Cv2.Dilate(src, src, kernel); //膨胀
|
||||
|
||||
Cv2.FindContours(src, out var contours, out _, RetrievalModes.External,
|
||||
ContourApproximationModes.ApproxSimple);
|
||||
if (contours.Length > 0)
|
||||
{
|
||||
var boxes = contours.Select(Cv2.BoundingRect).Where(r => r.Width > 50);
|
||||
return boxes.ToList();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.WriteLine(e);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
using OpenCvSharp;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Recognition.OpenCv;
|
||||
|
||||
public class ContoursHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 找到指定颜色的矩形
|
||||
/// </summary>
|
||||
/// <param name="srcMat">图像</param>
|
||||
/// <param name="low">RGB色彩低位</param>
|
||||
/// <param name="high">RGB色彩高位</param>
|
||||
/// <param name="minWidth">矩形最小宽度</param>
|
||||
/// <param name="minHeight">矩形最小高度</param>
|
||||
/// <returns></returns>
|
||||
public static List<Rect> FindSpecifyColorRects(Mat srcMat, Scalar low, Scalar high, int minWidth = -1, int minHeight = -1)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var src = srcMat.Clone();
|
||||
Cv2.CvtColor(src, src, ColorConversionCodes.BGR2RGB);
|
||||
Cv2.InRange(src, low, high, src);
|
||||
|
||||
Cv2.FindContours(src, out var contours, out _, RetrievalModes.External,
|
||||
ContourApproximationModes.ApproxSimple);
|
||||
if (contours.Length > 0)
|
||||
{
|
||||
var boxes = contours.Select(Cv2.BoundingRect).Where(r =>
|
||||
{
|
||||
if (minWidth > 0 && r.Width < minWidth)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (minHeight > 0 && r.Height < minHeight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
return boxes.ToList();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.WriteLine(e);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
public static List<Rect> FindSpecifyColorRects(Mat srcMat, Scalar color, int minWidth = -1, int minHeight = -1)
|
||||
{
|
||||
return FindSpecifyColorRects(srcMat, color, color, minWidth, minHeight);
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
using System;
|
||||
using OpenCvSharp;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Recognition.OpenCv;
|
||||
|
||||
/// <summary>
|
||||
/// 图片剪裁
|
||||
/// </summary>
|
||||
[Obsolete]
|
||||
public class CropHelper
|
||||
{
|
||||
public static Mat CutRightTop(Mat srcMat, int saveRightWidth, int saveTopHeight)
|
||||
{
|
||||
srcMat = new Mat(srcMat, new Rect(srcMat.Width - saveRightWidth, 0, saveRightWidth, saveTopHeight));
|
||||
return srcMat;
|
||||
}
|
||||
|
||||
public static Mat CutRightBottom(Mat srcMat, int saveRightWidth, int saveBottomHeight)
|
||||
{
|
||||
srcMat = new Mat(srcMat, new Rect(srcMat.Width - saveRightWidth, srcMat.Height - saveBottomHeight, saveRightWidth, saveBottomHeight));
|
||||
return srcMat;
|
||||
}
|
||||
|
||||
public static Mat CutLeftTop(Mat srcMat, int saveLeftWidth, int saveTopHeight)
|
||||
{
|
||||
srcMat = new Mat(srcMat, new Rect(0, 0, saveLeftWidth, saveTopHeight));
|
||||
return srcMat;
|
||||
}
|
||||
|
||||
public static Mat CutLeftBottom(Mat srcMat, int saveLeftWidth, int saveBottomHeight)
|
||||
{
|
||||
srcMat = new Mat(srcMat, new Rect(0, srcMat.Height - saveBottomHeight, saveLeftWidth, saveBottomHeight));
|
||||
return srcMat;
|
||||
}
|
||||
|
||||
public static Mat CutTop(Mat srcMat, int saveTopHeight)
|
||||
{
|
||||
srcMat = new Mat(srcMat, new Rect(0, 0, srcMat.Width, saveTopHeight));
|
||||
return srcMat;
|
||||
}
|
||||
|
||||
public static Mat CutBottom(Mat srcMat, int saveBottomHeight)
|
||||
{
|
||||
srcMat = new Mat(srcMat, new Rect(0, srcMat.Height - saveBottomHeight, srcMat.Width, saveBottomHeight));
|
||||
return srcMat;
|
||||
}
|
||||
|
||||
public static Mat CutRight(Mat srcMat, int saveRightWidth)
|
||||
{
|
||||
srcMat = new Mat(srcMat, new Rect(srcMat.Width - saveRightWidth, 0, saveRightWidth, srcMat.Height));
|
||||
return srcMat;
|
||||
}
|
||||
|
||||
public static Mat CutLeft(Mat srcMat, int saveLeftWidth)
|
||||
{
|
||||
srcMat = new Mat(srcMat, new Rect(0, 0, saveLeftWidth, srcMat.Height));
|
||||
return srcMat;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
namespace BetterGenshinImpact.Core.Recognition.OpenCv.FeatureMatch;
|
||||
|
||||
public enum Feature2DType
|
||||
{
|
||||
// ReSharper disable once InconsistentNaming
|
||||
SURF,
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
SIFT
|
||||
}
|
||||
@@ -1,245 +0,0 @@
|
||||
using BetterGenshinImpact.Core.Recognition.OpenCv.Model;
|
||||
using BetterGenshinImpact.Helpers;
|
||||
using OpenCvSharp;
|
||||
using OpenCvSharp.XFeatures2D;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using BetterGenshinImpact.GameTask.Common.Map;
|
||||
using OpenCvSharp.Features2D;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Recognition.OpenCv.FeatureMatch;
|
||||
|
||||
public class FeatureMatcher
|
||||
{
|
||||
private readonly double _threshold = 100; // SURF 100
|
||||
private readonly Feature2D _feature2D;
|
||||
private readonly Mat _trainMat; // 大图本身
|
||||
private readonly Mat _trainRet = new(); // 大图特征描述子
|
||||
private readonly KeyPoint[] _trainKeyPoints;
|
||||
|
||||
private readonly KeyPointFeatureBlock[][] _blocks; // 特征块存储
|
||||
private readonly int _splitRow = MapCoordinate.GameMapRows * 2; // 特征点拆分行数
|
||||
private readonly int _splitCol = MapCoordinate.GameMapCols * 2; // 特征点拆分列数
|
||||
private KeyPointFeatureBlock? _lastMergedBlock; // 上次合并的特征块
|
||||
|
||||
public FeatureMatcher(Mat trainMat, FeatureStorage? featureStorage = null, Feature2DType type = Feature2DType.SIFT, double threshold = 100)
|
||||
{
|
||||
_threshold = threshold;
|
||||
_trainMat = trainMat;
|
||||
if (Feature2DType.SURF == type)
|
||||
{
|
||||
_feature2D = SURF.Create(_threshold, 4, 3, false, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
_feature2D = SIFT.Create();
|
||||
}
|
||||
|
||||
if (featureStorage != null)
|
||||
{
|
||||
featureStorage.TypeName = type.ToString();
|
||||
var kpFromDisk = featureStorage.LoadKeyPointArray();
|
||||
if (kpFromDisk == null)
|
||||
{
|
||||
_feature2D.DetectAndCompute(trainMat, null, out _trainKeyPoints, _trainRet);
|
||||
featureStorage.SaveKeyPointArray(_trainKeyPoints);
|
||||
featureStorage.SaveDescMat(_trainRet);
|
||||
}
|
||||
else
|
||||
{
|
||||
_trainKeyPoints = kpFromDisk;
|
||||
_trainRet = featureStorage.LoadDescMat() ?? throw new Exception("加载特征描述矩阵失败");
|
||||
}
|
||||
}
|
||||
|
||||
Debug.WriteLine("被匹配的图像生成初始化KeyPoint完成");
|
||||
Stopwatch sw = new();
|
||||
sw.Start();
|
||||
_blocks = KeyPointFeatureBlockHelper.SplitFeatures(_trainMat, _splitRow, _splitCol, _trainKeyPoints, _trainRet);
|
||||
sw.Stop();
|
||||
Debug.WriteLine($"切割特征点耗时: {sw.ElapsedMilliseconds}ms");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 普通匹配(全图特征)
|
||||
/// </summary>
|
||||
/// <param name="queryMat"></param>
|
||||
/// <returns></returns>
|
||||
public Point2f[]? Match(Mat queryMat)
|
||||
{
|
||||
return Match(_trainKeyPoints, _trainRet, queryMat);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 合并邻近的特征点后匹配(临近特征)
|
||||
/// </summary>
|
||||
/// <param name="queryMat"></param>
|
||||
/// <param name="prevX">上次匹配到的坐标x</param>
|
||||
/// <param name="prevY">上次匹配到的坐标y</param>
|
||||
/// <returns></returns>
|
||||
public Point2f[]? Match(Mat queryMat, int prevX, int prevY)
|
||||
{
|
||||
var (cellRow, cellCol) = KeyPointFeatureBlockHelper.GetCellIndex(_trainMat, _splitRow, _splitCol, prevX, prevY);
|
||||
Debug.WriteLine($"当前坐标({prevX},{prevY})在特征块({cellRow},{cellCol})中");
|
||||
if (_lastMergedBlock == null || _lastMergedBlock.MergedCenterCellRow != cellRow || _lastMergedBlock.MergedCenterCellCol != cellCol)
|
||||
{
|
||||
Debug.WriteLine($"---------切换到新的特征块({cellRow},{cellCol}),合并特征点--------");
|
||||
_lastMergedBlock = KeyPointFeatureBlockHelper.MergeNeighboringFeatures(_blocks, _trainRet, cellRow, cellCol);
|
||||
}
|
||||
|
||||
return Match(_lastMergedBlock.KeyPointArray, _lastMergedBlock.Descriptor!, queryMat);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 普通匹配
|
||||
/// </summary>
|
||||
/// <param name="trainKeyPoints"></param>
|
||||
/// <param name="trainRet"></param>
|
||||
/// <param name="queryMat"></param>
|
||||
/// <returns></returns>
|
||||
public Point2f[]? Match(KeyPoint[] trainKeyPoints, Mat trainRet, Mat queryMat)
|
||||
{
|
||||
SpeedTimer speedTimer = new();
|
||||
|
||||
using var queryRet = new Mat();
|
||||
|
||||
_feature2D.DetectAndCompute(queryMat, null, out var queryKeyPoints, queryRet);
|
||||
speedTimer.Record("模板生成KeyPoint");
|
||||
|
||||
using var flnMatcher = new FlannBasedMatcher();
|
||||
var matches = flnMatcher.Match(queryRet, trainRet);
|
||||
//Finding the Minimum and Maximum Distance
|
||||
double minDistance = 1000; //Backward approximation
|
||||
double maxDistance = 0;
|
||||
for (int i = 0; i < queryRet.Rows; i++)
|
||||
{
|
||||
double distance = matches[i].Distance;
|
||||
if (distance > maxDistance)
|
||||
{
|
||||
maxDistance = distance;
|
||||
}
|
||||
|
||||
if (distance < minDistance)
|
||||
{
|
||||
minDistance = distance;
|
||||
}
|
||||
}
|
||||
|
||||
// Debug.WriteLine($"max distance : {maxDistance}");
|
||||
// Debug.WriteLine($"min distance : {minDistance}");
|
||||
|
||||
var pointsQuery = new List<Point2f>();
|
||||
var pointsTrain = new List<Point2f>();
|
||||
//Screening better matching points
|
||||
// var goodMatches = new List<DMatch>();
|
||||
for (int i = 0; i < queryRet.Rows; i++)
|
||||
{
|
||||
double distance = matches[i].Distance;
|
||||
if (distance < Math.Max(minDistance * 2, 0.02))
|
||||
{
|
||||
pointsQuery.Add(queryKeyPoints[matches[i].QueryIdx].Pt);
|
||||
pointsTrain.Add(trainKeyPoints[matches[i].TrainIdx].Pt);
|
||||
//Compression of new ones with distances less than ranges DMatch
|
||||
// goodMatches.Add(matches[i]);
|
||||
}
|
||||
}
|
||||
|
||||
speedTimer.Record("FlannMatch");
|
||||
|
||||
// var outMat = new Mat();
|
||||
|
||||
// algorithm RANSAC Filter the matched results
|
||||
var pQuery = pointsQuery.ToPoint2d();
|
||||
var pTrain = pointsTrain.ToPoint2d();
|
||||
var outMask = new Mat();
|
||||
// If the original matching result is null, Skip the filtering step
|
||||
if (pQuery.Count > 0 && pTrain.Count > 0)
|
||||
{
|
||||
var hMat = Cv2.FindHomography(pQuery, pTrain, HomographyMethods.Ransac, mask: outMask);
|
||||
speedTimer.Record("FindHomography");
|
||||
|
||||
var objCorners = new Point2f[4];
|
||||
objCorners[0] = new Point2f(0, 0);
|
||||
objCorners[1] = new Point2f(0, queryMat.Rows);
|
||||
objCorners[2] = new Point2f(queryMat.Cols, queryMat.Rows);
|
||||
objCorners[3] = new Point2f(queryMat.Cols, 0);
|
||||
|
||||
var sceneCorners = Cv2.PerspectiveTransform(objCorners, hMat);
|
||||
speedTimer.Record("PerspectiveTransform");
|
||||
speedTimer.DebugPrint();
|
||||
return sceneCorners;
|
||||
}
|
||||
|
||||
speedTimer.DebugPrint();
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// knn的方式匹配
|
||||
/// </summary>
|
||||
/// <param name="matSrc"></param>
|
||||
/// <returns></returns>
|
||||
[Obsolete]
|
||||
public Point2f[]? KnnMatch(Mat matSrc)
|
||||
{
|
||||
SpeedTimer speedTimer = new();
|
||||
|
||||
using var matSrcRet = new Mat();
|
||||
KeyPoint[] keyPointsSrc;
|
||||
using (var surf = SURF.Create(_threshold, 4, 3, false, true))
|
||||
{
|
||||
surf.DetectAndCompute(matSrc, null, out keyPointsSrc, matSrcRet);
|
||||
speedTimer.Record("模板生成KeyPoint");
|
||||
}
|
||||
|
||||
using var flnMatcher = new FlannBasedMatcher();
|
||||
var knnMatches = flnMatcher.KnnMatch(matSrcRet, _trainRet, 2);
|
||||
var minRatio = 0.66;
|
||||
|
||||
var pointsSrc = new List<Point2f>();
|
||||
var pointsDst = new List<Point2f>();
|
||||
//Screening better matching points
|
||||
// var goodMatches = new List<DMatch>();
|
||||
for (int i = 0; i < knnMatches.Length; i++)
|
||||
{
|
||||
var best = knnMatches[i][0];
|
||||
var better = knnMatches[i][1];
|
||||
var r = best.Distance / better.Distance;
|
||||
if (r > minRatio)
|
||||
{
|
||||
pointsSrc.Add(keyPointsSrc[best.QueryIdx].Pt);
|
||||
pointsDst.Add(_trainKeyPoints[best.TrainIdx].Pt);
|
||||
}
|
||||
}
|
||||
|
||||
speedTimer.Record("FlannMatch.KnnMatch");
|
||||
|
||||
// var outMat = new Mat();
|
||||
|
||||
// algorithm RANSAC Filter the matched results
|
||||
var pSrc = pointsSrc.ToPoint2d();
|
||||
var pDst = pointsDst.ToPoint2d();
|
||||
var outMask = new Mat();
|
||||
// If the original matching result is null, Skip the filtering step
|
||||
if (pSrc.Count > 0 && pDst.Count > 0)
|
||||
{
|
||||
var hMat = Cv2.FindHomography(pSrc, pDst, HomographyMethods.Ransac, mask: outMask);
|
||||
speedTimer.Record("FindHomography");
|
||||
|
||||
var objCorners = new Point2f[4];
|
||||
objCorners[0] = new Point2f(0, 0);
|
||||
objCorners[1] = new Point2f(0, matSrc.Rows);
|
||||
objCorners[2] = new Point2f(matSrc.Cols, matSrc.Rows);
|
||||
objCorners[3] = new Point2f(matSrc.Cols, 0);
|
||||
|
||||
var sceneCorners = Cv2.PerspectiveTransform(objCorners, hMat);
|
||||
speedTimer.Record("PerspectiveTransform");
|
||||
speedTimer.DebugPrint();
|
||||
return sceneCorners;
|
||||
}
|
||||
|
||||
speedTimer.DebugPrint();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,124 +0,0 @@
|
||||
using BetterGenshinImpact.Core.Config;
|
||||
using BetterGenshinImpact.Helpers;
|
||||
using OpenCvSharp;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Recognition.OpenCv.FeatureMatch;
|
||||
|
||||
public class FeatureStorage(string name)
|
||||
{
|
||||
private readonly string rootPath = Global.Absolute(@"User\Map\");
|
||||
|
||||
public void SetType(Feature2DType type)
|
||||
{
|
||||
TypeName = type.ToString();
|
||||
}
|
||||
|
||||
public string TypeName { get; set; } = "UNKNOWN";
|
||||
|
||||
public KeyPoint[]? LoadKeyPointArray()
|
||||
{
|
||||
CreateFolder();
|
||||
string kpPath = Path.Combine(rootPath, $"{name}_{TypeName}.kp");
|
||||
if (File.Exists(kpPath))
|
||||
{
|
||||
return ObjectUtils.Deserialize(File.ReadAllBytes(kpPath)) as KeyPoint[];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void SaveKeyPointArray(KeyPoint[] kpArray)
|
||||
{
|
||||
CreateFolder();
|
||||
string kpPath = Path.Combine(rootPath, $"{name}_{TypeName}.kp");
|
||||
File.WriteAllBytes(kpPath, ObjectUtils.Serialize(kpArray));
|
||||
}
|
||||
|
||||
private void CreateFolder()
|
||||
{
|
||||
if (Directory.Exists(rootPath) == false)
|
||||
{
|
||||
Directory.CreateDirectory(rootPath);
|
||||
}
|
||||
}
|
||||
|
||||
public Mat? LoadDescMat1()
|
||||
{
|
||||
CreateFolder();
|
||||
// 格式: Surf_336767x128.mat
|
||||
var files = Directory.GetFiles(rootPath, $"{name}_{TypeName}_*.mat", SearchOption.AllDirectories);
|
||||
if (files.Length == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else if (files.Length > 1)
|
||||
{
|
||||
Debug.WriteLine($"[FeatureSerializer] Found multiple files: {string.Join(", ", files)}");
|
||||
}
|
||||
var rowColPair = Path.GetFileNameWithoutExtension(files[0])
|
||||
.Replace($"{name}_{TypeName}_", "")
|
||||
.Split('x');
|
||||
if (rowColPair.Length != 2)
|
||||
{
|
||||
Debug.WriteLine($"[FeatureSerializer] Invalid file name: {files[0]}");
|
||||
return null;
|
||||
}
|
||||
GCHandle pinnedArray = GCHandle.Alloc(ObjectUtils.Deserialize(File.ReadAllBytes(files[0])), GCHandleType.Pinned);
|
||||
IntPtr pointer = pinnedArray.AddrOfPinnedObject();
|
||||
return new Mat(Convert.ToInt32(rowColPair[0]), Convert.ToInt32(rowColPair[1]), MatType.CV_32FC1, pointer);
|
||||
}
|
||||
|
||||
public Mat? LoadDescMat()
|
||||
{
|
||||
CreateFolder();
|
||||
var files = Directory.GetFiles(rootPath, $"{name}_{TypeName}.mat", SearchOption.AllDirectories);
|
||||
if (files.Length == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else if (files.Length > 1)
|
||||
{
|
||||
Debug.WriteLine($"[FeatureSerializer] Found multiple files: {string.Join(", ", files)}");
|
||||
}
|
||||
FileStorage fs = new(files[0], FileStorage.Modes.Read);
|
||||
var mat = fs["desc"]?.ReadMat();
|
||||
fs.Release();
|
||||
return mat;
|
||||
}
|
||||
|
||||
public void SaveDescMat1(Mat descMat)
|
||||
{
|
||||
CreateFolder();
|
||||
// 删除旧文件
|
||||
var files = Directory.GetFiles(rootPath, $"{name}_{TypeName}_*.mat", SearchOption.AllDirectories);
|
||||
foreach (var file in files)
|
||||
{
|
||||
File.Delete(file);
|
||||
}
|
||||
|
||||
var descPath = Path.Combine(rootPath, $"{name}_{TypeName}_{descMat.Rows}x{descMat.Cols}.mat");
|
||||
var bytes = new byte[descMat.Step(0) * descMat.Rows]; // matSrcRet.Total() * matSrcRet.ElemSize()
|
||||
Marshal.Copy(descMat.Data, bytes, 0, bytes.Length);
|
||||
File.WriteAllBytes(descPath, ObjectUtils.Serialize(bytes));
|
||||
}
|
||||
|
||||
public void SaveDescMat(Mat descMat)
|
||||
{
|
||||
CreateFolder();
|
||||
// 删除旧文件
|
||||
var fileName = $"{name}_{TypeName}.mat";
|
||||
var files = Directory.GetFiles(rootPath, fileName, SearchOption.AllDirectories);
|
||||
foreach (var file in files)
|
||||
{
|
||||
File.Delete(file);
|
||||
}
|
||||
|
||||
var descPath = Path.Combine(rootPath, fileName);
|
||||
FileStorage fs = new(descPath, FileStorage.Modes.Write);
|
||||
fs.Write("desc", descMat);
|
||||
fs.Release();
|
||||
}
|
||||
}
|
||||
@@ -1,190 +0,0 @@
|
||||
using BetterGenshinImpact.Core.Recognition.OpenCv.Model;
|
||||
using OpenCvSharp;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Recognition.OpenCv.FeatureMatch;
|
||||
|
||||
public class KeyPointFeatureBlockHelper
|
||||
{
|
||||
public static KeyPointFeatureBlock[][] SplitFeatures(Mat originalImage, int rows, int cols, KeyPoint[] keyPoints, Mat matches)
|
||||
{
|
||||
var matchesCols = matches.Cols; // SURF 64 SIFT 128
|
||||
// Calculate grid size
|
||||
int cellWidth = originalImage.Width / cols;
|
||||
int cellHeight = originalImage.Height / rows;
|
||||
|
||||
// Initialize arrays to store split features and matches
|
||||
var splitKeyPoints = new KeyPointFeatureBlock[rows][];
|
||||
|
||||
// Initialize each row
|
||||
for (int i = 0; i < rows; i++)
|
||||
{
|
||||
splitKeyPoints[i] = new KeyPointFeatureBlock[cols];
|
||||
}
|
||||
|
||||
// Split features and matches
|
||||
for (int i = 0; i < keyPoints.Length; i++)
|
||||
{
|
||||
int row = (int)(keyPoints[i].Pt.Y / cellHeight);
|
||||
int col = (int)(keyPoints[i].Pt.X / cellWidth);
|
||||
|
||||
// Ensure row and col are within bounds
|
||||
row = Math.Min(Math.Max(row, 0), rows - 1);
|
||||
col = Math.Min(Math.Max(col, 0), cols - 1);
|
||||
|
||||
// ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
|
||||
if (splitKeyPoints[row][col] == null)
|
||||
{
|
||||
splitKeyPoints[row][col] = new KeyPointFeatureBlock();
|
||||
}
|
||||
|
||||
splitKeyPoints[row][col].KeyPointList.Add(keyPoints[i]);
|
||||
splitKeyPoints[row][col].KeyPointIndexList.Add(i);
|
||||
}
|
||||
|
||||
// 遍历每个特征块,计算描述子
|
||||
for (int i = 0; i < rows; i++)
|
||||
{
|
||||
for (int j = 0; j < cols; j++)
|
||||
{
|
||||
// ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
|
||||
if (splitKeyPoints[i][j] == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var block = splitKeyPoints[i][j];
|
||||
|
||||
var descriptor = new Mat(block.KeyPointIndexList.Count, matchesCols, MatType.CV_32FC1);
|
||||
InitBlockMat(block.KeyPointIndexList, descriptor, matches);
|
||||
|
||||
block.Descriptor = descriptor;
|
||||
}
|
||||
}
|
||||
|
||||
return splitKeyPoints;
|
||||
}
|
||||
|
||||
public static (int, int) GetCellIndex(Mat originalImage, int rows, int cols, int x, int y)
|
||||
{
|
||||
// Calculate grid size
|
||||
int cellWidth = originalImage.Width / cols;
|
||||
int cellHeight = originalImage.Height / rows;
|
||||
|
||||
// Calculate cell index for the given point
|
||||
int cellRow = y / cellHeight;
|
||||
int cellCol = x / cellWidth;
|
||||
|
||||
return (cellRow, cellCol);
|
||||
}
|
||||
|
||||
public static KeyPointFeatureBlock MergeNeighboringFeatures(KeyPointFeatureBlock[][] splitKeyPoints, Mat matches, int cellRow, int cellCol)
|
||||
{
|
||||
var matchesCols = matches.Cols; // SURF 64 SIFT 128
|
||||
// Initialize lists to store neighboring features and matches
|
||||
var neighboringKeyPoints = new List<KeyPoint>();
|
||||
var neighboringKeyPointIndices = new List<int>();
|
||||
|
||||
// Loop through 9 neighboring cells
|
||||
for (int i = Math.Max(cellRow - 1, 0); i <= Math.Min(cellRow + 1, splitKeyPoints.Length - 1); i++)
|
||||
{
|
||||
for (int j = Math.Max(cellCol - 1, 0); j <= Math.Min(cellCol + 1, splitKeyPoints[i].Length - 1); j++)
|
||||
{
|
||||
// ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
|
||||
if (splitKeyPoints[i][j] != null)
|
||||
{
|
||||
neighboringKeyPoints.AddRange(splitKeyPoints[i][j].KeyPointList);
|
||||
neighboringKeyPointIndices.AddRange(splitKeyPoints[i][j].KeyPointIndexList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Merge neighboring features
|
||||
var mergedKeyPointBlock = new KeyPointFeatureBlock
|
||||
{
|
||||
MergedCenterCellCol = cellCol,
|
||||
MergedCenterCellRow = cellRow,
|
||||
KeyPointList = neighboringKeyPoints,
|
||||
KeyPointIndexList = neighboringKeyPointIndices
|
||||
};
|
||||
mergedKeyPointBlock.Descriptor = new Mat(mergedKeyPointBlock.KeyPointIndexList.Count, matchesCols, MatType.CV_32FC1);
|
||||
InitBlockMat(mergedKeyPointBlock.KeyPointIndexList, mergedKeyPointBlock.Descriptor, matches);
|
||||
|
||||
return mergedKeyPointBlock;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 按行拷贝matches到descriptor
|
||||
/// </summary>
|
||||
/// <param name="keyPointIndexList">记录了哪些行需要拷贝</param>
|
||||
/// <param name="descriptor">拷贝结果</param>
|
||||
/// <param name="matches">原始数据</param>
|
||||
private static unsafe void InitBlockMat(List<int> keyPointIndexList, Mat descriptor, Mat matches)
|
||||
{
|
||||
Size size = matches.Size();
|
||||
|
||||
Matrix<float> destMatrix = new(descriptor.DataPointer, size.Width, size.Height);
|
||||
Matrix<float> sourceMatrix = new(matches.DataPointer, size.Width, size.Height);
|
||||
|
||||
Span<int> keyPointIndexSpan = CollectionsMarshal.AsSpan(keyPointIndexList);
|
||||
ref int keyPointIndexRef = ref MemoryMarshal.GetReference(keyPointIndexSpan);
|
||||
for (int i = 0; i < keyPointIndexSpan.Length; i++)
|
||||
{
|
||||
ref int index = ref Unsafe.Add(ref keyPointIndexRef, i);
|
||||
sourceMatrix[index].CopyTo(destMatrix[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private readonly ref struct Matrix<T>
|
||||
{
|
||||
private readonly ref T reference;
|
||||
private readonly int width;
|
||||
private readonly int height;
|
||||
|
||||
public unsafe Matrix(void* pointer, int width, int height)
|
||||
{
|
||||
reference = ref Unsafe.AsRef<T>(pointer);
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public Span<T> this[int row]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (row < 0 || row >= height)
|
||||
{
|
||||
throw new IndexOutOfRangeException();
|
||||
}
|
||||
|
||||
return MemoryMarshal.CreateSpan(ref Unsafe.Add(ref reference, row * width), width);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 按行拷贝matches到descriptor
|
||||
/// </summary>
|
||||
/// <param name="keyPointIndexList">记录了哪些行需要拷贝</param>
|
||||
/// <param name="descriptor">拷贝结果</param>
|
||||
/// <param name="matches">原始数据</param>
|
||||
[Obsolete]
|
||||
private static unsafe void InitBlockMat2(IReadOnlyList<int> keyPointIndexList, Mat descriptor, Mat matches)
|
||||
{
|
||||
int cols = matches.Cols;
|
||||
float* ptrDest = (float*)descriptor.DataPointer;
|
||||
|
||||
for (int i = 0; i < keyPointIndexList.Count; i++)
|
||||
{
|
||||
var index = keyPointIndexList[i];
|
||||
float* ptrSrcRow = (float*)matches.Ptr(index);
|
||||
for (int j = 0; j < cols; j++)
|
||||
{
|
||||
*(ptrDest + i * cols + j) = ptrSrcRow[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,244 +0,0 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using OpenCvSharp;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Recognition.OpenCv;
|
||||
|
||||
/// <summary>
|
||||
/// 多目标模板匹配demo
|
||||
/// https://github.com/shimat/opencvsharp/issues/182
|
||||
/// </summary>
|
||||
public class MatchTemplateHelper
|
||||
{
|
||||
private static readonly ILogger<MatchTemplateHelper> _logger = App.GetLogger<MatchTemplateHelper>();
|
||||
|
||||
/// <summary>
|
||||
/// 模板匹配
|
||||
/// </summary>
|
||||
/// <param name="srcMat">原图像</param>
|
||||
/// <param name="dstMat">模板</param>
|
||||
/// <param name="matchMode">匹配方式</param>
|
||||
/// <param name="maskMat">遮罩</param>
|
||||
/// <param name="threshold">阈值</param>
|
||||
/// <returns>左上角的标点,由于(0,0)点作为未匹配的结果,所以不能做完全相同的模板匹配</returns>
|
||||
public static Point MatchTemplate(Mat srcMat, Mat dstMat, TemplateMatchModes matchMode, Mat? maskMat = null, double threshold = 0.8)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var result = new Mat();
|
||||
Cv2.MatchTemplate(srcMat, dstMat, result, matchMode, maskMat!);
|
||||
|
||||
if (matchMode is TemplateMatchModes.SqDiff or TemplateMatchModes.CCoeff or TemplateMatchModes.CCorr)
|
||||
{
|
||||
Cv2.Normalize(result, result, 0, 1, NormTypes.MinMax);
|
||||
}
|
||||
|
||||
Cv2.MinMaxLoc(result, out var minValue, out var maxValue, out var minLoc, out var maxLoc);
|
||||
|
||||
if (matchMode is TemplateMatchModes.SqDiff or TemplateMatchModes.SqDiffNormed)
|
||||
{
|
||||
if (minValue <= 1 - threshold)
|
||||
{
|
||||
return minLoc;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (maxValue >= threshold)
|
||||
{
|
||||
return maxLoc;
|
||||
}
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex.Message);
|
||||
_logger.LogDebug(ex, ex.Message);
|
||||
return default;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 模板匹配多个结果
|
||||
/// 不好用
|
||||
/// </summary>
|
||||
/// <param name="srcMat"></param>
|
||||
/// <param name="dstMat"></param>
|
||||
/// <param name="maskMat"></param>
|
||||
/// <param name="threshold"></param>
|
||||
/// <param name="maxCount"></param>
|
||||
/// <returns></returns>
|
||||
[Obsolete]
|
||||
public static List<Point> MatchTemplateMulti(Mat srcMat, Mat dstMat, Mat? maskMat = null, double threshold = 0.8, int maxCount = 8)
|
||||
{
|
||||
var points = new List<Point>();
|
||||
try
|
||||
{
|
||||
using var result = new Mat();
|
||||
Cv2.MatchTemplate(srcMat, dstMat, result, TemplateMatchModes.CCoeffNormed, maskMat!);
|
||||
|
||||
var mask = new Mat(result.Height, result.Width, MatType.CV_8UC1, Scalar.White);
|
||||
var maskSub = new Mat(result.Height, result.Width, MatType.CV_8UC1, Scalar.Black);
|
||||
while (true)
|
||||
{
|
||||
Cv2.MinMaxLoc(result, out _, out var maxValue, out _, out var maxLoc, mask);
|
||||
var maskRect = new Rect(maxLoc.X, maxLoc.Y, dstMat.Width, dstMat.Height);
|
||||
maskSub.Rectangle(maskRect, Scalar.White, -1);
|
||||
mask -= maskSub;
|
||||
if (maxValue >= threshold)
|
||||
points.Add(maxLoc);
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
return points;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex.Message);
|
||||
_logger.LogDebug(ex, ex.Message);
|
||||
return points;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<Point> MatchTemplateMulti(Mat srcMat, Mat dstMat, double threshold)
|
||||
{
|
||||
return MatchTemplateMulti(srcMat, dstMat, null, threshold);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在一张图中查找多个模板
|
||||
/// 查到一个遮盖一个的笨方法,效率很低,但是很准确
|
||||
/// </summary>
|
||||
/// <param name="srcMat"></param>
|
||||
/// <param name="imgSubDictionary"></param>
|
||||
/// <param name="threshold"></param>
|
||||
/// <returns></returns>
|
||||
public static Dictionary<string, List<Point>> MatchMultiPicForOnePic(Mat srcMat, Dictionary<string, Mat> imgSubDictionary, double threshold = 0.8)
|
||||
{
|
||||
var dictionary = new Dictionary<string, List<Point>>();
|
||||
foreach (var kvp in imgSubDictionary)
|
||||
{
|
||||
var list = new List<Point>();
|
||||
|
||||
while (true)
|
||||
{
|
||||
var point = MatchTemplate(srcMat, kvp.Value, TemplateMatchModes.CCoeffNormed, null, threshold);
|
||||
if (point != new Point())
|
||||
{
|
||||
// 把结果给遮掩掉,避免重复识别
|
||||
Cv2.Rectangle(srcMat, point, new Point(point.X + kvp.Value.Width, point.Y + kvp.Value.Height), Scalar.Black, -1);
|
||||
list.Add(point);
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
dictionary.Add(kvp.Key, list);
|
||||
}
|
||||
|
||||
return dictionary;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在一张图中查找多个模板
|
||||
/// 查到一个遮盖一个的笨方法,效率很低,但是很准确
|
||||
/// </summary>
|
||||
/// <param name="srcMat"></param>
|
||||
/// <param name="imgSubList"></param>
|
||||
/// <param name="threshold"></param>
|
||||
/// <returns></returns>
|
||||
public static List<Rect> MatchMultiPicForOnePic(Mat srcMat, List<Mat> imgSubList, double threshold = 0.8)
|
||||
{
|
||||
List<Rect> list = new();
|
||||
foreach (var sub in imgSubList)
|
||||
while (true)
|
||||
{
|
||||
var point = MatchTemplate(srcMat, sub, TemplateMatchModes.CCoeffNormed, null, threshold);
|
||||
if (point != new Point())
|
||||
{
|
||||
// 把结果给遮掩掉,避免重复识别
|
||||
Cv2.Rectangle(srcMat, point, new Point(point.X + sub.Width, point.Y + sub.Height), Scalar.Black, -1);
|
||||
list.Add(new Rect(point.X, point.Y, sub.Width, sub.Height));
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在一张图中查找一个个模板
|
||||
/// </summary>
|
||||
/// <param name="srcMat"></param>
|
||||
/// <param name="dstMat"></param>
|
||||
/// <param name="maskMat"></param>
|
||||
/// <param name="threshold"></param>
|
||||
/// <returns></returns>
|
||||
public static List<Rect> MatchOnePicForOnePic(Mat srcMat, Mat dstMat, Mat? maskMat = null, double threshold = 0.8)
|
||||
{
|
||||
List<Rect> list = new();
|
||||
|
||||
while (true)
|
||||
{
|
||||
var point = MatchTemplate(srcMat, dstMat, TemplateMatchModes.CCoeffNormed, maskMat, threshold);
|
||||
if (point != new Point())
|
||||
{
|
||||
// 把结果给遮掩掉,避免重复识别
|
||||
Cv2.Rectangle(srcMat, point, new Point(point.X + dstMat.Width, point.Y + dstMat.Height), Scalar.Black, -1);
|
||||
list.Add(new Rect(point.X, point.Y, dstMat.Width, dstMat.Height));
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在一张图中查找一个个模板
|
||||
/// </summary>
|
||||
/// <param name="srcMat"></param>
|
||||
/// <param name="dstMat"></param>
|
||||
/// <param name="matchMode"></param>
|
||||
/// <param name="maskMat"></param>
|
||||
/// <param name="threshold"></param>
|
||||
/// <param name="maxCount"></param>
|
||||
/// <returns></returns>
|
||||
public static List<Rect> MatchOnePicForOnePic(Mat srcMat, Mat dstMat, TemplateMatchModes matchMode, Mat? maskMat, double threshold, int maxCount = -1)
|
||||
{
|
||||
List<Rect> list = new();
|
||||
|
||||
if (maxCount < 0)
|
||||
{
|
||||
maxCount = srcMat.Width * srcMat.Height / dstMat.Width / dstMat.Height;
|
||||
}
|
||||
|
||||
for (int i = 0; i < maxCount; i++)
|
||||
{
|
||||
var point = MatchTemplate(srcMat, dstMat, matchMode, maskMat, threshold);
|
||||
if (point != new Point())
|
||||
{
|
||||
// 把结果给遮掩掉,避免重复识别
|
||||
Cv2.Rectangle(srcMat, point, new Point(point.X + dstMat.Width, point.Y + dstMat.Height), Scalar.Black, -1);
|
||||
list.Add(new Rect(point.X, point.Y, dstMat.Width, dstMat.Height));
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using OpenCvSharp;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Recognition.OpenCv.Model;
|
||||
|
||||
/// <summary>
|
||||
/// 特征块
|
||||
/// 对特征按图像区域进行划分
|
||||
/// </summary>
|
||||
public class KeyPointFeatureBlock
|
||||
{
|
||||
public List<KeyPoint> KeyPointList { get; set; } = new();
|
||||
|
||||
private KeyPoint[]? keyPointArray;
|
||||
|
||||
public KeyPoint[] KeyPointArray
|
||||
{
|
||||
get
|
||||
{
|
||||
keyPointArray ??= [.. KeyPointList];
|
||||
return keyPointArray;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在完整 KeyPoint[] 中的下标
|
||||
/// </summary>
|
||||
public List<int> KeyPointIndexList { get; set; } = new();
|
||||
|
||||
public Mat? Descriptor;
|
||||
|
||||
public int MergedCenterCellCol = -1;
|
||||
public int MergedCenterCellRow = -1;
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
using OpenCvSharp;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Recognition.OpenCv;
|
||||
|
||||
public class OpenCvCommonHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 计算灰度图中某个颜色的像素个数
|
||||
/// 快速遍历方法来自于: https://blog.csdn.net/TyroneKing/article/details/129108838
|
||||
/// </summary>
|
||||
/// <param name="mat"></param>
|
||||
/// <param name="color"></param>
|
||||
/// <returns></returns>
|
||||
public static int CountGrayMatColor(Mat mat, byte color)
|
||||
{
|
||||
Debug.Assert(mat.Depth() == MatType.CV_8U);
|
||||
var channels = mat.Channels();
|
||||
var nRows = mat.Rows;
|
||||
var nCols = mat.Cols * channels;
|
||||
if (mat.IsContinuous())
|
||||
{
|
||||
nCols *= nRows;
|
||||
nRows = 1;
|
||||
}
|
||||
|
||||
var sum = 0;
|
||||
unsafe
|
||||
{
|
||||
for (var i = 0; i < nRows; i++)
|
||||
{
|
||||
var p = mat.Ptr(i);
|
||||
var b = (byte*)p.ToPointer();
|
||||
for (var j = 0; j < nCols; j++)
|
||||
if (b[j] == color)
|
||||
sum++;
|
||||
}
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static int CountGrayMatColor(Mat mat, byte lowColor, byte highColor)
|
||||
{
|
||||
Debug.Assert(mat.Depth() == MatType.CV_8U);
|
||||
var channels = mat.Channels();
|
||||
var nRows = mat.Rows;
|
||||
var nCols = mat.Cols * channels;
|
||||
if (mat.IsContinuous())
|
||||
{
|
||||
nCols *= nRows;
|
||||
nRows = 1;
|
||||
}
|
||||
|
||||
var sum = 0;
|
||||
unsafe
|
||||
{
|
||||
for (var i = 0; i < nRows; i++)
|
||||
{
|
||||
var p = mat.Ptr(i);
|
||||
var b = (byte*)p.ToPointer();
|
||||
for (var j = 0; j < nCols; j++)
|
||||
if (b[j] >= lowColor && b[j] <= highColor)
|
||||
sum++;
|
||||
}
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static Mat Threshold(Mat src, Scalar low, Scalar high)
|
||||
{
|
||||
using var mask = new Mat();
|
||||
using var rgbMat = new Mat();
|
||||
|
||||
Cv2.CvtColor(src, rgbMat, ColorConversionCodes.BGR2RGB);
|
||||
Cv2.InRange(rgbMat, low, high, mask);
|
||||
Cv2.Threshold(mask, mask, 0, 255, ThresholdTypes.Binary); //二值化
|
||||
return mask.Clone();
|
||||
}
|
||||
|
||||
public static Mat InRangeHsv(Mat src, Scalar low, Scalar high)
|
||||
{
|
||||
using var mask = new Mat();
|
||||
using var rgbMat = new Mat();
|
||||
|
||||
Cv2.CvtColor(src, rgbMat, ColorConversionCodes.BGR2HSV);
|
||||
Cv2.InRange(rgbMat, low, high, mask);
|
||||
return mask.Clone();
|
||||
}
|
||||
|
||||
public static Mat Threshold(Mat src, Scalar s)
|
||||
{
|
||||
return Threshold(src, s, s);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 和二值化的颜色刚好相反
|
||||
/// </summary>
|
||||
/// <param name="src"></param>
|
||||
/// <param name="s"></param>
|
||||
/// <returns></returns>
|
||||
public static Mat CreateMask(Mat src, Scalar s)
|
||||
{
|
||||
var mask = new Mat();
|
||||
Cv2.InRange(src, s, s, mask);
|
||||
return 255 - mask;
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
using OpenCvSharp;
|
||||
using System;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Recognition.OpenCv;
|
||||
|
||||
public class ResizeHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 等比放大的
|
||||
/// </summary>
|
||||
/// <param name="src"></param>
|
||||
/// <param name="scale"></param>
|
||||
/// <returns></returns>
|
||||
public static Mat Resize(Mat src, double scale)
|
||||
{
|
||||
if (Math.Abs(scale - 1) > 0.00001)
|
||||
{
|
||||
return Resize(src, scale, scale);
|
||||
}
|
||||
return src;
|
||||
}
|
||||
|
||||
public static Mat Resize(Mat src, double widthScale, double heightScale)
|
||||
{
|
||||
if (Math.Abs(widthScale - 1) > 0.00001 || Math.Abs(heightScale - 1) > 0.00001)
|
||||
{
|
||||
var dst = new Mat();
|
||||
Cv2.Resize(src, dst, new Size(src.Width * widthScale, src.Height * heightScale));
|
||||
return dst;
|
||||
}
|
||||
|
||||
return src;
|
||||
}
|
||||
|
||||
public static Mat ResizeTo(Mat src, int width, int height)
|
||||
{
|
||||
if (src.Width != width || src.Height != height)
|
||||
{
|
||||
var dst = new Mat();
|
||||
Cv2.Resize(src, dst, new Size(width, height));
|
||||
return dst;
|
||||
}
|
||||
|
||||
return src;
|
||||
}
|
||||
}
|
||||
@@ -1,148 +0,0 @@
|
||||
using BetterGenshinImpact.Core.Recognition.OpenCv;
|
||||
using BetterGenshinImpact.Helpers.Extensions;
|
||||
using OpenCvSharp;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Recognition;
|
||||
|
||||
/// <summary>
|
||||
/// 识别对象
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class RecognitionObject
|
||||
{
|
||||
public RecognitionTypes RecognitionType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 感兴趣的区域
|
||||
/// </summary>
|
||||
public Rect RegionOfInterest { get; set; }
|
||||
|
||||
public string? Name { get; set; }
|
||||
|
||||
#region 模板匹配
|
||||
|
||||
/// <summary>
|
||||
/// 模板匹配的对象(彩色)
|
||||
/// </summary>
|
||||
public Mat? TemplateImageMat { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 模板匹配的对象(灰色)
|
||||
/// </summary>
|
||||
public Mat? TemplateImageGreyMat { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 模板匹配阈值。可选,默认 0.8 。
|
||||
/// </summary>
|
||||
public double Threshold { get; set; } = 0.8;
|
||||
|
||||
/// <summary>
|
||||
/// 是否使用 3 通道匹配。可选,默认 false 。
|
||||
/// </summary>
|
||||
public bool Use3Channels { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 模板匹配算法。可选,默认 CCoeffNormed 。
|
||||
/// https://docs.opencv.org/4.x/df/dfb/group__imgproc__object.html
|
||||
/// </summary>
|
||||
public TemplateMatchModes TemplateMatchMode { get; set; } = TemplateMatchModes.CCoeffNormed;
|
||||
|
||||
/// <summary>
|
||||
/// 匹配模板遮罩,指定图片中的某种色彩不需要匹配
|
||||
/// 使用时,需要将模板图片的背景色设置为纯绿色,即 (0, 255, 0)
|
||||
/// </summary>
|
||||
public bool UseMask { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 不需要匹配的颜色,默认绿色
|
||||
/// UseMask = true 的时候有用
|
||||
/// </summary>
|
||||
public Color MaskColor { get; set; } = Color.FromArgb(0, 255, 0);
|
||||
|
||||
public Mat? MaskMat { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 匹配成功时,是否在屏幕上绘制矩形框。可选,默认 false 。
|
||||
/// true 时 Name 必须有值。
|
||||
/// </summary>
|
||||
public bool DrawOnWindow { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// DrawOnWindow 为 true 时,绘制的矩形框的颜色。可选,默认红色。
|
||||
/// </summary>
|
||||
public Pen DrawOnWindowPen = new(Color.Red, 2);
|
||||
|
||||
/// <summary>
|
||||
/// 一个模板匹配多个结果的时候最大匹配数量。可选,默认 -1,即不限制。
|
||||
/// </summary>
|
||||
public int MaxMatchCount { get; set; } = -1;
|
||||
|
||||
public RecognitionObject InitTemplate()
|
||||
{
|
||||
if (TemplateImageMat != null && TemplateImageGreyMat == null)
|
||||
{
|
||||
TemplateImageGreyMat = new Mat();
|
||||
Cv2.CvtColor(TemplateImageMat, TemplateImageGreyMat, ColorConversionCodes.BGR2GRAY);
|
||||
}
|
||||
|
||||
if (UseMask && TemplateImageMat != null && MaskMat == null) MaskMat = OpenCvCommonHelper.CreateMask(TemplateImageMat, MaskColor.ToScalar());
|
||||
return this;
|
||||
}
|
||||
|
||||
#endregion 模板匹配
|
||||
|
||||
#region 颜色匹配
|
||||
|
||||
/// <summary>
|
||||
/// 颜色匹配方式。即 cv::ColorConversionCodes。可选,默认 4 (RGB)。
|
||||
/// 常用值:4 (RGB, 3 通道), 40 (HSV, 3 通道), 6 (GRAY, 1 通道)。
|
||||
/// https://docs.opencv.org/4.x/d8/d01/group__imgproc__color__conversions.html
|
||||
/// </summary>
|
||||
public ColorConversionCodes ColorConversionCode { get; set; } = ColorConversionCodes.BGR2RGB;
|
||||
|
||||
public Scalar LowerColor { get; set; }
|
||||
public Scalar UpperColor { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 符合的点的数量要求。可选,默认 1
|
||||
/// </summary>
|
||||
public int MatchCount { get; set; } = 1;
|
||||
|
||||
#endregion 颜色匹配
|
||||
|
||||
#region OCR文字识别
|
||||
|
||||
/// <summary>
|
||||
/// OCR 引擎。可选,只有 Paddle。
|
||||
/// </summary>
|
||||
public OcrEngineTypes OcrEngine { get; set; } = OcrEngineTypes.Paddle;
|
||||
|
||||
/// <summary>
|
||||
/// 部分文字识别结果不准确,进行替换。可选。
|
||||
/// </summary>
|
||||
public Dictionary<string, string[]> ReplaceDictionary { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// 包含匹配
|
||||
/// 多个值全匹配的情况下才算成功
|
||||
/// 复杂情况请用下面的正则匹配
|
||||
/// </summary>
|
||||
public List<string> AllContainMatchText { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// 包含匹配
|
||||
/// 一个值匹配就算成功
|
||||
/// </summary>
|
||||
public List<string> OneContainMatchText { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// 正则匹配
|
||||
/// 多个值全匹配的情况下才算成功
|
||||
/// </summary>
|
||||
public List<string> RegexMatchText { get; set; } = new();
|
||||
|
||||
#endregion OCR文字识别
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
namespace BetterGenshinImpact.Core.Recognition;
|
||||
|
||||
public enum RecognitionTypes
|
||||
{
|
||||
None,
|
||||
TemplateMatch, // 模板匹配
|
||||
ColorMatch, // 颜色匹配
|
||||
OcrMatch, // 文字识别并匹配
|
||||
Ocr, // 仅文字识别
|
||||
ColorRangeAndOcr, // 提取指定颜色后进行文字识别
|
||||
Detect
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
using BetterGenshinImpact.Helpers;
|
||||
using System.Threading;
|
||||
using System.Windows;
|
||||
using Vanara.PInvoke;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Simulator;
|
||||
|
||||
public class MouseEventSimulator
|
||||
{
|
||||
public void Move(int x, int y)
|
||||
{
|
||||
User32.mouse_event(User32.MOUSEEVENTF.MOUSEEVENTF_ABSOLUTE | User32.MOUSEEVENTF.MOUSEEVENTF_MOVE,
|
||||
x * 65535 / PrimaryScreen.WorkingArea.Width, y * 65535 / PrimaryScreen.WorkingArea.Height,
|
||||
0, 0);
|
||||
}
|
||||
|
||||
public void MoveAbsolute(int x, int y)
|
||||
{
|
||||
User32.mouse_event(User32.MOUSEEVENTF.MOUSEEVENTF_ABSOLUTE | User32.MOUSEEVENTF.MOUSEEVENTF_MOVE,
|
||||
x, y, 0, 0);
|
||||
}
|
||||
|
||||
public void LeftButtonDown()
|
||||
{
|
||||
User32.mouse_event(User32.MOUSEEVENTF.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
public void LeftButtonUp()
|
||||
{
|
||||
User32.mouse_event(User32.MOUSEEVENTF.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
public bool Click(int x, int y)
|
||||
{
|
||||
if (x == 0 && y == 0) return false;
|
||||
|
||||
Move(x, y);
|
||||
LeftButtonDown();
|
||||
Thread.Sleep(20);
|
||||
LeftButtonUp();
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Click(Point point)
|
||||
{
|
||||
return Click((int)point.X, (int)point.Y);
|
||||
}
|
||||
|
||||
public bool DoubleClick(Point point)
|
||||
{
|
||||
Click(point);
|
||||
Thread.Sleep(200);
|
||||
return Click(point);
|
||||
}
|
||||
}
|
||||
@@ -1,180 +0,0 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using Vanara.PInvoke;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Simulator;
|
||||
|
||||
/// <summary>
|
||||
/// 虚拟键代码
|
||||
/// https://learn.microsoft.com/zh-cn/windows/win32/inputdev/virtual-key-codes
|
||||
/// User32.VK.VK_SPACE 键盘空格键
|
||||
/// </summary>
|
||||
public class PostMessageSimulator
|
||||
{
|
||||
public static readonly uint WM_LBUTTONDOWN = 0x201; //按下鼠标左键
|
||||
|
||||
public static readonly uint WM_LBUTTONUP = 0x202; //释放鼠标左键
|
||||
|
||||
public static readonly uint WM_RBUTTONDOWN = 0x204;
|
||||
public static readonly uint WM_RBUTTONUP = 0x205;
|
||||
|
||||
private readonly IntPtr _hWnd;
|
||||
|
||||
public PostMessageSimulator(IntPtr hWnd)
|
||||
{
|
||||
_hWnd = hWnd;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 指定位置并按下左键
|
||||
/// </summary>
|
||||
/// <param name="x"></param>
|
||||
/// <param name="y"></param>
|
||||
public PostMessageSimulator LeftButtonClick(int x, int y)
|
||||
{
|
||||
IntPtr p = (y << 16) | x;
|
||||
User32.PostMessage(_hWnd, WM_LBUTTONDOWN, IntPtr.Zero, p);
|
||||
Thread.Sleep(100);
|
||||
User32.PostMessage(_hWnd, WM_LBUTTONUP, IntPtr.Zero, p);
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 指定位置并按下左键
|
||||
/// </summary>
|
||||
/// <param name="x"></param>
|
||||
/// <param name="y"></param>
|
||||
public PostMessageSimulator LeftButtonClickBackground(int x, int y)
|
||||
{
|
||||
User32.PostMessage(_hWnd, User32.WindowMessage.WM_ACTIVATE, 1, 0);
|
||||
var p = MakeLParam(x, y);
|
||||
User32.PostMessage(_hWnd, WM_LBUTTONDOWN, 1, p);
|
||||
Thread.Sleep(100);
|
||||
User32.PostMessage(_hWnd, WM_LBUTTONUP, 0, p);
|
||||
return this;
|
||||
}
|
||||
|
||||
public static int MakeLParam(int x, int y) => (y << 16) | (x & 0xFFFF);
|
||||
|
||||
public PostMessageSimulator LeftButtonClick()
|
||||
{
|
||||
IntPtr p = (16 << 16) | 16;
|
||||
User32.PostMessage(_hWnd, WM_LBUTTONDOWN, IntPtr.Zero, p);
|
||||
Thread.Sleep(100);
|
||||
User32.PostMessage(_hWnd, WM_LBUTTONUP, IntPtr.Zero, p);
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 默认位置左键按下
|
||||
/// </summary>
|
||||
public PostMessageSimulator LeftButtonDown()
|
||||
{
|
||||
User32.PostMessage(_hWnd, WM_LBUTTONDOWN, IntPtr.Zero);
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 默认位置左键释放
|
||||
/// </summary>
|
||||
public PostMessageSimulator LeftButtonUp()
|
||||
{
|
||||
User32.PostMessage(_hWnd, WM_LBUTTONUP, IntPtr.Zero);
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 默认位置右键按下
|
||||
/// </summary>
|
||||
public PostMessageSimulator RightButtonDown()
|
||||
{
|
||||
User32.PostMessage(_hWnd, WM_RBUTTONDOWN, IntPtr.Zero);
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 默认位置右键释放
|
||||
/// </summary>
|
||||
public PostMessageSimulator RightButtonUp()
|
||||
{
|
||||
User32.PostMessage(_hWnd, WM_RBUTTONUP, IntPtr.Zero);
|
||||
return this;
|
||||
}
|
||||
|
||||
public PostMessageSimulator RightButtonClick()
|
||||
{
|
||||
IntPtr p = (16 << 16) | 16;
|
||||
User32.PostMessage(_hWnd, WM_RBUTTONDOWN, IntPtr.Zero, p);
|
||||
Thread.Sleep(100);
|
||||
User32.PostMessage(_hWnd, WM_RBUTTONUP, IntPtr.Zero, p);
|
||||
return this;
|
||||
}
|
||||
|
||||
public PostMessageSimulator KeyPress(User32.VK vk)
|
||||
{
|
||||
//User32.PostMessage(_hWnd, User32.WindowMessage.WM_ACTIVATE, 1, 0);
|
||||
User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYDOWN, (nint)vk, 0x1e0001);
|
||||
User32.PostMessage(_hWnd, User32.WindowMessage.WM_CHAR, (nint)vk, 0x1e0001);
|
||||
User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYUP, (nint)vk, (nint)0xc01e0001);
|
||||
return this;
|
||||
}
|
||||
|
||||
public PostMessageSimulator KeyPress(User32.VK vk, int ms)
|
||||
{
|
||||
User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYDOWN, (nint)vk, 0x1e0001);
|
||||
Thread.Sleep(ms);
|
||||
User32.PostMessage(_hWnd, User32.WindowMessage.WM_CHAR, (nint)vk, 0x1e0001);
|
||||
User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYUP, (nint)vk, (nint)0xc01e0001);
|
||||
return this;
|
||||
}
|
||||
|
||||
public PostMessageSimulator LongKeyPress(User32.VK vk)
|
||||
{
|
||||
User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYDOWN, (nint)vk, 0x1e0001);
|
||||
Thread.Sleep(1000);
|
||||
User32.PostMessage(_hWnd, User32.WindowMessage.WM_CHAR, (nint)vk, 0x1e0001);
|
||||
User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYUP, (nint)vk, (nint)0xc01e0001);
|
||||
return this;
|
||||
}
|
||||
|
||||
public PostMessageSimulator KeyDown(User32.VK vk)
|
||||
{
|
||||
User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYDOWN, (nint)vk, 0x1e0001);
|
||||
return this;
|
||||
}
|
||||
|
||||
public PostMessageSimulator KeyUp(User32.VK vk)
|
||||
{
|
||||
User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYUP, (nint)vk, (nint)0xc01e0001);
|
||||
return this;
|
||||
}
|
||||
|
||||
public PostMessageSimulator KeyPressBackground(User32.VK vk)
|
||||
{
|
||||
User32.PostMessage(_hWnd, User32.WindowMessage.WM_ACTIVATE, 1, 0);
|
||||
User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYDOWN, (nint)vk, 0x1e0001);
|
||||
User32.PostMessage(_hWnd, User32.WindowMessage.WM_CHAR, (nint)vk, 0x1e0001);
|
||||
User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYUP, (nint)vk, (nint)0xc01e0001);
|
||||
return this;
|
||||
}
|
||||
|
||||
public PostMessageSimulator KeyDownBackground(User32.VK vk)
|
||||
{
|
||||
User32.PostMessage(_hWnd, User32.WindowMessage.WM_ACTIVATE, 1, 0);
|
||||
User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYDOWN, (nint)vk, 0x1e0001);
|
||||
return this;
|
||||
}
|
||||
|
||||
public PostMessageSimulator KeyUpBackground(User32.VK vk)
|
||||
{
|
||||
User32.PostMessage(_hWnd, User32.WindowMessage.WM_ACTIVATE, 1, 0);
|
||||
User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYUP, (nint)vk, (nint)0xc01e0001);
|
||||
return this;
|
||||
}
|
||||
|
||||
public PostMessageSimulator Sleep(int ms)
|
||||
{
|
||||
Thread.Sleep(ms);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
using Fischless.WindowsInput;
|
||||
using System;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Simulator;
|
||||
|
||||
public class Simulation
|
||||
{
|
||||
public static InputSimulator SendInput { get; } = new();
|
||||
|
||||
public static MouseEventSimulator MouseEvent { get; } = new();
|
||||
|
||||
public static PostMessageSimulator PostMessage(IntPtr hWnd)
|
||||
{
|
||||
return new PostMessageSimulator(hWnd);
|
||||
}
|
||||
}
|
||||