tesseract  4.0.0-1-g2a2b
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 ConstructionInit ()
 
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 144 of file blobbox.h.

Constructor & Destructor Documentation

◆ BLOBNBOX() [1/2]

BLOBNBOX::BLOBNBOX ( )
inline

Definition at line 147 of file blobbox.h.

147  {
149  }
void ConstructionInit()
Definition: blobbox.h:471

◆ BLOBNBOX() [2/2]

BLOBNBOX::BLOBNBOX ( C_BLOB srcblob)
inlineexplicit

Definition at line 150 of file blobbox.h.

150  {
151  box = srcblob->bounding_box();
153  cblob_ptr = srcblob;
154  area = static_cast<int>(srcblob->area());
155  }
void ConstructionInit()
Definition: blobbox.h:471
TBOX bounding_box() const
Definition: stepblob.cpp:255
int32_t area()
Definition: stepblob.cpp:275

◆ ~BLOBNBOX()

BLOBNBOX::~BLOBNBOX ( )
inline

Definition at line 156 of file blobbox.h.

156  {
157  if (owns_cblob_) delete cblob_ptr;
158  }

Member Function Documentation

◆ area_stroke_width()

float BLOBNBOX::area_stroke_width ( ) const
inline

Definition at line 350 of file blobbox.h.

350  {
351  return area_stroke_width_;
352  }

◆ base_char_blob()

BLOBNBOX* BLOBNBOX::base_char_blob ( ) const
inline

Definition at line 403 of file blobbox.h.

403  {
404  return base_char_blob_;
405  }

◆ base_char_bottom()

int BLOBNBOX::base_char_bottom ( ) const
inline

Definition at line 387 of file blobbox.h.

387  {
388  return base_char_bottom_;
389  }

◆ base_char_top()

int BLOBNBOX::base_char_top ( ) const
inline

Definition at line 384 of file blobbox.h.

384  {
385  return base_char_top_;
386  }

◆ baseline_position()

int BLOBNBOX::baseline_position ( ) const
inline

Definition at line 390 of file blobbox.h.

390  {
391  return baseline_y_;
392  }

◆ bounding_box()

const TBOX& BLOBNBOX::bounding_box ( ) const
inline

Definition at line 231 of file blobbox.h.

231  {
232  return box;
233  }

◆ BoundsWithinLimits()

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

Definition at line 334 of file blobbox.cpp.

334  {
335  FCOORD no_rotation(1.0f, 0.0f);
336  float top = box.top();
337  float bottom = box.bottom();
338  if (cblob_ptr != nullptr) {
339  find_cblob_limits(cblob_ptr, static_cast<float>(left),
340  static_cast<float>(right), no_rotation,
341  bottom, top);
342  }
343 
344  if (top < bottom) {
345  top = box.top();
346  bottom = box.bottom();
347  }
348  FCOORD bot_left(left, bottom);
349  FCOORD top_right(right, top);
350  TBOX shrunken_box(bot_left);
351  TBOX shrunken_box2(top_right);
352  shrunken_box += shrunken_box2;
353  return shrunken_box;
354 }
Definition: rect.h:34
int16_t top() const
Definition: rect.h:58
void find_cblob_limits(C_BLOB *blob, float leftx, float rightx, FCOORD rotation, float &ymin, float &ymax)
Definition: blobbox.cpp:500
Definition: points.h:189
int16_t bottom() const
Definition: rect.h:65

◆ BoxColor()

ScrollView::Color BLOBNBOX::BoxColor ( ) const

Definition at line 482 of file blobbox.cpp.

482  {
483  return TextlineColor(region_type_, flow_);
484 }
static ScrollView::Color TextlineColor(BlobRegionType region_type, BlobTextFlowType flow_type)
Definition: blobbox.cpp:445

◆ cblob()

C_BLOB* BLOBNBOX::cblob ( ) const
inline

Definition at line 269 of file blobbox.h.

269  {
270  return cblob_ptr;
271  }

◆ chop()

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

Definition at line 121 of file blobbox.cpp.

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

◆ CleanNeighbours() [1/2]

void BLOBNBOX::CleanNeighbours ( )

Definition at line 215 of file blobbox.cpp.

215  {
216  for (int dir = 0; dir < BND_COUNT; ++dir) {
217  BLOBNBOX* neighbour = neighbours_[dir];
218  if (neighbour != nullptr && neighbour->DeletableNoise()) {
219  neighbours_[dir] = nullptr;
220  good_stroke_neighbours_[dir] = false;
221  }
222  }
223 }
bool DeletableNoise() const
Definition: blobbox.h:204
BLOBNBOX * neighbour(BlobNeighbourDir n) const
Definition: blobbox.h:371

◆ CleanNeighbours() [2/2]

void BLOBNBOX::CleanNeighbours ( BLOBNBOX_LIST *  blobs)
static

Definition at line 365 of file blobbox.cpp.

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

◆ ClearNeighbours()

void BLOBNBOX::ClearNeighbours ( )
inline

Definition at line 511 of file blobbox.h.

511  {
512  for (int n = 0; n < BND_COUNT; ++n) {
513  neighbours_[n] = nullptr;
514  good_stroke_neighbours_[n] = false;
515  }
516  }

◆ compute_bounding_box()

void BLOBNBOX::compute_bounding_box ( )
inline

Definition at line 241 of file blobbox.h.

241  {
242  box = cblob_ptr->bounding_box();
243  base_char_top_ = box.top();
244  base_char_bottom_ = box.bottom();
245  baseline_y_ = box.bottom();
246  }
int16_t top() const
Definition: rect.h:58
TBOX bounding_box() const
Definition: stepblob.cpp:255
int16_t bottom() const
Definition: rect.h:65

◆ ComputeEdgeOffsets()

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

Definition at line 386 of file blobbox.cpp.

387  {
388  int grey_height = 0;
389  int thr_height = 0;
390  int scale_factor = 1;
391  if (thresholds != nullptr && grey != nullptr) {
392  grey_height = pixGetHeight(grey);
393  thr_height = pixGetHeight(thresholds);
394  scale_factor =
395  IntCastRounded(static_cast<double>(grey_height) / thr_height);
396  }
397  BLOBNBOX_IT blob_it(blobs);
398  for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
399  BLOBNBOX* blob = blob_it.data();
400  if (blob->cblob() != nullptr) {
401  // Get the threshold that applies to this blob.
402  l_uint32 threshold = 128;
403  if (thresholds != nullptr && grey != nullptr) {
404  const TBOX& box = blob->cblob()->bounding_box();
405  // Transform the coordinates if required.
406  TPOINT pt((box.left() + box.right()) / 2,
407  (box.top() + box.bottom()) / 2);
408  pixGetPixel(thresholds, pt.x / scale_factor,
409  thr_height - 1 - pt.y / scale_factor, &threshold);
410  }
411  blob->cblob()->ComputeEdgeOffsets(threshold, grey);
412  }
413  }
414 }
Definition: rect.h:34
void ComputeEdgeOffsets(int threshold, Pix *pix)
Definition: stepblob.cpp:415
int16_t left() const
Definition: rect.h:72
int16_t top() const
Definition: rect.h:58
int IntCastRounded(double x)
Definition: helpers.h:168
TBOX bounding_box() const
Definition: stepblob.cpp:255
int16_t right() const
Definition: rect.h:79
Definition: blobs.h:57
int16_t bottom() const
Definition: rect.h:65
C_BLOB * cblob() const
Definition: blobbox.h:269

◆ ConfirmNoTabViolation()

bool BLOBNBOX::ConfirmNoTabViolation ( const BLOBNBOX other) const

Definition at line 293 of file blobbox.cpp.

293  {
294  if (box.left() < other.box.left() && box.left() < other.left_rule_)
295  return false;
296  if (other.box.left() < box.left() && other.box.left() < left_rule_)
297  return false;
298  if (box.right() > other.box.right() && box.right() > other.right_rule_)
299  return false;
300  if (other.box.right() > box.right() && other.box.right() > right_rule_)
301  return false;
302  return true;
303 }
int16_t left() const
Definition: rect.h:72
int16_t right() const
Definition: rect.h:79

◆ ConstructionInit()

void BLOBNBOX::ConstructionInit ( )
inline

Definition at line 471 of file blobbox.h.

471  {
472  cblob_ptr = nullptr;
473  owns_cblob_ = false;
474  area = 0;
475  area_stroke_width_ = 0.0f;
476  horz_stroke_width_ = 0.0f;
477  vert_stroke_width_ = 0.0f;
478  ReInit();
479  }
void ReInit()
Definition: blobbox.h:482

◆ DefiniteIndividualFlow()

bool BLOBNBOX::DefiniteIndividualFlow ( )

Definition at line 253 of file blobbox.cpp.

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

◆ DeletableNoise()

bool BLOBNBOX::DeletableNoise ( ) const
inline

Definition at line 204 of file blobbox.h.

204  {
205  return owner() == nullptr && region_type() == BRT_NOISE;
206  }
BlobRegionType region_type() const
Definition: blobbox.h:284
tesseract::ColPartition * owner() const
Definition: blobbox.h:353

◆ DeleteNoiseBlobs()

void BLOBNBOX::DeleteNoiseBlobs ( BLOBNBOX_LIST *  blobs)
static

Definition at line 373 of file blobbox.cpp.

373  {
374  BLOBNBOX_IT blob_it(blobs);
375  for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
376  BLOBNBOX* blob = blob_it.data();
377  if (blob->DeletableNoise()) {
378  delete blob->cblob();
379  delete blob_it.extract();
380  }
381  }
382 }
bool DeletableNoise() const
Definition: blobbox.h:204
C_BLOB * cblob() const
Definition: blobbox.h:269

◆ enclosed_area()

int32_t BLOBNBOX::enclosed_area ( ) const
inline

Definition at line 254 of file blobbox.h.

254  {
255  return area;
256  }

◆ EstimateBaselinePosition()

void BLOBNBOX::EstimateBaselinePosition ( )

Definition at line 358 of file blobbox.cpp.

358  {
359  baseline_y_ = box.bottom(); // The default.
360  if (cblob_ptr == nullptr) return;
361  baseline_y_ = cblob_ptr->EstimateBaselinePosition();
362 }
int16_t EstimateBaselinePosition()
Definition: stepblob.cpp:433
int16_t bottom() const
Definition: rect.h:65

◆ flow()

BlobTextFlowType BLOBNBOX::flow ( ) const
inline

Definition at line 296 of file blobbox.h.

296  {
297  return flow_;
298  }

◆ good_stroke_neighbour()

bool BLOBNBOX::good_stroke_neighbour ( BlobNeighbourDir  n) const
inline

Definition at line 374 of file blobbox.h.

374  {
375  return good_stroke_neighbours_[n];
376  }

◆ GoodTextBlob()

int BLOBNBOX::GoodTextBlob ( ) const

Definition at line 227 of file blobbox.cpp.

227  {
228  int score = 0;
229  for (int dir = 0; dir < BND_COUNT; ++dir) {
230  BlobNeighbourDir bnd = static_cast<BlobNeighbourDir>(dir);
231  if (good_stroke_neighbour(bnd))
232  ++score;
233  }
234  return score;
235 }
BlobNeighbourDir
Definition: blobbox.h:88
bool good_stroke_neighbour(BlobNeighbourDir n) const
Definition: blobbox.h:374

◆ horz_possible()

bool BLOBNBOX::horz_possible ( ) const
inline

Definition at line 308 of file blobbox.h.

308  {
309  return horz_possible_;
310  }

◆ horz_stroke_width()

float BLOBNBOX::horz_stroke_width ( ) const
inline

Definition at line 338 of file blobbox.h.

338  {
339  return horz_stroke_width_;
340  }

◆ IsDiacritic()

bool BLOBNBOX::IsDiacritic ( ) const
inline

Definition at line 381 of file blobbox.h.

381  {
382  return base_char_top_ != box.top() || base_char_bottom_ != box.bottom();
383  }
int16_t top() const
Definition: rect.h:58
int16_t bottom() const
Definition: rect.h:65

◆ IsImageType()

static bool BLOBNBOX::IsImageType ( BlobRegionType  type)
inlinestatic

Definition at line 423 of file blobbox.h.

423  {
424  return type == BRT_RECTIMAGE || type == BRT_POLYIMAGE;
425  }

◆ IsLineType()

static bool BLOBNBOX::IsLineType ( BlobRegionType  type)
inlinestatic

Definition at line 427 of file blobbox.h.

427  {
428  return type == BRT_HLINE || type == BRT_VLINE;
429  }

◆ IsTextType()

static bool BLOBNBOX::IsTextType ( BlobRegionType  type)
inlinestatic

Definition at line 419 of file blobbox.h.

419  {
420  return type == BRT_TEXT || type == BRT_VERT_TEXT;
421  }

◆ joined_to_prev()

bool BLOBNBOX::joined_to_prev ( ) const
inline

Definition at line 257 of file blobbox.h.

257  {
258  return joined != 0;
259  }

◆ leader_on_left()

bool BLOBNBOX::leader_on_left ( ) const
inline

Definition at line 359 of file blobbox.h.

359  {
360  return leader_on_left_;
361  }

◆ leader_on_right()

bool BLOBNBOX::leader_on_right ( ) const
inline

Definition at line 365 of file blobbox.h.

365  {
366  return leader_on_right_;
367  }

◆ left_crossing_rule()

int BLOBNBOX::left_crossing_rule ( ) const
inline

Definition at line 326 of file blobbox.h.

326  {
327  return left_crossing_rule_;
328  }

◆ left_rule()

int BLOBNBOX::left_rule ( ) const
inline

Definition at line 314 of file blobbox.h.

314  {
315  return left_rule_;
316  }

◆ left_tab_type()

TabType BLOBNBOX::left_tab_type ( ) const
inline

Definition at line 272 of file blobbox.h.

272  {
273  return left_tab_type_;
274  }

◆ line_crossings()

int BLOBNBOX::line_crossings ( ) const
inline

Definition at line 393 of file blobbox.h.

393  {
394  return line_crossings_;
395  }

◆ MatchingStrokeWidth()

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

Definition at line 306 of file blobbox.cpp.

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

◆ merge()

void BLOBNBOX::merge ( BLOBNBOX nextblob)

Definition at line 93 of file blobbox.cpp.

95  {
96  box += nextblob->box; //merge boxes
97  set_diacritic_box(box);
98  nextblob->joined = TRUE;
99 }
#define TRUE
Definition: capi.h:51
void set_diacritic_box(const TBOX &diacritic_box)
Definition: blobbox.h:399

◆ MinMaxGapsClipped()

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

Definition at line 201 of file blobbox.cpp.

202  {
203  int max_dimension = std::max(box.width(), box.height());
204  int gaps[BND_COUNT];
205  NeighbourGaps(gaps);
206  *h_min = std::min(gaps[BND_LEFT], gaps[BND_RIGHT]);
207  *h_max = std::max(gaps[BND_LEFT], gaps[BND_RIGHT]);
208  if (*h_max > max_dimension && *h_min < max_dimension) *h_max = *h_min;
209  *v_min = std::min(gaps[BND_ABOVE], gaps[BND_BELOW]);
210  *v_max = std::max(gaps[BND_ABOVE], gaps[BND_BELOW]);
211  if (*v_max > max_dimension && *v_min < max_dimension) *v_max = *v_min;
212 }
int16_t width() const
Definition: rect.h:115
void NeighbourGaps(int gaps[BND_COUNT]) const
Definition: blobbox.cpp:182
int16_t height() const
Definition: rect.h:108

◆ neighbour()

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

Definition at line 371 of file blobbox.h.

371  {
372  return neighbours_[n];
373  }

◆ NeighbourGaps()

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

Definition at line 182 of file blobbox.cpp.

182  {
183  for (int dir = 0; dir < BND_COUNT; ++dir) {
184  gaps[dir] = INT16_MAX;
185  BLOBNBOX* neighbour = neighbours_[dir];
186  if (neighbour != nullptr) {
187  const TBOX& n_box = neighbour->bounding_box();
188  if (dir == BND_LEFT || dir == BND_RIGHT) {
189  gaps[dir] = box.x_gap(n_box);
190  } else {
191  gaps[dir] = box.y_gap(n_box);
192  }
193  }
194  }
195 }
int y_gap(const TBOX &box) const
Definition: rect.h:233
Definition: rect.h:34
int x_gap(const TBOX &box) const
Definition: rect.h:225
const TBOX & bounding_box() const
Definition: blobbox.h:231
BLOBNBOX * neighbour(BlobNeighbourDir n) const
Definition: blobbox.h:371

◆ NoisyNeighbours()

int BLOBNBOX::NoisyNeighbours ( ) const

Definition at line 238 of file blobbox.cpp.

238  {
239  int count = 0;
240  for (int dir = 0; dir < BND_COUNT; ++dir) {
241  BlobNeighbourDir bnd = static_cast<BlobNeighbourDir>(dir);
242  BLOBNBOX* blob = neighbour(bnd);
243  if (blob != nullptr && blob->region_type() == BRT_NOISE)
244  ++count;
245  }
246  return count;
247 }
BlobNeighbourDir
Definition: blobbox.h:88
int count(LIST var_list)
Definition: oldlist.cpp:98
BlobRegionType region_type() const
Definition: blobbox.h:284
BLOBNBOX * neighbour(BlobNeighbourDir n) const
Definition: blobbox.h:371

◆ owner()

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

Definition at line 353 of file blobbox.h.

353  {
354  return owner_;
355  }

◆ plot()

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

Definition at line 486 of file blobbox.cpp.

488  { // for holes
489  if (cblob_ptr != nullptr)
490  cblob_ptr->plot(window, blob_colour, child_colour);
491 }
void plot(ScrollView *window, ScrollView::Color blob_colour, ScrollView::Color child_colour)
Definition: stepblob.cpp:538

◆ PlotBlobs()

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

Definition at line 420 of file blobbox.cpp.

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

◆ PlotNoiseBlobs()

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

Definition at line 433 of file blobbox.cpp.

436  {
437  BLOBNBOX_IT it(list);
438  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
439  BLOBNBOX* blob = it.data();
440  if (blob->DeletableNoise())
441  blob->plot(win, body_colour, child_colour);
442  }
443 }
bool DeletableNoise() const
Definition: blobbox.h:204
void plot(ScrollView *window, ScrollView::Color blob_colour, ScrollView::Color child_colour)
Definition: blobbox.cpp:486

◆ RealBlob()

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

Definition at line 159 of file blobbox.h.

159  {
160  C_BLOB* blob = new C_BLOB(outline);
161  return new BLOBNBOX(blob);
162  }
BLOBNBOX()
Definition: blobbox.h:147

◆ really_merge()

void BLOBNBOX::really_merge ( BLOBNBOX other)

Definition at line 104 of file blobbox.cpp.

104  {
105  if (other->cblob_ptr != nullptr) {
106  C_OUTLINE_IT ol_it(cblob_ptr->out_list());
107  ol_it.add_list_after(other->cblob_ptr->out_list());
108  }
110 }
C_OUTLINE_LIST * out_list()
Definition: stepblob.h:70
void compute_bounding_box()
Definition: blobbox.h:241

◆ red_box_set()

bool BLOBNBOX::red_box_set ( ) const
inline

Definition at line 260 of file blobbox.h.

260  {
261  return reduced != 0;
262  }

◆ reduced_box()

const TBOX& BLOBNBOX::reduced_box ( ) const
inline

Definition at line 247 of file blobbox.h.

247  {
248  return red_box;
249  }

◆ reflect_box_in_y_axis()

void BLOBNBOX::reflect_box_in_y_axis ( )

Definition at line 63 of file blobbox.cpp.

63  {
64  int left = -box.right();
65  box.set_right(-box.left());
66  box.set_left(left);
67 }
void set_right(int x)
Definition: rect.h:82
int16_t left() const
Definition: rect.h:72
void set_left(int x)
Definition: rect.h:75
int16_t right() const
Definition: rect.h:79

◆ region_type()

BlobRegionType BLOBNBOX::region_type ( ) const
inline

Definition at line 284 of file blobbox.h.

284  {
285  return region_type_;
286  }

◆ ReInit()

void BLOBNBOX::ReInit ( )
inline

Definition at line 482 of file blobbox.h.

482  {
483  joined = false;
484  reduced = false;
485  repeated_set_ = 0;
486  left_tab_type_ = TT_NONE;
487  right_tab_type_ = TT_NONE;
488  region_type_ = BRT_UNKNOWN;
489  flow_ = BTFT_NONE;
490  spt_type_ = BSTT_SKIP;
491  left_rule_ = 0;
492  right_rule_ = 0;
493  left_crossing_rule_ = 0;
494  right_crossing_rule_ = 0;
495  if (area_stroke_width_ == 0.0f && area > 0 && cblob() != nullptr
496  && cblob()->perimeter()!=0)
497  area_stroke_width_ = 2.0f * area / cblob()->perimeter();
498  owner_ = nullptr;
499  base_char_top_ = box.top();
500  base_char_bottom_ = box.bottom();
501  baseline_y_ = box.bottom();
502  line_crossings_ = 0;
503  base_char_blob_ = nullptr;
504  horz_possible_ = false;
505  vert_possible_ = false;
506  leader_on_left_ = false;
507  leader_on_right_ = false;
508  ClearNeighbours();
509  }
int32_t perimeter()
Definition: stepblob.cpp:294
int16_t top() const
Definition: rect.h:58
void ClearNeighbours()
Definition: blobbox.h:511
int16_t bottom() const
Definition: rect.h:65
C_BLOB * cblob() const
Definition: blobbox.h:269

◆ repeated_set()

int BLOBNBOX::repeated_set ( ) const
inline

Definition at line 263 of file blobbox.h.

263  {
264  return repeated_set_;
265  }

◆ right_crossing_rule()

int BLOBNBOX::right_crossing_rule ( ) const
inline

Definition at line 332 of file blobbox.h.

332  {
333  return right_crossing_rule_;
334  }

◆ right_rule()

int BLOBNBOX::right_rule ( ) const
inline

Definition at line 320 of file blobbox.h.

320  {
321  return right_rule_;
322  }

◆ right_tab_type()

TabType BLOBNBOX::right_tab_type ( ) const
inline

Definition at line 278 of file blobbox.h.

278  {
279  return right_tab_type_;
280  }

◆ rotate()

void BLOBNBOX::rotate ( FCOORD  rotation)

Definition at line 56 of file blobbox.cpp.

56  {
57  cblob_ptr->rotate(rotation);
58  rotate_box(rotation);
60 }
void rotate_box(FCOORD rotation)
Definition: blobbox.cpp:72
void rotate(const FCOORD &rotation)
Definition: stepblob.cpp:393
void compute_bounding_box()
Definition: blobbox.h:241

◆ rotate_box()

void BLOBNBOX::rotate_box ( FCOORD  rotation)

Definition at line 72 of file blobbox.cpp.

72  {
73  if (IsDiacritic()) {
74  ASSERT_HOST(rotation.x() >= kCosSmallAngle)
75  ICOORD top_pt((box.left() + box.right()) / 2, base_char_top_);
76  ICOORD bottom_pt(top_pt.x(), base_char_bottom_);
77  top_pt.rotate(rotation);
78  base_char_top_ = top_pt.y();
79  bottom_pt.rotate(rotation);
80  base_char_bottom_ = bottom_pt.y();
81  box.rotate(rotation);
82  } else {
83  box.rotate(rotation);
84  set_diacritic_box(box);
85  }
86 }
void rotate(const FCOORD &vec)
Definition: rect.h:197
void set_diacritic_box(const TBOX &diacritic_box)
Definition: blobbox.h:399
bool IsDiacritic() const
Definition: blobbox.h:381
int16_t left() const
Definition: rect.h:72
integer coordinate
Definition: points.h:32
const double kCosSmallAngle
Definition: blobbox.cpp:45
void rotate(const FCOORD &vec)
Definition: points.h:537
int16_t right() const
Definition: rect.h:79
float x() const
Definition: points.h:208
#define ASSERT_HOST(x)
Definition: errcode.h:84

◆ set_base_char_blob()

void BLOBNBOX::set_base_char_blob ( BLOBNBOX blob)
inline

Definition at line 406 of file blobbox.h.

406  {
407  base_char_blob_ = blob;
408  }

◆ set_bounding_box()

void BLOBNBOX::set_bounding_box ( const TBOX new_box)
inline

Definition at line 236 of file blobbox.h.

236  {
237  box = new_box;
238  base_char_top_ = box.top();
239  base_char_bottom_ = box.bottom();
240  }
int16_t top() const
Definition: rect.h:58
int16_t bottom() const
Definition: rect.h:65

◆ set_diacritic_box()

void BLOBNBOX::set_diacritic_box ( const TBOX diacritic_box)
inline

Definition at line 399 of file blobbox.h.

399  {
400  base_char_top_ = diacritic_box.top();
401  base_char_bottom_ = diacritic_box.bottom();
402  }
int16_t top() const
Definition: rect.h:58
int16_t bottom() const
Definition: rect.h:65

◆ set_flow()

void BLOBNBOX::set_flow ( BlobTextFlowType  value)
inline

Definition at line 299 of file blobbox.h.

299  {
300  flow_ = value;
301  }

◆ set_horz_possible()

void BLOBNBOX::set_horz_possible ( bool  value)
inline

Definition at line 311 of file blobbox.h.

311  {
312  horz_possible_ = value;
313  }

◆ set_horz_stroke_width()

void BLOBNBOX::set_horz_stroke_width ( float  width)
inline

Definition at line 341 of file blobbox.h.

341  {
342  horz_stroke_width_ = width;
343  }

◆ set_leader_on_left()

void BLOBNBOX::set_leader_on_left ( bool  flag)
inline

Definition at line 362 of file blobbox.h.

362  {
363  leader_on_left_ = flag;
364  }

◆ set_leader_on_right()

void BLOBNBOX::set_leader_on_right ( bool  flag)
inline

Definition at line 368 of file blobbox.h.

368  {
369  leader_on_right_ = flag;
370  }

◆ set_left_crossing_rule()

void BLOBNBOX::set_left_crossing_rule ( int  new_left)
inline

Definition at line 329 of file blobbox.h.

329  {
330  left_crossing_rule_ = new_left;
331  }

◆ set_left_rule()

void BLOBNBOX::set_left_rule ( int  new_left)
inline

Definition at line 317 of file blobbox.h.

317  {
318  left_rule_ = new_left;
319  }

◆ set_left_tab_type()

void BLOBNBOX::set_left_tab_type ( TabType  new_type)
inline

Definition at line 275 of file blobbox.h.

275  {
276  left_tab_type_ = new_type;
277  }

◆ set_line_crossings()

void BLOBNBOX::set_line_crossings ( int  value)
inline

Definition at line 396 of file blobbox.h.

396  {
397  line_crossings_ = value;
398  }

◆ set_neighbour()

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

Definition at line 377 of file blobbox.h.

377  {
378  neighbours_[n] = neighbour;
379  good_stroke_neighbours_[n] = good;
380  }
BLOBNBOX * neighbour(BlobNeighbourDir n) const
Definition: blobbox.h:371

◆ set_owner()

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

Definition at line 356 of file blobbox.h.

356  {
357  owner_ = new_owner;
358  }

◆ set_owns_cblob()

void BLOBNBOX::set_owns_cblob ( bool  value)
inline

Definition at line 409 of file blobbox.h.

409 { owns_cblob_ = value; }

◆ set_reduced_box()

void BLOBNBOX::set_reduced_box ( TBOX  new_box)
inline

Definition at line 250 of file blobbox.h.

250  {
251  red_box = new_box;
252  reduced = true;
253  }

◆ set_region_type()

void BLOBNBOX::set_region_type ( BlobRegionType  new_type)
inline

Definition at line 287 of file blobbox.h.

287  {
288  region_type_ = new_type;
289  }

◆ set_repeated_set()

void BLOBNBOX::set_repeated_set ( int  set_id)
inline

Definition at line 266 of file blobbox.h.

266  {
267  repeated_set_ = set_id;
268  }

◆ set_right_crossing_rule()

void BLOBNBOX::set_right_crossing_rule ( int  new_right)
inline

Definition at line 335 of file blobbox.h.

335  {
336  right_crossing_rule_ = new_right;
337  }

◆ set_right_rule()

void BLOBNBOX::set_right_rule ( int  new_right)
inline

Definition at line 323 of file blobbox.h.

323  {
324  right_rule_ = new_right;
325  }

◆ set_right_tab_type()

void BLOBNBOX::set_right_tab_type ( TabType  new_type)
inline

Definition at line 281 of file blobbox.h.

281  {
282  right_tab_type_ = new_type;
283  }

◆ set_special_text_type()

void BLOBNBOX::set_special_text_type ( BlobSpecialTextType  new_type)
inline

Definition at line 293 of file blobbox.h.

293  {
294  spt_type_ = new_type;
295  }

◆ set_vert_possible()

void BLOBNBOX::set_vert_possible ( bool  value)
inline

Definition at line 305 of file blobbox.h.

305  {
306  vert_possible_ = value;
307  }

◆ set_vert_stroke_width()

void BLOBNBOX::set_vert_stroke_width ( float  width)
inline

Definition at line 347 of file blobbox.h.

347  {
348  vert_stroke_width_ = width;
349  }

◆ special_text_type()

BlobSpecialTextType BLOBNBOX::special_text_type ( ) const
inline

Definition at line 290 of file blobbox.h.

290  {
291  return spt_type_;
292  }

◆ TextlineColor()

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

Definition at line 445 of file blobbox.cpp.

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

◆ translate_box()

void BLOBNBOX::translate_box ( ICOORD  v)
inline

Definition at line 175 of file blobbox.h.

175  {
176  if (IsDiacritic()) {
177  box.move(v);
178  base_char_top_ += v.y();
179  base_char_bottom_ += v.y();
180  } else {
181  box.move(v);
182  set_diacritic_box(box);
183  }
184  }
void set_diacritic_box(const TBOX &diacritic_box)
Definition: blobbox.h:399
int16_t y() const
access_function
Definition: points.h:57
bool IsDiacritic() const
Definition: blobbox.h:381
void move(const ICOORD vec)
Definition: rect.h:157

◆ UniquelyHorizontal()

bool BLOBNBOX::UniquelyHorizontal ( ) const
inline

Definition at line 414 of file blobbox.h.

414  {
415  return horz_possible_ && !vert_possible_;
416  }

◆ UniquelyVertical()

bool BLOBNBOX::UniquelyVertical ( ) const
inline

Definition at line 411 of file blobbox.h.

411  {
412  return vert_possible_ && !horz_possible_;
413  }

◆ UnMergeableType()

static bool BLOBNBOX::UnMergeableType ( BlobRegionType  type)
inlinestatic

Definition at line 431 of file blobbox.h.

431  {
432  return IsLineType(type) || IsImageType(type);
433  }
static bool IsImageType(BlobRegionType type)
Definition: blobbox.h:423
static bool IsLineType(BlobRegionType type)
Definition: blobbox.h:427

◆ vert_possible()

bool BLOBNBOX::vert_possible ( ) const
inline

Definition at line 302 of file blobbox.h.

302  {
303  return vert_possible_;
304  }

◆ vert_stroke_width()

float BLOBNBOX::vert_stroke_width ( ) const
inline

Definition at line 344 of file blobbox.h.

344  {
345  return vert_stroke_width_;
346  }

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