tesseract  5.0.0-alpha-619-ge9db
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 282 of file blobs.h.

Constructor & Destructor Documentation

◆ TBLOB() [1/2]

TBLOB::TBLOB ( )
inline

Definition at line 283 of file blobs.h.

283 {

◆ TBLOB() [2/2]

TBLOB::TBLOB ( const TBLOB src)
inline

Definition at line 284 of file blobs.h.

284  : outlines(nullptr) {}
285  TBLOB(const TBLOB& src) : outlines(nullptr) {
286  CopyFrom(src);

◆ ~TBLOB()

TBLOB::~TBLOB ( )
inline

Definition at line 287 of file blobs.h.

288  {
289  Clear();

Member Function Documentation

◆ BBArea()

int TBLOB::BBArea ( ) const
inline

Definition at line 370 of file blobs.h.

371  {
372  int total_area = 0;
373  for (TESSLINE* outline = outlines; outline != nullptr; outline = outline->next)
374  total_area += outline->BBArea();
375  return total_area;

◆ bounding_box()

TBOX TBLOB::bounding_box ( ) const

Definition at line 466 of file blobs.cpp.

467  {
468  if (outlines == nullptr) return TBOX(0, 0, 0, 0);
469  TESSLINE* outline = outlines;
470  TBOX box = outline->bounding_box();
471  for (outline = outline->next; outline != nullptr; outline = outline->next) {
472  box += outline->bounding_box();
473  }
474  return box;

◆ ClassifyNormalizeIfNeeded()

TBLOB * TBLOB::ClassifyNormalizeIfNeeded ( ) const

Definition at line 345 of file blobs.cpp.

345  {
346  TBLOB* rotated_blob = nullptr;
347  // If necessary, copy the blob and rotate it. The rotation is always
348  // +/- 90 degrees, as 180 was already taken care of.
349  if (denorm_.block() != nullptr &&
350  denorm_.block()->classify_rotation().y() != 0.0) {
351  TBOX box = bounding_box();
352  int x_middle = (box.left() + box.right()) / 2;
353  int y_middle = (box.top() + box.bottom()) / 2;
354  rotated_blob = new TBLOB(*this);
355  const FCOORD& rotation = denorm_.block()->classify_rotation();
356  // Move the rotated blob back to the same y-position so that we
357  // can still distinguish similar glyphs with differeny y-position.
358  float target_y =
360  (rotation.y() > 0 ? x_middle - box.left() : box.right() - x_middle);
361  rotated_blob->Normalize(nullptr, &rotation, &denorm_, x_middle, y_middle,
362  1.0f, 1.0f, 0.0f, target_y, denorm_.inverse(),
363  denorm_.pix());
364  }
365  return rotated_blob;
366 }

◆ Clear()

void TBLOB::Clear ( )

Definition at line 385 of file blobs.cpp.

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

◆ ComputeBoundingBoxes()

void TBLOB::ComputeBoundingBoxes ( )

Definition at line 445 of file blobs.cpp.

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

◆ ComputeMoments()

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

Definition at line 520 of file blobs.cpp.

521  {
522  // Compute 1st and 2nd moments of the original outline.
523  LLSQ accumulator;
524  TBOX box = bounding_box();
525  // Iterate the outlines, accumulating edges relative the box.botleft().
526  CollectEdges(box, nullptr, &accumulator, nullptr, nullptr);
527  *center = accumulator.mean_point() + box.botleft();
528  // The 2nd moments are just the standard deviation of the point positions.
529  double x2nd = sqrt(accumulator.x_variance());
530  double y2nd = sqrt(accumulator.y_variance());
531  if (x2nd < 1.0) x2nd = 1.0;
532  if (y2nd < 1.0) y2nd = 1.0;
533  second_moments->set_x(x2nd);
534  second_moments->set_y(y2nd);
535  return accumulator.count();

◆ Contains()

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

Definition at line 345 of file blobs.h.

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

◆ CopyFrom()

void TBLOB::CopyFrom ( const TBLOB src)

Definition at line 369 of file blobs.cpp.

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

◆ CorrectBlobOrder()

void TBLOB::CorrectBlobOrder ( TBLOB next)

Definition at line 499 of file blobs.cpp.

500  {
501  TBOX box = bounding_box();
502  TBOX next_box = next->bounding_box();
503  if (box.x_middle() > next_box.x_middle()) {
504  Swap(&outlines, &next->outlines);
505  }

◆ denorm()

const DENORM& TBLOB::denorm ( ) const
inline

Definition at line 361 of file blobs.h.

362  {
363  return denorm_;

◆ EliminateDuplicateOutlines()

void TBLOB::EliminateDuplicateOutlines ( )

Definition at line 478 of file blobs.cpp.

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

◆ GetEdgeCoords()

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

Definition at line 555 of file blobs.cpp.

558  {
559  GenericVector<int> empty;
560  x_coords->init_to_size(box.height(), empty);
561  y_coords->init_to_size(box.width(), empty);
562  CollectEdges(box, nullptr, nullptr, x_coords, y_coords);
563  // Sort the output vectors.
564  for (int i = 0; i < x_coords->size(); ++i) (*x_coords)[i].sort();
565  for (int i = 0; i < y_coords->size(); ++i) (*y_coords)[i].sort();

◆ GetPreciseBoundingBox()

void TBLOB::GetPreciseBoundingBox ( TBOX precise_box) const

Definition at line 539 of file blobs.cpp.

540  {
541  TBOX box = bounding_box();
542  *precise_box = TBOX();
543  CollectEdges(box, precise_box, nullptr, nullptr, nullptr);
544  precise_box->move(box.botleft());

◆ Move()

void TBLOB::Move ( const ICOORD  vec)

Definition at line 429 of file blobs.cpp.

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

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

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

◆ NumOutlines()

int TBLOB::NumOutlines ( ) const

Definition at line 453 of file blobs.cpp.

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

◆ operator=()

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

Definition at line 290 of file blobs.h.

291  {
292  CopyFrom(src);
293  return *this;

◆ plot()

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

Definition at line 508 of file blobs.cpp.

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

◆ PolygonalCopy()

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

Definition at line 326 of file blobs.cpp.

326  {
327  auto* tblob = new TBLOB;
328  ApproximateOutlineList(allow_detailed_fx, src->out_list(), false,
329  &tblob->outlines);
330  return tblob;
331 }

◆ Rotate()

void TBLOB::Rotate ( const FCOORD  rotation)

Definition at line 421 of file blobs.cpp.

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

◆ Scale()

void TBLOB::Scale ( float  factor)

Definition at line 437 of file blobs.cpp.

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

◆ SegmentCrossesOutline()

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

Definition at line 337 of file blobs.h.

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

◆ ShallowCopy()

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

Definition at line 334 of file blobs.cpp.

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

Member Data Documentation

◆ outlines

TESSLINE* TBLOB::outlines

Definition at line 398 of file blobs.h.


The documentation for this struct was generated from the following files:
TBOX
Definition: cleanapi_test.cc:19
TBOX::move
void move(const ICOORD vec)
Definition: rect.h:156
C_BLOB::out_list
C_OUTLINE_LIST * out_list()
Definition: stepblob.h:69
LLSQ
Definition: linlsq.h:27
TESSLINE::loop
EDGEPT * loop
Definition: blobs.h:278
LLSQ::y_variance
double y_variance() const
Definition: linlsq.h:86
LLSQ::mean_point
FCOORD mean_point() const
Definition: linlsq.cpp:158
TBLOB::Clear
void Clear()
Definition: blobs.cpp:385
FCOORD::set_x
void set_x(float xin)
rewrite function
Definition: points.h:213
TBLOB::outlines
TESSLINE * outlines
Definition: blobs.h:398
FCOORD::y
float y() const
Definition: points.h:209
DENORM::set_inverse
void set_inverse(bool value)
Definition: normalis.h:254
TESSLINE
Definition: blobs.h:201
TBOX::top
int16_t top() const
Definition: rect.h:57
LLSQ::count
int32_t count() const
Definition: linlsq.h:42
TESSLINE::bounding_box
TBOX bounding_box() const
Definition: blobs.cpp:256
TESSLINE::next
TESSLINE * next
Definition: blobs.h:279
FCOORD
Definition: points.h:187
FCOORD::set_y
void set_y(float yin)
rewrite function
Definition: points.h:217
TBOX::height
int16_t height() const
Definition: rect.h:107
DENORM::block
const BLOCK * block() const
Definition: normalis.h:272
DENORM::SetupNormalization
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:95
TBLOB::TBLOB
TBLOB()
Definition: blobs.h:283
TBOX::x_middle
int x_middle() const
Definition: rect.h:84
DENORM::LocalNormBlob
void LocalNormBlob(TBLOB *blob) const
Definition: normalis.cpp:411
TBOX::width
int16_t width() const
Definition: rect.h:114
TBOX::bottom
int16_t bottom() const
Definition: rect.h:64
TBLOB::Normalize
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:396
TBOX::botleft
const ICOORD & botleft() const
Definition: rect.h:91
TBLOB::bounding_box
TBOX bounding_box() const
Definition: blobs.cpp:466
GenericVector< int >
DENORM::inverse
bool inverse() const
Definition: normalis.h:251
DENORM::set_pix
void set_pix(Pix *pix)
Definition: normalis.h:248
TBLOB
Definition: blobs.h:282
TBOX::left
int16_t left() const
Definition: rect.h:71
TBOX::right
int16_t right() const
Definition: rect.h:78
GenericVector::init_to_size
void init_to_size(int size, const T &t)
Definition: genericvector.h:706
TBLOB::CopyFrom
void CopyFrom(const TBLOB &src)
Definition: blobs.cpp:369
BLOCK::classify_rotation
FCOORD classify_rotation() const
Definition: ocrblock.h:139
Swap
void Swap(T *p1, T *p2)
Definition: helpers.h:93
DENORM::pix
Pix * pix() const
Definition: normalis.h:245
GenericVector::size
int size() const
Definition: genericvector.h:71
LLSQ::x_variance
double x_variance() const
Definition: linlsq.h:80
TESSLINE::is_hole
bool is_hole
Definition: blobs.h:277
kBlnBaselineOffset
const int kBlnBaselineOffset
Definition: normalis.h:24
TBOX
Definition: rect.h:33