Table of Contents

Method RunAsync

Namespace
LMKit.Integrations.AWS.Ocr.Textract
Assembly
LM-Kit.NET.dll

RunAsync(OcrParameters, CancellationToken)

Executes the OCR process using the provided parameters. Concrete subclasses must override this method to implement specific OCR logic (e.g., calling a third‐party OCR library).

public override Task<OcrResult> RunAsync(OcrParameters ocrParameters, CancellationToken cancellationToken = default)

Parameters

ocrParameters OcrParameters

An OcrParameters instance that encapsulates the image buffer, any associated attachment metadata, and any additional configuration options.

cancellationToken CancellationToken

A CancellationToken that can be used to cancel the OCR operation at any time.

Returns

Task<OcrResult>

A Task<TResult> that, when completed, provides an OcrResult containing the extracted text, layout information, and any other data produced by the OCR engine.

Examples

public class TesseractOcrEngine : OcrEngine
{
    public override async Task<OcrResult> RunAsync(
        OcrParameters ocrParameters,
        CancellationToken cancellationToken = default)
    {
        string text = await Tesseract.RecognizeAsync(ocrParameters.ImageData, cancellationToken);
        return new OcrResult(text);
    }
}

Exceptions

OperationCanceledException

Thrown if the operation is canceled via the provided cancellationToken.

Exception

Concrete implementations may throw other exceptions to indicate failures in the underlying OCR processing (e.g., I/O errors, service faults, invalid image format). It is recommended to document those specifics in the subclass’s implementation.

Share