feat: add CaptureContent

This commit is contained in:
huiyadanli
2023-09-24 14:05:10 +08:00
parent 360789fdb2
commit a009aab264
10 changed files with 82 additions and 22 deletions

View File

@@ -27,7 +27,6 @@
<ItemGroup>
<Folder Include="GameTask\AutoFishing\" />
<Folder Include="GameTask\AutoGeniusInvokation\" />
<Folder Include="GameTask\AutoPick\" />
<Folder Include="GameTask\QuickEnhanceArtifacts\" />
<Folder Include="GameTask\UseActiveCode\" />
<Folder Include="Service\Interface\" />

Binary file not shown.

After

Width:  |  Height:  |  Size: 503 B

View File

@@ -0,0 +1,15 @@
using BetterGenshinImpact.Core.Config;
using OpenCvSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BetterGenshinImpact.GameTask.AutoPick.Assets
{
public class AutoPickAssets
{
public static Mat StopAutoButtonMat = new(Global.Absolute(@"GameTask\AutoPick\Assets\1920x1080\F.png"), ImreadModes.Grayscale);
}
}

View File

@@ -27,20 +27,20 @@ namespace BetterGenshinImpact.GameTask.AutoSkip
IsEnabled = true;
}
public void OnCapture(Mat matSrc, int frameIndex)
public void OnCapture(CaptureContent content)
{
if (frameIndex % 2 == 0)
if (content.FrameIndex % 2 == 0)
{
return;
}
var grayMat = new Mat();
Cv2.CvtColor(matSrc, grayMat, ColorConversionCodes.BGR2GRAY);
var grayMat = content.SrcGreyMat;
// 找左上角剧情自动的按钮
var grayLeftTopMat = CutHelper.CutLeftTop(grayMat, grayMat.Width / 5, grayMat.Height / 5);
var p1 = MatchTemplateHelper.FindSingleTarget(grayLeftTopMat, AutoSkipAssets.StopAutoButtonMat, 0.9);
if (p1 is { X: > 0, Y: > 0 })
{
//_logger.LogInformation($"找到剧情自动按钮:{p1}");
VisionContext.Instance().DrawContent.PutRect("StopAutoButton",
p1.CenterPointToRect(AutoSkipAssets.StopAutoButtonMat));
new InputSimulator().Keyboard.KeyPress(VirtualKeyCode.SPACE);

View File

@@ -98,17 +98,17 @@ namespace BetterGenshinImpact.GameTask
}
// 循环执行所有触发器 有独占状态的触发器的时候只执行独占触发器
var mat = bitmap.ToMat();
var content = new CaptureContent(bitmap, _frameIndex);
var exclusiveTrigger = _triggers.FirstOrDefault(t => t is { IsEnabled: true, IsExclusive: true });
if (exclusiveTrigger != null)
{
exclusiveTrigger.OnCapture(mat, _frameIndex);
exclusiveTrigger.OnCapture(content);
}
else
{
foreach (var trigger in _triggers.Where(trigger => trigger.IsEnabled))
{
trigger.OnCapture(mat, _frameIndex);
trigger.OnCapture(content);
}
}
}

View File

@@ -119,7 +119,7 @@ namespace BetterGenshinImpact.ViewModel
_maskWindow.Top = y;
_maskWindow.Width = w;
_maskWindow.Height = h;
_maskWindow.Logger = App.GetLogger<MaskWindow>();
_maskWindow.Show();
_logger.LogInformation("Mask Window showed 遮罩窗口启动成功");

View File

@@ -54,7 +54,8 @@
Foreground="LightGray"
FontFamily="Cascadia Mono, Consolas, Courier New, monospace"
BorderThickness="0"
VerticalScrollBarVisibility="Auto" />
VerticalScrollBarVisibility="Hidden" Margin="0,0,-258,10">
</RichTextBox>
</ContentControl>
<!--<ContentControl Width="230"

View File

@@ -47,9 +47,15 @@ namespace Vision.Recognition
private MaskWindow()
{
InitializeComponent();
LogTextBox.TextChanged += LogTextBoxTextChanged;
//AddAreaSettingsControl("测试识别窗口");
}
private void LogTextBoxTextChanged(object sender, TextChangedEventArgs e)
{
LogTextBox.ScrollToEnd();
}
public void Refresh()
{
@@ -58,6 +64,7 @@ namespace Vision.Recognition
protected override void OnRender(DrawingContext drawingContext)
{
Logger?.LogInformation("绘制识别结果");
try
{
foreach (var kv in VisionContext.Instance().DrawContent.RectList)

View File

@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenCvSharp;
using Vision.Recognition.Helper.OpenCv;
namespace Vision.Recognition.Task
{
/// <summary>
/// 捕获的内容
/// 以及一些多个trigger会用到的内容
/// </summary>
public class CaptureContent
{
public Bitmap SrcBitmap { get; }
public int FrameIndex { get; private set; }
public CaptureContent(Bitmap srcBitmap, int frameIndex)
{
SrcBitmap = srcBitmap;
FrameIndex = frameIndex;
}
private Mat? _srcMat;
public Mat SrcMat
{
get
{
_srcMat ??= SrcBitmap.ToMat();
return _srcMat;
}
}
private Mat? _srcGreyMat;
public Mat SrcGreyMat
{
get
{
_srcGreyMat ??= new Mat();
Cv2.CvtColor(SrcMat, _srcGreyMat, ColorConversionCodes.BGR2GRAY);
return _srcGreyMat;
}
}
}
}

View File

@@ -46,17 +46,7 @@ namespace Vision.Recognition.Task
/// <summary>
/// 捕获图像后操作
/// </summary>
/// <param name="bitmap"></param>
/// <param name="frameIndex"></param>
void OnCapture(Bitmap bitmap, int frameIndex)
{
OnCapture(bitmap.ToMat(), frameIndex);
}
/// <summary>
/// 捕获图像后操作
/// </summary>
/// <param name="matSrc">OpenCV的图片对象</param>
/// <param name="frameIndex"></param>
void OnCapture(Mat matSrc, int frameIndex);
/// <param name="content">捕获的图片等内容</param>
void OnCapture(CaptureContent content);
}
}