tesseract 4.1.1
Loading...
Searching...
No Matches
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 143 of file blobbox.h.

Constructor & Destructor Documentation

◆ BLOBNBOX() [1/2]

BLOBNBOX::BLOBNBOX ( )
inline

Definition at line 146 of file blobbox.h.

146 {
147 ReInit();
148 }
void ReInit()
Definition: blobbox.h:470

◆ BLOBNBOX() [2/2]

BLOBNBOX::BLOBNBOX ( C_BLOB srcblob)
inlineexplicit

Definition at line 149 of file blobbox.h.

149 {
150 box = srcblob->bounding_box();
151 ReInit();
152 cblob_ptr = srcblob;
153 area = static_cast<int>(srcblob->area());
154 }
int32_t area()
Definition: stepblob.cpp:273
TBOX bounding_box() const
Definition: stepblob.cpp:253

◆ ~BLOBNBOX()

BLOBNBOX::~BLOBNBOX ( )
inline

Definition at line 155 of file blobbox.h.

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

Member Function Documentation

◆ area_stroke_width()

float BLOBNBOX::area_stroke_width ( ) const
inline

Definition at line 349 of file blobbox.h.

349 {
350 return area_stroke_width_;
351 }

◆ base_char_blob()

BLOBNBOX * BLOBNBOX::base_char_blob ( ) const
inline

Definition at line 402 of file blobbox.h.

402 {
403 return base_char_blob_;
404 }

◆ base_char_bottom()

int BLOBNBOX::base_char_bottom ( ) const
inline

Definition at line 386 of file blobbox.h.

386 {
387 return base_char_bottom_;
388 }

◆ base_char_top()

int BLOBNBOX::base_char_top ( ) const
inline

Definition at line 383 of file blobbox.h.

383 {
384 return base_char_top_;
385 }

◆ baseline_position()

int BLOBNBOX::baseline_position ( ) const
inline

Definition at line 389 of file blobbox.h.

389 {
390 return baseline_y_;
391 }

◆ bounding_box()

const TBOX & BLOBNBOX::bounding_box ( ) const
inline

Definition at line 230 of file blobbox.h.

230 {
231 return box;
232 }

◆ BoundsWithinLimits()

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

Definition at line 333 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;
352 return shrunken_box;
353}
void find_cblob_limits(C_BLOB *blob, float leftx, float rightx, FCOORD rotation, float &ymin, float &ymax)
Definition: blobbox.cpp:499
Definition: points.h:189
Definition: rect.h:34
int16_t top() const
Definition: rect.h:58
int16_t bottom() const
Definition: rect.h:65

◆ BoxColor()

ScrollView::Color BLOBNBOX::BoxColor ( ) const

Definition at line 481 of file blobbox.cpp.

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

◆ cblob()

C_BLOB * BLOBNBOX::cblob ( ) const
inline

Definition at line 268 of file blobbox.h.

268 {
269 return cblob_ptr;
270 }

◆ chop()

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

Definition at line 120 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 }
176 }
177}
void find_cblob_vlimits(C_BLOB *blob, float leftx, float rightx, float &ymin, float &ymax)
Definition: blobbox.cpp:539
void UpdateRange(const T1 &x, T2 *lower_bound, T2 *upper_bound)
Definition: helpers.h:120
BLOBNBOX()
Definition: blobbox.h:146
integer coordinate
Definition: points.h:32
int16_t y() const
access_function
Definition: points.h:56
int16_t width() const
Definition: rect.h:115
int16_t left() const
Definition: rect.h:72
int16_t right() const
Definition: rect.h:79

◆ CleanNeighbours() [1/2]

void BLOBNBOX::CleanNeighbours ( )

Definition at line 214 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 }
221 }
222}
@ BND_COUNT
Definition: blobbox.h:92
BLOBNBOX * neighbour(BlobNeighbourDir n) const
Definition: blobbox.h:370
bool DeletableNoise() const
Definition: blobbox.h:203

◆ CleanNeighbours() [2/2]

void BLOBNBOX::CleanNeighbours ( BLOBNBOX_LIST *  blobs)
static

Definition at line 364 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();
368 }
369}

◆ ClearNeighbours()

void BLOBNBOX::ClearNeighbours ( )
inline

Definition at line 499 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 }
504 }

◆ compute_bounding_box()

void BLOBNBOX::compute_bounding_box ( )
inline

Definition at line 240 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();
245 }

◆ ComputeEdgeOffsets()

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

Definition at line 385 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 }
412 }
413}
int IntCastRounded(double x)
Definition: helpers.h:175
C_BLOB * cblob() const
Definition: blobbox.h:268
Definition: blobs.h:51
void ComputeEdgeOffsets(int threshold, Pix *pix)
Definition: stepblob.cpp:413

◆ ConfirmNoTabViolation()

bool BLOBNBOX::ConfirmNoTabViolation ( const BLOBNBOX other) const

Definition at line 292 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;
301 return true;
302}

◆ DefiniteIndividualFlow()

bool BLOBNBOX::DefiniteIndividualFlow ( )

Definition at line 252 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 }
288 return false;
289}
const double kDefiniteAspectRatio
Definition: blobbox.cpp:46
const double kComplexShapePerimeterRatio
Definition: blobbox.cpp:48
float vert_stroke_width() const
Definition: blobbox.h:343
float horz_stroke_width() const
Definition: blobbox.h:337
void set_horz_possible(bool value)
Definition: blobbox.h:310
void set_vert_possible(bool value)
Definition: blobbox.h:304
int16_t height() const
Definition: rect.h:108
int32_t perimeter()
Definition: stepblob.cpp:292

◆ DeletableNoise()

bool BLOBNBOX::DeletableNoise ( ) const
inline

Definition at line 203 of file blobbox.h.

203 {
204 return owner() == nullptr && region_type() == BRT_NOISE;
205 }
@ BRT_NOISE
Definition: blobbox.h:73
BlobRegionType region_type() const
Definition: blobbox.h:283
tesseract::ColPartition * owner() const
Definition: blobbox.h:352

◆ DeleteNoiseBlobs()

void BLOBNBOX::DeleteNoiseBlobs ( BLOBNBOX_LIST *  blobs)
static

Definition at line 372 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 }
380 }
381}

◆ enclosed_area()

int32_t BLOBNBOX::enclosed_area ( ) const
inline

Definition at line 253 of file blobbox.h.

253 {
254 return area;
255 }

◆ EstimateBaselinePosition()

void BLOBNBOX::EstimateBaselinePosition ( )

Definition at line 357 of file blobbox.cpp.

357 {
358 baseline_y_ = box.bottom(); // The default.
359 if (cblob_ptr == nullptr) return;
360 baseline_y_ = cblob_ptr->EstimateBaselinePosition();
361}
int16_t EstimateBaselinePosition()
Definition: stepblob.cpp:431

◆ flow()

BlobTextFlowType BLOBNBOX::flow ( ) const
inline

Definition at line 295 of file blobbox.h.

295 {
296 return flow_;
297 }

◆ good_stroke_neighbour()

bool BLOBNBOX::good_stroke_neighbour ( BlobNeighbourDir  n) const
inline

Definition at line 373 of file blobbox.h.

373 {
374 return good_stroke_neighbours_[n];
375 }

◆ GoodTextBlob()

int BLOBNBOX::GoodTextBlob ( ) const

Definition at line 226 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 }
233 return score;
234}
BlobNeighbourDir
Definition: blobbox.h:87
bool good_stroke_neighbour(BlobNeighbourDir n) const
Definition: blobbox.h:373

◆ horz_possible()

bool BLOBNBOX::horz_possible ( ) const
inline

Definition at line 307 of file blobbox.h.

307 {
308 return horz_possible_;
309 }

◆ horz_stroke_width()

float BLOBNBOX::horz_stroke_width ( ) const
inline

Definition at line 337 of file blobbox.h.

337 {
338 return horz_stroke_width_;
339 }

◆ IsDiacritic()

bool BLOBNBOX::IsDiacritic ( ) const
inline

Definition at line 380 of file blobbox.h.

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

◆ IsImageType()

static bool BLOBNBOX::IsImageType ( BlobRegionType  type)
inlinestatic

Definition at line 422 of file blobbox.h.

422 {
423 return type == BRT_RECTIMAGE || type == BRT_POLYIMAGE;
424 }
@ BRT_RECTIMAGE
Definition: blobbox.h:76
@ BRT_POLYIMAGE
Definition: blobbox.h:77

◆ IsLineType()

static bool BLOBNBOX::IsLineType ( BlobRegionType  type)
inlinestatic

Definition at line 426 of file blobbox.h.

426 {
427 return type == BRT_HLINE || type == BRT_VLINE;
428 }
@ BRT_HLINE
Definition: blobbox.h:74
@ BRT_VLINE
Definition: blobbox.h:75

◆ IsTextType()

static bool BLOBNBOX::IsTextType ( BlobRegionType  type)
inlinestatic

Definition at line 418 of file blobbox.h.

418 {
419 return type == BRT_TEXT || type == BRT_VERT_TEXT;
420 }
@ BRT_TEXT
Definition: blobbox.h:80
@ BRT_VERT_TEXT
Definition: blobbox.h:79

◆ joined_to_prev()

bool BLOBNBOX::joined_to_prev ( ) const
inline

Definition at line 256 of file blobbox.h.

256 {
257 return joined;
258 }

◆ leader_on_left()

bool BLOBNBOX::leader_on_left ( ) const
inline

Definition at line 358 of file blobbox.h.

358 {
359 return leader_on_left_;
360 }

◆ leader_on_right()

bool BLOBNBOX::leader_on_right ( ) const
inline

Definition at line 364 of file blobbox.h.

364 {
365 return leader_on_right_;
366 }

◆ left_crossing_rule()

int BLOBNBOX::left_crossing_rule ( ) const
inline

Definition at line 325 of file blobbox.h.

325 {
326 return left_crossing_rule_;
327 }

◆ left_rule()

int BLOBNBOX::left_rule ( ) const
inline

Definition at line 313 of file blobbox.h.

313 {
314 return left_rule_;
315 }

◆ left_tab_type()

TabType BLOBNBOX::left_tab_type ( ) const
inline

Definition at line 271 of file blobbox.h.

271 {
272 return left_tab_type_;
273 }

◆ line_crossings()

int BLOBNBOX::line_crossings ( ) const
inline

Definition at line 392 of file blobbox.h.

392 {
393 return line_crossings_;
394 }

◆ MatchingStrokeWidth()

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

Definition at line 305 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.
328 return p_ok || ((v_ok || h_ok) && (h_ok || h_zero) && (v_ok || v_zero));
329}
bool NearlyEqual(T x, T y, T tolerance)
Definition: host.h:37
float area_stroke_width() const
Definition: blobbox.h:349

◆ merge()

void BLOBNBOX::merge ( BLOBNBOX nextblob)

Definition at line 92 of file blobbox.cpp.

94 {
95 box += nextblob->box; //merge boxes
97 nextblob->joined = true;
98}
void set_diacritic_box(const TBOX &diacritic_box)
Definition: blobbox.h:398

◆ MinMaxGapsClipped()

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

Definition at line 200 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]);
210 if (*v_max > max_dimension && *v_min < max_dimension) *v_max = *v_min;
211}
@ BND_ABOVE
Definition: blobbox.h:91
@ BND_LEFT
Definition: blobbox.h:88
@ BND_BELOW
Definition: blobbox.h:89
@ BND_RIGHT
Definition: blobbox.h:90
void NeighbourGaps(int gaps[BND_COUNT]) const
Definition: blobbox.cpp:181

◆ neighbour()

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

Definition at line 370 of file blobbox.h.

370 {
371 return neighbours_[n];
372 }

◆ NeighbourGaps()

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

Definition at line 181 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 }
193 }
194}
const TBOX & bounding_box() const
Definition: blobbox.h:230
int y_gap(const TBOX &box) const
Definition: rect.h:233
int x_gap(const TBOX &box) const
Definition: rect.h:225

◆ NoisyNeighbours()

int BLOBNBOX::NoisyNeighbours ( ) const

Definition at line 237 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 }
245 return count;
246}
int count(LIST var_list)
Definition: oldlist.cpp:95

◆ owner()

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

Definition at line 352 of file blobbox.h.

352 {
353 return owner_;
354 }

◆ plot()

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

Definition at line 485 of file blobbox.cpp.

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

◆ PlotBlobs()

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

Definition at line 419 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);
426 }
427}

◆ PlotNoiseBlobs()

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

Definition at line 432 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);
441 }
442}
void plot(ScrollView *window, ScrollView::Color blob_colour, ScrollView::Color child_colour)
Definition: blobbox.cpp:485

◆ RealBlob()

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

Definition at line 158 of file blobbox.h.

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

◆ really_merge()

void BLOBNBOX::really_merge ( BLOBNBOX other)

Definition at line 103 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 }
109}
void compute_bounding_box()
Definition: blobbox.h:240
C_OUTLINE_LIST * out_list()
Definition: stepblob.h:70

◆ red_box_set()

bool BLOBNBOX::red_box_set ( ) const
inline

Definition at line 259 of file blobbox.h.

259 {
260 return reduced;
261 }

◆ reduced_box()

const TBOX & BLOBNBOX::reduced_box ( ) const
inline

Definition at line 246 of file blobbox.h.

246 {
247 return red_box;
248 }

◆ 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}
void set_right(int x)
Definition: rect.h:82
void set_left(int x)
Definition: rect.h:75

◆ region_type()

BlobRegionType BLOBNBOX::region_type ( ) const
inline

Definition at line 283 of file blobbox.h.

283 {
284 return region_type_;
285 }

◆ ReInit()

void BLOBNBOX::ReInit ( )
inline

Definition at line 470 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;
497 }
@ TT_NONE
Definition: blobbox.h:60
@ BSTT_SKIP
Definition: blobbox.h:102
@ BTFT_NONE
Definition: blobbox.h:115
@ BRT_UNKNOWN
Definition: blobbox.h:78
void ClearNeighbours()
Definition: blobbox.h:499

◆ repeated_set()

int BLOBNBOX::repeated_set ( ) const
inline

Definition at line 262 of file blobbox.h.

262 {
263 return repeated_set_;
264 }

◆ right_crossing_rule()

int BLOBNBOX::right_crossing_rule ( ) const
inline

Definition at line 331 of file blobbox.h.

331 {
332 return right_crossing_rule_;
333 }

◆ right_rule()

int BLOBNBOX::right_rule ( ) const
inline

Definition at line 319 of file blobbox.h.

319 {
320 return right_rule_;
321 }

◆ right_tab_type()

TabType BLOBNBOX::right_tab_type ( ) const
inline

Definition at line 277 of file blobbox.h.

277 {
278 return right_tab_type_;
279 }

◆ 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}
void rotate_box(FCOORD rotation)
Definition: blobbox.cpp:71
void rotate(const FCOORD &rotation)
Definition: stepblob.cpp:391

◆ 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);
84 }
85}
const double kCosSmallAngle
Definition: blobbox.cpp:44
#define ASSERT_HOST(x)
Definition: errcode.h:88
bool IsDiacritic() const
Definition: blobbox.h:380
float x() const
Definition: points.h:207
void rotate(const FCOORD &vec)
Definition: rect.h:197

◆ set_base_char_blob()

void BLOBNBOX::set_base_char_blob ( BLOBNBOX blob)
inline

Definition at line 405 of file blobbox.h.

405 {
406 base_char_blob_ = blob;
407 }

◆ set_bounding_box()

void BLOBNBOX::set_bounding_box ( const TBOX new_box)
inline

Definition at line 235 of file blobbox.h.

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

◆ set_diacritic_box()

void BLOBNBOX::set_diacritic_box ( const TBOX diacritic_box)
inline

Definition at line 398 of file blobbox.h.

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

◆ set_flow()

void BLOBNBOX::set_flow ( BlobTextFlowType  value)
inline

Definition at line 298 of file blobbox.h.

298 {
299 flow_ = value;
300 }

◆ set_horz_possible()

void BLOBNBOX::set_horz_possible ( bool  value)
inline

Definition at line 310 of file blobbox.h.

310 {
311 horz_possible_ = value;
312 }

◆ set_horz_stroke_width()

void BLOBNBOX::set_horz_stroke_width ( float  width)
inline

Definition at line 340 of file blobbox.h.

340 {
341 horz_stroke_width_ = width;
342 }

◆ set_leader_on_left()

void BLOBNBOX::set_leader_on_left ( bool  flag)
inline

Definition at line 361 of file blobbox.h.

361 {
362 leader_on_left_ = flag;
363 }

◆ set_leader_on_right()

void BLOBNBOX::set_leader_on_right ( bool  flag)
inline

Definition at line 367 of file blobbox.h.

367 {
368 leader_on_right_ = flag;
369 }

◆ set_left_crossing_rule()

void BLOBNBOX::set_left_crossing_rule ( int  new_left)
inline

Definition at line 328 of file blobbox.h.

328 {
329 left_crossing_rule_ = new_left;
330 }

◆ set_left_rule()

void BLOBNBOX::set_left_rule ( int  new_left)
inline

Definition at line 316 of file blobbox.h.

316 {
317 left_rule_ = new_left;
318 }

◆ set_left_tab_type()

void BLOBNBOX::set_left_tab_type ( TabType  new_type)
inline

Definition at line 274 of file blobbox.h.

274 {
275 left_tab_type_ = new_type;
276 }

◆ set_line_crossings()

void BLOBNBOX::set_line_crossings ( int  value)
inline

Definition at line 395 of file blobbox.h.

395 {
396 line_crossings_ = value;
397 }

◆ set_neighbour()

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

Definition at line 376 of file blobbox.h.

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

◆ set_owner()

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

Definition at line 355 of file blobbox.h.

355 {
356 owner_ = new_owner;
357 }

◆ set_owns_cblob()

void BLOBNBOX::set_owns_cblob ( bool  value)
inline

Definition at line 408 of file blobbox.h.

408{ owns_cblob_ = value; }

◆ set_reduced_box()

void BLOBNBOX::set_reduced_box ( TBOX  new_box)
inline

Definition at line 249 of file blobbox.h.

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

◆ set_region_type()

void BLOBNBOX::set_region_type ( BlobRegionType  new_type)
inline

Definition at line 286 of file blobbox.h.

286 {
287 region_type_ = new_type;
288 }

◆ set_repeated_set()

void BLOBNBOX::set_repeated_set ( int  set_id)
inline

Definition at line 265 of file blobbox.h.

265 {
266 repeated_set_ = set_id;
267 }

◆ set_right_crossing_rule()

void BLOBNBOX::set_right_crossing_rule ( int  new_right)
inline

Definition at line 334 of file blobbox.h.

334 {
335 right_crossing_rule_ = new_right;
336 }

◆ set_right_rule()

void BLOBNBOX::set_right_rule ( int  new_right)
inline

Definition at line 322 of file blobbox.h.

322 {
323 right_rule_ = new_right;
324 }

◆ set_right_tab_type()

void BLOBNBOX::set_right_tab_type ( TabType  new_type)
inline

Definition at line 280 of file blobbox.h.

280 {
281 right_tab_type_ = new_type;
282 }

◆ set_special_text_type()

void BLOBNBOX::set_special_text_type ( BlobSpecialTextType  new_type)
inline

Definition at line 292 of file blobbox.h.

292 {
293 spt_type_ = new_type;
294 }

◆ set_vert_possible()

void BLOBNBOX::set_vert_possible ( bool  value)
inline

Definition at line 304 of file blobbox.h.

304 {
305 vert_possible_ = value;
306 }

◆ set_vert_stroke_width()

void BLOBNBOX::set_vert_stroke_width ( float  width)
inline

Definition at line 346 of file blobbox.h.

346 {
347 vert_stroke_width_ = width;
348 }

◆ special_text_type()

BlobSpecialTextType BLOBNBOX::special_text_type ( ) const
inline

Definition at line 289 of file blobbox.h.

289 {
290 return spt_type_;
291 }

◆ TextlineColor()

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

Definition at line 444 of file blobbox.cpp.

445 {
446 switch (region_type) {
447 case BRT_HLINE:
448 return ScrollView::BROWN;
449 case BRT_VLINE:
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)
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)
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;
477 }
478}
@ BTFT_TEXT_ON_IMAGE
Definition: blobbox.h:120
@ BTFT_LEADER
Definition: blobbox.h:121
@ BTFT_CHAIN
Definition: blobbox.h:118
@ BTFT_STRONG_CHAIN
Definition: blobbox.h:119
@ BTFT_NONTEXT
Definition: blobbox.h:116

◆ translate_box()

void BLOBNBOX::translate_box ( ICOORD  v)
inline

Definition at line 174 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);
182 }
183 }
void move(const ICOORD vec)
Definition: rect.h:157

◆ UniquelyHorizontal()

bool BLOBNBOX::UniquelyHorizontal ( ) const
inline

Definition at line 413 of file blobbox.h.

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

◆ UniquelyVertical()

bool BLOBNBOX::UniquelyVertical ( ) const
inline

Definition at line 410 of file blobbox.h.

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

◆ UnMergeableType()

static bool BLOBNBOX::UnMergeableType ( BlobRegionType  type)
inlinestatic

Definition at line 430 of file blobbox.h.

430 {
431 return IsLineType(type) || IsImageType(type);
432 }
static bool IsImageType(BlobRegionType type)
Definition: blobbox.h:422
static bool IsLineType(BlobRegionType type)
Definition: blobbox.h:426

◆ vert_possible()

bool BLOBNBOX::vert_possible ( ) const
inline

Definition at line 301 of file blobbox.h.

301 {
302 return vert_possible_;
303 }

◆ vert_stroke_width()

float BLOBNBOX::vert_stroke_width ( ) const
inline

Definition at line 343 of file blobbox.h.

343 {
344 return vert_stroke_width_;
345 }

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