private void DoCommandShowOptions() { DlgOptions dlg = new DlgOptions(); dlg.DataPath = _tessData; if (dlg.ShowDialog(this) == DialogResult.OK) { _tessData = dlg.DataPath; _lang = dlg.Language; _ocrEngineMode = (int)dlg.OcrEngineMode; bool status = _ocrProcessor.Init(_tessData, _lang, _ocrEngineMode); Console.WriteLine(string.Format("[DEBUG] Init status: {0}", status)); string msg = string.Format("{0} to initialize Tesseract Engine {1}.", (status ? "Succeed" : "Failed"), _ocrProcessor.GetTesseractEngineVersion()); MessageBox.Show(msg); } }
public string UseTesseract(string imgFile) { this.ErrMsg = string.Empty; string defLang = "eng"; string strResult = string.Empty; try { using (TesseractProcessor processor = new TesseractProcessor()) { processor.Init(this.TESSDATA, defLang, this.oem); processor.SetPageSegMode((ePageSegMode)Enum.Parse(typeof(ePageSegMode), this.pageSegMode)); #if DEBUG System.Diagnostics.Debug.WriteLine("processor:"); System.Diagnostics.Debug.WriteLine(processor.GetTesseractEngineVersion()); #endif string strIndicate = Path.GetFileNameWithoutExtension(imgFile); strResult = processor.Recognize(imgFile); if (!string.IsNullOrEmpty(strResult)) { // correct common errors caused by OCR strResult = this.CorrectOCRErrors(strResult); // correct letter cases strResult = this.CorrectLetterCases(strResult); } } strResult = strResult.Replace("\n", Environment.NewLine); } catch (Exception ex) { this.ErrMsg = ex.ToString(); strResult = string.Empty; } return strResult; }