public static int Main(string[] args) { // to test //args = new string[] { @"C:\localdata\test.bmp"}; if (args.Length == 0) { Console.WriteLine(USAGE); return(-1); } string filename = args[0]; ModiLanguage language = ModiLanguage.ENGLISH; if (args.Length >= 2) { language = (ModiLanguage)Enum.Parse(typeof(ModiLanguage), args[1]); } bool orientimage = true; if (args.Length >= 3) { orientimage = bool.Parse(args[2]); } bool straightenImage = true; if (args.Length >= 4) { straightenImage = bool.Parse(args[3]); } try { if (File.Exists(filename) || "-c".Equals(filename)) { using (ModiDocu modiDocument = COMWrapper.GetOrCreateInstance <ModiDocu>()) { if (modiDocument == null) { Console.WriteLine("MODI not installed"); return(-2); } if ("-c".Equals(filename)) { return(0); } modiDocument.Create(filename); modiDocument.OCR(language, orientimage, straightenImage); IImage modiImage = modiDocument.Images[0]; ILayout layout = modiImage.Layout; Console.WriteLine(layout.Text); modiDocument.Close(false); return(0); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(-1); }
public static int Main(string[] args) { if (args.Length == 0) { Console.WriteLine(Usage); return(-1); } string filename = args[0]; ModiLanguage language = ModiLanguage.ENGLISH; if (args.Length >= 2) { language = (ModiLanguage)Enum.Parse(typeof(ModiLanguage), args[1]); } bool orientimage = true; if (args.Length >= 3) { orientimage = bool.Parse(args[2]); } bool straightenImage = true; if (args.Length >= 4) { straightenImage = bool.Parse(args[3]); } try { if (File.Exists(filename) || "-c".Equals(filename)) { using (var document = COMWrapper.GetOrCreateInstance <IDocument>()) { if (document == null) { Console.WriteLine("MODI not installed"); return(-2); } if ("-c".Equals(filename)) { return(0); } document.Create(filename); document.OCR(language, orientimage, straightenImage); var modiImage = document.Images[0]; var layout = modiImage.Layout; if (layout != null) { #if DEBUG if (layout.Words != null) { foreach (var word in ToEnumerable(layout.Words)) { if (word.Rects != null) { foreach (var rect in ToEnumerable(word.Rects)) { Debug.WriteLine($"Rect {rect.Left},{rect.Top},{rect.Right},{rect.Bottom} - Word {word.Text} : Confidence: {word.RecognitionConfidence}"); } } } } #endif if (layout.Text != null) { // For for BUG-1884: // Although trim is done in the OCR Plugin, it does make sense in the command too. Console.WriteLine(layout.Text.Trim()); } } document.Close(false); return(0); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(-1); }