Method RunAsync
- Namespace
- LMKit.Extraction.Ocr
- Assembly
- LM-Kit.NET.dll
RunAsync(OcrParameters, CancellationToken)
Runs OCR on the specified page using the configured multimodal language model.
public override Task<OcrResult> RunAsync(OcrParameters ocrParameters, CancellationToken cancellationToken = default)
Parameters
ocrParametersOcrParametersThe OcrParameters containing the image data and attachment metadata for the page to be transcribed.
cancellationTokenCancellationTokenA CancellationToken that can be used to cancel the operation.
Returns
- Task<OcrResult>
A Task<TResult> that produces an OcrResult containing the page-level transcription returned by the model.
Remarks
This method implements the OcrEngine contract and is intended for consumers that only need the final OcrResult in a document-oriented workflow. For advanced scenarios that require access to model-level details, use Run(Attachment, CancellationToken) or RunAsync(Attachment, CancellationToken).
Exceptions
- ArgumentNullException
Thrown if
ocrParametersisnull.- OperationCanceledException
Thrown if the operation is canceled via
cancellationToken.
RunAsync(Attachment, CancellationToken)
Runs OCR on the specified attachment and returns a detailed result.
public Task<VlmOcr.VlmOcrResult> RunAsync(Attachment attachment, CancellationToken cancellationToken = default)
Parameters
attachmentAttachmentThe Attachment representing the image to be transcribed. The attachment may carry additional metadata (for example, page index or layout information) that can be used elsewhere in the extraction pipeline.
cancellationTokenCancellationTokenA CancellationToken that can be used to cancel the operation.
Returns
- Task<VlmOcr.VlmOcrResult>
A Task<TResult> that produces a VlmOcr.VlmOcrResult containing both the raw text-generation result and the constructed PageElement.
Exceptions
- ArgumentNullException
Thrown if
attachmentisnull.- OperationCanceledException
Thrown if the operation is canceled via
cancellationToken.
RunAsync(ImageBuffer, CancellationToken)
Runs OCR on the specified image and returns a detailed result.
public Task<VlmOcr.VlmOcrResult> RunAsync(ImageBuffer image, CancellationToken cancellationToken = default)
Parameters
imageImageBufferThe ImageBuffer containing the image to be transcribed.
cancellationTokenCancellationTokenA CancellationToken that can be used to cancel the operation.
Returns
- Task<VlmOcr.VlmOcrResult>
A Task<TResult> that produces a VlmOcr.VlmOcrResult containing both the raw text-generation result and the constructed PageElement.
Examples
var model = LM.LoadFromModelID("lmkit-tasks:4b-preview");
var ocr = new VlmOcr(model);
using var image = ImageBuffer.LoadAsRGB("invoice.png");
var result = await ocr.RunAsync(image, cancellationToken);
string text = result.PageElement.GetText();
Exceptions
- ArgumentNullException
Thrown if
imageisnull.- OperationCanceledException
Thrown if the operation is canceled via
cancellationToken.