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

Constructor & Destructor Documentation

◆ TWERD() [1/2]

TWERD::TWERD ( )
inline

Definition at line 396 of file blobs.h.

396 : latin_script(false) {}
bool latin_script
Definition: blobs.h:437

◆ TWERD() [2/2]

TWERD::TWERD ( const TWERD src)
inline

Definition at line 397 of file blobs.h.

397  {
398  CopyFrom(src);
399  }
void CopyFrom(const TWERD &src)
Definition: blobs.cpp:857

◆ ~TWERD()

TWERD::~TWERD ( )
inline

Definition at line 400 of file blobs.h.

400  {
401  Clear();
402  }
void Clear()
Definition: blobs.cpp:867

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

811  {
812  TBOX word_box = bounding_box();
813  if (norm_box != NULL) word_box = *norm_box;
814  float word_middle = (word_box.left() + word_box.right()) / 2.0f;
815  float input_y_offset = 0.0f;
816  float final_y_offset = static_cast<float>(kBlnBaselineOffset);
817  float scale = kBlnXHeight / x_height;
818  if (row == NULL) {
819  word_middle = word_box.left();
820  input_y_offset = word_box.bottom();
821  final_y_offset = 0.0f;
822  } else {
823  input_y_offset = row->base_line(word_middle) + baseline_shift;
824  }
825  for (int b = 0; b < blobs.size(); ++b) {
826  TBLOB* blob = blobs[b];
827  TBOX blob_box = blob->bounding_box();
828  float mid_x = (blob_box.left() + blob_box.right()) / 2.0f;
829  float baseline = input_y_offset;
830  float blob_scale = scale;
831  if (numeric_mode) {
832  baseline = blob_box.bottom();
833  blob_scale = ClipToRange(kBlnXHeight * 4.0f / (3 * blob_box.height()),
834  scale, scale * 1.5f);
835  } else if (row != NULL) {
836  baseline = row->base_line(mid_x) + baseline_shift;
837  }
838  // The image will be 8-bit grey if the input was grey or color. Note that in
839  // a grey image 0 is black and 255 is white. If the input was binary, then
840  // the pix will be binary and 0 is white, with 1 being black.
841  // To tell the difference pixGetDepth() will return 8 or 1.
842  // The inverse flag will be true iff the word has been determined to be
843  // white on black, and is independent of whether the pix is 8 bit or 1 bit.
844  blob->Normalize(block, NULL, NULL, word_middle, baseline, blob_scale,
845  blob_scale, 0.0f, final_y_offset, inverse, pix);
846  }
847  if (word_denorm != NULL) {
848  word_denorm->SetupNormalization(block, NULL, NULL, word_middle,
849  input_y_offset, scale, scale,
850  0.0f, final_y_offset);
851  word_denorm->set_inverse(inverse);
852  word_denorm->set_pix(pix);
853  }
854 }
void set_inverse(bool value)
Definition: normalis.h:257
const int kBlnXHeight
Definition: normalis.h:28
const int kBlnBaselineOffset
Definition: normalis.h:29
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
int size() const
Definition: genericvector.h:72
inT16 left() const
Definition: rect.h:68
T ClipToRange(const T &x, const T &lower_bound, const T &upper_bound)
Definition: helpers.h:122
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
Definition: rect.h:30
GenericVector< TBLOB * > blobs
Definition: blobs.h:436
Definition: blobs.h:261
inT16 height() const
Definition: rect.h:104
inT16 right() const
Definition: rect.h:75
inT16 bottom() const
Definition: rect.h:61
float base_line(float xpos) const
Definition: ocrrow.h:56
TBOX bounding_box() const
Definition: blobs.cpp:482
void set_pix(Pix *pix)
Definition: normalis.h:251
TBOX bounding_box() const
Definition: blobs.cpp:879

◆ bounding_box()

TBOX TWERD::bounding_box ( ) const

Definition at line 879 of file blobs.cpp.

879  {
880  TBOX result;
881  for (int b = 0; b < blobs.size(); ++b) {
882  TBOX box = blobs[b]->bounding_box();
883  result += box;
884  }
885  return result;
886 }
int size() const
Definition: genericvector.h:72
Definition: rect.h:30
GenericVector< TBLOB * > blobs
Definition: blobs.h:436

◆ Clear()

void TWERD::Clear ( )

Definition at line 867 of file blobs.cpp.

867  {
869  blobs.clear();
870 }
GenericVector< TBLOB * > blobs
Definition: blobs.h:436
void delete_data_pointers()

◆ ComputeBoundingBoxes()

void TWERD::ComputeBoundingBoxes ( )

Definition at line 873 of file blobs.cpp.

873  {
874  for (int b = 0; b < blobs.size(); ++b) {
875  blobs[b]->ComputeBoundingBoxes();
876  }
877 }
int size() const
Definition: genericvector.h:72
GenericVector< TBLOB * > blobs
Definition: blobs.h:436

◆ CopyFrom()

void TWERD::CopyFrom ( const TWERD src)

Definition at line 857 of file blobs.cpp.

857  {
858  Clear();
860  for (int b = 0; b < src.blobs.size(); ++b) {
861  TBLOB* new_blob = new TBLOB(*src.blobs[b]);
862  blobs.push_back(new_blob);
863  }
864 }
int push_back(T object)
int size() const
Definition: genericvector.h:72
void Clear()
Definition: blobs.cpp:867
GenericVector< TBLOB * > blobs
Definition: blobs.h:436
bool latin_script
Definition: blobs.h:437
Definition: blobs.h:261

◆ MergeBlobs()

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

Definition at line 890 of file blobs.cpp.

890  {
891  if (start >= blobs.size() - 1) return; // Nothing to do.
892  TESSLINE* outline = blobs[start]->outlines;
893  for (int i = start + 1; i < end && i < blobs.size(); ++i) {
894  TBLOB* next_blob = blobs[i];
895  // Take the outlines from the next blob.
896  if (outline == NULL) {
897  blobs[start]->outlines = next_blob->outlines;
898  outline = blobs[start]->outlines;
899  } else {
900  while (outline->next != NULL)
901  outline = outline->next;
902  outline->next = next_blob->outlines;
903  next_blob->outlines = NULL;
904  }
905  // Delete the next blob and move on.
906  delete next_blob;
907  blobs[i] = NULL;
908  }
909  // Remove dead blobs from the vector.
910  for (int i = start + 1; i < end && start + 1 < blobs.size(); ++i) {
911  blobs.remove(start + 1);
912  }
913 }
TESSLINE * next
Definition: blobs.h:258
void remove(int index)
TESSLINE * outlines
Definition: blobs.h:377
int size() const
Definition: genericvector.h:72
GenericVector< TBLOB * > blobs
Definition: blobs.h:436
Definition: blobs.h:261

◆ NumBlobs()

int TWERD::NumBlobs ( ) const
inline

Definition at line 425 of file blobs.h.

425  {
426  return blobs.size();
427  }
int size() const
Definition: genericvector.h:72
GenericVector< TBLOB * > blobs
Definition: blobs.h:436

◆ operator=()

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

Definition at line 403 of file blobs.h.

403  {
404  CopyFrom(src);
405  return *this;
406  }
void CopyFrom(const TWERD &src)
Definition: blobs.cpp:857

◆ plot()

void TWERD::plot ( ScrollView window)

Definition at line 916 of file blobs.cpp.

916  {
918  for (int b = 0; b < blobs.size(); ++b) {
919  blobs[b]->plot(window, color, ScrollView::BROWN);
920  color = WERD::NextColor(color);
921  }
922 }
static ScrollView::Color NextColor(ScrollView::Color colour)
Definition: werd.cpp:306
int size() const
Definition: genericvector.h:72
GenericVector< TBLOB * > blobs
Definition: blobs.h:436

◆ PolygonalCopy()

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

Definition at line 793 of file blobs.cpp.

793  {
794  TWERD* tessword = new TWERD;
795  tessword->latin_script = src->flag(W_SCRIPT_IS_LATIN);
796  C_BLOB_IT b_it(src->cblob_list());
797  for (b_it.mark_cycle_pt(); !b_it.cycled_list(); b_it.forward()) {
798  C_BLOB* blob = b_it.data();
799  TBLOB* tblob = TBLOB::PolygonalCopy(allow_detailed_fx, blob);
800  tessword->blobs.push_back(tblob);
801  }
802  return tessword;
803 }
int push_back(T object)
BOOL8 flag(WERD_FLAGS mask) const
Definition: werd.h:128
Definition: blobs.h:395
GenericVector< TBLOB * > blobs
Definition: blobs.h:436
bool latin_script
Definition: blobs.h:437
Definition: blobs.h:261
C_BLOB_LIST * cblob_list()
Definition: werd.h:100
static TBLOB * PolygonalCopy(bool allow_detailed_fx, C_BLOB *src)
Definition: blobs.cpp:344
TWERD()
Definition: blobs.h:396

Member Data Documentation

◆ blobs

GenericVector<TBLOB*> TWERD::blobs

Definition at line 436 of file blobs.h.

◆ latin_script

bool TWERD::latin_script

Definition at line 437 of file blobs.h.


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