Interface IOcrEngine
A text recognition (OCR) engine: an image in, words with their boxes out. Egami ships no engine; plug one in, such as CommandOcrEngine for any program that writes hOCR or ALTO, or your own class around an OS or cloud service.
public interface IOcrEngine
Examples
// An engine is one method: an image in, lines of words out. This one finds a single word; a real one wraps an OCR program,
// an OS service or a cloud API (see samples/Ocr).
public sealed class OneWordEngine : IOcrEngine
{
public OcrEngineInfo Info { get; } = new("one-word") { Languages = ["eng"], IsThreadSafe = true };
public Task<OcrResult> RecognizeAsync(OcrRequest request, CancellationToken cancellationToken = default)
{
OcrQuad box = OcrQuad.FromBounds(10, 10, request.Image.Width / 2, 20);
OcrLine line = new([new OcrWord("Duck", box, Confidence: 0.9, Language: "eng")]);
return Task.FromResult(new OcrResult([line]) { ImageSize = new Size(request.Image.Width, request.Image.Height) });
}
}
Remarks
Implementations must not change or dispose Image. A call may run on any thread; when IsThreadSafe is true, callers may run several at once.
Properties
Info
Gets what the engine can do: its name, languages, largest image and whether calls may overlap.
OcrEngineInfo Info { get; }
Property Value
Methods
RecognizeAsync(OcrRequest, CancellationToken)
Recognizes the text in one image.
Task<OcrResult> RecognizeAsync(OcrRequest request, CancellationToken cancellationToken = default)
Parameters
requestOcrRequestThe image and how to read it.
cancellationTokenCancellationTokenCancels the recognition.