tesseract  5.0.0-alpha-619-ge9db
BLOBNBOX Class Reference

#include <blobbox.h>

Inheritance diagram for BLOBNBOX:
ELIST_LINK

Public Member Functions

 BLOBNBOX ()
 
 BLOBNBOX (C_BLOB *srcblob)
 
 ~BLOBNBOX ()
 
void rotate (FCOORD rotation)
 
void reflect_box_in_y_axis ()
 
void rotate_box (FCOORD rotation)
 
void translate_box (ICOORD v)
 
void merge (BLOBNBOX *nextblob)
 
void really_merge (BLOBNBOX *other)
 
void chop (BLOBNBOX_IT *start_it, BLOBNBOX_IT *blob_it, FCOORD rotation, float xheight)
 
void NeighbourGaps (int gaps[BND_COUNT]) const
 
void MinMaxGapsClipped (int *h_min, int *h_max, int *v_min, int *v_max) const
 
void CleanNeighbours ()
 
int GoodTextBlob () const
 
int NoisyNeighbours () const
 
bool DeletableNoise () const
 
bool DefiniteIndividualFlow ()
 
bool ConfirmNoTabViolation (const BLOBNBOX &other) const
 
bool MatchingStrokeWidth (const BLOBNBOX &other, double fractional_tolerance, double constant_tolerance) const
 
TBOX BoundsWithinLimits (int left, int right)
 
void EstimateBaselinePosition ()
 
const TBOXbounding_box () const
 
void set_bounding_box (const TBOX &new_box)
 
void compute_bounding_box ()
 
const TBOXreduced_box () const
 
void set_reduced_box (TBOX new_box)
 
int32_t enclosed_area () const
 
bool joined_to_prev () const
 
bool red_box_set () const
 
int repeated_set () const
 
void set_repeated_set (int set_id)
 
C_BLOBcblob () const
 
TabType left_tab_type () const
 
void set_left_tab_type (TabType new_type)
 
TabType right_tab_type () const
 
void set_right_tab_type (TabType new_type)
 
BlobRegionType region_type () const
 
void set_region_type (BlobRegionType new_type)
 
BlobSpecialTextType special_text_type () const
 
void set_special_text_type (BlobSpecialTextType new_type)
 
BlobTextFlowType flow () const
 
void set_flow (BlobTextFlowType value)
 
bool vert_possible () const
 
void set_vert_possible (bool value)
 
bool horz_possible () const
 
void set_horz_possible (bool value)
 
int left_rule () const
 
void set_left_rule (int new_left)
 
int right_rule () const
 
void set_right_rule (int new_right)
 
int left_crossing_rule () const
 
void set_left_crossing_rule (int new_left)
 
int right_crossing_rule () const
 
void set_right_crossing_rule (int new_right)
 
float horz_stroke_width () const
 
void set_horz_stroke_width (float width)
 
float vert_stroke_width () const
 
void set_vert_stroke_width (float width)
 
float area_stroke_width () const
 
tesseract::ColPartitionowner () const
 
void set_owner (tesseract::ColPartition *new_owner)
 
bool leader_on_left () const
 
void set_leader_on_left (bool flag)
 
bool leader_on_right () const
 
void set_leader_on_right (bool flag)
 
BLOBNBOXneighbour (BlobNeighbourDir n) const
 
bool good_stroke_neighbour (BlobNeighbourDir n) const
 
void set_neighbour (BlobNeighbourDir n, BLOBNBOX *neighbour, bool good)
 
bool IsDiacritic () const
 
int base_char_top () const
 
int base_char_bottom () const
 
int baseline_position () const
 
int line_crossings () const
 
void set_line_crossings (int value)
 
void set_diacritic_box (const TBOX &diacritic_box)
 
BLOBNBOXbase_char_blob () const
 
void set_base_char_blob (BLOBNBOX *blob)
 
void set_owns_cblob (bool value)
 
bool UniquelyVertical () const
 
bool UniquelyHorizontal () const
 
ScrollView::Color BoxColor () const
 
void plot (ScrollView *window, ScrollView::Color blob_colour, ScrollView::Color child_colour)
 
void ReInit ()
 
void ClearNeighbours ()
 
- Public Member Functions inherited from ELIST_LINK
 ELIST_LINK ()
 
 ELIST_LINK (const ELIST_LINK &)
 
void operator= (const ELIST_LINK &)
 

Static Public Member Functions

static BLOBNBOXRealBlob (C_OUTLINE *outline)
 
static bool IsTextType (BlobRegionType type)
 
static bool IsImageType (BlobRegionType type)
 
static bool IsLineType (BlobRegionType type)
 
static bool UnMergeableType (BlobRegionType type)
 
static void CleanNeighbours (BLOBNBOX_LIST *blobs)
 
static void DeleteNoiseBlobs (BLOBNBOX_LIST *blobs)
 
static void ComputeEdgeOffsets (Pix *thresholds, Pix *grey, BLOBNBOX_LIST *blobs)
 
static void PlotBlobs (BLOBNBOX_LIST *list, ScrollView::Color body_colour, ScrollView::Color child_colour, ScrollView *win)
 
static void PlotNoiseBlobs (BLOBNBOX_LIST *list, ScrollView::Color body_colour, ScrollView::Color child_colour, ScrollView *win)
 
static ScrollView::Color TextlineColor (BlobRegionType region_type, BlobTextFlowType flow_type)
 

Detailed Description

Definition at line 142 of file blobbox.h.

Constructor & Destructor Documentation

◆ BLOBNBOX() [1/2]

BLOBNBOX::BLOBNBOX ( )
inline

Definition at line 145 of file blobbox.h.

145  :
146  BLOBNBOX() {
147  ReInit();

◆ BLOBNBOX() [2/2]

BLOBNBOX::BLOBNBOX ( C_BLOB srcblob)
inlineexplicit

Definition at line 148 of file blobbox.h.

149  {
150  box = srcblob->bounding_box();
151  ReInit();
152  cblob_ptr = srcblob;
153  area = static_cast<int>(srcblob->area());

◆ ~BLOBNBOX()

BLOBNBOX::~BLOBNBOX ( )
inline

Definition at line 154 of file blobbox.h.

155  {
156  if (owns_cblob_) delete cblob_ptr;

Member Function Documentation

◆ area_stroke_width()

float BLOBNBOX::area_stroke_width ( ) const
inline

Definition at line 348 of file blobbox.h.

349  {
350  return area_stroke_width_;

◆ base_char_blob()

BLOBNBOX* BLOBNBOX::base_char_blob ( ) const
inline

Definition at line 401 of file blobbox.h.

402  {
403  return base_char_blob_;

◆ base_char_bottom()

int BLOBNBOX::base_char_bottom ( ) const
inline

Definition at line 385 of file blobbox.h.

386  {
387  return base_char_bottom_;

◆ base_char_top()

int BLOBNBOX::base_char_top ( ) const
inline

Definition at line 382 of file blobbox.h.

383  {
384  return base_char_top_;

◆ baseline_position()

int BLOBNBOX::baseline_position ( ) const
inline

Definition at line 388 of file blobbox.h.

389  {
390  return baseline_y_;

◆ bounding_box()

const TBOX& BLOBNBOX::bounding_box ( ) const
inline

Definition at line 229 of file blobbox.h.

230  {
231  return box;

◆ BoundsWithinLimits()

TBOX BLOBNBOX::BoundsWithinLimits ( int  left,
int  right 
)

Definition at line 331 of file blobbox.cpp.

333  {
334  FCOORD no_rotation(1.0f, 0.0f);
335  float top = box.top();
336  float bottom = box.bottom();
337  if (cblob_ptr != nullptr) {
338  find_cblob_limits(cblob_ptr, static_cast<float>(left),
339  static_cast<float>(right), no_rotation,
340  bottom, top);
341  }
342 
343  if (top < bottom) {
344  top = box.top();
345  bottom = box.bottom();
346  }
347  FCOORD bot_left(left, bottom);
348  FCOORD top_right(right, top);
349  TBOX shrunken_box(bot_left);
350  TBOX shrunken_box2(top_right);
351  shrunken_box += shrunken_box2;

◆ BoxColor()

ScrollView::Color BLOBNBOX::BoxColor ( ) const

Definition at line 479 of file blobbox.cpp.

481  {

◆ cblob()

C_BLOB* BLOBNBOX::cblob ( ) const
inline

Definition at line 267 of file blobbox.h.

268  {
269  return cblob_ptr;

◆ chop()

void BLOBNBOX::chop ( BLOBNBOX_IT *  start_it,
BLOBNBOX_IT *  blob_it,
FCOORD  rotation,
float  xheight 
)

Definition at line 118 of file blobbox.cpp.

125  {
126  int16_t blobcount; //no of blobs
127  BLOBNBOX *newblob; //fake blob
128  BLOBNBOX *blob; //current blob
129  int16_t blobindex; //number of chop
130  int16_t leftx; //left edge of blob
131  float blobwidth; //width of each
132  float rightx; //right edge to scan
133  float ymin, ymax; //limits of new blob
134  float test_ymin, test_ymax; //limits of part blob
135  ICOORD bl, tr; //corners of box
136  BLOBNBOX_IT blob_it; //blob iterator
137 
138  //get no of chops
139  blobcount = static_cast<int16_t>(floor (box.width () / xheight));
140  if (blobcount > 1 && cblob_ptr != nullptr) {
141  //width of each
142  blobwidth = static_cast<float>(box.width () + 1) / blobcount;
143  for (blobindex = blobcount - 1, rightx = box.right ();
144  blobindex >= 0; blobindex--, rightx -= blobwidth) {
145  ymin = static_cast<float>(INT32_MAX);
146  ymax = static_cast<float>(-INT32_MAX);
147  blob_it = *start_it;
148  do {
149  blob = blob_it.data ();
150  find_cblob_vlimits(blob->cblob_ptr, rightx - blobwidth,
151  rightx,
152  /*rotation, */ test_ymin, test_ymax);
153  blob_it.forward ();
154  UpdateRange(test_ymin, test_ymax, &ymin, &ymax);
155  }
156  while (blob != end_it->data ());
157  if (ymin < ymax) {
158  leftx = static_cast<int16_t>(floor (rightx - blobwidth));
159  if (leftx < box.left ())
160  leftx = box.left (); //clip to real box
161  bl = ICOORD (leftx, static_cast<int16_t>(floor (ymin)));
162  tr = ICOORD (static_cast<int16_t>(ceil (rightx)), static_cast<int16_t>(ceil (ymax)));
163  if (blobindex == 0)
164  box = TBOX (bl, tr); //change box
165  else {
166  newblob = new BLOBNBOX;
167  //box is all it has
168  newblob->box = TBOX (bl, tr);
169  //stay on current
170  newblob->base_char_top_ = tr.y();
171  newblob->base_char_bottom_ = bl.y();
172  end_it->add_after_stay_put (newblob);
173  }
174  }
175  }

◆ CleanNeighbours() [1/2]

void BLOBNBOX::CleanNeighbours ( )

Definition at line 212 of file blobbox.cpp.

214  {
215  for (int dir = 0; dir < BND_COUNT; ++dir) {
216  BLOBNBOX* neighbour = neighbours_[dir];
217  if (neighbour != nullptr && neighbour->DeletableNoise()) {
218  neighbours_[dir] = nullptr;
219  good_stroke_neighbours_[dir] = false;
220  }

◆ CleanNeighbours() [2/2]

void BLOBNBOX::CleanNeighbours ( BLOBNBOX_LIST *  blobs)
static

Definition at line 362 of file blobbox.cpp.

364  {
365  BLOBNBOX_IT blob_it(blobs);
366  for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
367  blob_it.data()->CleanNeighbours();

◆ ClearNeighbours()

void BLOBNBOX::ClearNeighbours ( )
inline

Definition at line 498 of file blobbox.h.

499  {
500  for (int n = 0; n < BND_COUNT; ++n) {
501  neighbours_[n] = nullptr;
502  good_stroke_neighbours_[n] = false;
503  }

◆ compute_bounding_box()

void BLOBNBOX::compute_bounding_box ( )
inline

Definition at line 239 of file blobbox.h.

240  {
241  box = cblob_ptr->bounding_box();
242  base_char_top_ = box.top();
243  base_char_bottom_ = box.bottom();
244  baseline_y_ = box.bottom();

◆ ComputeEdgeOffsets()

void BLOBNBOX::ComputeEdgeOffsets ( Pix *  thresholds,
Pix *  grey,
BLOBNBOX_LIST *  blobs 
)
static

Definition at line 383 of file blobbox.cpp.

386  {
387  int grey_height = 0;
388  int thr_height = 0;
389  int scale_factor = 1;
390  if (thresholds != nullptr && grey != nullptr) {
391  grey_height = pixGetHeight(grey);
392  thr_height = pixGetHeight(thresholds);
393  scale_factor =
394  IntCastRounded(static_cast<double>(grey_height) / thr_height);
395  }
396  BLOBNBOX_IT blob_it(blobs);
397  for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
398  BLOBNBOX* blob = blob_it.data();
399  if (blob->cblob() != nullptr) {
400  // Get the threshold that applies to this blob.
401  l_uint32 threshold = 128;
402  if (thresholds != nullptr && grey != nullptr) {
403  const TBOX& box = blob->cblob()->bounding_box();
404  // Transform the coordinates if required.
405  TPOINT pt((box.left() + box.right()) / 2,
406  (box.top() + box.bottom()) / 2);
407  pixGetPixel(thresholds, pt.x / scale_factor,
408  thr_height - 1 - pt.y / scale_factor, &threshold);
409  }
410  blob->cblob()->ComputeEdgeOffsets(threshold, grey);
411  }

◆ ConfirmNoTabViolation()

bool BLOBNBOX::ConfirmNoTabViolation ( const BLOBNBOX other) const

Definition at line 290 of file blobbox.cpp.

292  {
293  if (box.left() < other.box.left() && box.left() < other.left_rule_)
294  return false;
295  if (other.box.left() < box.left() && other.box.left() < left_rule_)
296  return false;
297  if (box.right() > other.box.right() && box.right() > other.right_rule_)
298  return false;
299  if (other.box.right() > box.right() && other.box.right() > right_rule_)
300  return false;

◆ DefiniteIndividualFlow()

bool BLOBNBOX::DefiniteIndividualFlow ( )

Definition at line 250 of file blobbox.cpp.

252  {
253  if (cblob() == nullptr) return false;
254  int box_perimeter = 2 * (box.height() + box.width());
255  if (box.width() > box.height() * kDefiniteAspectRatio) {
256  // Attempt to distinguish a wide joined word from a dash.
257  // If it is a dash, then its perimeter is approximately
258  // 2 * (box width + stroke width), but more if the outline is noisy,
259  // so perimeter - 2*(box width + stroke width) should be close to zero.
260  // A complex shape such as a joined word should have a much larger value.
261  int perimeter = cblob()->perimeter();
262  if (vert_stroke_width() > 0 || perimeter <= 0)
263  perimeter -= 2 * vert_stroke_width();
264  else
265  perimeter -= 4 * cblob()->area() / perimeter;
266  perimeter -= 2 * box.width();
267  // Use a multiple of the box perimeter as a threshold.
268  if (perimeter > kComplexShapePerimeterRatio * box_perimeter) {
269  set_vert_possible(false);
270  set_horz_possible(true);
271  return true;
272  }
273  }
274  if (box.height() > box.width() * kDefiniteAspectRatio) {
275  // As above, but for a putative vertical word vs a I/1/l.
276  int perimeter = cblob()->perimeter();
277  if (horz_stroke_width() > 0 || perimeter <= 0)
278  perimeter -= 2 * horz_stroke_width();
279  else
280  perimeter -= 4 * cblob()->area() / perimeter;
281  perimeter -= 2 * box.height();
282  if (perimeter > kComplexShapePerimeterRatio * box_perimeter) {
283  set_vert_possible(true);
284  set_horz_possible(false);
285  return true;
286  }
287  }

◆ DeletableNoise()

bool BLOBNBOX::DeletableNoise ( ) const
inline

Definition at line 202 of file blobbox.h.

203  {
204  return owner() == nullptr && region_type() == BRT_NOISE;

◆ DeleteNoiseBlobs()

void BLOBNBOX::DeleteNoiseBlobs ( BLOBNBOX_LIST *  blobs)
static

Definition at line 370 of file blobbox.cpp.

372  {
373  BLOBNBOX_IT blob_it(blobs);
374  for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
375  BLOBNBOX* blob = blob_it.data();
376  if (blob->DeletableNoise()) {
377  delete blob->cblob();
378  delete blob_it.extract();
379  }

◆ enclosed_area()

int32_t BLOBNBOX::enclosed_area ( ) const
inline

Definition at line 252 of file blobbox.h.

253  {
254  return area;

◆ EstimateBaselinePosition()

void BLOBNBOX::EstimateBaselinePosition ( )

Definition at line 355 of file blobbox.cpp.

357  {
358  baseline_y_ = box.bottom(); // The default.
359  if (cblob_ptr == nullptr) return;

◆ flow()

BlobTextFlowType BLOBNBOX::flow ( ) const
inline

Definition at line 294 of file blobbox.h.

295  {
296  return flow_;

◆ good_stroke_neighbour()

bool BLOBNBOX::good_stroke_neighbour ( BlobNeighbourDir  n) const
inline

Definition at line 372 of file blobbox.h.

373  {
374  return good_stroke_neighbours_[n];

◆ GoodTextBlob()

int BLOBNBOX::GoodTextBlob ( ) const

Definition at line 224 of file blobbox.cpp.

226  {
227  int score = 0;
228  for (int dir = 0; dir < BND_COUNT; ++dir) {
229  auto bnd = static_cast<BlobNeighbourDir>(dir);
230  if (good_stroke_neighbour(bnd))
231  ++score;
232  }

◆ horz_possible()

bool BLOBNBOX::horz_possible ( ) const
inline

Definition at line 306 of file blobbox.h.

307  {
308  return horz_possible_;

◆ horz_stroke_width()

float BLOBNBOX::horz_stroke_width ( ) const
inline

Definition at line 336 of file blobbox.h.

337  {
338  return horz_stroke_width_;

◆ IsDiacritic()

bool BLOBNBOX::IsDiacritic ( ) const
inline

Definition at line 379 of file blobbox.h.

380  {
381  return base_char_top_ != box.top() || base_char_bottom_ != box.bottom();

◆ IsImageType()

static bool BLOBNBOX::IsImageType ( BlobRegionType  type)
inlinestatic

Definition at line 421 of file blobbox.h.

422  {
423  return type == BRT_RECTIMAGE || type == BRT_POLYIMAGE;

◆ IsLineType()

static bool BLOBNBOX::IsLineType ( BlobRegionType  type)
inlinestatic

Definition at line 425 of file blobbox.h.

426  {
427  return type == BRT_HLINE || type == BRT_VLINE;

◆ IsTextType()

static bool BLOBNBOX::IsTextType ( BlobRegionType  type)
inlinestatic

Definition at line 417 of file blobbox.h.

418  {
419  return type == BRT_TEXT || type == BRT_VERT_TEXT;

◆ joined_to_prev()

bool BLOBNBOX::joined_to_prev ( ) const
inline

Definition at line 255 of file blobbox.h.

256  {
257  return joined;

◆ leader_on_left()

bool BLOBNBOX::leader_on_left ( ) const
inline

Definition at line 357 of file blobbox.h.

358  {
359  return leader_on_left_;

◆ leader_on_right()

bool BLOBNBOX::leader_on_right ( ) const
inline

Definition at line 363 of file blobbox.h.

364  {
365  return leader_on_right_;

◆ left_crossing_rule()

int BLOBNBOX::left_crossing_rule ( ) const
inline

Definition at line 324 of file blobbox.h.

325  {
326  return left_crossing_rule_;

◆ left_rule()

int BLOBNBOX::left_rule ( ) const
inline

Definition at line 312 of file blobbox.h.

313  {
314  return left_rule_;

◆ left_tab_type()

TabType BLOBNBOX::left_tab_type ( ) const
inline

Definition at line 270 of file blobbox.h.

271  {
272  return left_tab_type_;

◆ line_crossings()

int BLOBNBOX::line_crossings ( ) const
inline

Definition at line 391 of file blobbox.h.

392  {
393  return line_crossings_;

◆ MatchingStrokeWidth()

bool BLOBNBOX::MatchingStrokeWidth ( const BLOBNBOX other,
double  fractional_tolerance,
double  constant_tolerance 
) const

Definition at line 303 of file blobbox.cpp.

307  {
308  // The perimeter-based width is used as a backup in case there is
309  // no information in the blob.
310  double p_width = area_stroke_width();
311  double n_p_width = other.area_stroke_width();
312  float h_tolerance = horz_stroke_width_ * fractional_tolerance
313  + constant_tolerance;
314  float v_tolerance = vert_stroke_width_ * fractional_tolerance
315  + constant_tolerance;
316  double p_tolerance = p_width * fractional_tolerance
317  + constant_tolerance;
318  bool h_zero = horz_stroke_width_ == 0.0f || other.horz_stroke_width_ == 0.0f;
319  bool v_zero = vert_stroke_width_ == 0.0f || other.vert_stroke_width_ == 0.0f;
320  bool h_ok = !h_zero && NearlyEqual(horz_stroke_width_,
321  other.horz_stroke_width_, h_tolerance);
322  bool v_ok = !v_zero && NearlyEqual(vert_stroke_width_,
323  other.vert_stroke_width_, v_tolerance);
324  bool p_ok = h_zero && v_zero && NearlyEqual(p_width, n_p_width, p_tolerance);
325  // For a match, at least one of the horizontal and vertical widths
326  // must match, and the other one must either match or be zero.
327  // Only if both are zero will we look at the perimeter metric.

◆ merge()

void BLOBNBOX::merge ( BLOBNBOX nextblob)

Definition at line 91 of file blobbox.cpp.

94  {
95  box += nextblob->box; //merge boxes
96  set_diacritic_box(box);
97  nextblob->joined = true;

◆ MinMaxGapsClipped()

void BLOBNBOX::MinMaxGapsClipped ( int *  h_min,
int *  h_max,
int *  v_min,
int *  v_max 
) const

Definition at line 198 of file blobbox.cpp.

201  {
202  int max_dimension = std::max(box.width(), box.height());
203  int gaps[BND_COUNT];
204  NeighbourGaps(gaps);
205  *h_min = std::min(gaps[BND_LEFT], gaps[BND_RIGHT]);
206  *h_max = std::max(gaps[BND_LEFT], gaps[BND_RIGHT]);
207  if (*h_max > max_dimension && *h_min < max_dimension) *h_max = *h_min;
208  *v_min = std::min(gaps[BND_ABOVE], gaps[BND_BELOW]);
209  *v_max = std::max(gaps[BND_ABOVE], gaps[BND_BELOW]);

◆ neighbour()

BLOBNBOX* BLOBNBOX::neighbour ( BlobNeighbourDir  n) const
inline

Definition at line 369 of file blobbox.h.

370  {
371  return neighbours_[n];

◆ NeighbourGaps()

void BLOBNBOX::NeighbourGaps ( int  gaps[BND_COUNT]) const

Definition at line 179 of file blobbox.cpp.

181  {
182  for (int dir = 0; dir < BND_COUNT; ++dir) {
183  gaps[dir] = INT16_MAX;
184  BLOBNBOX* neighbour = neighbours_[dir];
185  if (neighbour != nullptr) {
186  const TBOX& n_box = neighbour->bounding_box();
187  if (dir == BND_LEFT || dir == BND_RIGHT) {
188  gaps[dir] = box.x_gap(n_box);
189  } else {
190  gaps[dir] = box.y_gap(n_box);
191  }
192  }

◆ NoisyNeighbours()

int BLOBNBOX::NoisyNeighbours ( ) const

Definition at line 235 of file blobbox.cpp.

237  {
238  int count = 0;
239  for (int dir = 0; dir < BND_COUNT; ++dir) {
240  auto bnd = static_cast<BlobNeighbourDir>(dir);
241  BLOBNBOX* blob = neighbour(bnd);
242  if (blob != nullptr && blob->region_type() == BRT_NOISE)
243  ++count;
244  }

◆ owner()

tesseract::ColPartition* BLOBNBOX::owner ( ) const
inline

Definition at line 351 of file blobbox.h.

352  {
353  return owner_;

◆ plot()

void BLOBNBOX::plot ( ScrollView window,
ScrollView::Color  blob_colour,
ScrollView::Color  child_colour 
)

Definition at line 483 of file blobbox.cpp.

487  { // for holes
488  if (cblob_ptr != nullptr)

◆ PlotBlobs()

void BLOBNBOX::PlotBlobs ( BLOBNBOX_LIST *  list,
ScrollView::Color  body_colour,
ScrollView::Color  child_colour,
ScrollView win 
)
static

Definition at line 417 of file blobbox.cpp.

422  {
423  BLOBNBOX_IT it(list);
424  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
425  it.data()->plot(win, body_colour, child_colour);

◆ PlotNoiseBlobs()

void BLOBNBOX::PlotNoiseBlobs ( BLOBNBOX_LIST *  list,
ScrollView::Color  body_colour,
ScrollView::Color  child_colour,
ScrollView win 
)
static

Definition at line 430 of file blobbox.cpp.

435  {
436  BLOBNBOX_IT it(list);
437  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
438  BLOBNBOX* blob = it.data();
439  if (blob->DeletableNoise())
440  blob->plot(win, body_colour, child_colour);

◆ RealBlob()

static BLOBNBOX* BLOBNBOX::RealBlob ( C_OUTLINE outline)
inlinestatic

Definition at line 157 of file blobbox.h.

158  {
159  auto* blob = new C_BLOB(outline);
160  return new BLOBNBOX(blob);

◆ really_merge()

void BLOBNBOX::really_merge ( BLOBNBOX other)

Definition at line 102 of file blobbox.cpp.

103  {
104  if (other->cblob_ptr != nullptr) {
105  C_OUTLINE_IT ol_it(cblob_ptr->out_list());
106  ol_it.add_list_after(other->cblob_ptr->out_list());
107  }

◆ red_box_set()

bool BLOBNBOX::red_box_set ( ) const
inline

Definition at line 258 of file blobbox.h.

259  {
260  return reduced;

◆ reduced_box()

const TBOX& BLOBNBOX::reduced_box ( ) const
inline

Definition at line 245 of file blobbox.h.

246  {
247  return red_box;

◆ reflect_box_in_y_axis()

void BLOBNBOX::reflect_box_in_y_axis ( )

Definition at line 62 of file blobbox.cpp.

62  {
63  int left = -box.right();
64  box.set_right(-box.left());
65  box.set_left(left);
66 }

◆ region_type()

BlobRegionType BLOBNBOX::region_type ( ) const
inline

Definition at line 282 of file blobbox.h.

283  {
284  return region_type_;

◆ ReInit()

void BLOBNBOX::ReInit ( )
inline

Definition at line 469 of file blobbox.h.

470  {
471  joined = false;
472  reduced = false;
473  repeated_set_ = 0;
474  left_tab_type_ = TT_NONE;
475  right_tab_type_ = TT_NONE;
476  region_type_ = BRT_UNKNOWN;
477  flow_ = BTFT_NONE;
478  spt_type_ = BSTT_SKIP;
479  left_rule_ = 0;
480  right_rule_ = 0;
481  left_crossing_rule_ = 0;
482  right_crossing_rule_ = 0;
483  if (area_stroke_width_ == 0.0f && area > 0 && cblob() != nullptr
484  && cblob()->perimeter()!=0)
485  area_stroke_width_ = 2.0f * area / cblob()->perimeter();
486  owner_ = nullptr;
487  base_char_top_ = box.top();
488  base_char_bottom_ = box.bottom();
489  baseline_y_ = box.bottom();
490  line_crossings_ = 0;
491  base_char_blob_ = nullptr;
492  horz_possible_ = false;
493  vert_possible_ = false;
494  leader_on_left_ = false;
495  leader_on_right_ = false;
496  ClearNeighbours();

◆ repeated_set()

int BLOBNBOX::repeated_set ( ) const
inline

Definition at line 261 of file blobbox.h.

262  {
263  return repeated_set_;

◆ right_crossing_rule()

int BLOBNBOX::right_crossing_rule ( ) const
inline

Definition at line 330 of file blobbox.h.

331  {
332  return right_crossing_rule_;

◆ right_rule()

int BLOBNBOX::right_rule ( ) const
inline

Definition at line 318 of file blobbox.h.

319  {
320  return right_rule_;

◆ right_tab_type()

TabType BLOBNBOX::right_tab_type ( ) const
inline

Definition at line 276 of file blobbox.h.

277  {
278  return right_tab_type_;

◆ rotate()

void BLOBNBOX::rotate ( FCOORD  rotation)

Definition at line 55 of file blobbox.cpp.

55  {
56  cblob_ptr->rotate(rotation);
57  rotate_box(rotation);
59 }

◆ rotate_box()

void BLOBNBOX::rotate_box ( FCOORD  rotation)

Definition at line 71 of file blobbox.cpp.

71  {
72  if (IsDiacritic()) {
73  ASSERT_HOST(rotation.x() >= kCosSmallAngle);
74  ICOORD top_pt((box.left() + box.right()) / 2, base_char_top_);
75  ICOORD bottom_pt(top_pt.x(), base_char_bottom_);
76  top_pt.rotate(rotation);
77  base_char_top_ = top_pt.y();
78  bottom_pt.rotate(rotation);
79  base_char_bottom_ = bottom_pt.y();
80  box.rotate(rotation);
81  } else {
82  box.rotate(rotation);
83  set_diacritic_box(box);
84  }
85 }

◆ set_base_char_blob()

void BLOBNBOX::set_base_char_blob ( BLOBNBOX blob)
inline

Definition at line 404 of file blobbox.h.

405  {
406  base_char_blob_ = blob;

◆ set_bounding_box()

void BLOBNBOX::set_bounding_box ( const TBOX new_box)
inline

Definition at line 234 of file blobbox.h.

235  {
236  box = new_box;
237  base_char_top_ = box.top();
238  base_char_bottom_ = box.bottom();

◆ set_diacritic_box()

void BLOBNBOX::set_diacritic_box ( const TBOX diacritic_box)
inline

Definition at line 397 of file blobbox.h.

398  {
399  base_char_top_ = diacritic_box.top();
400  base_char_bottom_ = diacritic_box.bottom();

◆ set_flow()

void BLOBNBOX::set_flow ( BlobTextFlowType  value)
inline

Definition at line 297 of file blobbox.h.

298  {
299  flow_ = value;

◆ set_horz_possible()

void BLOBNBOX::set_horz_possible ( bool  value)
inline

Definition at line 309 of file blobbox.h.

310  {
311  horz_possible_ = value;

◆ set_horz_stroke_width()

void BLOBNBOX::set_horz_stroke_width ( float  width)
inline

Definition at line 339 of file blobbox.h.

340  {
341  horz_stroke_width_ = width;

◆ set_leader_on_left()

void BLOBNBOX::set_leader_on_left ( bool  flag)
inline

Definition at line 360 of file blobbox.h.

361  {
362  leader_on_left_ = flag;

◆ set_leader_on_right()

void BLOBNBOX::set_leader_on_right ( bool  flag)
inline

Definition at line 366 of file blobbox.h.

367  {
368  leader_on_right_ = flag;

◆ set_left_crossing_rule()

void BLOBNBOX::set_left_crossing_rule ( int  new_left)
inline

Definition at line 327 of file blobbox.h.

328  {
329  left_crossing_rule_ = new_left;

◆ set_left_rule()

void BLOBNBOX::set_left_rule ( int  new_left)
inline

Definition at line 315 of file blobbox.h.

316  {
317  left_rule_ = new_left;

◆ set_left_tab_type()

void BLOBNBOX::set_left_tab_type ( TabType  new_type)
inline

Definition at line 273 of file blobbox.h.

274  {
275  left_tab_type_ = new_type;

◆ set_line_crossings()

void BLOBNBOX::set_line_crossings ( int  value)
inline

Definition at line 394 of file blobbox.h.

395  {
396  line_crossings_ = value;

◆ set_neighbour()

void BLOBNBOX::set_neighbour ( BlobNeighbourDir  n,
BLOBNBOX neighbour,
bool  good 
)
inline

Definition at line 375 of file blobbox.h.

376  {
377  neighbours_[n] = neighbour;
378  good_stroke_neighbours_[n] = good;

◆ set_owner()

void BLOBNBOX::set_owner ( tesseract::ColPartition new_owner)
inline

Definition at line 354 of file blobbox.h.

355  {
356  owner_ = new_owner;

◆ set_owns_cblob()

void BLOBNBOX::set_owns_cblob ( bool  value)
inline

Definition at line 407 of file blobbox.h.

408 { owns_cblob_ = value; }

◆ set_reduced_box()

void BLOBNBOX::set_reduced_box ( TBOX  new_box)
inline

Definition at line 248 of file blobbox.h.

249  {
250  red_box = new_box;
251  reduced = true;

◆ set_region_type()

void BLOBNBOX::set_region_type ( BlobRegionType  new_type)
inline

Definition at line 285 of file blobbox.h.

286  {
287  region_type_ = new_type;

◆ set_repeated_set()

void BLOBNBOX::set_repeated_set ( int  set_id)
inline

Definition at line 264 of file blobbox.h.

265  {
266  repeated_set_ = set_id;

◆ set_right_crossing_rule()

void BLOBNBOX::set_right_crossing_rule ( int  new_right)
inline

Definition at line 333 of file blobbox.h.

334  {
335  right_crossing_rule_ = new_right;

◆ set_right_rule()

void BLOBNBOX::set_right_rule ( int  new_right)
inline

Definition at line 321 of file blobbox.h.

322  {
323  right_rule_ = new_right;

◆ set_right_tab_type()

void BLOBNBOX::set_right_tab_type ( TabType  new_type)
inline

Definition at line 279 of file blobbox.h.

280  {
281  right_tab_type_ = new_type;

◆ set_special_text_type()

void BLOBNBOX::set_special_text_type ( BlobSpecialTextType  new_type)
inline

Definition at line 291 of file blobbox.h.

292  {
293  spt_type_ = new_type;

◆ set_vert_possible()

void BLOBNBOX::set_vert_possible ( bool  value)
inline

Definition at line 303 of file blobbox.h.

304  {
305  vert_possible_ = value;

◆ set_vert_stroke_width()

void BLOBNBOX::set_vert_stroke_width ( float  width)
inline

Definition at line 345 of file blobbox.h.

346  {
347  vert_stroke_width_ = width;

◆ special_text_type()

BlobSpecialTextType BLOBNBOX::special_text_type ( ) const
inline

Definition at line 288 of file blobbox.h.

289  {
290  return spt_type_;

◆ TextlineColor()

ScrollView::Color BLOBNBOX::TextlineColor ( BlobRegionType  region_type,
BlobTextFlowType  flow_type 
)
static

Definition at line 442 of file blobbox.cpp.

445  {
446  switch (region_type) {
447  case BRT_HLINE:
448  return ScrollView::BROWN;
449  case BRT_VLINE:
450  return ScrollView::DARK_GREEN;
451  case BRT_RECTIMAGE:
452  return ScrollView::RED;
453  case BRT_POLYIMAGE:
454  return ScrollView::ORANGE;
455  case BRT_UNKNOWN:
456  return flow_type == BTFT_NONTEXT ? ScrollView::CYAN : ScrollView::WHITE;
457  case BRT_VERT_TEXT:
458  if (flow_type == BTFT_STRONG_CHAIN || flow_type == BTFT_TEXT_ON_IMAGE)
459  return ScrollView::GREEN;
460  if (flow_type == BTFT_CHAIN)
461  return ScrollView::LIME_GREEN;
462  return ScrollView::YELLOW;
463  case BRT_TEXT:
464  if (flow_type == BTFT_STRONG_CHAIN)
465  return ScrollView::BLUE;
466  if (flow_type == BTFT_TEXT_ON_IMAGE)
467  return ScrollView::LIGHT_BLUE;
468  if (flow_type == BTFT_CHAIN)
470  if (flow_type == BTFT_LEADER)
471  return ScrollView::WHEAT;
472  if (flow_type == BTFT_NONTEXT)
473  return ScrollView::PINK;
474  return ScrollView::MAGENTA;
475  default:
476  return ScrollView::GREY;

◆ translate_box()

void BLOBNBOX::translate_box ( ICOORD  v)
inline

Definition at line 173 of file blobbox.h.

174  {
175  if (IsDiacritic()) {
176  box.move(v);
177  base_char_top_ += v.y();
178  base_char_bottom_ += v.y();
179  } else {
180  box.move(v);
181  set_diacritic_box(box);
182  }

◆ UniquelyHorizontal()

bool BLOBNBOX::UniquelyHorizontal ( ) const
inline

Definition at line 412 of file blobbox.h.

413  {
414  return horz_possible_ && !vert_possible_;

◆ UniquelyVertical()

bool BLOBNBOX::UniquelyVertical ( ) const
inline

Definition at line 409 of file blobbox.h.

410  {
411  return vert_possible_ && !horz_possible_;

◆ UnMergeableType()

static bool BLOBNBOX::UnMergeableType ( BlobRegionType  type)
inlinestatic

Definition at line 429 of file blobbox.h.

430  {
431  return IsLineType(type) || IsImageType(type);

◆ vert_possible()

bool BLOBNBOX::vert_possible ( ) const
inline

Definition at line 300 of file blobbox.h.

301  {
302  return vert_possible_;

◆ vert_stroke_width()

float BLOBNBOX::vert_stroke_width ( ) const
inline

Definition at line 342 of file blobbox.h.

343  {
344  return vert_stroke_width_;

The documentation for this class was generated from the following files:
ScrollView::GREY
Definition: scrollview.h:133
BLOBNBOX::ClearNeighbours
void ClearNeighbours()
Definition: blobbox.h:498
TBOX
Definition: cleanapi_test.cc:19
C_BLOB::bounding_box
TBOX bounding_box() const
Definition: stepblob.cpp:247
TBOX::move
void move(const ICOORD vec)
Definition: rect.h:156
C_BLOB::perimeter
int32_t perimeter()
Definition: stepblob.cpp:284
BND_RIGHT
Definition: blobbox.h:89
BLOBNBOX::rotate_box
void rotate_box(FCOORD rotation)
Definition: blobbox.cpp:71
BTFT_NONE
Definition: blobbox.h:114
kDefiniteAspectRatio
const double kDefiniteAspectRatio
Definition: blobbox.cpp:46
ScrollView::DARK_GREEN
Definition: scrollview.h:124
C_BLOB::out_list
C_OUTLINE_LIST * out_list()
Definition: stepblob.h:69
BTFT_STRONG_CHAIN
Definition: blobbox.h:118
BLOBNBOX::set_diacritic_box
void set_diacritic_box(const TBOX &diacritic_box)
Definition: blobbox.h:397
TPOINT
Definition: blobs.h:49
BRT_NOISE
Definition: blobbox.h:72
kCosSmallAngle
const double kCosSmallAngle
Definition: blobbox.cpp:44
BLOBNBOX::plot
void plot(ScrollView *window, ScrollView::Color blob_colour, ScrollView::Color child_colour)
Definition: blobbox.cpp:483
TT_NONE
Definition: blobbox.h:59
ASSERT_HOST
#define ASSERT_HOST(x)
Definition: errcode.h:87
BLOBNBOX::IsImageType
static bool IsImageType(BlobRegionType type)
Definition: blobbox.h:421
BND_BELOW
Definition: blobbox.h:88
NearlyEqual
bool NearlyEqual(T x, T y, T tolerance)
Definition: host.h:36
BRT_UNKNOWN
Definition: blobbox.h:77
ICOORD
integer coordinate
Definition: points.h:30
ICOORD::rotate
void rotate(const FCOORD &vec)
Definition: points.h:522
BLOBNBOX::compute_bounding_box
void compute_bounding_box()
Definition: blobbox.h:239
FCOORD::x
float x() const
Definition: points.h:206
TBOX::top
int16_t top() const
Definition: rect.h:57
BRT_VERT_TEXT
Definition: blobbox.h:78
ScrollView::BROWN
Definition: scrollview.h:120
BLOBNBOX::NeighbourGaps
void NeighbourGaps(int gaps[BND_COUNT]) const
Definition: blobbox.cpp:179
find_cblob_vlimits
void find_cblob_vlimits(C_BLOB *blob, float leftx, float rightx, float &ymin, float &ymax)
Definition: blobbox.cpp:535
ScrollView::CYAN
Definition: scrollview.h:107
BLOBNBOX::good_stroke_neighbour
bool good_stroke_neighbour(BlobNeighbourDir n) const
Definition: blobbox.h:372
IntCastRounded
int IntCastRounded(double x)
Definition: helpers.h:173
ScrollView::MEDIUM_BLUE
Definition: scrollview.h:113
BSTT_SKIP
Definition: blobbox.h:101
BRT_RECTIMAGE
Definition: blobbox.h:75
FCOORD
Definition: points.h:187
BLOBNBOX
Definition: blobbox.h:142
BND_ABOVE
Definition: blobbox.h:90
BTFT_CHAIN
Definition: blobbox.h:117
ScrollView::BLUE
Definition: scrollview.h:108
BRT_HLINE
Definition: blobbox.h:73
BTFT_LEADER
Definition: blobbox.h:120
BRT_POLYIMAGE
Definition: blobbox.h:76
C_BLOB
Definition: stepblob.h:36
C_BLOB::area
int32_t area()
Definition: stepblob.cpp:266
TBOX::rotate
void rotate(const FCOORD &vec)
Definition: rect.h:196
kComplexShapePerimeterRatio
const double kComplexShapePerimeterRatio
Definition: blobbox.cpp:48
BLOBNBOX::horz_stroke_width
float horz_stroke_width() const
Definition: blobbox.h:336
TBOX::height
int16_t height() const
Definition: rect.h:107
TBOX::y_gap
int y_gap(const TBOX &box) const
Definition: rect.h:232
BTFT_NONTEXT
Definition: blobbox.h:115
BLOBNBOX::IsLineType
static bool IsLineType(BlobRegionType type)
Definition: blobbox.h:425
BLOBNBOX::neighbour
BLOBNBOX * neighbour(BlobNeighbourDir n) const
Definition: blobbox.h:369
TBOX::set_right
void set_right(int x)
Definition: rect.h:81
ScrollView::ORANGE
Definition: scrollview.h:136
BTFT_TEXT_ON_IMAGE
Definition: blobbox.h:119
ScrollView::LIGHT_BLUE
Definition: scrollview.h:112
ScrollView::MAGENTA
Definition: scrollview.h:109
BRT_TEXT
Definition: blobbox.h:79
find_cblob_limits
void find_cblob_limits(C_BLOB *blob, float leftx, float rightx, FCOORD rotation, float &ymin, float &ymax)
Definition: blobbox.cpp:496
TBOX::width
int16_t width() const
Definition: rect.h:114
ScrollView::YELLOW
Definition: scrollview.h:105
TBOX::bottom
int16_t bottom() const
Definition: rect.h:64
BLOBNBOX::IsDiacritic
bool IsDiacritic() const
Definition: blobbox.h:379
ScrollView::WHITE
Definition: scrollview.h:103
BND_LEFT
Definition: blobbox.h:87
ScrollView::WHEAT
Definition: scrollview.h:148
ScrollView::RED
Definition: scrollview.h:104
BLOBNBOX::bounding_box
const TBOX & bounding_box() const
Definition: blobbox.h:229
BLOBNBOX::DeletableNoise
bool DeletableNoise() const
Definition: blobbox.h:202
ScrollView::PINK
Definition: scrollview.h:138
BLOBNBOX::area_stroke_width
float area_stroke_width() const
Definition: blobbox.h:348
ScrollView::LIME_GREEN
Definition: scrollview.h:127
BLOBNBOX::BLOBNBOX
BLOBNBOX()
Definition: blobbox.h:145
count
int count(LIST var_list)
Definition: oldlist.cpp:79
C_BLOB::rotate
void rotate(const FCOORD &rotation)
Definition: stepblob.cpp:379
BRT_VLINE
Definition: blobbox.h:74
TBOX::left
int16_t left() const
Definition: rect.h:71
ScrollView::GREEN
Definition: scrollview.h:106
BND_COUNT
Definition: blobbox.h:91
BLOBNBOX::region_type
BlobRegionType region_type() const
Definition: blobbox.h:282
BLOBNBOX::set_horz_possible
void set_horz_possible(bool value)
Definition: blobbox.h:309
TBOX::right
int16_t right() const
Definition: rect.h:78
tesstrain_utils.type
type
Definition: tesstrain_utils.py:141
UpdateRange
void UpdateRange(const T1 &x, T2 *lower_bound, T2 *upper_bound)
Definition: helpers.h:118
BLOBNBOX::cblob
C_BLOB * cblob() const
Definition: blobbox.h:267
BLOBNBOX::owner
tesseract::ColPartition * owner() const
Definition: blobbox.h:351
BLOBNBOX::ReInit
void ReInit()
Definition: blobbox.h:469
BLOBNBOX::vert_stroke_width
float vert_stroke_width() const
Definition: blobbox.h:342
TBOX::set_left
void set_left(int x)
Definition: rect.h:74
TBOX::x_gap
int x_gap(const TBOX &box) const
Definition: rect.h:224
ICOORD::y
int16_t y() const
access_function
Definition: points.h:55
BLOBNBOX::set_vert_possible
void set_vert_possible(bool value)
Definition: blobbox.h:303
C_BLOB::ComputeEdgeOffsets
void ComputeEdgeOffsets(int threshold, Pix *pix)
Definition: stepblob.cpp:401
TBOX
Definition: rect.h:33