Property OcrEngine
- Namespace
- LMKit.Extraction
- Assembly
- LM-Kit.NET.dll
OcrEngine
Gets or sets an optional OcrEngine used to perform traditional OCR on raster content.
public OcrEngine OcrEngine { get; set; }
Property Value
Examples
using LMKit.Extraction;
using LMKit.Extraction.Ocr;
var te = new TextExtraction(LM.LoadFromModelID("lmkit-tasks:4b-preview"));
// Any concrete implementation of OcrEngine can be used here
OcrEngine ocr = new MyOcrEngine();
te.OcrEngine = ocr;
te.Elements = new List<TextExtractionElement>
{
new TextExtractionElement("Total", ElementType.Decimal)
};
te.SetContent(new Attachment("invoice_scan.png"));
var result = te.Parse();
Console.WriteLine(result.GetValue<decimal>("Total"));
Remarks
This property is optional; if no OCR engine is provided (i.e., left null
),
image-based extraction will be skipped regardless of the input content.
When set, OCR may be invoked automatically during extraction depending on the PreferredInferenceModality and the structure of the input:
- If PreferredInferenceModality is Vision or Multimodal, the engine will attempt to extract text from any raster attachments before invoking the language model.
- If the input includes both text and images, providing an OCR engine can substantially improve recognition accuracy by converting visual text into a format the language model can process directly.
For purely text-based inputs or when no OCR engine is supplied, the extraction process will rely solely on the language model’s text understanding capabilities.