Method Run
- Namespace
- LMKit.Extraction.Ocr
- Assembly
- LM-Kit.NET.dll
Run(Attachment, int, CancellationToken)
Runs OCR synchronously on the specified attachment and returns a detailed result.
public VlmOcr.VlmOcrResult Run(Attachment attachment, int pageIndex = 0, CancellationToken cancellationToken = default)
Parameters
attachmentAttachmentThe Attachment representing the image to be transcribed. This is typically used when the image is already part of a larger data source (for example, a page extracted from a document).
pageIndexintcancellationTokenCancellationTokenA CancellationToken that can be used to cancel the operation while waiting for the underlying asynchronous work to complete.
Returns
- VlmOcr.VlmOcrResult
A VlmOcr.VlmOcrResult containing both the raw text-generation result and the constructed PageElement.
Examples
var ocr = new VlmOcr(model);
var attachment = new Attachment("document.pdf");
VlmOcr.VlmOcrResult result = ocr.Run(attachment, pageIndex: 0);
Console.WriteLine(result.PageElement.Text);
Remarks
This is a convenience wrapper around RunAsync(Attachment, int, CancellationToken) for callers that prefer a synchronous API or cannot easily use async/await.
Exceptions
- ArgumentNullException
Thrown if
attachmentisnull.- OperationCanceledException
Thrown if the operation is canceled via
cancellationToken.
Run(ImageBuffer, CancellationToken)
Runs OCR synchronously on the specified image and returns a detailed result.
public VlmOcr.VlmOcrResult Run(ImageBuffer image, CancellationToken cancellationToken = default)
Parameters
imageImageBufferThe ImageBuffer containing the image to be transcribed.
cancellationTokenCancellationTokenA CancellationToken that can be used to cancel the operation while waiting for the underlying asynchronous work to complete.
Returns
- VlmOcr.VlmOcrResult
A VlmOcr.VlmOcrResult containing both the raw text-generation result and the constructed PageElement.
Examples
var ocr = new VlmOcr(model);
using var image = ImageBuffer.LoadAsRGB("scan.png");
VlmOcr.VlmOcrResult result = ocr.Run(image);
Console.WriteLine(result.PageElement.Text);
Remarks
This overload is convenient when you already have an ImageBuffer (for example, loaded via LoadAsRGB(string)). The image is internally wrapped into an attachment for processing.
Exceptions
- ArgumentNullException
Thrown if
imageisnull.- OperationCanceledException
Thrown if the operation is canceled via
cancellationToken.