tesseract  4.00.00dev
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 261 of file blobs.h.

Constructor & Destructor Documentation

◆ TBLOB() [1/2]

TBLOB::TBLOB ( )
inline

Definition at line 262 of file blobs.h.

262 : outlines(NULL) {}
TESSLINE * outlines
Definition: blobs.h:377

◆ TBLOB() [2/2]

TBLOB::TBLOB ( const TBLOB src)
inline

Definition at line 263 of file blobs.h.

263  : outlines(NULL) {
264  CopyFrom(src);
265  }
TESSLINE * outlines
Definition: blobs.h:377
void CopyFrom(const TBLOB &src)
Definition: blobs.cpp:386

◆ ~TBLOB()

TBLOB::~TBLOB ( )
inline

Definition at line 266 of file blobs.h.

266  {
267  Clear();
268  }
void Clear()
Definition: blobs.cpp:402

Member Function Documentation

◆ BBArea()

int TBLOB::BBArea ( ) const
inline

Definition at line 349 of file blobs.h.

349  {
350  int total_area = 0;
351  for (TESSLINE* outline = outlines; outline != NULL; outline = outline->next)
352  total_area += outline->BBArea();
353  return total_area;
354  }
TESSLINE * next
Definition: blobs.h:258
TESSLINE * outlines
Definition: blobs.h:377

◆ bounding_box()

TBOX TBLOB::bounding_box ( ) const

Definition at line 482 of file blobs.cpp.

482  {
483  if (outlines == NULL)
484  return TBOX(0, 0, 0, 0);
485  TESSLINE *outline = outlines;
486  TBOX box = outline->bounding_box();
487  for (outline = outline->next; outline != NULL; outline = outline->next) {
488  box += outline->bounding_box();
489  }
490  return box;
491 }
TESSLINE * next
Definition: blobs.h:258
TESSLINE * outlines
Definition: blobs.h:377
TBOX bounding_box() const
Definition: blobs.cpp:273
Definition: rect.h:30

◆ ClassifyNormalizeIfNeeded()

TBLOB * TBLOB::ClassifyNormalizeIfNeeded ( ) const

Definition at line 363 of file blobs.cpp.

363  {
364  TBLOB* rotated_blob = NULL;
365  // If necessary, copy the blob and rotate it. The rotation is always
366  // +/- 90 degrees, as 180 was already taken care of.
367  if (denorm_.block() != NULL &&
368  denorm_.block()->classify_rotation().y() != 0.0) {
369  TBOX box = bounding_box();
370  int x_middle = (box.left() + box.right()) / 2;
371  int y_middle = (box.top() + box.bottom()) / 2;
372  rotated_blob = new TBLOB(*this);
373  const FCOORD& rotation = denorm_.block()->classify_rotation();
374  // Move the rotated blob back to the same y-position so that we
375  // can still distinguish similar glyphs with differeny y-position.
376  float target_y = kBlnBaselineOffset +
377  (rotation.y() > 0 ? x_middle - box.left() : box.right() - x_middle);
378  rotated_blob->Normalize(NULL, &rotation, &denorm_, x_middle, y_middle,
379  1.0f, 1.0f, 0.0f, target_y,
380  denorm_.inverse(), denorm_.pix());
381  }
382  return rotated_blob;
383 }
Pix * pix() const
Definition: normalis.h:248
Definition: points.h:189
const int kBlnBaselineOffset
Definition: normalis.h:29
inT16 left() const
Definition: rect.h:68
bool inverse() const
Definition: normalis.h:254
TBLOB()
Definition: blobs.h:262
const BLOCK * block() const
Definition: normalis.h:275
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:413
inT16 top() const
Definition: rect.h:54
Definition: rect.h:30
Definition: blobs.h:261
float y() const
Definition: points.h:212
inT16 right() const
Definition: rect.h:75
inT16 bottom() const
Definition: rect.h:61
TBOX bounding_box() const
Definition: blobs.cpp:482
FCOORD classify_rotation() const
Definition: ocrblock.h:144

◆ Clear()

void TBLOB::Clear ( )

Definition at line 402 of file blobs.cpp.

402  {
403  for (TESSLINE* next_outline = NULL; outlines != NULL;
404  outlines = next_outline) {
405  next_outline = outlines->next;
406  delete outlines;
407  }
408 }
TESSLINE * next
Definition: blobs.h:258
TESSLINE * outlines
Definition: blobs.h:377

◆ ComputeBoundingBoxes()

void TBLOB::ComputeBoundingBoxes ( )

Definition at line 462 of file blobs.cpp.

462  {
463  for (TESSLINE* outline = outlines; outline != NULL; outline = outline->next) {
464  outline->ComputeBoundingBox();
465  }
466 }
TESSLINE * next
Definition: blobs.h:258
TESSLINE * outlines
Definition: blobs.h:377

◆ ComputeMoments()

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

Definition at line 535 of file blobs.cpp.

535  {
536  // Compute 1st and 2nd moments of the original outline.
537  LLSQ accumulator;
538  TBOX box = bounding_box();
539  // Iterate the outlines, accumulating edges relative the box.botleft().
540  CollectEdges(box, NULL, &accumulator, NULL, NULL);
541  *center = accumulator.mean_point() + box.botleft();
542  // The 2nd moments are just the standard deviation of the point positions.
543  double x2nd = sqrt(accumulator.x_variance());
544  double y2nd = sqrt(accumulator.y_variance());
545  if (x2nd < 1.0) x2nd = 1.0;
546  if (y2nd < 1.0) y2nd = 1.0;
547  second_moments->set_x(x2nd);
548  second_moments->set_y(y2nd);
549  return accumulator.count();
550 }
double x_variance() const
Definition: linlsq.h:79
FCOORD mean_point() const
Definition: linlsq.cpp:167
inT32 count() const
Definition: linlsq.h:41
void set_x(float xin)
rewrite function
Definition: points.h:216
void set_y(float yin)
rewrite function
Definition: points.h:220
Definition: rect.h:30
Definition: linlsq.h:26
double y_variance() const
Definition: linlsq.h:85
const ICOORD & botleft() const
Definition: rect.h:88
TBOX bounding_box() const
Definition: blobs.cpp:482

◆ Contains()

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

Definition at line 324 of file blobs.h.

324  {
325  for (const TESSLINE* outline = outlines; outline != NULL;
326  outline = outline->next) {
327  if (outline->Contains(pt)) return true;
328  }
329  return false;
330  }
TESSLINE * next
Definition: blobs.h:258
TESSLINE * outlines
Definition: blobs.h:377

◆ CopyFrom()

void TBLOB::CopyFrom ( const TBLOB src)

Definition at line 386 of file blobs.cpp.

386  {
387  Clear();
388  TESSLINE* prev_outline = NULL;
389  for (TESSLINE* srcline = src.outlines; srcline != NULL;
390  srcline = srcline->next) {
391  TESSLINE* new_outline = new TESSLINE(*srcline);
392  if (outlines == NULL)
393  outlines = new_outline;
394  else
395  prev_outline->next = new_outline;
396  prev_outline = new_outline;
397  }
398  denorm_ = src.denorm_;
399 }
void Clear()
Definition: blobs.cpp:402
TESSLINE * next
Definition: blobs.h:258
TESSLINE * outlines
Definition: blobs.h:377

◆ CorrectBlobOrder()

void TBLOB::CorrectBlobOrder ( TBLOB next)

Definition at line 515 of file blobs.cpp.

515  {
516  TBOX box = bounding_box();
517  TBOX next_box = next->bounding_box();
518  if (box.x_middle() > next_box.x_middle()) {
519  Swap(&outlines, &next->outlines);
520  }
521 }
void Swap(T *p1, T *p2)
Definition: helpers.h:97
TESSLINE * outlines
Definition: blobs.h:377
Definition: rect.h:30
TBOX bounding_box() const
Definition: blobs.cpp:482
int x_middle() const
Definition: rect.h:81

◆ denorm()

const DENORM& TBLOB::denorm ( ) const
inline

Definition at line 340 of file blobs.h.

340  {
341  return denorm_;
342  }

◆ EliminateDuplicateOutlines()

void TBLOB::EliminateDuplicateOutlines ( )

Definition at line 495 of file blobs.cpp.

495  {
496  for (TESSLINE* outline = outlines; outline != NULL; outline = outline->next) {
497  TESSLINE* last_outline = outline;
498  for (TESSLINE* other_outline = outline->next; other_outline != NULL;
499  last_outline = other_outline, other_outline = other_outline->next) {
500  if (outline->SameBox(*other_outline)) {
501  last_outline->next = other_outline->next;
502  // This doesn't leak - the outlines share the EDGEPTs.
503  other_outline->loop = NULL;
504  delete other_outline;
505  other_outline = last_outline;
506  // If it is part of a cut, then it can't be a hole any more.
507  outline->is_hole = false;
508  }
509  }
510  }
511 }
TESSLINE * next
Definition: blobs.h:258
TESSLINE * outlines
Definition: blobs.h:377
bool is_hole
Definition: blobs.h:256
EDGEPT * loop
Definition: blobs.h:257

◆ GetEdgeCoords()

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

Definition at line 570 of file blobs.cpp.

572  {
573  GenericVector<int> empty;
574  x_coords->init_to_size(box.height(), empty);
575  y_coords->init_to_size(box.width(), empty);
576  CollectEdges(box, NULL, NULL, x_coords, y_coords);
577  // Sort the output vectors.
578  for (int i = 0; i < x_coords->size(); ++i)
579  (*x_coords)[i].sort();
580  for (int i = 0; i < y_coords->size(); ++i)
581  (*y_coords)[i].sort();
582 }
void init_to_size(int size, T t)
int size() const
Definition: genericvector.h:72
inT16 height() const
Definition: rect.h:104
inT16 width() const
Definition: rect.h:111

◆ GetPreciseBoundingBox()

void TBLOB::GetPreciseBoundingBox ( TBOX precise_box) const

Definition at line 554 of file blobs.cpp.

554  {
555  TBOX box = bounding_box();
556  *precise_box = TBOX();
557  CollectEdges(box, precise_box, NULL, NULL, NULL);
558  precise_box->move(box.botleft());
559 }
Definition: rect.h:30
void move(const ICOORD vec)
Definition: rect.h:153
const ICOORD & botleft() const
Definition: rect.h:88
TBOX bounding_box() const
Definition: blobs.cpp:482

◆ Move()

void TBLOB::Move ( const ICOORD  vec)

Definition at line 448 of file blobs.cpp.

448  {
449  for (TESSLINE* outline = outlines; outline != NULL; outline = outline->next) {
450  outline->Move(vec);
451  }
452 }
TESSLINE * next
Definition: blobs.h:258
TESSLINE * outlines
Definition: blobs.h:377

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

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

◆ NumOutlines()

int TBLOB::NumOutlines ( ) const

Definition at line 469 of file blobs.cpp.

469  {
470  int result = 0;
471  for (TESSLINE* outline = outlines; outline != NULL; outline = outline->next)
472  ++result;
473  return result;
474 }
TESSLINE * next
Definition: blobs.h:258
TESSLINE * outlines
Definition: blobs.h:377

◆ operator=()

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

Definition at line 269 of file blobs.h.

269  {
270  CopyFrom(src);
271  return *this;
272  }
void CopyFrom(const TBLOB &src)
Definition: blobs.cpp:386

◆ plot()

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

Definition at line 524 of file blobs.cpp.

525  {
526  for (TESSLINE* outline = outlines; outline != NULL; outline = outline->next)
527  outline->plot(window, color, child_color);
528 }
TESSLINE * next
Definition: blobs.h:258
TESSLINE * outlines
Definition: blobs.h:377

◆ PolygonalCopy()

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

Definition at line 344 of file blobs.cpp.

344  {
345  TBLOB* tblob = new TBLOB;
346  ApproximateOutlineList(allow_detailed_fx, src->out_list(), false,
347  &tblob->outlines);
348  return tblob;
349 }
C_OUTLINE_LIST * out_list()
Definition: stepblob.h:64
TESSLINE * outlines
Definition: blobs.h:377
TBLOB()
Definition: blobs.h:262
Definition: blobs.h:261

◆ Rotate()

void TBLOB::Rotate ( const FCOORD  rotation)

Definition at line 441 of file blobs.cpp.

441  {
442  for (TESSLINE* outline = outlines; outline != NULL; outline = outline->next) {
443  outline->Rotate(rotation);
444  }
445 }
TESSLINE * next
Definition: blobs.h:258
TESSLINE * outlines
Definition: blobs.h:377

◆ Scale()

void TBLOB::Scale ( float  factor)

Definition at line 455 of file blobs.cpp.

455  {
456  for (TESSLINE* outline = outlines; outline != NULL; outline = outline->next) {
457  outline->Scale(factor);
458  }
459 }
TESSLINE * next
Definition: blobs.h:258
TESSLINE * outlines
Definition: blobs.h:377

◆ SegmentCrossesOutline()

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

Definition at line 316 of file blobs.h.

316  {
317  for (const TESSLINE* outline = outlines; outline != NULL;
318  outline = outline->next) {
319  if (outline->SegmentCrosses(pt1, pt2)) return true;
320  }
321  return false;
322  }
TESSLINE * next
Definition: blobs.h:258
TESSLINE * outlines
Definition: blobs.h:377

◆ ShallowCopy()

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

Definition at line 352 of file blobs.cpp.

352  {
353  TBLOB* blob = new TBLOB;
354  blob->denorm_ = src.denorm_;
355  return blob;
356 }
TBLOB()
Definition: blobs.h:262
Definition: blobs.h:261

Member Data Documentation

◆ outlines

TESSLINE* TBLOB::outlines

Definition at line 377 of file blobs.h.


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