tesseract  4.0.0-1-g2a2b
ROW_RES Class Reference

#include <pageres.h>

Inheritance diagram for ROW_RES:
ELIST_LINK

Public Member Functions

 ROW_RES ()=default
 
 ROW_RES (bool merge_similar_words, ROW *the_row)
 
 ~ROW_RES ()=default
 
- Public Member Functions inherited from ELIST_LINK
 ELIST_LINK ()
 
 ELIST_LINK (const ELIST_LINK &)
 
void operator= (const ELIST_LINK &)
 

Public Attributes

ROWrow
 
int32_t char_count
 
int32_t rej_count
 
int32_t whole_word_rej_count
 
WERD_RES_LIST word_res_list
 

Detailed Description

Definition at line 141 of file pageres.h.

Constructor & Destructor Documentation

◆ ROW_RES() [1/2]

ROW_RES::ROW_RES ( )
default

◆ ROW_RES() [2/2]

ROW_RES::ROW_RES ( bool  merge_similar_words,
ROW the_row 
)

Definition at line 124 of file pageres.cpp.

124  {
125  WERD_IT word_it(the_row->word_list());
126  WERD_RES_IT word_res_it(&word_res_list);
127  WERD_RES *combo = nullptr; // current combination of fuzzies
128  WERD *copy_word;
129 
130  char_count = 0;
131  rej_count = 0;
133 
134  row = the_row;
135  bool add_next_word = false;
136  TBOX union_box;
137  float line_height = the_row->x_height() + the_row->ascenders() -
138  the_row->descenders();
139  for (word_it.mark_cycle_pt(); !word_it.cycled_list(); word_it.forward()) {
140  WERD_RES* word_res = new WERD_RES(word_it.data());
141  word_res->x_height = the_row->x_height();
142  if (add_next_word) {
143  ASSERT_HOST(combo != nullptr);
144  // We are adding this word to the combination.
145  word_res->part_of_combo = TRUE;
146  combo->copy_on(word_res);
147  } else if (merge_similar_words) {
148  union_box = word_res->word->bounding_box();
149  add_next_word = !word_res->word->flag(W_REP_CHAR) &&
150  union_box.height() <= line_height * kMaxWordSizeRatio;
151  word_res->odd_size = !add_next_word;
152  }
153  WERD* next_word = word_it.data_relative(1);
154  if (merge_similar_words) {
155  if (add_next_word && !next_word->flag(W_REP_CHAR)) {
156  // Next word will be added on if all of the following are true:
157  // Not a rep char.
158  // Box height small enough.
159  // Union box height small enough.
160  // Horizontal gap small enough.
161  TBOX next_box = next_word->bounding_box();
162  int prev_right = union_box.right();
163  union_box += next_box;
164  if (next_box.height() > line_height * kMaxWordSizeRatio ||
165  union_box.height() > line_height * kMaxLineSizeRatio ||
166  next_box.left() > prev_right + line_height * kMaxWordGapRatio) {
167  add_next_word = false;
168  }
169  }
170  next_word->set_flag(W_FUZZY_NON, add_next_word);
171  } else {
172  add_next_word = next_word->flag(W_FUZZY_NON);
173  }
174  if (add_next_word) {
175  if (combo == nullptr) {
176  copy_word = new WERD;
177  *copy_word = *(word_it.data()); // deep copy
178  combo = new WERD_RES(copy_word);
179  combo->x_height = the_row->x_height();
180  combo->combination = TRUE;
181  word_res_it.add_to_end(combo);
182  }
183  word_res->part_of_combo = TRUE;
184  } else {
185  combo = nullptr;
186  }
187  word_res_it.add_to_end(word_res);
188  }
189 }
WERD_RES_LIST word_res_list
Definition: pageres.h:147
const double kMaxWordGapRatio
Definition: pageres.cpp:62
#define TRUE
Definition: capi.h:51
const double kMaxLineSizeRatio
Definition: pageres.cpp:60
int32_t whole_word_rej_count
Definition: pageres.h:146
TBOX bounding_box() const
Definition: werd.cpp:159
Definition: rect.h:34
WERD_LIST * word_list()
Definition: ocrrow.h:55
bool odd_size
Definition: pageres.h:300
void set_flag(WERD_FLAGS mask, bool value)
Definition: werd.h:127
int16_t left() const
Definition: rect.h:72
float ascenders() const
Definition: ocrrow.h:82
bool flag(WERD_FLAGS mask) const
Definition: werd.h:126
float x_height() const
Definition: ocrrow.h:64
void copy_on(WERD_RES *word_res)
Definition: pageres.h:660
Definition: werd.h:59
float descenders() const
Definition: ocrrow.h:85
bool combination
Definition: pageres.h:334
float x_height
Definition: pageres.h:311
const double kMaxWordSizeRatio
Definition: pageres.cpp:58
bool part_of_combo
Definition: pageres.h:335
int16_t right() const
Definition: rect.h:79
int32_t char_count
Definition: pageres.h:144
int32_t rej_count
Definition: pageres.h:145
int16_t height() const
Definition: rect.h:108
ROW * row
Definition: pageres.h:143
#define ASSERT_HOST(x)
Definition: errcode.h:84
WERD * word
Definition: pageres.h:189

◆ ~ROW_RES()

ROW_RES::~ROW_RES ( )
default

Member Data Documentation

◆ char_count

int32_t ROW_RES::char_count

Definition at line 144 of file pageres.h.

◆ rej_count

int32_t ROW_RES::rej_count

Definition at line 145 of file pageres.h.

◆ row

ROW* ROW_RES::row

Definition at line 143 of file pageres.h.

◆ whole_word_rej_count

int32_t ROW_RES::whole_word_rej_count

Definition at line 146 of file pageres.h.

◆ word_res_list

WERD_RES_LIST ROW_RES::word_res_list

Definition at line 147 of file pageres.h.


The documentation for this class was generated from the following files: