Free C# OCR library
Posted: Mon Oct 22, 2018 4:10 am
Does anyone know a good free C# OCR library ?
Code: Select all
//---------------------------------------------------------------------
/// <summary>
/// Read graphical Text with the Tesseract OCR module
/// </summary>
[UserCodeMethod]
public static string OCRRead(Bitmap bmp, string whitelist,string enginePath)
{
try{
Tesseract.Pix px = PixConverter.ToPix(bmp);
TesseractEngine engine = new TesseractEngine(enginePath, "eng", Tesseract.EngineMode.Default);
engine.DefaultPageSegMode=Tesseract.PageSegMode.Auto;
//engine.SetVariable("classify_bln_numeric_mode",0);
if (whitelist!="")
{
engine.SetVariable("tessedit_char_whitelist",whitelist);
}
Tesseract.Page pg = engine.Process(px);
string text = pg.GetText();
return text;
} catch(Exception ex) {
Debug.WriteLine("EnginePath: "+enginePath);
Debug.WriteLine("Whitelist: "+whitelist);
throw new ExceptionOcrImage(ex.ToString(),bmp);
}
}
Code: Select all
Bitmap bmp ; // bitmap, e.g. from screenshot
string whitelist = "0123456789:._-/| ";
string tesseractFile=@"D:\tesseract\DataFiles\tessdata";
string ocrDatetime = OCRRead(bmp, whitelist, tesseractFile);