tesseract v5.3.3.20231005
tesseract::BLOBNBOX Class Reference

#include <blobbox.h>

Inheritance diagram for tesseract::BLOBNBOX:
tesseract::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
 
C_BLOBremove_cblob ()
 
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 tesseract::ELIST_LINK
 ELIST_LINK ()
 
 ELIST_LINK (const ELIST_LINK &)
 
void operator= (const ELIST_LINK &)
 

Static Public Member Functions

static void clear_blobnboxes (BLOBNBOX_LIST *boxes)
 
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 (Image thresholds, Image 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 141 of file blobbox.h.

Constructor & Destructor Documentation

◆ BLOBNBOX() [1/2]

tesseract::BLOBNBOX::BLOBNBOX ( )
inline

Definition at line 143 of file blobbox.h.

143 {
144 ReInit();
145 }

◆ BLOBNBOX() [2/2]

tesseract::BLOBNBOX::BLOBNBOX ( C_BLOB srcblob)
inlineexplicit

Definition at line 146 of file blobbox.h.

146 {
147 box = srcblob->bounding_box();
148 ReInit();
149 cblob_ptr = srcblob;
150 area = static_cast<int>(srcblob->area());
151 }

◆ ~BLOBNBOX()

tesseract::BLOBNBOX::~BLOBNBOX ( )
inline

Definition at line 152 of file blobbox.h.

152 {
153 if (owns_cblob_) {
154 delete cblob_ptr;
155 }
156 }

Member Function Documentation

◆ area_stroke_width()

float tesseract::BLOBNBOX::area_stroke_width ( ) const
inline

Definition at line 364 of file blobbox.h.

364 {
365 return area_stroke_width_;
366 }

◆ base_char_blob()

BLOBNBOX * tesseract::BLOBNBOX::base_char_blob ( ) const
inline

Definition at line 417 of file blobbox.h.

417 {
418 return base_char_blob_;
419 }

◆ base_char_bottom()

int tesseract::BLOBNBOX::base_char_bottom ( ) const
inline

Definition at line 401 of file blobbox.h.

401 {
402 return base_char_bottom_;
403 }

◆ base_char_top()

int tesseract::BLOBNBOX::base_char_top ( ) const
inline

Definition at line 398 of file blobbox.h.

398 {
399 return base_char_top_;
400 }

◆ baseline_position()

int tesseract::BLOBNBOX::baseline_position ( ) const
inline

Definition at line 404 of file blobbox.h.

404 {
405 return baseline_y_;
406 }

◆ bounding_box()

const TBOX & tesseract::BLOBNBOX::bounding_box ( ) const
inline

Definition at line 239 of file blobbox.h.

239 {
240 return box;
241 }

◆ BoundsWithinLimits()

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

Definition at line 337 of file blobbox.cpp.

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

◆ BoxColor()

ScrollView::Color tesseract::BLOBNBOX::BoxColor ( ) const

Definition at line 485 of file blobbox.cpp.

485 {
486 return TextlineColor(region_type_, flow_);
487}
static ScrollView::Color TextlineColor(BlobRegionType region_type, BlobTextFlowType flow_type)
Definition: blobbox.cpp:442

◆ cblob()

C_BLOB * tesseract::BLOBNBOX::cblob ( ) const
inline

Definition at line 277 of file blobbox.h.

277 {
278 return cblob_ptr;
279 }

◆ chop()

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

Definition at line 118 of file blobbox.cpp.

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

◆ CleanNeighbours() [1/2]

void tesseract::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:89
bool DeletableNoise() const
Definition: blobbox.h:213
BLOBNBOX * neighbour(BlobNeighbourDir n) const
Definition: blobbox.h:385

◆ CleanNeighbours() [2/2]

void tesseract::BLOBNBOX::CleanNeighbours ( BLOBNBOX_LIST *  blobs)
static

Definition at line 369 of file blobbox.cpp.

369 {
370 BLOBNBOX_IT blob_it(blobs);
371 for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
372 blob_it.data()->CleanNeighbours();
373 }
374}

◆ clear_blobnboxes()

static void tesseract::BLOBNBOX::clear_blobnboxes ( BLOBNBOX_LIST *  boxes)
inlinestatic

Definition at line 158 of file blobbox.h.

158 {
159 BLOBNBOX_IT it = boxes;
160 // A BLOBNBOX generally doesn't own its blobs, so if they do, you
161 // have to delete them explicitly.
162 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
163 BLOBNBOX *box = it.data();
164 // TODO: remove next line, currently still needed for resultiterator_test.
165 delete box->remove_cblob();
166 }
167 }

◆ ClearNeighbours()

void tesseract::BLOBNBOX::ClearNeighbours ( )
inline

Definition at line 510 of file blobbox.h.

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

◆ compute_bounding_box()

void tesseract::BLOBNBOX::compute_bounding_box ( )
inline

Definition at line 249 of file blobbox.h.

249 {
250 box = cblob_ptr->bounding_box();
251 base_char_top_ = box.top();
252 base_char_bottom_ = box.bottom();
253 baseline_y_ = box.bottom();
254 }
TBOX bounding_box() const
Definition: stepblob.cpp:250

◆ ComputeEdgeOffsets()

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

Definition at line 390 of file blobbox.cpp.

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

◆ ConfirmNoTabViolation()

bool tesseract::BLOBNBOX::ConfirmNoTabViolation ( const BLOBNBOX other) const

Definition at line 298 of file blobbox.cpp.

298 {
299 if (box.left() < other.box.left() && box.left() < other.left_rule_) {
300 return false;
301 }
302 if (other.box.left() < box.left() && other.box.left() < left_rule_) {
303 return false;
304 }
305 if (box.right() > other.box.right() && box.right() > other.right_rule_) {
306 return false;
307 }
308 if (other.box.right() > box.right() && other.box.right() > right_rule_) {
309 return false;
310 }
311 return true;
312}

◆ DefiniteIndividualFlow()

bool tesseract::BLOBNBOX::DefiniteIndividualFlow ( )

Definition at line 254 of file blobbox.cpp.

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

◆ DeletableNoise()

bool tesseract::BLOBNBOX::DeletableNoise ( ) const
inline

Definition at line 213 of file blobbox.h.

213 {
214 return owner() == nullptr && region_type() == BRT_NOISE;
215 }
@ BRT_NOISE
Definition: blobbox.h:75
BlobRegionType region_type() const
Definition: blobbox.h:298
tesseract::ColPartition * owner() const
Definition: blobbox.h:367

◆ DeleteNoiseBlobs()

void tesseract::BLOBNBOX::DeleteNoiseBlobs ( BLOBNBOX_LIST *  blobs)
static

Definition at line 377 of file blobbox.cpp.

377 {
378 BLOBNBOX_IT blob_it(blobs);
379 for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
380 BLOBNBOX *blob = blob_it.data();
381 if (blob->DeletableNoise()) {
382 delete blob->remove_cblob();
383 delete blob_it.extract();
384 }
385 }
386}

◆ enclosed_area()

int32_t tesseract::BLOBNBOX::enclosed_area ( ) const
inline

Definition at line 262 of file blobbox.h.

262 {
263 return area;
264 }

◆ EstimateBaselinePosition()

void tesseract::BLOBNBOX::EstimateBaselinePosition ( )

Definition at line 360 of file blobbox.cpp.

360 {
361 baseline_y_ = box.bottom(); // The default.
362 if (cblob_ptr == nullptr) {
363 return;
364 }
365 baseline_y_ = cblob_ptr->EstimateBaselinePosition();
366}
int16_t EstimateBaselinePosition()
Definition: stepblob.cpp:416

◆ flow()

BlobTextFlowType tesseract::BLOBNBOX::flow ( ) const
inline

Definition at line 310 of file blobbox.h.

310 {
311 return flow_;
312 }

◆ good_stroke_neighbour()

bool tesseract::BLOBNBOX::good_stroke_neighbour ( BlobNeighbourDir  n) const
inline

Definition at line 388 of file blobbox.h.

388 {
389 return good_stroke_neighbours_[n];
390 }

◆ GoodTextBlob()

int tesseract::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 }
234 return score;
235}
BlobNeighbourDir
Definition: blobbox.h:89
bool good_stroke_neighbour(BlobNeighbourDir n) const
Definition: blobbox.h:388

◆ horz_possible()

bool tesseract::BLOBNBOX::horz_possible ( ) const
inline

Definition at line 322 of file blobbox.h.

322 {
323 return horz_possible_;
324 }

◆ horz_stroke_width()

float tesseract::BLOBNBOX::horz_stroke_width ( ) const
inline

Definition at line 352 of file blobbox.h.

352 {
353 return horz_stroke_width_;
354 }

◆ IsDiacritic()

bool tesseract::BLOBNBOX::IsDiacritic ( ) const
inline

Definition at line 395 of file blobbox.h.

395 {
396 return base_char_top_ != box.top() || base_char_bottom_ != box.bottom();
397 }

◆ IsImageType()

static bool tesseract::BLOBNBOX::IsImageType ( BlobRegionType  type)
inlinestatic

Definition at line 439 of file blobbox.h.

439 {
440 return type == BRT_RECTIMAGE || type == BRT_POLYIMAGE;
441 }
@ BRT_POLYIMAGE
Definition: blobbox.h:79
@ BRT_RECTIMAGE
Definition: blobbox.h:78
type
Definition: upload.py:458

◆ IsLineType()

static bool tesseract::BLOBNBOX::IsLineType ( BlobRegionType  type)
inlinestatic

Definition at line 443 of file blobbox.h.

443 {
444 return type == BRT_HLINE || type == BRT_VLINE;
445 }
@ BRT_HLINE
Definition: blobbox.h:76
@ BRT_VLINE
Definition: blobbox.h:77

◆ IsTextType()

static bool tesseract::BLOBNBOX::IsTextType ( BlobRegionType  type)
inlinestatic

Definition at line 435 of file blobbox.h.

435 {
436 return type == BRT_TEXT || type == BRT_VERT_TEXT;
437 }
@ BRT_TEXT
Definition: blobbox.h:82
@ BRT_VERT_TEXT
Definition: blobbox.h:81

◆ joined_to_prev()

bool tesseract::BLOBNBOX::joined_to_prev ( ) const
inline

Definition at line 265 of file blobbox.h.

265 {
266 return joined;
267 }

◆ leader_on_left()

bool tesseract::BLOBNBOX::leader_on_left ( ) const
inline

Definition at line 373 of file blobbox.h.

373 {
374 return leader_on_left_;
375 }

◆ leader_on_right()

bool tesseract::BLOBNBOX::leader_on_right ( ) const
inline

Definition at line 379 of file blobbox.h.

379 {
380 return leader_on_right_;
381 }

◆ left_crossing_rule()

int tesseract::BLOBNBOX::left_crossing_rule ( ) const
inline

Definition at line 340 of file blobbox.h.

340 {
341 return left_crossing_rule_;
342 }

◆ left_rule()

int tesseract::BLOBNBOX::left_rule ( ) const
inline

Definition at line 328 of file blobbox.h.

328 {
329 return left_rule_;
330 }

◆ left_tab_type()

TabType tesseract::BLOBNBOX::left_tab_type ( ) const
inline

Definition at line 286 of file blobbox.h.

286 {
287 return left_tab_type_;
288 }

◆ line_crossings()

int tesseract::BLOBNBOX::line_crossings ( ) const
inline

Definition at line 407 of file blobbox.h.

407 {
408 return line_crossings_;
409 }

◆ MatchingStrokeWidth()

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

Definition at line 315 of file blobbox.cpp.

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

◆ merge()

void tesseract::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:413

◆ MinMaxGapsClipped()

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

Definition at line 197 of file blobbox.cpp.

197 {
198 int max_dimension = std::max(box.width(), box.height());
199 int gaps[BND_COUNT];
200 NeighbourGaps(gaps);
201 *h_min = std::min(gaps[BND_LEFT], gaps[BND_RIGHT]);
202 *h_max = std::max(gaps[BND_LEFT], gaps[BND_RIGHT]);
203 if (*h_max > max_dimension && *h_min < max_dimension) {
204 *h_max = *h_min;
205 }
206 *v_min = std::min(gaps[BND_ABOVE], gaps[BND_BELOW]);
207 *v_max = std::max(gaps[BND_ABOVE], gaps[BND_BELOW]);
208 if (*v_max > max_dimension && *v_min < max_dimension) {
209 *v_max = *v_min;
210 }
211}
@ BND_LEFT
Definition: blobbox.h:89
@ BND_RIGHT
Definition: blobbox.h:89
@ BND_BELOW
Definition: blobbox.h:89
@ BND_ABOVE
Definition: blobbox.h:89
void NeighbourGaps(int gaps[BND_COUNT]) const
Definition: blobbox.cpp:178

◆ neighbour()

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

Definition at line 385 of file blobbox.h.

385 {
386 return neighbours_[n];
387 }

◆ NeighbourGaps()

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

Definition at line 178 of file blobbox.cpp.

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

◆ NoisyNeighbours()

int tesseract::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 auto bnd = static_cast<BlobNeighbourDir>(dir);
242 BLOBNBOX *blob = neighbour(bnd);
243 if (blob != nullptr && blob->region_type() == BRT_NOISE) {
244 ++count;
245 }
246 }
247 return count;
248}
int * count

◆ owner()

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

Definition at line 367 of file blobbox.h.

367 {
368 return owner_;
369 }

◆ plot()

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

Definition at line 489 of file blobbox.cpp.

491 { // for holes
492 if (cblob_ptr != nullptr) {
493 cblob_ptr->plot(window, blob_colour, child_colour);
494 }
495}
void plot(ScrollView *window, ScrollView::Color blob_colour, ScrollView::Color child_colour)
Definition: stepblob.cpp:526

◆ PlotBlobs()

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

Definition at line 420 of file blobbox.cpp.

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

◆ PlotNoiseBlobs()

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

Definition at line 431 of file blobbox.cpp.

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

◆ RealBlob()

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

Definition at line 169 of file blobbox.h.

169 {
170 auto *blob = new C_BLOB(outline);
171 return new BLOBNBOX(blob);
172 }

◆ really_merge()

void tesseract::BLOBNBOX::really_merge ( BLOBNBOX other)

Definition at line 102 of file blobbox.cpp.

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

◆ red_box_set()

bool tesseract::BLOBNBOX::red_box_set ( ) const
inline

Definition at line 268 of file blobbox.h.

268 {
269 return reduced;
270 }

◆ reduced_box()

const TBOX & tesseract::BLOBNBOX::reduced_box ( ) const
inline

Definition at line 255 of file blobbox.h.

255 {
256 return red_box;
257 }

◆ reflect_box_in_y_axis()

void tesseract::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:92
void set_left(int x)
Definition: rect.h:85

◆ region_type()

BlobRegionType tesseract::BLOBNBOX::region_type ( ) const
inline

Definition at line 298 of file blobbox.h.

298 {
299 return region_type_;
300 }

◆ ReInit()

void tesseract::BLOBNBOX::ReInit ( )
inline

Definition at line 481 of file blobbox.h.

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

◆ remove_cblob()

C_BLOB * tesseract::BLOBNBOX::remove_cblob ( )
inline

Definition at line 280 of file blobbox.h.

280 {
281 auto blob = cblob_ptr;
282 cblob_ptr = nullptr;
283 owns_cblob_ = false;
284 return blob;
285 }

◆ repeated_set()

int tesseract::BLOBNBOX::repeated_set ( ) const
inline

Definition at line 271 of file blobbox.h.

271 {
272 return repeated_set_;
273 }

◆ right_crossing_rule()

int tesseract::BLOBNBOX::right_crossing_rule ( ) const
inline

Definition at line 346 of file blobbox.h.

346 {
347 return right_crossing_rule_;
348 }

◆ right_rule()

int tesseract::BLOBNBOX::right_rule ( ) const
inline

Definition at line 334 of file blobbox.h.

334 {
335 return right_rule_;
336 }

◆ right_tab_type()

TabType tesseract::BLOBNBOX::right_tab_type ( ) const
inline

Definition at line 292 of file blobbox.h.

292 {
293 return right_tab_type_;
294 }

◆ rotate()

void tesseract::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:375

◆ rotate_box()

void tesseract::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}
#define ASSERT_HOST(x)
Definition: errcode.h:54
const double kCosSmallAngle
Definition: blobbox.cpp:44
bool IsDiacritic() const
Definition: blobbox.h:395
void rotate(const FCOORD &vec)
Definition: rect.h:210

◆ set_base_char_blob()

void tesseract::BLOBNBOX::set_base_char_blob ( BLOBNBOX blob)
inline

Definition at line 420 of file blobbox.h.

420 {
421 base_char_blob_ = blob;
422 }

◆ set_bounding_box()

void tesseract::BLOBNBOX::set_bounding_box ( const TBOX new_box)
inline

Definition at line 244 of file blobbox.h.

244 {
245 box = new_box;
246 base_char_top_ = box.top();
247 base_char_bottom_ = box.bottom();
248 }

◆ set_diacritic_box()

void tesseract::BLOBNBOX::set_diacritic_box ( const TBOX diacritic_box)
inline

Definition at line 413 of file blobbox.h.

413 {
414 base_char_top_ = diacritic_box.top();
415 base_char_bottom_ = diacritic_box.bottom();
416 }

◆ set_flow()

void tesseract::BLOBNBOX::set_flow ( BlobTextFlowType  value)
inline

Definition at line 313 of file blobbox.h.

313 {
314 flow_ = value;
315 }
int value

◆ set_horz_possible()

void tesseract::BLOBNBOX::set_horz_possible ( bool  value)
inline

Definition at line 325 of file blobbox.h.

325 {
326 horz_possible_ = value;
327 }

◆ set_horz_stroke_width()

void tesseract::BLOBNBOX::set_horz_stroke_width ( float  width)
inline

Definition at line 355 of file blobbox.h.

355 {
356 horz_stroke_width_ = width;
357 }

◆ set_leader_on_left()

void tesseract::BLOBNBOX::set_leader_on_left ( bool  flag)
inline

Definition at line 376 of file blobbox.h.

376 {
377 leader_on_left_ = flag;
378 }

◆ set_leader_on_right()

void tesseract::BLOBNBOX::set_leader_on_right ( bool  flag)
inline

Definition at line 382 of file blobbox.h.

382 {
383 leader_on_right_ = flag;
384 }

◆ set_left_crossing_rule()

void tesseract::BLOBNBOX::set_left_crossing_rule ( int  new_left)
inline

Definition at line 343 of file blobbox.h.

343 {
344 left_crossing_rule_ = new_left;
345 }

◆ set_left_rule()

void tesseract::BLOBNBOX::set_left_rule ( int  new_left)
inline

Definition at line 331 of file blobbox.h.

331 {
332 left_rule_ = new_left;
333 }

◆ set_left_tab_type()

void tesseract::BLOBNBOX::set_left_tab_type ( TabType  new_type)
inline

Definition at line 289 of file blobbox.h.

289 {
290 left_tab_type_ = new_type;
291 }

◆ set_line_crossings()

void tesseract::BLOBNBOX::set_line_crossings ( int  value)
inline

Definition at line 410 of file blobbox.h.

410 {
411 line_crossings_ = value;
412 }

◆ set_neighbour()

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

Definition at line 391 of file blobbox.h.

391 {
392 neighbours_[n] = neighbour;
393 good_stroke_neighbours_[n] = good;
394 }

◆ set_owner()

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

Definition at line 370 of file blobbox.h.

370 {
371 owner_ = new_owner;
372 }

◆ set_owns_cblob()

void tesseract::BLOBNBOX::set_owns_cblob ( bool  value)
inline

Definition at line 423 of file blobbox.h.

423 {
424 owns_cblob_ = value;
425 }

◆ set_reduced_box()

void tesseract::BLOBNBOX::set_reduced_box ( TBOX  new_box)
inline

Definition at line 258 of file blobbox.h.

258 {
259 red_box = new_box;
260 reduced = true;
261 }

◆ set_region_type()

void tesseract::BLOBNBOX::set_region_type ( BlobRegionType  new_type)
inline

Definition at line 301 of file blobbox.h.

301 {
302 region_type_ = new_type;
303 }

◆ set_repeated_set()

void tesseract::BLOBNBOX::set_repeated_set ( int  set_id)
inline

Definition at line 274 of file blobbox.h.

274 {
275 repeated_set_ = set_id;
276 }

◆ set_right_crossing_rule()

void tesseract::BLOBNBOX::set_right_crossing_rule ( int  new_right)
inline

Definition at line 349 of file blobbox.h.

349 {
350 right_crossing_rule_ = new_right;
351 }

◆ set_right_rule()

void tesseract::BLOBNBOX::set_right_rule ( int  new_right)
inline

Definition at line 337 of file blobbox.h.

337 {
338 right_rule_ = new_right;
339 }

◆ set_right_tab_type()

void tesseract::BLOBNBOX::set_right_tab_type ( TabType  new_type)
inline

Definition at line 295 of file blobbox.h.

295 {
296 right_tab_type_ = new_type;
297 }

◆ set_special_text_type()

void tesseract::BLOBNBOX::set_special_text_type ( BlobSpecialTextType  new_type)
inline

Definition at line 307 of file blobbox.h.

307 {
308 spt_type_ = new_type;
309 }

◆ set_vert_possible()

void tesseract::BLOBNBOX::set_vert_possible ( bool  value)
inline

Definition at line 319 of file blobbox.h.

319 {
320 vert_possible_ = value;
321 }

◆ set_vert_stroke_width()

void tesseract::BLOBNBOX::set_vert_stroke_width ( float  width)
inline

Definition at line 361 of file blobbox.h.

361 {
362 vert_stroke_width_ = width;
363 }

◆ special_text_type()

BlobSpecialTextType tesseract::BLOBNBOX::special_text_type ( ) const
inline

Definition at line 304 of file blobbox.h.

304 {
305 return spt_type_;
306 }

◆ TextlineColor()

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

Definition at line 442 of file blobbox.cpp.

442 {
443 switch (region_type) {
444 case BRT_HLINE:
445 return ScrollView::BROWN;
446 case BRT_VLINE:
448 case BRT_RECTIMAGE:
449 return ScrollView::RED;
450 case BRT_POLYIMAGE:
451 return ScrollView::ORANGE;
452 case BRT_UNKNOWN:
453 return flow_type == BTFT_NONTEXT ? ScrollView::CYAN : ScrollView::WHITE;
454 case BRT_VERT_TEXT:
455 if (flow_type == BTFT_STRONG_CHAIN || flow_type == BTFT_TEXT_ON_IMAGE) {
456 return ScrollView::GREEN;
457 }
458 if (flow_type == BTFT_CHAIN) {
460 }
461 return ScrollView::YELLOW;
462 case BRT_TEXT:
463 if (flow_type == BTFT_STRONG_CHAIN) {
464 return ScrollView::BLUE;
465 }
466 if (flow_type == BTFT_TEXT_ON_IMAGE) {
468 }
469 if (flow_type == BTFT_CHAIN) {
471 }
472 if (flow_type == BTFT_LEADER) {
473 return ScrollView::WHEAT;
474 }
475 if (flow_type == BTFT_NONTEXT) {
476 return ScrollView::PINK;
477 }
478 return ScrollView::MAGENTA;
479 default:
480 return ScrollView::GREY;
481 }
482}
@ BTFT_STRONG_CHAIN
Definition: blobbox.h:115
@ BTFT_CHAIN
Definition: blobbox.h:114
@ BTFT_LEADER
Definition: blobbox.h:117
@ BTFT_TEXT_ON_IMAGE
Definition: blobbox.h:116
@ BTFT_NONTEXT
Definition: blobbox.h:112

◆ translate_box()

void tesseract::BLOBNBOX::translate_box ( ICOORD  v)
inline

Definition at line 185 of file blobbox.h.

185 {
186 if (IsDiacritic()) {
187 box.move(v);
188 base_char_top_ += v.y();
189 base_char_bottom_ += v.y();
190 } else {
191 box.move(v);
193 }
194 }
void move(const ICOORD vec)
Definition: rect.h:170

◆ UniquelyHorizontal()

bool tesseract::BLOBNBOX::UniquelyHorizontal ( ) const
inline

Definition at line 430 of file blobbox.h.

430 {
431 return horz_possible_ && !vert_possible_;
432 }

◆ UniquelyVertical()

bool tesseract::BLOBNBOX::UniquelyVertical ( ) const
inline

Definition at line 427 of file blobbox.h.

427 {
428 return vert_possible_ && !horz_possible_;
429 }

◆ UnMergeableType()

static bool tesseract::BLOBNBOX::UnMergeableType ( BlobRegionType  type)
inlinestatic

Definition at line 447 of file blobbox.h.

447 {
448 return IsLineType(type) || IsImageType(type);
449 }
static bool IsImageType(BlobRegionType type)
Definition: blobbox.h:439
static bool IsLineType(BlobRegionType type)
Definition: blobbox.h:443

◆ vert_possible()

bool tesseract::BLOBNBOX::vert_possible ( ) const
inline

Definition at line 316 of file blobbox.h.

316 {
317 return vert_possible_;
318 }

◆ vert_stroke_width()

float tesseract::BLOBNBOX::vert_stroke_width ( ) const
inline

Definition at line 358 of file blobbox.h.

358 {
359 return vert_stroke_width_;
360 }

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