tesseract  4.0.0-1-g2a2b
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 268 of file blobs.h.

Constructor & Destructor Documentation

◆ TBLOB() [1/2]

TBLOB::TBLOB ( )
inline

Definition at line 269 of file blobs.h.

269 : outlines(nullptr) {}
TESSLINE * outlines
Definition: blobs.h:384

◆ TBLOB() [2/2]

TBLOB::TBLOB ( const TBLOB src)
inline

Definition at line 270 of file blobs.h.

270  : outlines(nullptr) {
271  CopyFrom(src);
272  }
void CopyFrom(const TBLOB &src)
Definition: blobs.cpp:380
TESSLINE * outlines
Definition: blobs.h:384

◆ ~TBLOB()

TBLOB::~TBLOB ( )
inline

Definition at line 273 of file blobs.h.

273  {
274  Clear();
275  }
void Clear()
Definition: blobs.cpp:396

Member Function Documentation

◆ BBArea()

int TBLOB::BBArea ( ) const
inline

Definition at line 356 of file blobs.h.

356  {
357  int total_area = 0;
358  for (TESSLINE* outline = outlines; outline != nullptr; outline = outline->next)
359  total_area += outline->BBArea();
360  return total_area;
361  }
TESSLINE * next
Definition: blobs.h:265
TESSLINE * outlines
Definition: blobs.h:384

◆ bounding_box()

TBOX TBLOB::bounding_box ( ) const

Definition at line 478 of file blobs.cpp.

478  {
479  if (outlines == nullptr) return TBOX(0, 0, 0, 0);
480  TESSLINE* outline = outlines;
481  TBOX box = outline->bounding_box();
482  for (outline = outline->next; outline != nullptr; outline = outline->next) {
483  box += outline->bounding_box();
484  }
485  return box;
486 }
TESSLINE * next
Definition: blobs.h:265
TBOX bounding_box() const
Definition: blobs.cpp:267
Definition: rect.h:34
TESSLINE * outlines
Definition: blobs.h:384

◆ ClassifyNormalizeIfNeeded()

TBLOB * TBLOB::ClassifyNormalizeIfNeeded ( ) const

Definition at line 356 of file blobs.cpp.

356  {
357  TBLOB* rotated_blob = nullptr;
358  // If necessary, copy the blob and rotate it. The rotation is always
359  // +/- 90 degrees, as 180 was already taken care of.
360  if (denorm_.block() != nullptr &&
361  denorm_.block()->classify_rotation().y() != 0.0) {
362  TBOX box = bounding_box();
363  int x_middle = (box.left() + box.right()) / 2;
364  int y_middle = (box.top() + box.bottom()) / 2;
365  rotated_blob = new TBLOB(*this);
366  const FCOORD& rotation = denorm_.block()->classify_rotation();
367  // Move the rotated blob back to the same y-position so that we
368  // can still distinguish similar glyphs with differeny y-position.
369  float target_y =
371  (rotation.y() > 0 ? x_middle - box.left() : box.right() - x_middle);
372  rotated_blob->Normalize(nullptr, &rotation, &denorm_, x_middle, y_middle,
373  1.0f, 1.0f, 0.0f, target_y, denorm_.inverse(),
374  denorm_.pix());
375  }
376  return rotated_blob;
377 }
bool inverse() const
Definition: normalis.h:252
const BLOCK * block() const
Definition: normalis.h:273
Definition: rect.h:34
const int kBlnBaselineOffset
Definition: normalis.h:25
TBLOB()
Definition: blobs.h:269
int16_t left() const
Definition: rect.h:72
int16_t top() const
Definition: rect.h:58
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:407
FCOORD classify_rotation() const
Definition: ocrblock.h:142
TBOX bounding_box() const
Definition: blobs.cpp:478
Definition: points.h:189
int16_t right() const
Definition: rect.h:79
Pix * pix() const
Definition: normalis.h:246
Definition: blobs.h:268
int16_t bottom() const
Definition: rect.h:65
float y() const
Definition: points.h:211

◆ Clear()

void TBLOB::Clear ( )

Definition at line 396 of file blobs.cpp.

396  {
397  for (TESSLINE* next_outline = nullptr; outlines != nullptr;
398  outlines = next_outline) {
399  next_outline = outlines->next;
400  delete outlines;
401  }
402 }
TESSLINE * next
Definition: blobs.h:265
TESSLINE * outlines
Definition: blobs.h:384

◆ ComputeBoundingBoxes()

void TBLOB::ComputeBoundingBoxes ( )

Definition at line 456 of file blobs.cpp.

456  {
457  for (TESSLINE* outline = outlines; outline != nullptr;
458  outline = outline->next) {
459  outline->ComputeBoundingBox();
460  }
461 }
TESSLINE * next
Definition: blobs.h:265
TESSLINE * outlines
Definition: blobs.h:384

◆ ComputeMoments()

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

Definition at line 532 of file blobs.cpp.

532  {
533  // Compute 1st and 2nd moments of the original outline.
534  LLSQ accumulator;
535  TBOX box = bounding_box();
536  // Iterate the outlines, accumulating edges relative the box.botleft().
537  CollectEdges(box, nullptr, &accumulator, nullptr, nullptr);
538  *center = accumulator.mean_point() + box.botleft();
539  // The 2nd moments are just the standard deviation of the point positions.
540  double x2nd = sqrt(accumulator.x_variance());
541  double y2nd = sqrt(accumulator.y_variance());
542  if (x2nd < 1.0) x2nd = 1.0;
543  if (y2nd < 1.0) y2nd = 1.0;
544  second_moments->set_x(x2nd);
545  second_moments->set_y(y2nd);
546  return accumulator.count();
547 }
int32_t count() const
Definition: linlsq.h:43
Definition: rect.h:34
void set_x(float xin)
rewrite function
Definition: points.h:215
FCOORD mean_point() const
Definition: linlsq.cpp:166
Definition: linlsq.h:28
TBOX bounding_box() const
Definition: blobs.cpp:478
const ICOORD & botleft() const
Definition: rect.h:92
double y_variance() const
Definition: linlsq.h:87
double x_variance() const
Definition: linlsq.h:81
void set_y(float yin)
rewrite function
Definition: points.h:219

◆ Contains()

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

Definition at line 331 of file blobs.h.

331  {
332  for (const TESSLINE* outline = outlines; outline != nullptr;
333  outline = outline->next) {
334  if (outline->Contains(pt)) return true;
335  }
336  return false;
337  }
TESSLINE * next
Definition: blobs.h:265
TESSLINE * outlines
Definition: blobs.h:384

◆ CopyFrom()

void TBLOB::CopyFrom ( const TBLOB src)

Definition at line 380 of file blobs.cpp.

380  {
381  Clear();
382  TESSLINE* prev_outline = nullptr;
383  for (TESSLINE* srcline = src.outlines; srcline != nullptr;
384  srcline = srcline->next) {
385  TESSLINE* new_outline = new TESSLINE(*srcline);
386  if (outlines == nullptr)
387  outlines = new_outline;
388  else
389  prev_outline->next = new_outline;
390  prev_outline = new_outline;
391  }
392  denorm_ = src.denorm_;
393 }
void Clear()
Definition: blobs.cpp:396
TESSLINE * next
Definition: blobs.h:265
TESSLINE * outlines
Definition: blobs.h:384

◆ CorrectBlobOrder()

void TBLOB::CorrectBlobOrder ( TBLOB next)

Definition at line 511 of file blobs.cpp.

511  {
512  TBOX box = bounding_box();
513  TBOX next_box = next->bounding_box();
514  if (box.x_middle() > next_box.x_middle()) {
515  Swap(&outlines, &next->outlines);
516  }
517 }
void Swap(T *p1, T *p2)
Definition: helpers.h:98
Definition: rect.h:34
TBOX bounding_box() const
Definition: blobs.cpp:478
int x_middle() const
Definition: rect.h:85
TESSLINE * outlines
Definition: blobs.h:384

◆ denorm()

const DENORM& TBLOB::denorm ( ) const
inline

Definition at line 347 of file blobs.h.

347  {
348  return denorm_;
349  }

◆ EliminateDuplicateOutlines()

void TBLOB::EliminateDuplicateOutlines ( )

Definition at line 490 of file blobs.cpp.

490  {
491  for (TESSLINE* outline = outlines; outline != nullptr;
492  outline = outline->next) {
493  TESSLINE* last_outline = outline;
494  for (TESSLINE* other_outline = outline->next; other_outline != nullptr;
495  last_outline = other_outline, other_outline = other_outline->next) {
496  if (outline->SameBox(*other_outline)) {
497  last_outline->next = other_outline->next;
498  // This doesn't leak - the outlines share the EDGEPTs.
499  other_outline->loop = nullptr;
500  delete other_outline;
501  other_outline = last_outline;
502  // If it is part of a cut, then it can't be a hole any more.
503  outline->is_hole = false;
504  }
505  }
506  }
507 }
TESSLINE * next
Definition: blobs.h:265
EDGEPT * loop
Definition: blobs.h:264
bool is_hole
Definition: blobs.h:263
TESSLINE * outlines
Definition: blobs.h:384

◆ GetEdgeCoords()

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

Definition at line 567 of file blobs.cpp.

569  {
570  GenericVector<int> empty;
571  x_coords->init_to_size(box.height(), empty);
572  y_coords->init_to_size(box.width(), empty);
573  CollectEdges(box, nullptr, nullptr, x_coords, y_coords);
574  // Sort the output vectors.
575  for (int i = 0; i < x_coords->size(); ++i) (*x_coords)[i].sort();
576  for (int i = 0; i < y_coords->size(); ++i) (*y_coords)[i].sort();
577 }
int size() const
Definition: genericvector.h:71
int16_t width() const
Definition: rect.h:115
void init_to_size(int size, const T &t)
int16_t height() const
Definition: rect.h:108

◆ GetPreciseBoundingBox()

void TBLOB::GetPreciseBoundingBox ( TBOX precise_box) const

Definition at line 551 of file blobs.cpp.

551  {
552  TBOX box = bounding_box();
553  *precise_box = TBOX();
554  CollectEdges(box, precise_box, nullptr, nullptr, nullptr);
555  precise_box->move(box.botleft());
556 }
Definition: rect.h:34
void move(const ICOORD vec)
Definition: rect.h:157
TBOX bounding_box() const
Definition: blobs.cpp:478
const ICOORD & botleft() const
Definition: rect.h:92

◆ Move()

void TBLOB::Move ( const ICOORD  vec)

Definition at line 440 of file blobs.cpp.

440  {
441  for (TESSLINE* outline = outlines; outline != nullptr;
442  outline = outline->next) {
443  outline->Move(vec);
444  }
445 }
TESSLINE * next
Definition: blobs.h:265
TESSLINE * outlines
Definition: blobs.h:384

◆ 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 407 of file blobs.cpp.

410  {
411  denorm_.SetupNormalization(block, rotation, predecessor, x_origin, y_origin,
412  x_scale, y_scale, final_xshift, final_yshift);
413  denorm_.set_inverse(inverse);
414  denorm_.set_pix(pix);
415  // TODO(rays) outline->Normalize is more accurate, but breaks tests due
416  // the changes it makes. Reinstate this code with a retraining.
417  // The reason this change is troublesome is that it normalizes for the
418  // baseline value computed independently at each x-coord. If the baseline
419  // is not horizontal, this introduces shear into the normalized blob, which
420  // is useful on the rare occasions that the baseline is really curved, but
421  // the baselines need to be stabilized the rest of the time.
422 #if 0
423  for (TESSLINE* outline = outlines; outline != nullptr; outline = outline->next) {
424  outline->Normalize(denorm_);
425  }
426 #else
427  denorm_.LocalNormBlob(this);
428 #endif
429 }
TESSLINE * next
Definition: blobs.h:265
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
void LocalNormBlob(TBLOB *blob) const
Definition: normalis.cpp:412
void set_pix(Pix *pix)
Definition: normalis.h:249
void set_inverse(bool value)
Definition: normalis.h:255
TESSLINE * outlines
Definition: blobs.h:384

◆ NumOutlines()

int TBLOB::NumOutlines ( ) const

Definition at line 464 of file blobs.cpp.

464  {
465  int result = 0;
466  for (TESSLINE* outline = outlines; outline != nullptr;
467  outline = outline->next)
468  ++result;
469  return result;
470 }
TESSLINE * next
Definition: blobs.h:265
TESSLINE * outlines
Definition: blobs.h:384

◆ operator=()

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

Definition at line 276 of file blobs.h.

276  {
277  CopyFrom(src);
278  return *this;
279  }
void CopyFrom(const TBLOB &src)
Definition: blobs.cpp:380

◆ plot()

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

Definition at line 520 of file blobs.cpp.

521  {
522  for (TESSLINE* outline = outlines; outline != nullptr;
523  outline = outline->next)
524  outline->plot(window, color, child_color);
525 }
TESSLINE * next
Definition: blobs.h:265
TESSLINE * outlines
Definition: blobs.h:384

◆ PolygonalCopy()

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

Definition at line 337 of file blobs.cpp.

337  {
338  TBLOB* tblob = new TBLOB;
339  ApproximateOutlineList(allow_detailed_fx, src->out_list(), false,
340  &tblob->outlines);
341  return tblob;
342 }
TBLOB()
Definition: blobs.h:269
C_OUTLINE_LIST * out_list()
Definition: stepblob.h:70
Definition: blobs.h:268
TESSLINE * outlines
Definition: blobs.h:384

◆ Rotate()

void TBLOB::Rotate ( const FCOORD  rotation)

Definition at line 432 of file blobs.cpp.

432  {
433  for (TESSLINE* outline = outlines; outline != nullptr;
434  outline = outline->next) {
435  outline->Rotate(rotation);
436  }
437 }
TESSLINE * next
Definition: blobs.h:265
TESSLINE * outlines
Definition: blobs.h:384

◆ Scale()

void TBLOB::Scale ( float  factor)

Definition at line 448 of file blobs.cpp.

448  {
449  for (TESSLINE* outline = outlines; outline != nullptr;
450  outline = outline->next) {
451  outline->Scale(factor);
452  }
453 }
TESSLINE * next
Definition: blobs.h:265
TESSLINE * outlines
Definition: blobs.h:384

◆ SegmentCrossesOutline()

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

Definition at line 323 of file blobs.h.

323  {
324  for (const TESSLINE* outline = outlines; outline != nullptr;
325  outline = outline->next) {
326  if (outline->SegmentCrosses(pt1, pt2)) return true;
327  }
328  return false;
329  }
TESSLINE * next
Definition: blobs.h:265
TESSLINE * outlines
Definition: blobs.h:384

◆ ShallowCopy()

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

Definition at line 345 of file blobs.cpp.

345  {
346  TBLOB* blob = new TBLOB;
347  blob->denorm_ = src.denorm_;
348  return blob;
349 }
TBLOB()
Definition: blobs.h:269
Definition: blobs.h:268

Member Data Documentation

◆ outlines

TESSLINE* TBLOB::outlines

Definition at line 384 of file blobs.h.


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