截取物品图标独立任务 (#1856)

This commit is contained in:
FishmanTheMurloc
2025-07-09 23:26:18 +08:00
committed by GitHub
parent 0a5c8c169a
commit d73f21464e
11 changed files with 841 additions and 78 deletions

View File

@@ -1,4 +1,4 @@
using GameTask.Model.GameUI;
using BetterGenshinImpact.GameTask.Model.GameUI;
using OpenCvSharp;
using System;
using System.Collections.Generic;
@@ -10,6 +10,43 @@ namespace BetterGenshinImpact.UnitTest.GameTaskTests.Model.GameUI
{
public class GridScreenTests
{
[Theory]
[InlineData(@"AutoArtifactSalvage\ArtifactGrid.png", 4, 2)]
[InlineData(@"GetGridIcons\WeaponGrid3.png", 32, 8)]
/// <summary>
/// 测试获取各种界面中的物品图标,结果应正确
/// </summary>
public void GetGridIcons_ShouldBeRight(string screenshot, int count, int columns)
{
//
using Mat mat = new Mat(@$"..\..\..\Assets\{screenshot}");
//
var result = GridScreen.GridEnumerator.GetGridItems(mat, columns);
//
Assert.Equal(count, result.Count());
}
[Theory]
[InlineData(@"GetGridIcons\FoodGrid.png", 32, 8)]
[InlineData(@"GetGridIcons\WeaponGrid.png", 4, 2)]
[InlineData(@"GetGridIcons\WeaponGrid3.png", 32, 8)]
/// <summary>
/// 测试获取各种界面中的物品图标使用复杂的cv算法结果应正确
/// </summary>
public void GetGridIconsAlpha_ShouldBeRight(string screenshot, int count, int columns)
{
//
using Mat mat = new Mat(@$"..\..\..\Assets\{screenshot}");
//
var result = GridScreen.GridEnumerator.GetGridItems(mat, columns, findContoursAlpha: true);
//
Assert.Equal(count, result.Count());
}
[Fact]
/// <summary>
/// 测试判断前后两张图是否属于滚动,结果应正确
@@ -25,7 +62,7 @@ namespace BetterGenshinImpact.UnitTest.GameTaskTests.Model.GameUI
cropped.CopyTo(pos);
//
bool result1 = GridScreen.GridEnumerator.IsScrolling(mat, scrolled, out Point2d shift);
bool result1 = GridScreen.GridEnumerator.IsScrolling(mat, scrolled, out Point2d shift, upperThreshold: 0.99);
bool result2 = GridScreen.GridEnumerator.IsScrolling(mat, mat, out Point2d _);
bool result3 = GridScreen.GridEnumerator.IsScrolling(mat, black, out Point2d _);