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

Constructor & Destructor Documentation

◆ TWERD() [1/2]

TWERD::TWERD ( )
inline

Definition at line 403 of file blobs.h.

403 : latin_script(false) {}
bool latin_script
Definition: blobs.h:444

◆ TWERD() [2/2]

TWERD::TWERD ( const TWERD src)
inline

Definition at line 404 of file blobs.h.

404  {
405  CopyFrom(src);
406  }
void CopyFrom(const TWERD &src)
Definition: blobs.cpp:849

◆ ~TWERD()

TWERD::~TWERD ( )
inline

Definition at line 407 of file blobs.h.

407  {
408  Clear();
409  }
void Clear()
Definition: blobs.cpp:859

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

803  {
804  TBOX word_box = bounding_box();
805  if (norm_box != nullptr) word_box = *norm_box;
806  float word_middle = (word_box.left() + word_box.right()) / 2.0f;
807  float input_y_offset = 0.0f;
808  float final_y_offset = static_cast<float>(kBlnBaselineOffset);
809  float scale = kBlnXHeight / x_height;
810  if (row == nullptr) {
811  word_middle = word_box.left();
812  input_y_offset = word_box.bottom();
813  final_y_offset = 0.0f;
814  } else {
815  input_y_offset = row->base_line(word_middle) + baseline_shift;
816  }
817  for (int b = 0; b < blobs.size(); ++b) {
818  TBLOB* blob = blobs[b];
819  TBOX blob_box = blob->bounding_box();
820  float mid_x = (blob_box.left() + blob_box.right()) / 2.0f;
821  float baseline = input_y_offset;
822  float blob_scale = scale;
823  if (numeric_mode) {
824  baseline = blob_box.bottom();
825  blob_scale = ClipToRange(kBlnXHeight * 4.0f / (3 * blob_box.height()),
826  scale, scale * 1.5f);
827  } else if (row != nullptr) {
828  baseline = row->base_line(mid_x) + baseline_shift;
829  }
830  // The image will be 8-bit grey if the input was grey or color. Note that in
831  // a grey image 0 is black and 255 is white. If the input was binary, then
832  // the pix will be binary and 0 is white, with 1 being black.
833  // To tell the difference pixGetDepth() will return 8 or 1.
834  // The inverse flag will be true iff the word has been determined to be
835  // white on black, and is independent of whether the pix is 8 bit or 1 bit.
836  blob->Normalize(block, nullptr, nullptr, word_middle, baseline, blob_scale,
837  blob_scale, 0.0f, final_y_offset, inverse, pix);
838  }
839  if (word_denorm != nullptr) {
840  word_denorm->SetupNormalization(block, nullptr, nullptr, word_middle,
841  input_y_offset, scale, scale, 0.0f,
842  final_y_offset);
843  word_denorm->set_inverse(inverse);
844  word_denorm->set_pix(pix);
845  }
846 }
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
int size() const
Definition: genericvector.h:71
float base_line(float xpos) const
Definition: ocrrow.h:59
TBOX bounding_box() const
Definition: blobs.cpp:871
Definition: rect.h:34
const int kBlnXHeight
Definition: normalis.h:24
const int kBlnBaselineOffset
Definition: normalis.h:25
int16_t left() const
Definition: rect.h:72
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
void set_pix(Pix *pix)
Definition: normalis.h:249
TBOX bounding_box() const
Definition: blobs.cpp:478
void set_inverse(bool value)
Definition: normalis.h:255
GenericVector< TBLOB * > blobs
Definition: blobs.h:443
int16_t right() const
Definition: rect.h:79
T ClipToRange(const T &x, const T &lower_bound, const T &upper_bound)
Definition: helpers.h:111
Definition: blobs.h:268
int16_t bottom() const
Definition: rect.h:65
int16_t height() const
Definition: rect.h:108

◆ bounding_box()

TBOX TWERD::bounding_box ( ) const

Definition at line 871 of file blobs.cpp.

871  {
872  TBOX result;
873  for (int b = 0; b < blobs.size(); ++b) {
874  TBOX box = blobs[b]->bounding_box();
875  result += box;
876  }
877  return result;
878 }
int size() const
Definition: genericvector.h:71
Definition: rect.h:34
GenericVector< TBLOB * > blobs
Definition: blobs.h:443

◆ Clear()

void TWERD::Clear ( )

Definition at line 859 of file blobs.cpp.

859  {
861  blobs.clear();
862 }
GenericVector< TBLOB * > blobs
Definition: blobs.h:443
void delete_data_pointers()

◆ ComputeBoundingBoxes()

void TWERD::ComputeBoundingBoxes ( )

Definition at line 865 of file blobs.cpp.

865  {
866  for (int b = 0; b < blobs.size(); ++b) {
867  blobs[b]->ComputeBoundingBoxes();
868  }
869 }
int size() const
Definition: genericvector.h:71
GenericVector< TBLOB * > blobs
Definition: blobs.h:443

◆ CopyFrom()

void TWERD::CopyFrom ( const TWERD src)

Definition at line 849 of file blobs.cpp.

849  {
850  Clear();
852  for (int b = 0; b < src.blobs.size(); ++b) {
853  TBLOB* new_blob = new TBLOB(*src.blobs[b]);
854  blobs.push_back(new_blob);
855  }
856 }
int size() const
Definition: genericvector.h:71
bool latin_script
Definition: blobs.h:444
int push_back(T object)
GenericVector< TBLOB * > blobs
Definition: blobs.h:443
void Clear()
Definition: blobs.cpp:859
Definition: blobs.h:268

◆ MergeBlobs()

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

Definition at line 882 of file blobs.cpp.

882  {
883  if (start >= blobs.size() - 1) return; // Nothing to do.
884  TESSLINE* outline = blobs[start]->outlines;
885  for (int i = start + 1; i < end && i < blobs.size(); ++i) {
886  TBLOB* next_blob = blobs[i];
887  // Take the outlines from the next blob.
888  if (outline == nullptr) {
889  blobs[start]->outlines = next_blob->outlines;
890  outline = blobs[start]->outlines;
891  } else {
892  while (outline->next != nullptr) outline = outline->next;
893  outline->next = next_blob->outlines;
894  next_blob->outlines = nullptr;
895  }
896  // Delete the next blob and move on.
897  delete next_blob;
898  blobs[i] = nullptr;
899  }
900  // Remove dead blobs from the vector.
901  for (int i = start + 1; i < end && start + 1 < blobs.size(); ++i) {
902  blobs.remove(start + 1);
903  }
904 }
TESSLINE * next
Definition: blobs.h:265
int size() const
Definition: genericvector.h:71
void remove(int index)
GenericVector< TBLOB * > blobs
Definition: blobs.h:443
Definition: blobs.h:268
TESSLINE * outlines
Definition: blobs.h:384

◆ NumBlobs()

int TWERD::NumBlobs ( ) const
inline

Definition at line 432 of file blobs.h.

432  {
433  return blobs.size();
434  }
int size() const
Definition: genericvector.h:71
GenericVector< TBLOB * > blobs
Definition: blobs.h:443

◆ operator=()

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

Definition at line 410 of file blobs.h.

410  {
411  CopyFrom(src);
412  return *this;
413  }
void CopyFrom(const TWERD &src)
Definition: blobs.cpp:849

◆ plot()

void TWERD::plot ( ScrollView window)

Definition at line 907 of file blobs.cpp.

907  {
909  for (int b = 0; b < blobs.size(); ++b) {
910  blobs[b]->plot(window, color, ScrollView::BROWN);
911  color = WERD::NextColor(color);
912  }
913 }
int size() const
Definition: genericvector.h:71
static ScrollView::Color NextColor(ScrollView::Color colour)
Definition: werd.cpp:305
GenericVector< TBLOB * > blobs
Definition: blobs.h:443

◆ PolygonalCopy()

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

Definition at line 786 of file blobs.cpp.

786  {
787  TWERD* tessword = new TWERD;
788  tessword->latin_script = src->flag(W_SCRIPT_IS_LATIN);
789  C_BLOB_IT b_it(src->cblob_list());
790  for (b_it.mark_cycle_pt(); !b_it.cycled_list(); b_it.forward()) {
791  C_BLOB* blob = b_it.data();
792  TBLOB* tblob = TBLOB::PolygonalCopy(allow_detailed_fx, blob);
793  tessword->blobs.push_back(tblob);
794  }
795  return tessword;
796 }
static TBLOB * PolygonalCopy(bool allow_detailed_fx, C_BLOB *src)
Definition: blobs.cpp:337
Definition: blobs.h:402
bool latin_script
Definition: blobs.h:444
bool flag(WERD_FLAGS mask) const
Definition: werd.h:126
TWERD()
Definition: blobs.h:403
C_BLOB_LIST * cblob_list()
Definition: werd.h:98
int push_back(T object)
GenericVector< TBLOB * > blobs
Definition: blobs.h:443
Definition: blobs.h:268

Member Data Documentation

◆ blobs

GenericVector<TBLOB*> TWERD::blobs

Definition at line 443 of file blobs.h.

◆ latin_script

bool TWERD::latin_script

Definition at line 444 of file blobs.h.


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