tesseract  5.0.0
tesseract::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, Image 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, std::vector< std::vector< int >> &x_coords, std::vector< std::vector< 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 291 of file blobs.h.

Constructor & Destructor Documentation

◆ TBLOB() [1/2]

tesseract::TBLOB::TBLOB ( )
inline

Definition at line 292 of file blobs.h.

292 : outlines(nullptr) {}
TESSLINE * outlines
Definition: blobs.h:404

◆ TBLOB() [2/2]

tesseract::TBLOB::TBLOB ( const TBLOB src)
inline

Definition at line 293 of file blobs.h.

293  : outlines(nullptr) {
294  CopyFrom(src);
295  }
void CopyFrom(const TBLOB &src)
Definition: blobs.cpp:374

◆ ~TBLOB()

tesseract::TBLOB::~TBLOB ( )
inline

Definition at line 296 of file blobs.h.

296  {
297  Clear();
298  }
void Clear()
Definition: blobs.cpp:390

Member Function Documentation

◆ BBArea()

int tesseract::TBLOB::BBArea ( ) const
inline

Definition at line 376 of file blobs.h.

376  {
377  int total_area = 0;
378  for (TESSLINE *outline = outlines; outline != nullptr; outline = outline->next) {
379  total_area += outline->BBArea();
380  }
381  return total_area;
382  }
TESSLINE * next
Definition: blobs.h:288

◆ bounding_box()

TBOX tesseract::TBLOB::bounding_box ( ) const

Definition at line 466 of file blobs.cpp.

466  {
467  if (outlines == nullptr) {
468  return TBOX(0, 0, 0, 0);
469  }
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

◆ ClassifyNormalizeIfNeeded()

TBLOB * tesseract::TBLOB::ClassifyNormalizeIfNeeded ( ) const

Definition at line 353 of file blobs.cpp.

353  {
354  TBLOB *rotated_blob = nullptr;
355  // If necessary, copy the blob and rotate it. The rotation is always
356  // +/- 90 degrees, as 180 was already taken care of.
357  if (denorm_.block() != nullptr && denorm_.block()->classify_rotation().y() != 0.0) {
358  TBOX box = bounding_box();
359  int x_middle = (box.left() + box.right()) / 2;
360  int y_middle = (box.top() + box.bottom()) / 2;
361  rotated_blob = new TBLOB(*this);
362  const FCOORD &rotation = denorm_.block()->classify_rotation();
363  // Move the rotated blob back to the same y-position so that we
364  // can still distinguish similar glyphs with differeny y-position.
365  float target_y =
366  kBlnBaselineOffset + (rotation.y() > 0 ? x_middle - box.left() : box.right() - x_middle);
367  rotated_blob->Normalize(nullptr, &rotation, &denorm_, x_middle, y_middle, 1.0f, 1.0f, 0.0f,
368  target_y, denorm_.inverse(), denorm_.pix());
369  }
370  return rotated_blob;
371 }
const int kBlnBaselineOffset
Definition: normalis.h:34
TBOX bounding_box() const
Definition: blobs.cpp:466
const BLOCK * block() const
Definition: normalis.h:265
Image pix() const
Definition: normalis.h:237
bool inverse() const
Definition: normalis.h:243
FCOORD classify_rotation() const
Definition: ocrblock.h:135
float y() const
Definition: points.h:209

◆ Clear()

void tesseract::TBLOB::Clear ( )

Definition at line 390 of file blobs.cpp.

390  {
391  for (TESSLINE *next_outline = nullptr; outlines != nullptr; outlines = next_outline) {
392  next_outline = outlines->next;
393  delete outlines;
394  }
395 }

◆ ComputeBoundingBoxes()

void tesseract::TBLOB::ComputeBoundingBoxes ( )

Definition at line 445 of file blobs.cpp.

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

◆ ComputeMoments()

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

Definition at line 520 of file blobs.cpp.

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

◆ Contains()

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

Definition at line 351 of file blobs.h.

351  {
352  for (const TESSLINE *outline = outlines; outline != nullptr; outline = outline->next) {
353  if (outline->Contains(pt)) {
354  return true;
355  }
356  }
357  return false;
358  }

◆ CopyFrom()

void tesseract::TBLOB::CopyFrom ( const TBLOB src)

Definition at line 374 of file blobs.cpp.

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

◆ CorrectBlobOrder()

void tesseract::TBLOB::CorrectBlobOrder ( TBLOB next)

Definition at line 500 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  std::swap(outlines, next->outlines);
505  }
506 }

◆ denorm()

const DENORM& tesseract::TBLOB::denorm ( ) const
inline

Definition at line 368 of file blobs.h.

368  {
369  return denorm_;
370  }

◆ EliminateDuplicateOutlines()

void tesseract::TBLOB::EliminateDuplicateOutlines ( )

Definition at line 480 of file blobs.cpp.

480  {
481  for (TESSLINE *outline = outlines; outline != nullptr; 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  }
496 }

◆ GetEdgeCoords()

void tesseract::TBLOB::GetEdgeCoords ( const TBOX box,
std::vector< std::vector< int >> &  x_coords,
std::vector< std::vector< int >> &  y_coords 
) const

Definition at line 559 of file blobs.cpp.

560  {
561  x_coords.clear();
562  x_coords.resize(box.height());
563  y_coords.clear();
564  y_coords.resize(box.width());
565  CollectEdges(box, nullptr, nullptr, &x_coords, &y_coords);
566  // Sort the output vectors.
567  for (auto &coord : x_coords) {
568  std::sort(coord.begin(), coord.end());
569  }
570  for (auto &coord : y_coords) {
571  std::sort(coord.begin(), coord.end());
572  }
573 }

◆ GetPreciseBoundingBox()

void tesseract::TBLOB::GetPreciseBoundingBox ( TBOX precise_box) const

Definition at line 543 of file blobs.cpp.

543  {
544  TBOX box = bounding_box();
545  *precise_box = TBOX();
546  CollectEdges(box, precise_box, nullptr, nullptr, nullptr);
547  precise_box->move(box.botleft());
548 }

◆ Move()

void tesseract::TBLOB::Move ( const ICOORD  vec)

Definition at line 431 of file blobs.cpp.

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

◆ Normalize()

void tesseract::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,
Image  pix 
)

Definition at line 400 of file blobs.cpp.

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

◆ NumOutlines()

int tesseract::TBLOB::NumOutlines ( ) const

Definition at line 452 of file blobs.cpp.

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

◆ operator=()

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

Definition at line 299 of file blobs.h.

299  {
300  CopyFrom(src);
301  return *this;
302  }

◆ plot()

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

Definition at line 509 of file blobs.cpp.

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

◆ PolygonalCopy()

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

Definition at line 335 of file blobs.cpp.

335  {
336  auto *tblob = new TBLOB;
337  ApproximateOutlineList(allow_detailed_fx, src->out_list(), false, &tblob->outlines);
338  return tblob;
339 }

◆ Rotate()

void tesseract::TBLOB::Rotate ( const FCOORD  rotation)

Definition at line 424 of file blobs.cpp.

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

◆ Scale()

void tesseract::TBLOB::Scale ( float  factor)

Definition at line 438 of file blobs.cpp.

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

◆ SegmentCrossesOutline()

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

Definition at line 342 of file blobs.h.

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

◆ ShallowCopy()

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

Definition at line 342 of file blobs.cpp.

342  {
343  auto *blob = new TBLOB;
344  blob->denorm_ = src.denorm_;
345  return blob;
346 }

Member Data Documentation

◆ outlines

TESSLINE* tesseract::TBLOB::outlines

Definition at line 404 of file blobs.h.


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