public void Print(ResultIterator iter) { logger.Log("Is beginning of block: {0}", iter.IsAtBeginningOf(PageIteratorLevel.Block)); logger.Log("Is beginning of para: {0}", iter.IsAtBeginningOf(PageIteratorLevel.Para)); logger.Log("Is beginning of text line: {0}", iter.IsAtBeginningOf(PageIteratorLevel.TextLine)); logger.Log("Is beginning of word: {0}", iter.IsAtBeginningOf(PageIteratorLevel.Word)); logger.Log("Is beginning of symbol: {0}", iter.IsAtBeginningOf(PageIteratorLevel.Symbol)); logger.Log("Block text: \"{0}\"", iter.GetText(PageIteratorLevel.Block)); logger.Log("Para text: \"{0}\"", iter.GetText(PageIteratorLevel.Para)); logger.Log("TextLine text: \"{0}\"", iter.GetText(PageIteratorLevel.TextLine)); logger.Log("Word text: \"{0}\"", iter.GetText(PageIteratorLevel.Word)); logger.Log("Symbol text: \"{0}\"", iter.GetText(PageIteratorLevel.Symbol)); }
public static string RecognizeBlocks(byte[] imageBytes) { StringBuilder sb = new StringBuilder(); try { using (var engine = new TesseractEngine(@"./tessdata", "eng", EngineMode.Default)) { using (Pix pix = Pix.LoadFromMemory(imageBytes)) { using (var page = engine.Process(pix)) { sb.AppendLine("Text (iterator):"); using (ResultIterator iter = page.GetIterator()) { iter.Begin(); do { do { do { do { if (iter.IsAtBeginningOf(PageIteratorLevel.Block)) { sb.AppendLine("<BLOCK>"); } sb.Append(iter.GetText(PageIteratorLevel.Word)); sb.Append(" "); if (iter.IsAtFinalOf(PageIteratorLevel.TextLine, PageIteratorLevel.Word)) { sb.AppendLine(); } } while (iter.Next(PageIteratorLevel.TextLine, PageIteratorLevel.Word)); if (iter.IsAtFinalOf(PageIteratorLevel.Para, PageIteratorLevel.TextLine)) { sb.AppendLine(); } } while (iter.Next(PageIteratorLevel.Para, PageIteratorLevel.TextLine)); } while (iter.Next(PageIteratorLevel.Block, PageIteratorLevel.Para)); } while (iter.Next(PageIteratorLevel.Block)); } } } } } catch (Exception e) { Trace.TraceError(e.ToString()); } return(sb.ToString()); }
private static void IterateBlocks(Page page) { Console.WriteLine("Text (iterator):"); using (ResultIterator iter = page.GetIterator()) { iter.Begin(); do { do { do { do { if (iter.IsAtBeginningOf(PageIteratorLevel.Block)) { Console.WriteLine("<BLOCK>"); } Console.Write(iter.GetText(PageIteratorLevel.Word)); Console.Write(" "); if (iter.IsAtFinalOf(PageIteratorLevel.TextLine, PageIteratorLevel.Word)) { Console.WriteLine(); } }while (iter.Next(PageIteratorLevel.TextLine, PageIteratorLevel.Word)); if (iter.IsAtFinalOf(PageIteratorLevel.Para, PageIteratorLevel.TextLine)) { Console.WriteLine(); } }while (iter.Next(PageIteratorLevel.Para, PageIteratorLevel.TextLine)); }while (iter.Next(PageIteratorLevel.Block, PageIteratorLevel.Para)); }while (iter.Next(PageIteratorLevel.Block)); } }