All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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::TWERD ( )
inline

Definition at line 396 of file blobs.h.

396 : latin_script(false) {}
bool latin_script
Definition: blobs.h:437
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:859
TWERD::~TWERD ( )
inline

Definition at line 400 of file blobs.h.

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

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

Definition at line 881 of file blobs.cpp.

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

Definition at line 869 of file blobs.cpp.

869  {
871  blobs.clear();
872 }
void delete_data_pointers()
GenericVector< TBLOB * > blobs
Definition: blobs.h:436
void TWERD::ComputeBoundingBoxes ( )

Definition at line 875 of file blobs.cpp.

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

Definition at line 859 of file blobs.cpp.

859  {
860  Clear();
862  for (int b = 0; b < src.blobs.size(); ++b) {
863  TBLOB* new_blob = new TBLOB(*src.blobs[b]);
864  blobs.push_back(new_blob);
865  }
866 }
Definition: blobs.h:261
int size() const
Definition: genericvector.h:72
void Clear()
Definition: blobs.cpp:869
int push_back(T object)
bool latin_script
Definition: blobs.h:437
GenericVector< TBLOB * > blobs
Definition: blobs.h:436
void TWERD::MergeBlobs ( int  start,
int  end 
)

Definition at line 892 of file blobs.cpp.

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

Definition at line 918 of file blobs.cpp.

918  {
920  for (int b = 0; b < blobs.size(); ++b) {
921  blobs[b]->plot(window, color, ScrollView::BROWN);
922  color = WERD::NextColor(color);
923  }
924 }
int size() const
Definition: genericvector.h:72
static ScrollView::Color NextColor(ScrollView::Color colour)
Definition: werd.cpp:306
GenericVector< TBLOB * > blobs
Definition: blobs.h:436
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 }
Definition: blobs.h:261
int push_back(T object)
static TBLOB * PolygonalCopy(bool allow_detailed_fx, C_BLOB *src)
Definition: blobs.cpp:344
bool latin_script
Definition: blobs.h:437
GenericVector< TBLOB * > blobs
Definition: blobs.h:436
BOOL8 flag(WERD_FLAGS mask) const
Definition: werd.h:128
TWERD()
Definition: blobs.h:396
Definition: blobs.h:395
C_BLOB_LIST * cblob_list()
Definition: werd.h:100

Member Data Documentation

GenericVector<TBLOB*> TWERD::blobs

Definition at line 436 of file blobs.h.

bool TWERD::latin_script

Definition at line 437 of file blobs.h.


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