Example #1
3
        public static void Main(string[] args)
        {
            var testImagePath = "./phototest.tif";
            if (args.Length > 0) {
                testImagePath = args[0];
            }

            try {
                var logger = new FormattedConsoleLogger();
                var resultPrinter = new ResultPrinter(logger);
                using (var engine = new TesseractEngine(@"./tessdata", "eng", EngineMode.Default)) {
                    using (var img = Pix.LoadFromFile(testImagePath)) {
                        using (logger.Begin("Process image")) {
                            var i = 1;
                            using (var page = engine.Process(img)) {
                                var text = page.GetText();
                                logger.Log("Text: {0}", text);
                                logger.Log("Mean confidence: {0}", page.GetMeanConfidence());

                                using (var iter = page.GetIterator()) {
                                    iter.Begin();
                                    do {
                                        if (i % 2 == 0) {
                                            using (logger.Begin("Line {0}", i)) {
                                                do {
                                                    using (logger.Begin("Word Iteration")) {
                                                        if (iter.IsAtBeginningOf(PageIteratorLevel.Block)) {
                                                            logger.Log("New block");
                                                        }
                                                        if (iter.IsAtBeginningOf(PageIteratorLevel.Para)) {
                                                            logger.Log("New paragraph");
                                                        }
                                                        if (iter.IsAtBeginningOf(PageIteratorLevel.TextLine)) {
                                                            logger.Log("New line");
                                                        }
                                                        logger.Log("word: " + iter.GetText(PageIteratorLevel.Word));
                                                        ResultIterator testiter = iter.Clone ();
                                                        logger.Log("from clone: " + testiter.GetText(PageIteratorLevel.Word));
                                                    }
                                                } while (iter.Next(PageIteratorLevel.TextLine, PageIteratorLevel.Word));
                                            }
                                        }
                                        i++;
                                    } while (iter.Next(PageIteratorLevel.Para, PageIteratorLevel.TextLine));
                                }
                            }
                        }
                    }
                }
            } catch (Exception e) {
                Trace.TraceError(e.ToString());
                Console.WriteLine("Unexpected Error: " + e.Message);
                Console.WriteLine("Details: ");
                Console.WriteLine(e.ToString());
            }
            Console.Write("Press any key to continue . . . ");
            Console.ReadKey(true);
        }
Example #2
1
 public ResultPrinter(FormattedConsoleLogger logger)
 {
     this.logger = logger;
 }
Example #3
0
            public Scope(FormattedConsoleLogger container, int indentLevel)
            {
                this.container   = container;
                this.indentLevel = indentLevel;
                StringBuilder indent = new StringBuilder();

                for (int i = 0; i < indentLevel; i++)
                {
                    indent.Append(Tab);
                }
                this.indent = indent.ToString();
            }
Example #4
0
 public ResultPrinter(FormattedConsoleLogger logger)
 {
     this.logger = logger;
 }
Example #5
0
        public static void Main(string[] args)
        {
            var testImagePath = "./phototest.tif";

            if (args.Length > 0)
            {
                testImagePath = args[0];
            }

            try {
                var logger        = new FormattedConsoleLogger();
                var resultPrinter = new ResultPrinter(logger);
                using (var engine = new TesseractEngine(@"./tessdata", "eng", EngineMode.Default)) {
                    using (var img = Pix.LoadFromFile(testImagePath)) {
                        using (logger.Begin("Process image")) {
                            var i = 1;
                            using (var page = engine.Process(img)) {
                                var text = page.GetText();
                                logger.Log("Text: {0}", text);
                                logger.Log("Mean confidence: {0}", page.GetMeanConfidence());

                                using (var iter = page.GetIterator()) {
                                    iter.Begin();
                                    do
                                    {
                                        if (i % 2 == 0)
                                        {
                                            using (logger.Begin("Line {0}", i)) {
                                                do
                                                {
                                                    using (logger.Begin("Word Iteration")) {
                                                        if (iter.IsAtBeginningOf(PageIteratorLevel.Block))
                                                        {
                                                            logger.Log("New block");
                                                        }
                                                        if (iter.IsAtBeginningOf(PageIteratorLevel.Para))
                                                        {
                                                            logger.Log("New paragraph");
                                                        }
                                                        if (iter.IsAtBeginningOf(PageIteratorLevel.TextLine))
                                                        {
                                                            logger.Log("New line");
                                                        }
                                                        logger.Log("word: " + iter.GetText(PageIteratorLevel.Word));
                                                    }
                                                } while (iter.Next(PageIteratorLevel.TextLine, PageIteratorLevel.Word));
                                            }
                                        }
                                        i++;
                                    } while (iter.Next(PageIteratorLevel.Para, PageIteratorLevel.TextLine));
                                }
                            }
                        }
                    }
                }
            } catch (Exception e) {
                Trace.TraceError(e.ToString());
                Console.WriteLine("Unexpected Error: " + e.Message);
                Console.WriteLine("Details: ");
                Console.WriteLine(e.ToString());
            }
            Console.Write("Press any key to continue . . . ");
            Console.ReadKey(true);
        }
 public Scope(FormattedConsoleLogger container, int indentLevel)
 {
     this.container = container;
     this.indentLevel = indentLevel;
     StringBuilder indent = new StringBuilder();
     for (int i = 0; i < indentLevel; i++) {
         indent.Append('\t');
     }
     this.indent = indent.ToString();
 }
Example #7
-1
 public static void Main(string[] args)
 {
     try {
         var logger = new FormattedConsoleLogger();
         var resultPrinter = new ResultPrinter(logger);
         using (var engine = new Engine(@"./tessdata", "eng", EngineMode.Default)) {
             using (var img = Pix.LoadFromFile("./phototest.tif")) {
                 using (logger.Begin("Image")) {
                     var i = 1;
                     using (var iter = engine.Process(img)) {
                         iter.Begin();
                         do {
                             if (i % 2 == 0) {
                                 using(logger.Begin("Line {0}", i)) {
                                     do {
                                         using (logger.Begin("Word Iteration")) {
                                             if (iter.IsAtBeginningOf(PageIteratorLevel.Block)) {
                                                 logger.Log("New block");
                                             }
                                             if (iter.IsAtBeginningOf(PageIteratorLevel.Para)) {
                                                 logger.Log("New paragraph");
                                             }
                                             if (iter.IsAtBeginningOf(PageIteratorLevel.TextLine)) {
                                                 logger.Log("New line");
                                             }
                                             logger.Log("word: " + iter.GetText(PageIteratorLevel.Word));
                                         }
                                     } while (iter.Next(PageIteratorLevel.TextLine, PageIteratorLevel.Word));
                                 }
                             }
                             i++;
                         } while (iter.Next(PageIteratorLevel.Para, PageIteratorLevel.TextLine));
                     }
                 }
             }
         }
     } catch (Exception e) {
         Trace.TraceError(e.ToString());
         Console.WriteLine("Unexpected Error: " + e.Message);
         Console.WriteLine("Details: ");
         Console.WriteLine(e.ToString());
     }
     Console.Write("Press any key to continue . . . ");
     Console.ReadKey(true);
 }