Ejemplo n.º 1
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();
            }
Ejemplo n.º 2
0
        static void Main()
        {
            Initialize();

            TakePicture picture = new TakePicture();

            var testImagePath = @"depth.png";

            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);

                                if (File.Exists(@"output.txt"))
                                {
                                    File.Delete(@"output.txt");
                                }
                                using (var Stream = File.Open(@"output.txt", FileMode.OpenOrCreate))
                                {
                                    using (var writer = new BinaryWriter(Stream, Encoding.UTF8))
                                    {
                                        writer.Write(text.Where(c => char.IsDigit(c)).ToArray());
                                    }
                                    Stream.Close();
                                }
                                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);
        }
Ejemplo n.º 3
0
 public ResultPrinter(FormattedConsoleLogger logger)
 {
     this.logger = logger;
 }