tesseract  5.0.0-alpha-619-ge9db
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 416 of file blobs.h.

Constructor & Destructor Documentation

◆ TWERD() [1/2]

TWERD::TWERD ( )
inline

Definition at line 417 of file blobs.h.

417 {

◆ TWERD() [2/2]

TWERD::TWERD ( const TWERD src)
inline

Definition at line 418 of file blobs.h.

418  : latin_script(false) {}
419  TWERD(const TWERD& src) {
420  CopyFrom(src);

◆ ~TWERD()

TWERD::~TWERD ( )
inline

Definition at line 421 of file blobs.h.

422  {
423  Clear();

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

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

◆ bounding_box()

TBOX TWERD::bounding_box ( ) const

Definition at line 859 of file blobs.cpp.

860  {
861  TBOX result;
862  for (int b = 0; b < blobs.size(); ++b) {
863  TBOX box = blobs[b]->bounding_box();
864  result += box;
865  }
866  return result;

◆ Clear()

void TWERD::Clear ( )

Definition at line 847 of file blobs.cpp.

848  {
850  blobs.clear();

◆ ComputeBoundingBoxes()

void TWERD::ComputeBoundingBoxes ( )

Definition at line 853 of file blobs.cpp.

854  {
855  for (int b = 0; b < blobs.size(); ++b) {
856  blobs[b]->ComputeBoundingBoxes();
857  }

◆ CopyFrom()

void TWERD::CopyFrom ( const TWERD src)

Definition at line 837 of file blobs.cpp.

838  {
839  Clear();
841  for (int b = 0; b < src.blobs.size(); ++b) {
842  auto* new_blob = new TBLOB(*src.blobs[b]);
843  blobs.push_back(new_blob);
844  }

◆ MergeBlobs()

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

Definition at line 870 of file blobs.cpp.

871  {
872  if (start >= blobs.size() - 1) return; // Nothing to do.
873  TESSLINE* outline = blobs[start]->outlines;
874  for (int i = start + 1; i < end && i < blobs.size(); ++i) {
875  TBLOB* next_blob = blobs[i];
876  // Take the outlines from the next blob.
877  if (outline == nullptr) {
878  blobs[start]->outlines = next_blob->outlines;
879  outline = blobs[start]->outlines;
880  } else {
881  while (outline->next != nullptr) outline = outline->next;
882  outline->next = next_blob->outlines;
883  next_blob->outlines = nullptr;
884  }
885  // Delete the next blob and move on.
886  delete next_blob;
887  blobs[i] = nullptr;
888  }
889  // Remove dead blobs from the vector.
890  for (int i = start + 1; i < end && start + 1 < blobs.size(); ++i) {
891  blobs.remove(start + 1);
892  }

◆ NumBlobs()

int TWERD::NumBlobs ( ) const
inline

Definition at line 446 of file blobs.h.

447  {
448  return blobs.size();

◆ operator=()

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

Definition at line 424 of file blobs.h.

425  {
426  CopyFrom(src);
427  return *this;

◆ plot()

void TWERD::plot ( ScrollView window)

Definition at line 895 of file blobs.cpp.

896  {
898  for (int b = 0; b < blobs.size(); ++b) {
899  blobs[b]->plot(window, color, ScrollView::BROWN);
900  color = WERD::NextColor(color);
901  }

◆ PolygonalCopy()

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

Definition at line 774 of file blobs.cpp.

775  {
776  auto* tessword = new TWERD;
777  tessword->latin_script = src->flag(W_SCRIPT_IS_LATIN);
778  C_BLOB_IT b_it(src->cblob_list());
779  for (b_it.mark_cycle_pt(); !b_it.cycled_list(); b_it.forward()) {
780  C_BLOB* blob = b_it.data();
781  TBLOB* tblob = TBLOB::PolygonalCopy(allow_detailed_fx, blob);
782  tessword->blobs.push_back(tblob);
783  }
784  return tessword;

Member Data Documentation

◆ blobs

GenericVector<TBLOB*> TWERD::blobs

Definition at line 457 of file blobs.h.

◆ latin_script

bool TWERD::latin_script

Definition at line 458 of file blobs.h.


The documentation for this struct was generated from the following files:
W_SCRIPT_IS_LATIN
Special case latin for y. splitting.
Definition: werd.h:50
GenericVector::delete_data_pointers
void delete_data_pointers()
Definition: genericvector.h:872
GenericVector::remove
void remove(int index)
Definition: genericvector.h:765
ClipToRange
T ClipToRange(const T &x, const T &lower_bound, const T &upper_bound)
Definition: helpers.h:106
TWERD::latin_script
bool latin_script
Definition: blobs.h:458
ROW::base_line
float base_line(float xpos) const
Definition: ocrrow.h:58
WERD::flag
bool flag(WERD_FLAGS mask) const
Definition: werd.h:116
kBlnXHeight
const int kBlnXHeight
Definition: normalis.h:23
WERD::NextColor
static ScrollView::Color NextColor(ScrollView::Color colour)
Definition: werd.cpp:291
TWERD
Definition: blobs.h:416
TBLOB::outlines
TESSLINE * outlines
Definition: blobs.h:398
baseline
Definition: mfoutline.h:62
DENORM::set_inverse
void set_inverse(bool value)
Definition: normalis.h:254
TESSLINE
Definition: blobs.h:201
ScrollView::BROWN
Definition: scrollview.h:120
TWERD::Clear
void Clear()
Definition: blobs.cpp:847
TESSLINE::next
TESSLINE * next
Definition: blobs.h:279
C_BLOB
Definition: stepblob.h:36
TBOX::height
int16_t height() const
Definition: rect.h:107
WERD::cblob_list
C_BLOB_LIST * cblob_list()
Definition: werd.h:94
TWERD::CopyFrom
void CopyFrom(const TWERD &src)
Definition: blobs.cpp:837
TWERD::TWERD
TWERD()
Definition: blobs.h:417
GenericVector::push_back
int push_back(T object)
Definition: genericvector.h:799
DENORM::SetupNormalization
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
ScrollView::BLACK
Definition: scrollview.h:102
TWERD::blobs
GenericVector< TBLOB * > blobs
Definition: blobs.h:457
TBOX::bottom
int16_t bottom() const
Definition: rect.h:64
TBLOB::PolygonalCopy
static TBLOB * PolygonalCopy(bool allow_detailed_fx, C_BLOB *src)
Definition: blobs.cpp:326
TBLOB::Normalize
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:396
TBLOB::bounding_box
TBOX bounding_box() const
Definition: blobs.cpp:466
DENORM::set_pix
void set_pix(Pix *pix)
Definition: normalis.h:248
TBLOB
Definition: blobs.h:282
TBOX::left
int16_t left() const
Definition: rect.h:71
GenericVector::clear
void clear()
Definition: genericvector.h:857
TBOX::right
int16_t right() const
Definition: rect.h:78
TWERD::bounding_box
TBOX bounding_box() const
Definition: blobs.cpp:859
ScrollView::Color
Color
Definition: scrollview.h:100
GenericVector::size
int size() const
Definition: genericvector.h:71
kBlnBaselineOffset
const int kBlnBaselineOffset
Definition: normalis.h:24
TBOX
Definition: rect.h:33