50 lines
1.2 KiB
C#
50 lines
1.2 KiB
C#
using ImageMagick;
|
|
using Lookup.Memory;
|
|
using Ocr.Tesseract.Models;
|
|
using Process.Interface;
|
|
|
|
namespace Common;
|
|
|
|
/// <summary>
|
|
/// Scanner class, scanning <see cref="MagickImage"/>s for <see cref="Word"/>s
|
|
/// via optical character recognition. Optimized for digital Screenshots.
|
|
/// </summary>
|
|
public class ScreenshotScanner
|
|
{
|
|
/// <summary>
|
|
/// The screenshot processor
|
|
/// </summary>
|
|
protected IProcessor<MagickImage, ScanResult> Processor { get; }
|
|
|
|
/// <summary>
|
|
/// Data storage
|
|
/// </summary>
|
|
public Lookup.Interface.ILookup<Word, MagickImage> Lookup { get; } =
|
|
new MemoryLookup<Word, MagickImage>();
|
|
|
|
/// <summary>
|
|
/// Constructor
|
|
/// </summary>
|
|
public ScreenshotScanner(IProcessor<MagickImage, ScanResult> processor)
|
|
{
|
|
Processor = processor;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Process the provided <paramref name="images"/> and add the results to
|
|
/// the <see cref="Lookup"/>
|
|
/// </summary>
|
|
/// <param name="images">The <see cref="MagickImage"/>s to process</param>
|
|
public void Process(IEnumerable<MagickImage> images)
|
|
{
|
|
foreach (var kv in Processor.Process(images))
|
|
{
|
|
Lookup.Add(kv.Word, kv.Image);
|
|
}
|
|
}
|
|
|
|
public virtual void Clear()
|
|
{
|
|
Lookup.Clear();
|
|
}
|
|
} |