tesseract 4.1.1
Loading...
Searching...
No Matches
TBLOB Struct Reference

#include <blobs.h>

Public Member Functions

 TBLOB ()
 
 TBLOB (const TBLOB &src)
 
 ~TBLOB ()
 
TBLOBoperator= (const TBLOB &src)
 
TBLOBClassifyNormalizeIfNeeded () const
 
void CopyFrom (const TBLOB &src)
 
void Clear ()
 
void Normalize (const BLOCK *block, const FCOORD *rotation, const DENORM *predecessor, float x_origin, float y_origin, float x_scale, float y_scale, float final_xshift, float final_yshift, bool inverse, Pix *pix)
 
void Rotate (const FCOORD rotation)
 
void Move (const ICOORD vec)
 
void Scale (float factor)
 
void ComputeBoundingBoxes ()
 
int NumOutlines () const
 
TBOX bounding_box () const
 
bool SegmentCrossesOutline (const TPOINT &pt1, const TPOINT &pt2) const
 
bool Contains (const TPOINT &pt) const
 
void EliminateDuplicateOutlines ()
 
void CorrectBlobOrder (TBLOB *next)
 
const DENORMdenorm () const
 
void plot (ScrollView *window, ScrollView::Color color, ScrollView::Color child_color)
 
int BBArea () const
 
int ComputeMoments (FCOORD *center, FCOORD *second_moments) const
 
void GetPreciseBoundingBox (TBOX *precise_box) const
 
void GetEdgeCoords (const TBOX &box, GenericVector< GenericVector< int > > *x_coords, GenericVector< GenericVector< int > > *y_coords) const
 

Static Public Member Functions

static TBLOBPolygonalCopy (bool allow_detailed_fx, C_BLOB *src)
 
static TBLOBShallowCopy (const TBLOB &src)
 

Public Attributes

TESSLINEoutlines
 

Detailed Description

Definition at line 284 of file blobs.h.

Constructor & Destructor Documentation

◆ TBLOB() [1/2]

TBLOB::TBLOB ( )
inline

Definition at line 285 of file blobs.h.

285: outlines(nullptr) {}
TESSLINE * outlines
Definition: blobs.h:400

◆ TBLOB() [2/2]

TBLOB::TBLOB ( const TBLOB src)
inline

Definition at line 286 of file blobs.h.

286 : outlines(nullptr) {
287 CopyFrom(src);
288 }
void CopyFrom(const TBLOB &src)
Definition: blobs.cpp:370

◆ ~TBLOB()

TBLOB::~TBLOB ( )
inline

Definition at line 289 of file blobs.h.

289 {
290 Clear();
291 }
void Clear()
Definition: blobs.cpp:386

Member Function Documentation

◆ BBArea()

int TBLOB::BBArea ( ) const
inline

Definition at line 372 of file blobs.h.

372 {
373 int total_area = 0;
374 for (TESSLINE* outline = outlines; outline != nullptr; outline = outline->next)
375 total_area += outline->BBArea();
376 return total_area;
377 }
TESSLINE * next
Definition: blobs.h:281

◆ bounding_box()

TBOX TBLOB::bounding_box ( ) const

Definition at line 468 of file blobs.cpp.

468 {
469 if (outlines == nullptr) return TBOX(0, 0, 0, 0);
470 TESSLINE* outline = outlines;
471 TBOX box = outline->bounding_box();
472 for (outline = outline->next; outline != nullptr; outline = outline->next) {
473 box += outline->bounding_box();
474 }
475 return box;
476}
TBOX bounding_box() const
Definition: blobs.cpp:257
Definition: rect.h:34

◆ ClassifyNormalizeIfNeeded()

TBLOB * TBLOB::ClassifyNormalizeIfNeeded ( ) const

Definition at line 346 of file blobs.cpp.

346 {
347 TBLOB* rotated_blob = nullptr;
348 // If necessary, copy the blob and rotate it. The rotation is always
349 // +/- 90 degrees, as 180 was already taken care of.
350 if (denorm_.block() != nullptr &&
351 denorm_.block()->classify_rotation().y() != 0.0) {
352 TBOX box = bounding_box();
353 int x_middle = (box.left() + box.right()) / 2;
354 int y_middle = (box.top() + box.bottom()) / 2;
355 rotated_blob = new TBLOB(*this);
356 const FCOORD& rotation = denorm_.block()->classify_rotation();
357 // Move the rotated blob back to the same y-position so that we
358 // can still distinguish similar glyphs with differeny y-position.
359 float target_y =
361 (rotation.y() > 0 ? x_middle - box.left() : box.right() - x_middle);
362 rotated_blob->Normalize(nullptr, &rotation, &denorm_, x_middle, y_middle,
363 1.0f, 1.0f, 0.0f, target_y, denorm_.inverse(),
364 denorm_.pix());
365 }
366 return rotated_blob;
367}
const int kBlnBaselineOffset
Definition: normalis.h:25
Definition: blobs.h:284
TBOX bounding_box() const
Definition: blobs.cpp:468
void Normalize(const BLOCK *block, const FCOORD *rotation, const DENORM *predecessor, float x_origin, float y_origin, float x_scale, float y_scale, float final_xshift, float final_yshift, bool inverse, Pix *pix)
Definition: blobs.cpp:397
TBLOB()
Definition: blobs.h:285
bool inverse() const
Definition: normalis.h:252
Pix * pix() const
Definition: normalis.h:246
const BLOCK * block() const
Definition: normalis.h:273
FCOORD classify_rotation() const
Definition: ocrblock.h:140
Definition: points.h:189
float y() const
Definition: points.h:210
int16_t top() const
Definition: rect.h:58
int16_t left() const
Definition: rect.h:72
int16_t bottom() const
Definition: rect.h:65
int16_t right() const
Definition: rect.h:79

◆ Clear()

void TBLOB::Clear ( )

Definition at line 386 of file blobs.cpp.

386 {
387 for (TESSLINE* next_outline = nullptr; outlines != nullptr;
388 outlines = next_outline) {
389 next_outline = outlines->next;
390 delete outlines;
391 }
392}

◆ ComputeBoundingBoxes()

void TBLOB::ComputeBoundingBoxes ( )

Definition at line 446 of file blobs.cpp.

446 {
447 for (TESSLINE* outline = outlines; outline != nullptr;
448 outline = outline->next) {
449 outline->ComputeBoundingBox();
450 }
451}

◆ ComputeMoments()

int TBLOB::ComputeMoments ( FCOORD center,
FCOORD second_moments 
) const

Definition at line 522 of file blobs.cpp.

522 {
523 // Compute 1st and 2nd moments of the original outline.
524 LLSQ accumulator;
525 TBOX box = bounding_box();
526 // Iterate the outlines, accumulating edges relative the box.botleft().
527 CollectEdges(box, nullptr, &accumulator, nullptr, nullptr);
528 *center = accumulator.mean_point() + box.botleft();
529 // The 2nd moments are just the standard deviation of the point positions.
530 double x2nd = sqrt(accumulator.x_variance());
531 double y2nd = sqrt(accumulator.y_variance());
532 if (x2nd < 1.0) x2nd = 1.0;
533 if (y2nd < 1.0) y2nd = 1.0;
534 second_moments->set_x(x2nd);
535 second_moments->set_y(y2nd);
536 return accumulator.count();
537}
Definition: linlsq.h:28
double y_variance() const
Definition: linlsq.h:87
double x_variance() const
Definition: linlsq.h:81
int32_t count() const
Definition: linlsq.h:43
FCOORD mean_point() const
Definition: linlsq.cpp:166
void set_y(float yin)
rewrite function
Definition: points.h:218
void set_x(float xin)
rewrite function
Definition: points.h:214
const ICOORD & botleft() const
Definition: rect.h:92

◆ Contains()

bool TBLOB::Contains ( const TPOINT pt) const
inline

Definition at line 347 of file blobs.h.

347 {
348 for (const TESSLINE* outline = outlines; outline != nullptr;
349 outline = outline->next) {
350 if (outline->Contains(pt)) return true;
351 }
352 return false;
353 }

◆ CopyFrom()

void TBLOB::CopyFrom ( const TBLOB src)

Definition at line 370 of file blobs.cpp.

370 {
371 Clear();
372 TESSLINE* prev_outline = nullptr;
373 for (TESSLINE* srcline = src.outlines; srcline != nullptr;
374 srcline = srcline->next) {
375 auto* new_outline = new TESSLINE(*srcline);
376 if (outlines == nullptr)
377 outlines = new_outline;
378 else
379 prev_outline->next = new_outline;
380 prev_outline = new_outline;
381 }
382 denorm_ = src.denorm_;
383}

◆ CorrectBlobOrder()

void TBLOB::CorrectBlobOrder ( TBLOB next)

Definition at line 501 of file blobs.cpp.

501 {
502 TBOX box = bounding_box();
503 TBOX next_box = next->bounding_box();
504 if (box.x_middle() > next_box.x_middle()) {
505 Swap(&outlines, &next->outlines);
506 }
507}
void Swap(T *p1, T *p2)
Definition: helpers.h:95
int x_middle() const
Definition: rect.h:85

◆ denorm()

const DENORM & TBLOB::denorm ( ) const
inline

Definition at line 363 of file blobs.h.

363 {
364 return denorm_;
365 }

◆ EliminateDuplicateOutlines()

void TBLOB::EliminateDuplicateOutlines ( )

Definition at line 480 of file blobs.cpp.

480 {
481 for (TESSLINE* outline = outlines; outline != nullptr;
482 outline = outline->next) {
483 TESSLINE* last_outline = outline;
484 for (TESSLINE* other_outline = outline->next; other_outline != nullptr;
485 last_outline = other_outline, other_outline = other_outline->next) {
486 if (outline->SameBox(*other_outline)) {
487 last_outline->next = other_outline->next;
488 // This doesn't leak - the outlines share the EDGEPTs.
489 other_outline->loop = nullptr;
490 delete other_outline;
491 other_outline = last_outline;
492 // If it is part of a cut, then it can't be a hole any more.
493 outline->is_hole = false;
494 }
495 }
496 }
497}
EDGEPT * loop
Definition: blobs.h:280
bool is_hole
Definition: blobs.h:279

◆ GetEdgeCoords()

void TBLOB::GetEdgeCoords ( const TBOX box,
GenericVector< GenericVector< int > > *  x_coords,
GenericVector< GenericVector< int > > *  y_coords 
) const

Definition at line 557 of file blobs.cpp.

559 {
560 GenericVector<int> empty;
561 x_coords->init_to_size(box.height(), empty);
562 y_coords->init_to_size(box.width(), empty);
563 CollectEdges(box, nullptr, nullptr, x_coords, y_coords);
564 // Sort the output vectors.
565 for (int i = 0; i < x_coords->size(); ++i) (*x_coords)[i].sort();
566 for (int i = 0; i < y_coords->size(); ++i) (*y_coords)[i].sort();
567}
void init_to_size(int size, const T &t)
int size() const
Definition: genericvector.h:72
int16_t width() const
Definition: rect.h:115
int16_t height() const
Definition: rect.h:108

◆ GetPreciseBoundingBox()

void TBLOB::GetPreciseBoundingBox ( TBOX precise_box) const

Definition at line 541 of file blobs.cpp.

541 {
542 TBOX box = bounding_box();
543 *precise_box = TBOX();
544 CollectEdges(box, precise_box, nullptr, nullptr, nullptr);
545 precise_box->move(box.botleft());
546}
void move(const ICOORD vec)
Definition: rect.h:157

◆ Move()

void TBLOB::Move ( const ICOORD  vec)

Definition at line 430 of file blobs.cpp.

430 {
431 for (TESSLINE* outline = outlines; outline != nullptr;
432 outline = outline->next) {
433 outline->Move(vec);
434 }
435}

◆ Normalize()

void TBLOB::Normalize ( const BLOCK block,
const FCOORD rotation,
const DENORM predecessor,
float  x_origin,
float  y_origin,
float  x_scale,
float  y_scale,
float  final_xshift,
float  final_yshift,
bool  inverse,
Pix *  pix 
)

Definition at line 397 of file blobs.cpp.

400 {
401 denorm_.SetupNormalization(block, rotation, predecessor, x_origin, y_origin,
402 x_scale, y_scale, final_xshift, final_yshift);
403 denorm_.set_inverse(inverse);
404 denorm_.set_pix(pix);
405 // TODO(rays) outline->Normalize is more accurate, but breaks tests due
406 // the changes it makes. Reinstate this code with a retraining.
407 // The reason this change is troublesome is that it normalizes for the
408 // baseline value computed independently at each x-coord. If the baseline
409 // is not horizontal, this introduces shear into the normalized blob, which
410 // is useful on the rare occasions that the baseline is really curved, but
411 // the baselines need to be stabilized the rest of the time.
412#if 0
413 for (TESSLINE* outline = outlines; outline != nullptr; outline = outline->next) {
414 outline->Normalize(denorm_);
415 }
416#else
417 denorm_.LocalNormBlob(this);
418#endif
419}
void set_pix(Pix *pix)
Definition: normalis.h:249
void LocalNormBlob(TBLOB *blob) const
Definition: normalis.cpp:412
void set_inverse(bool value)
Definition: normalis.h:255
void SetupNormalization(const BLOCK *block, const FCOORD *rotation, const DENORM *predecessor, float x_origin, float y_origin, float x_scale, float y_scale, float final_xshift, float final_yshift)
Definition: normalis.cpp:96

◆ NumOutlines()

int TBLOB::NumOutlines ( ) const

Definition at line 454 of file blobs.cpp.

454 {
455 int result = 0;
456 for (TESSLINE* outline = outlines; outline != nullptr;
457 outline = outline->next)
458 ++result;
459 return result;
460}

◆ operator=()

TBLOB & TBLOB::operator= ( const TBLOB src)
inline

Definition at line 292 of file blobs.h.

292 {
293 CopyFrom(src);
294 return *this;
295 }

◆ plot()

void TBLOB::plot ( ScrollView window,
ScrollView::Color  color,
ScrollView::Color  child_color 
)

Definition at line 510 of file blobs.cpp.

511 {
512 for (TESSLINE* outline = outlines; outline != nullptr;
513 outline = outline->next)
514 outline->plot(window, color, child_color);
515}

◆ PolygonalCopy()

TBLOB * TBLOB::PolygonalCopy ( bool  allow_detailed_fx,
C_BLOB src 
)
static

Definition at line 327 of file blobs.cpp.

327 {
328 auto* tblob = new TBLOB;
329 ApproximateOutlineList(allow_detailed_fx, src->out_list(), false,
330 &tblob->outlines);
331 return tblob;
332}
C_OUTLINE_LIST * out_list()
Definition: stepblob.h:70

◆ Rotate()

void TBLOB::Rotate ( const FCOORD  rotation)

Definition at line 422 of file blobs.cpp.

422 {
423 for (TESSLINE* outline = outlines; outline != nullptr;
424 outline = outline->next) {
425 outline->Rotate(rotation);
426 }
427}

◆ Scale()

void TBLOB::Scale ( float  factor)

Definition at line 438 of file blobs.cpp.

438 {
439 for (TESSLINE* outline = outlines; outline != nullptr;
440 outline = outline->next) {
441 outline->Scale(factor);
442 }
443}

◆ SegmentCrossesOutline()

bool TBLOB::SegmentCrossesOutline ( const TPOINT pt1,
const TPOINT pt2 
) const
inline

Definition at line 339 of file blobs.h.

339 {
340 for (const TESSLINE* outline = outlines; outline != nullptr;
341 outline = outline->next) {
342 if (outline->SegmentCrosses(pt1, pt2)) return true;
343 }
344 return false;
345 }

◆ ShallowCopy()

TBLOB * TBLOB::ShallowCopy ( const TBLOB src)
static

Definition at line 335 of file blobs.cpp.

335 {
336 auto* blob = new TBLOB;
337 blob->denorm_ = src.denorm_;
338 return blob;
339}

Member Data Documentation

◆ outlines

TESSLINE* TBLOB::outlines

Definition at line 400 of file blobs.h.


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