tesseract  5.0.0
tesseract::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, Image 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 ()
 
unsigned NumBlobs () const
 
TBOX bounding_box () const
 
void MergeBlobs (unsigned start, unsigned end)
 
void plot (ScrollView *window)
 

Static Public Member Functions

static TWERDPolygonalCopy (bool allow_detailed_fx, WERD *src)
 

Public Attributes

std::vector< TBLOB * > blobs
 
bool latin_script
 

Detailed Description

Definition at line 421 of file blobs.h.

Constructor & Destructor Documentation

◆ TWERD() [1/2]

tesseract::TWERD::TWERD ( )
inline

Definition at line 422 of file blobs.h.

422 : latin_script(false) {}
bool latin_script
Definition: blobs.h:463

◆ TWERD() [2/2]

tesseract::TWERD::TWERD ( const TWERD src)
inline

Definition at line 423 of file blobs.h.

423  {
424  CopyFrom(src);
425  }
void CopyFrom(const TWERD &src)
Definition: blobs.cpp:839

◆ ~TWERD()

tesseract::TWERD::~TWERD ( )
inline

Definition at line 426 of file blobs.h.

426  {
427  Clear();
428  }
void Clear()
Definition: blobs.cpp:849

Member Function Documentation

◆ BLNormalize()

void tesseract::TWERD::BLNormalize ( const BLOCK block,
const ROW row,
Image  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 792 of file blobs.cpp.

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

◆ bounding_box()

TBOX tesseract::TWERD::bounding_box ( ) const

Definition at line 863 of file blobs.cpp.

863  {
864  TBOX result;
865  for (auto blob : blobs) {
866  TBOX box = blob->bounding_box();
867  result += box;
868  }
869  return result;
870 }

◆ Clear()

void tesseract::TWERD::Clear ( )

Definition at line 849 of file blobs.cpp.

849  {
850  for (auto blob : blobs) {
851  delete blob;
852  }
853  blobs.clear();
854 }

◆ ComputeBoundingBoxes()

void tesseract::TWERD::ComputeBoundingBoxes ( )

Definition at line 857 of file blobs.cpp.

857  {
858  for (auto &blob : blobs) {
859  blob->ComputeBoundingBoxes();
860  }
861 }

◆ CopyFrom()

void tesseract::TWERD::CopyFrom ( const TWERD src)

Definition at line 839 of file blobs.cpp.

839  {
840  Clear();
841  latin_script = src.latin_script;
842  for (auto blob : src.blobs) {
843  auto *new_blob = new TBLOB(*blob);
844  blobs.push_back(new_blob);
845  }
846 }

◆ MergeBlobs()

void tesseract::TWERD::MergeBlobs ( unsigned  start,
unsigned  end 
)

Definition at line 874 of file blobs.cpp.

874  {
875  if (end > blobs.size()) {
876  end = blobs.size();
877  }
878  if (start >= end) {
879  return; // Nothing to do.
880  }
881  TESSLINE *outline = blobs[start]->outlines;
882  for (auto i = start + 1; i < end; ++i) {
883  TBLOB *next_blob = blobs[i];
884  // Take the outlines from the next blob.
885  if (outline == nullptr) {
886  blobs[start]->outlines = next_blob->outlines;
887  outline = blobs[start]->outlines;
888  } else {
889  while (outline->next != nullptr) {
890  outline = outline->next;
891  }
892  outline->next = next_blob->outlines;
893  next_blob->outlines = nullptr;
894  }
895  // Delete the next blob and move on.
896  delete next_blob;
897  blobs[i] = nullptr;
898  }
899  // Remove dead blobs from the vector.
900  // TODO: optimize.
901  for (auto i = start + 1; i < end && start + 1 < blobs.size(); ++i) {
902  blobs.erase(blobs.begin() + start + 1);
903  }
904 }

◆ NumBlobs()

unsigned tesseract::TWERD::NumBlobs ( ) const
inline

Definition at line 449 of file blobs.h.

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

◆ operator=()

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

Definition at line 429 of file blobs.h.

429  {
430  CopyFrom(src);
431  return *this;
432  }

◆ plot()

void tesseract::TWERD::plot ( ScrollView window)

Definition at line 907 of file blobs.cpp.

907  {
909  for (auto &blob : blobs) {
910  blob->plot(window, color, ScrollView::BROWN);
911  color = WERD::NextColor(color);
912  }
913 }
static ScrollView::Color NextColor(ScrollView::Color colour)
Definition: werd.cpp:298

◆ PolygonalCopy()

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

Definition at line 778 of file blobs.cpp.

778  {
779  auto *tessword = new TWERD;
780  tessword->latin_script = src->flag(W_SCRIPT_IS_LATIN);
781  C_BLOB_IT b_it(src->cblob_list());
782  for (b_it.mark_cycle_pt(); !b_it.cycled_list(); b_it.forward()) {
783  C_BLOB *blob = b_it.data();
784  TBLOB *tblob = TBLOB::PolygonalCopy(allow_detailed_fx, blob);
785  tessword->blobs.push_back(tblob);
786  }
787  return tessword;
788 }
@ W_SCRIPT_IS_LATIN
Special case latin for y. splitting.
Definition: werd.h:38
static TBLOB * PolygonalCopy(bool allow_detailed_fx, C_BLOB *src)
Definition: blobs.cpp:335

Member Data Documentation

◆ blobs

std::vector<TBLOB *> tesseract::TWERD::blobs

Definition at line 462 of file blobs.h.

◆ latin_script

bool tesseract::TWERD::latin_script

Definition at line 463 of file blobs.h.


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