tesseract  4.1.0
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 397 of file blobs.h.

Constructor & Destructor Documentation

TWERD::TWERD ( )
inline

Definition at line 398 of file blobs.h.

398 : latin_script(false) {}
bool latin_script
Definition: blobs.h:439
TWERD::TWERD ( const TWERD src)
inline

Definition at line 399 of file blobs.h.

399  {
400  CopyFrom(src);
401  }
void CopyFrom(const TWERD &src)
Definition: blobs.cpp:843
TWERD::~TWERD ( )
inline

Definition at line 402 of file blobs.h.

402  {
403  Clear();
404  }
void Clear()
Definition: blobs.cpp:853

Member Function Documentation

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

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

Definition at line 865 of file blobs.cpp.

865  {
866  TBOX result;
867  for (int b = 0; b < blobs.size(); ++b) {
868  TBOX box = blobs[b]->bounding_box();
869  result += box;
870  }
871  return result;
872 }
Definition: rect.h:34
GenericVector< TBLOB * > blobs
Definition: blobs.h:438
int size() const
Definition: genericvector.h:70
void TWERD::Clear ( )

Definition at line 853 of file blobs.cpp.

853  {
855  blobs.clear();
856 }
void delete_data_pointers()
GenericVector< TBLOB * > blobs
Definition: blobs.h:438
void TWERD::ComputeBoundingBoxes ( )

Definition at line 859 of file blobs.cpp.

859  {
860  for (int b = 0; b < blobs.size(); ++b) {
861  blobs[b]->ComputeBoundingBoxes();
862  }
863 }
GenericVector< TBLOB * > blobs
Definition: blobs.h:438
int size() const
Definition: genericvector.h:70
void TWERD::CopyFrom ( const TWERD src)

Definition at line 843 of file blobs.cpp.

843  {
844  Clear();
846  for (int b = 0; b < src.blobs.size(); ++b) {
847  auto* new_blob = new TBLOB(*src.blobs[b]);
848  blobs.push_back(new_blob);
849  }
850 }
GenericVector< TBLOB * > blobs
Definition: blobs.h:438
void Clear()
Definition: blobs.cpp:853
Definition: blobs.h:263
bool latin_script
Definition: blobs.h:439
int push_back(T object)
int size() const
Definition: genericvector.h:70
void TWERD::MergeBlobs ( int  start,
int  end 
)

Definition at line 876 of file blobs.cpp.

876  {
877  if (start >= blobs.size() - 1) return; // Nothing to do.
878  TESSLINE* outline = blobs[start]->outlines;
879  for (int i = start + 1; i < end && i < blobs.size(); ++i) {
880  TBLOB* next_blob = blobs[i];
881  // Take the outlines from the next blob.
882  if (outline == nullptr) {
883  blobs[start]->outlines = next_blob->outlines;
884  outline = blobs[start]->outlines;
885  } else {
886  while (outline->next != nullptr) outline = outline->next;
887  outline->next = next_blob->outlines;
888  next_blob->outlines = nullptr;
889  }
890  // Delete the next blob and move on.
891  delete next_blob;
892  blobs[i] = nullptr;
893  }
894  // Remove dead blobs from the vector.
895  for (int i = start + 1; i < end && start + 1 < blobs.size(); ++i) {
896  blobs.remove(start + 1);
897  }
898 }
TESSLINE * next
Definition: blobs.h:260
GenericVector< TBLOB * > blobs
Definition: blobs.h:438
TESSLINE * outlines
Definition: blobs.h:379
Definition: blobs.h:263
void remove(int index)
int size() const
Definition: genericvector.h:70
int TWERD::NumBlobs ( ) const
inline

Definition at line 427 of file blobs.h.

427  {
428  return blobs.size();
429  }
GenericVector< TBLOB * > blobs
Definition: blobs.h:438
int size() const
Definition: genericvector.h:70
TWERD& TWERD::operator= ( const TWERD src)
inline

Definition at line 405 of file blobs.h.

405  {
406  CopyFrom(src);
407  return *this;
408  }
void CopyFrom(const TWERD &src)
Definition: blobs.cpp:843
void TWERD::plot ( ScrollView window)

Definition at line 901 of file blobs.cpp.

901  {
903  for (int b = 0; b < blobs.size(); ++b) {
904  blobs[b]->plot(window, color, ScrollView::BROWN);
905  color = WERD::NextColor(color);
906  }
907 }
GenericVector< TBLOB * > blobs
Definition: blobs.h:438
static ScrollView::Color NextColor(ScrollView::Color colour)
Definition: werd.cpp:292
int size() const
Definition: genericvector.h:70
TWERD * TWERD::PolygonalCopy ( bool  allow_detailed_fx,
WERD src 
)
static

Definition at line 780 of file blobs.cpp.

780  {
781  auto* tessword = new TWERD;
782  tessword->latin_script = src->flag(W_SCRIPT_IS_LATIN);
783  C_BLOB_IT b_it(src->cblob_list());
784  for (b_it.mark_cycle_pt(); !b_it.cycled_list(); b_it.forward()) {
785  C_BLOB* blob = b_it.data();
786  TBLOB* tblob = TBLOB::PolygonalCopy(allow_detailed_fx, blob);
787  tessword->blobs.push_back(tblob);
788  }
789  return tessword;
790 }
Special case latin for y. splitting.
Definition: werd.h:36
Definition: blobs.h:263
bool flag(WERD_FLAGS mask) const
Definition: werd.h:117
static TBLOB * PolygonalCopy(bool allow_detailed_fx, C_BLOB *src)
Definition: blobs.cpp:331
TWERD()
Definition: blobs.h:398
C_BLOB_LIST * cblob_list()
Definition: werd.h:95

Member Data Documentation

GenericVector<TBLOB*> TWERD::blobs

Definition at line 438 of file blobs.h.

bool TWERD::latin_script

Definition at line 439 of file blobs.h.


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