Table of Contents

Interface IOcrEngine

Namespace
Egami.Ocr
Assembly
Egami.dll

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

OcrEngineInfo

Methods

RecognizeAsync(OcrRequest, CancellationToken)

Recognizes the text in one image.

Task<OcrResult> RecognizeAsync(OcrRequest request, CancellationToken cancellationToken = default)

Parameters

request OcrRequest

The image and how to read it.

cancellationToken CancellationToken

Cancels the recognition.

Returns

Task<OcrResult>

The lines and words found, in pixels of Image with the origin at the top left.