tesseract  4.0.0-1-g2a2b
ocrblock.h File Reference
#include "ocrpara.h"
#include "ocrrow.h"
#include "pdblock.h"

Go to the source code of this file.

Classes

class  BLOCK
 

Functions

void PrintSegmentationStats (BLOCK_LIST *block_list)
 
void ExtractBlobsFromSegmentation (BLOCK_LIST *blocks, C_BLOB_LIST *output_blob_list)
 
void RefreshWordBlobsFromNewBlobs (BLOCK_LIST *block_list, C_BLOB_LIST *new_blobs, C_BLOB_LIST *not_found_blobs)
 

Function Documentation

◆ ExtractBlobsFromSegmentation()

void ExtractBlobsFromSegmentation ( BLOCK_LIST *  blocks,
C_BLOB_LIST *  output_blob_list 
)

Definition at line 442 of file ocrblock.cpp.

443  {
444  C_BLOB_IT return_list_it(output_blob_list);
445  BLOCK_IT block_it(blocks);
446  for (block_it.mark_cycle_pt(); !block_it.cycled_list(); block_it.forward()) {
447  BLOCK* block = block_it.data();
448  ROW_IT row_it(block->row_list());
449  for (row_it.mark_cycle_pt(); !row_it.cycled_list(); row_it.forward()) {
450  ROW* row = row_it.data();
451  // Iterate over all werds in the row.
452  WERD_IT werd_it(row->word_list());
453  for (werd_it.mark_cycle_pt(); !werd_it.cycled_list(); werd_it.forward()) {
454  WERD* werd = werd_it.data();
455  return_list_it.move_to_last();
456  return_list_it.add_list_after(werd->cblob_list());
457  return_list_it.move_to_last();
458  return_list_it.add_list_after(werd->rej_cblob_list());
459  }
460  }
461  }
462 }
ROW_LIST * row_list()
get rows
Definition: ocrblock.h:118
WERD_LIST * word_list()
Definition: ocrrow.h:55
C_BLOB_LIST * rej_cblob_list()
Definition: werd.h:93
Definition: werd.h:59
Definition: ocrrow.h:36
Definition: ocrblock.h:30
C_BLOB_LIST * cblob_list()
Definition: werd.h:98

◆ PrintSegmentationStats()

void PrintSegmentationStats ( BLOCK_LIST *  block_list)

Definition at line 409 of file ocrblock.cpp.

409  {
410  int num_blocks = 0;
411  int num_rows = 0;
412  int num_words = 0;
413  int num_blobs = 0;
414  BLOCK_IT block_it(block_list);
415  for (block_it.mark_cycle_pt(); !block_it.cycled_list(); block_it.forward()) {
416  BLOCK* block = block_it.data();
417  ++num_blocks;
418  ROW_IT row_it(block->row_list());
419  for (row_it.mark_cycle_pt(); !row_it.cycled_list(); row_it.forward()) {
420  ++num_rows;
421  ROW* row = row_it.data();
422  // Iterate over all werds in the row.
423  WERD_IT werd_it(row->word_list());
424  for (werd_it.mark_cycle_pt(); !werd_it.cycled_list(); werd_it.forward()) {
425  WERD* werd = werd_it.data();
426  ++num_words;
427  num_blobs += werd->cblob_list()->length();
428  }
429  }
430  }
431  tprintf("Block list stats:\nBlocks = %d\nRows = %d\nWords = %d\nBlobs = %d\n",
432  num_blocks, num_rows, num_words, num_blobs);
433 }
ROW_LIST * row_list()
get rows
Definition: ocrblock.h:118
WERD_LIST * word_list()
Definition: ocrrow.h:55
Definition: werd.h:59
Definition: ocrrow.h:36
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:37
Definition: ocrblock.h:30
C_BLOB_LIST * cblob_list()
Definition: werd.h:98

◆ RefreshWordBlobsFromNewBlobs()

void RefreshWordBlobsFromNewBlobs ( BLOCK_LIST *  block_list,
C_BLOB_LIST *  new_blobs,
C_BLOB_LIST *  not_found_blobs 
)

Definition at line 477 of file ocrblock.cpp.

479  {
480  // Now iterate over all the blobs in the segmentation_block_list_, and just
481  // replace the corresponding c-blobs inside the werds.
482  BLOCK_IT block_it(block_list);
483  for (block_it.mark_cycle_pt(); !block_it.cycled_list(); block_it.forward()) {
484  BLOCK* block = block_it.data();
485  if (block->pdblk.poly_block() != nullptr && !block->pdblk.poly_block()->IsText())
486  continue; // Don't touch non-text blocks.
487  // Iterate over all rows in the block.
488  ROW_IT row_it(block->row_list());
489  for (row_it.mark_cycle_pt(); !row_it.cycled_list(); row_it.forward()) {
490  ROW* row = row_it.data();
491  // Iterate over all werds in the row.
492  WERD_IT werd_it(row->word_list());
493  WERD_LIST new_words;
494  WERD_IT new_words_it(&new_words);
495  for (werd_it.mark_cycle_pt(); !werd_it.cycled_list(); werd_it.forward()) {
496  WERD* werd = werd_it.extract();
497  WERD* new_werd = werd->ConstructWerdWithNewBlobs(new_blobs,
498  not_found_blobs);
499  if (new_werd) {
500  // Insert this new werd into the actual row's werd-list. Remove the
501  // existing one.
502  new_words_it.add_after_then_move(new_werd);
503  delete werd;
504  } else {
505  // Reinsert the older word back, for lack of better options.
506  // This is critical since dropping the words messes up segmentation:
507  // eg. 1st word in the row might otherwise have W_FUZZY_NON turned on.
508  new_words_it.add_after_then_move(werd);
509  }
510  }
511  // Get rid of the old word list & replace it with the new one.
512  row->word_list()->clear();
513  werd_it.move_to_first();
514  werd_it.add_list_after(&new_words);
515  }
516  }
517 }
ROW_LIST * row_list()
get rows
Definition: ocrblock.h:118
WERD_LIST * word_list()
Definition: ocrrow.h:55
POLY_BLOCK * poly_block() const
Definition: pdblock.h:56
Definition: werd.h:59
Definition: ocrrow.h:36
bool IsText() const
Definition: polyblk.h:49
Definition: ocrblock.h:30
WERD * ConstructWerdWithNewBlobs(C_BLOB_LIST *all_blobs, C_BLOB_LIST *orphan_blobs)
Definition: werd.cpp:411
PDBLK pdblk
Definition: ocrblock.h:192