Skip to content

Commit

Permalink
升级ImageLocator以改善体验
Browse files Browse the repository at this point in the history
  • Loading branch information
Rcmcpe committed Jul 11, 2020
1 parent 8610e82 commit 31ece8d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions Arknights Automation Library/Assets.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
using System;
using System.Collections.Generic;
using System.IO;
using OpenCvSharp;
using REVUnit.ImageLocator;

namespace REVUnit.AutoArknights.Core
{
public class Assets : IDisposable
{
private readonly Cache<string, Mat> _cache = new Cache<string, Mat>();
private readonly Dictionary<string, Mat> _memoryCacheMap = new Dictionary<string, Mat>();

public void Dispose()
{
foreach (Mat mat in _cache.CachedItems) mat.Dispose();
foreach (Mat mat in _memoryCacheMap.Values) mat.Dispose();
}

public Mat Get(string expr)
{
expr = expr.Trim();
if (!_cache.Get(expr, out Mat mat))
if (!_memoryCacheMap.TryGetValue(expr, out Mat mat))
{
string fileName = GetFileName(expr);
if (!File.Exists(fileName)) throw new IOException($"Asset not found: {expr}");
mat = Utils.Imread(fileName);
if (mat.Empty()) throw new IOException($"Invalid asset: {expr}");

_cache.Register(expr, mat);
_memoryCacheMap.Add(expr, mat);
}

return mat;
Expand Down
2 changes: 1 addition & 1 deletion Arknights Automation Library/Interactor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class Interactor : IDisposable
private readonly Adb _adb;
private readonly Assets _assets = new Assets();

private readonly FMLocator _loc = new FMLocator(new Feature2DInfo(Feature2Ds.Sift), "Assets\\Cache");
private readonly FMLocator _loc = new FMLocator(Feature2DType.Sift, "Assets\\Cache");

public Interactor(string adbPath)
{
Expand Down
2 changes: 1 addition & 1 deletion ImageLocator

0 comments on commit 31ece8d

Please sign in to comment.