tesseract  4.1.1
TWERD Struct Reference

#include <blobs.h>

Public Member Functions

 TWERD ()
 
 TWERD (const TWERD &src)
 
 ~TWERD ()
 
TWERDoperator= (const TWERD &src)
 
void BLNormalize (const BLOCK *block, const ROW *row, Pix *pix, bool inverse, float x_height, float baseline_shift, bool numeric_mode, tesseract::OcrEngineMode hint, const TBOX *norm_box, DENORM *word_denorm)
 
void CopyFrom (const TWERD &src)
 
void Clear ()
 
void ComputeBoundingBoxes ()
 
int NumBlobs () const
 
TBOX bounding_box () const
 
void MergeBlobs (int start, int end)
 
void plot (ScrollView *window)
 

Static Public Member Functions

static TWERDPolygonalCopy (bool allow_detailed_fx, WERD *src)
 

Public Attributes

GenericVector< TBLOB * > blobs
 
bool latin_script
 

Detailed Description

Definition at line 418 of file blobs.h.

Constructor & Destructor Documentation

◆ TWERD() [1/2]

TWERD::TWERD ( )
inline

Definition at line 419 of file blobs.h.

419 : latin_script(false) {}

◆ TWERD() [2/2]

TWERD::TWERD ( const TWERD src)
inline

Definition at line 420 of file blobs.h.

420  {
421  CopyFrom(src);
422  }

◆ ~TWERD()

TWERD::~TWERD ( )
inline

Definition at line 423 of file blobs.h.

423  {
424  Clear();
425  }

Member Function Documentation

◆ BLNormalize()

void TWERD::BLNormalize ( const BLOCK block,
const ROW row,
Pix *  pix,
bool  inverse,
float  x_height,
float  baseline_shift,
bool  numeric_mode,
tesseract::OcrEngineMode  hint,
const TBOX norm_box,
DENORM word_denorm 
)

Definition at line 790 of file blobs.cpp.

793  {
794  TBOX word_box = bounding_box();
795  if (norm_box != nullptr) word_box = *norm_box;
796  float word_middle = (word_box.left() + word_box.right()) / 2.0f;
797  float input_y_offset = 0.0f;
798  auto final_y_offset = static_cast<float>(kBlnBaselineOffset);
799  float scale = kBlnXHeight / x_height;
800  if (row == nullptr) {
801  word_middle = word_box.left();
802  input_y_offset = word_box.bottom();
803  final_y_offset = 0.0f;
804  } else {
805  input_y_offset = row->base_line(word_middle) + baseline_shift;
806  }
807  for (int b = 0; b < blobs.size(); ++b) {
808  TBLOB* blob = blobs[b];
809  TBOX blob_box = blob->bounding_box();
810  float mid_x = (blob_box.left() + blob_box.right()) / 2.0f;
811  float baseline = input_y_offset;
812  float blob_scale = scale;
813  if (numeric_mode) {
814  baseline = blob_box.bottom();
815  blob_scale = ClipToRange(kBlnXHeight * 4.0f / (3 * blob_box.height()),
816  scale, scale * 1.5f);
817  } else if (row != nullptr) {
818  baseline = row->base_line(mid_x) + baseline_shift;
819  }
820  // The image will be 8-bit grey if the input was grey or color. Note that in
821  // a grey image 0 is black and 255 is white. If the input was binary, then
822  // the pix will be binary and 0 is white, with 1 being black.
823  // To tell the difference pixGetDepth() will return 8 or 1.
824  // The inverse flag will be true iff the word has been determined to be
825  // white on black, and is independent of whether the pix is 8 bit or 1 bit.
826  blob->Normalize(block, nullptr, nullptr, word_middle, baseline, blob_scale,
827  blob_scale, 0.0f, final_y_offset, inverse, pix);
828  }
829  if (word_denorm != nullptr) {
830  word_denorm->SetupNormalization(block, nullptr, nullptr, word_middle,
831  input_y_offset, scale, scale, 0.0f,
832  final_y_offset);
833  word_denorm->set_inverse(inverse);
834  word_denorm->set_pix(pix);
835  }
836 }

◆ bounding_box()

TBOX TWERD::bounding_box ( ) const

Definition at line 861 of file blobs.cpp.

861  {
862  TBOX result;
863  for (int b = 0; b < blobs.size(); ++b) {
864  TBOX box = blobs[b]->bounding_box();
865  result += box;
866  }
867  return result;
868 }

◆ Clear()

void TWERD::Clear ( )

Definition at line 849 of file blobs.cpp.

849  {
851  blobs.clear();
852 }

◆ ComputeBoundingBoxes()

void TWERD::ComputeBoundingBoxes ( )

Definition at line 855 of file blobs.cpp.

855  {
856  for (int b = 0; b < blobs.size(); ++b) {
857  blobs[b]->ComputeBoundingBoxes();
858  }
859 }

◆ CopyFrom()

void TWERD::CopyFrom ( const TWERD src)

Definition at line 839 of file blobs.cpp.

839  {
840  Clear();
842  for (int b = 0; b < src.blobs.size(); ++b) {
843  auto* new_blob = new TBLOB(*src.blobs[b]);
844  blobs.push_back(new_blob);
845  }
846 }

◆ MergeBlobs()

void TWERD::MergeBlobs ( int  start,
int  end 
)

Definition at line 872 of file blobs.cpp.

872  {
873  if (start >= blobs.size() - 1) return; // Nothing to do.
874  TESSLINE* outline = blobs[start]->outlines;
875  for (int i = start + 1; i < end && i < blobs.size(); ++i) {
876  TBLOB* next_blob = blobs[i];
877  // Take the outlines from the next blob.
878  if (outline == nullptr) {
879  blobs[start]->outlines = next_blob->outlines;
880  outline = blobs[start]->outlines;
881  } else {
882  while (outline->next != nullptr) outline = outline->next;
883  outline->next = next_blob->outlines;
884  next_blob->outlines = nullptr;
885  }
886  // Delete the next blob and move on.
887  delete next_blob;
888  blobs[i] = nullptr;
889  }
890  // Remove dead blobs from the vector.
891  for (int i = start + 1; i < end && start + 1 < blobs.size(); ++i) {
892  blobs.remove(start + 1);
893  }
894 }

◆ NumBlobs()

int TWERD::NumBlobs ( ) const
inline

Definition at line 448 of file blobs.h.

448  {
449  return blobs.size();
450  }

◆ operator=()

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

Definition at line 426 of file blobs.h.

426  {
427  CopyFrom(src);
428  return *this;
429  }

◆ plot()

void TWERD::plot ( ScrollView window)

Definition at line 897 of file blobs.cpp.

897  {
899  for (int b = 0; b < blobs.size(); ++b) {
900  blobs[b]->plot(window, color, ScrollView::BROWN);
901  color = WERD::NextColor(color);
902  }
903 }

◆ PolygonalCopy()

TWERD * TWERD::PolygonalCopy ( bool  allow_detailed_fx,
WERD src 
)
static

Definition at line 776 of file blobs.cpp.

776  {
777  auto* tessword = new TWERD;
778  tessword->latin_script = src->flag(W_SCRIPT_IS_LATIN);
779  C_BLOB_IT b_it(src->cblob_list());
780  for (b_it.mark_cycle_pt(); !b_it.cycled_list(); b_it.forward()) {
781  C_BLOB* blob = b_it.data();
782  TBLOB* tblob = TBLOB::PolygonalCopy(allow_detailed_fx, blob);
783  tessword->blobs.push_back(tblob);
784  }
785  return tessword;
786 }

Member Data Documentation

◆ blobs

GenericVector<TBLOB*> TWERD::blobs

Definition at line 459 of file blobs.h.

◆ latin_script

bool TWERD::latin_script

Definition at line 460 of file blobs.h.


The documentation for this struct was generated from the following files:
TBOX
Definition: rect.h:34
TWERD::latin_script
bool latin_script
Definition: blobs.h:460
TWERD::bounding_box
TBOX bounding_box() const
Definition: blobs.cpp:861
WERD::flag
bool flag(WERD_FLAGS mask) const
Definition: werd.h:117
TWERD::Clear
void Clear()
Definition: blobs.cpp:849
W_SCRIPT_IS_LATIN
@ W_SCRIPT_IS_LATIN
Special case latin for y. splitting.
Definition: werd.h:52
TBOX::right
int16_t right() const
Definition: rect.h:79
WERD::cblob_list
C_BLOB_LIST * cblob_list()
Definition: werd.h:95
GenericVector::remove
void remove(int index)
Definition: genericvector.h:803
TWERD::blobs
GenericVector< TBLOB * > blobs
Definition: blobs.h:459
ClipToRange
T ClipToRange(const T &x, const T &lower_bound, const T &upper_bound)
Definition: helpers.h:108
TBOX::left
int16_t left() const
Definition: rect.h:72
GenericVector::clear
void clear()
Definition: genericvector.h:895
TESSLINE::next
TESSLINE * next
Definition: blobs.h:281
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:397
ScrollView::BROWN
@ BROWN
Definition: scrollview.h:121
TWERD::TWERD
TWERD()
Definition: blobs.h:419
DENORM::set_pix
void set_pix(Pix *pix)
Definition: normalis.h:249
ScrollView::Color
Color
Definition: scrollview.h:101
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:96
TBOX::height
int16_t height() const
Definition: rect.h:108
kBlnXHeight
const int kBlnXHeight
Definition: normalis.h:24
TBLOB::PolygonalCopy
static TBLOB * PolygonalCopy(bool allow_detailed_fx, C_BLOB *src)
Definition: blobs.cpp:327
ScrollView::BLACK
@ BLACK
Definition: scrollview.h:103
TWERD::CopyFrom
void CopyFrom(const TWERD &src)
Definition: blobs.cpp:839
kBlnBaselineOffset
const int kBlnBaselineOffset
Definition: normalis.h:25
GenericVector::size
int size() const
Definition: genericvector.h:72
TBLOB
Definition: blobs.h:284
WERD::NextColor
static ScrollView::Color NextColor(ScrollView::Color colour)
Definition: werd.cpp:292
baseline
@ baseline
Definition: mfoutline.h:63
ROW::base_line
float base_line(float xpos) const
Definition: ocrrow.h:59
C_BLOB
Definition: stepblob.h:38
TBLOB::bounding_box
TBOX bounding_box() const
Definition: blobs.cpp:468
GenericVector::delete_data_pointers
void delete_data_pointers()
Definition: genericvector.h:912
DENORM::set_inverse
void set_inverse(bool value)
Definition: normalis.h:255
TBLOB::outlines
TESSLINE * outlines
Definition: blobs.h:400
TBOX::bottom
int16_t bottom() const
Definition: rect.h:65
TESSLINE
Definition: blobs.h:203
GenericVector::push_back
int push_back(T object)
Definition: genericvector.h:837