tesseract  5.0.0
tesseract::BLOB_CHOICE Class Reference

#include <ratngs.h>

Inheritance diagram for tesseract::BLOB_CHOICE:
tesseract::ELIST_LINK

Public Member Functions

 BLOB_CHOICE ()
 
 BLOB_CHOICE (UNICHAR_ID src_unichar_id, float src_rating, float src_cert, int script_id, float min_xheight, float max_xheight, float yshift, BlobChoiceClassifier c)
 
 BLOB_CHOICE (const BLOB_CHOICE &other)
 
 ~BLOB_CHOICE ()=default
 
UNICHAR_ID unichar_id () const
 
float rating () const
 
float certainty () const
 
int16_t fontinfo_id () const
 
int16_t fontinfo_id2 () const
 
const std::vector< ScoredFont > & fonts () const
 
void set_fonts (const std::vector< ScoredFont > &fonts)
 
int script_id () const
 
const MATRIX_COORDmatrix_cell ()
 
float min_xheight () const
 
float max_xheight () const
 
float yshift () const
 
BlobChoiceClassifier classifier () const
 
bool IsAdapted () const
 
bool IsClassified () const
 
void set_unichar_id (UNICHAR_ID newunichar_id)
 
void set_rating (float newrat)
 
void set_certainty (float newrat)
 
void set_script (int newscript_id)
 
void set_matrix_cell (int col, int row)
 
void set_classifier (BlobChoiceClassifier classifier)
 
bool PosAndSizeAgree (const BLOB_CHOICE &other, float x_height, bool debug) const
 
void print (const UNICHARSET *unicharset) const
 
void print_full () const
 
- Public Member Functions inherited from tesseract::ELIST_LINK
 ELIST_LINK ()
 
 ELIST_LINK (const ELIST_LINK &)
 
void operator= (const ELIST_LINK &)
 

Static Public Member Functions

static BLOB_CHOICEdeep_copy (const BLOB_CHOICE *src)
 
static int SortByRating (const void *p1, const void *p2)
 

Detailed Description

Definition at line 56 of file ratngs.h.

Constructor & Destructor Documentation

◆ BLOB_CHOICE() [1/3]

tesseract::BLOB_CHOICE::BLOB_CHOICE ( )
inline

Definition at line 58 of file ratngs.h.

58  {
59  unichar_id_ = UNICHAR_SPACE;
60  fontinfo_id_ = -1;
61  fontinfo_id2_ = -1;
62  rating_ = 10.0;
63  certainty_ = -1.0;
64  script_id_ = -1;
65  min_xheight_ = 0.0f;
66  max_xheight_ = 0.0f;
67  yshift_ = 0.0f;
68  classifier_ = BCC_FAKE;
69  }
@ UNICHAR_SPACE
Definition: unicharset.h:36
@ BCC_FAKE
Definition: ratngs.h:53

◆ BLOB_CHOICE() [2/3]

tesseract::BLOB_CHOICE::BLOB_CHOICE ( UNICHAR_ID  src_unichar_id,
float  src_rating,
float  src_cert,
int  src_script_id,
float  min_xheight,
float  max_xheight,
float  yshift,
BlobChoiceClassifier  c 
)

BLOB_CHOICE::BLOB_CHOICE

Constructor to build a BLOB_CHOICE from a char, rating and certainty.

Definition at line 88 of file ratngs.cpp.

95  { // adapted match or other
96  unichar_id_ = src_unichar_id;
97  rating_ = src_rating;
98  certainty_ = src_cert;
99  fontinfo_id_ = -1;
100  fontinfo_id2_ = -1;
101  script_id_ = src_script_id;
102  min_xheight_ = min_xheight;
103  max_xheight_ = max_xheight;
104  yshift_ = yshift;
105  classifier_ = c;
106 }
float min_xheight() const
Definition: ratngs.h:124
float yshift() const
Definition: ratngs.h:130
float max_xheight() const
Definition: ratngs.h:127

◆ BLOB_CHOICE() [3/3]

tesseract::BLOB_CHOICE::BLOB_CHOICE ( const BLOB_CHOICE other)

BLOB_CHOICE::BLOB_CHOICE

Constructor to build a BLOB_CHOICE from another BLOB_CHOICE.

Definition at line 113 of file ratngs.cpp.

113  : ELIST_LINK(other) {
114  unichar_id_ = other.unichar_id();
115  rating_ = other.rating();
116  certainty_ = other.certainty();
117  fontinfo_id_ = other.fontinfo_id();
118  fontinfo_id2_ = other.fontinfo_id2();
119  script_id_ = other.script_id();
120  matrix_cell_ = other.matrix_cell_;
121  min_xheight_ = other.min_xheight_;
122  max_xheight_ = other.max_xheight_;
123  yshift_ = other.yshift();
124  classifier_ = other.classifier_;
125 #ifndef DISABLED_LEGACY_ENGINE
126  fonts_ = other.fonts_;
127 #endif // ndef DISABLED_LEGACY_ENGINE
128 }

◆ ~BLOB_CHOICE()

tesseract::BLOB_CHOICE::~BLOB_CHOICE ( )
default

Member Function Documentation

◆ certainty()

float tesseract::BLOB_CHOICE::certainty ( ) const
inline

Definition at line 87 of file ratngs.h.

87  {
88  return certainty_;
89  }

◆ classifier()

BlobChoiceClassifier tesseract::BLOB_CHOICE::classifier ( ) const
inline

Definition at line 133 of file ratngs.h.

133  {
134  return classifier_;
135  }

◆ deep_copy()

static BLOB_CHOICE* tesseract::BLOB_CHOICE::deep_copy ( const BLOB_CHOICE src)
inlinestatic

Definition at line 163 of file ratngs.h.

163  {
164  auto *choice = new BLOB_CHOICE;
165  *choice = *src;
166  return choice;
167  }

◆ fontinfo_id()

int16_t tesseract::BLOB_CHOICE::fontinfo_id ( ) const
inline

Definition at line 90 of file ratngs.h.

90  {
91  return fontinfo_id_;
92  }

◆ fontinfo_id2()

int16_t tesseract::BLOB_CHOICE::fontinfo_id2 ( ) const
inline

Definition at line 93 of file ratngs.h.

93  {
94  return fontinfo_id2_;
95  }

◆ fonts()

const std::vector<ScoredFont>& tesseract::BLOB_CHOICE::fonts ( ) const
inline

Definition at line 97 of file ratngs.h.

97  {
98  return fonts_;
99  }

◆ IsAdapted()

bool tesseract::BLOB_CHOICE::IsAdapted ( ) const
inline

Definition at line 136 of file ratngs.h.

136  {
137  return classifier_ == BCC_ADAPTED_CLASSIFIER;
138  }
@ BCC_ADAPTED_CLASSIFIER
Definition: ratngs.h:50

◆ IsClassified()

bool tesseract::BLOB_CHOICE::IsClassified ( ) const
inline

Definition at line 139 of file ratngs.h.

139  {
140  return classifier_ == BCC_STATIC_CLASSIFIER || classifier_ == BCC_ADAPTED_CLASSIFIER ||
141  classifier_ == BCC_SPECKLE_CLASSIFIER;
142  }
@ BCC_SPECKLE_CLASSIFIER
Definition: ratngs.h:51
@ BCC_STATIC_CLASSIFIER
Definition: ratngs.h:49

◆ matrix_cell()

const MATRIX_COORD& tesseract::BLOB_CHOICE::matrix_cell ( )
inline

Definition at line 121 of file ratngs.h.

121  {
122  return matrix_cell_;
123  }

◆ max_xheight()

float tesseract::BLOB_CHOICE::max_xheight ( ) const
inline

Definition at line 127 of file ratngs.h.

127  {
128  return max_xheight_;
129  }

◆ min_xheight()

float tesseract::BLOB_CHOICE::min_xheight ( ) const
inline

Definition at line 124 of file ratngs.h.

124  {
125  return min_xheight_;
126  }

◆ PosAndSizeAgree()

bool tesseract::BLOB_CHOICE::PosAndSizeAgree ( const BLOB_CHOICE other,
float  x_height,
bool  debug 
) const

Definition at line 152 of file ratngs.cpp.

152  {
153  double baseline_diff = std::fabs(yshift() - other.yshift());
154  if (baseline_diff > kMaxBaselineDrift * x_height) {
155  if (debug) {
156  tprintf("Baseline diff %g for %d v %d\n", baseline_diff, unichar_id_, other.unichar_id_);
157  }
158  return false;
159  }
160  double this_range = max_xheight() - min_xheight();
161  double other_range = other.max_xheight() - other.min_xheight();
162  double denominator =
163  ClipToRange(std::min(this_range, other_range), 1.0, kMaxOverlapDenominator * x_height);
164  double overlap =
165  std::min(max_xheight(), other.max_xheight()) - std::max(min_xheight(), other.min_xheight());
166  overlap /= denominator;
167  if (debug) {
168  tprintf("PosAndSize for %d v %d: bl diff = %g, ranges %g, %g / %g ->%g\n", unichar_id_,
169  other.unichar_id_, baseline_diff, this_range, other_range, denominator, overlap);
170  }
171 
172  return overlap >= kMinXHeightMatch;
173 }
const double kMinXHeightMatch
Definition: ratngs.cpp:48
void tprintf(const char *format,...)
Definition: tprintf.cpp:41
const double kMaxBaselineDrift
Definition: ratngs.cpp:51
const double kMaxOverlapDenominator
Definition: ratngs.cpp:45
T ClipToRange(const T &x, const T &lower_bound, const T &upper_bound)
Definition: helpers.h:110

◆ print()

void tesseract::BLOB_CHOICE::print ( const UNICHARSET unicharset) const
inline

Definition at line 172 of file ratngs.h.

172  {
173  tprintf("r%.2f c%.2f x[%g,%g]: %d %s", rating_, certainty_, min_xheight_, max_xheight_,
174  unichar_id_, (unicharset == nullptr) ? "" : unicharset->debug_str(unichar_id_).c_str());
175  }

◆ print_full()

void tesseract::BLOB_CHOICE::print_full ( ) const
inline

Definition at line 176 of file ratngs.h.

176  {
177  print(nullptr);
178  tprintf(" script=%d, font1=%d, font2=%d, yshift=%g, classifier=%d\n", script_id_, fontinfo_id_,
179  fontinfo_id2_, yshift_, classifier_);
180  }
void print(const UNICHARSET *unicharset) const
Definition: ratngs.h:172

◆ rating()

float tesseract::BLOB_CHOICE::rating ( ) const
inline

Definition at line 84 of file ratngs.h.

84  {
85  return rating_;
86  }

◆ script_id()

int tesseract::BLOB_CHOICE::script_id ( ) const
inline

Definition at line 118 of file ratngs.h.

118  {
119  return script_id_;
120  }

◆ set_certainty()

void tesseract::BLOB_CHOICE::set_certainty ( float  newrat)
inline

Definition at line 150 of file ratngs.h.

150  {
151  certainty_ = newrat;
152  }

◆ set_classifier()

void tesseract::BLOB_CHOICE::set_classifier ( BlobChoiceClassifier  classifier)
inline

Definition at line 160 of file ratngs.h.

160  {
161  classifier_ = classifier;
162  }
BlobChoiceClassifier classifier() const
Definition: ratngs.h:133

◆ set_fonts()

void tesseract::BLOB_CHOICE::set_fonts ( const std::vector< ScoredFont > &  fonts)
inline

Definition at line 100 of file ratngs.h.

100  {
101  fonts_ = fonts;
102  int score1 = 0, score2 = 0;
103  fontinfo_id_ = -1;
104  fontinfo_id2_ = -1;
105  for (auto &f : fonts_) {
106  if (f.score > score1) {
107  score2 = score1;
108  fontinfo_id2_ = fontinfo_id_;
109  score1 = f.score;
110  fontinfo_id_ = f.fontinfo_id;
111  } else if (f.score > score2) {
112  score2 = f.score;
113  fontinfo_id2_ = f.fontinfo_id;
114  }
115  }
116  }
const std::vector< ScoredFont > & fonts() const
Definition: ratngs.h:97

◆ set_matrix_cell()

void tesseract::BLOB_CHOICE::set_matrix_cell ( int  col,
int  row 
)
inline

Definition at line 156 of file ratngs.h.

156  {
157  matrix_cell_.col = col;
158  matrix_cell_.row = row;
159  }

◆ set_rating()

void tesseract::BLOB_CHOICE::set_rating ( float  newrat)
inline

Definition at line 147 of file ratngs.h.

147  {
148  rating_ = newrat;
149  }

◆ set_script()

void tesseract::BLOB_CHOICE::set_script ( int  newscript_id)
inline

Definition at line 153 of file ratngs.h.

153  {
154  script_id_ = newscript_id;
155  }

◆ set_unichar_id()

void tesseract::BLOB_CHOICE::set_unichar_id ( UNICHAR_ID  newunichar_id)
inline

Definition at line 144 of file ratngs.h.

144  {
145  unichar_id_ = newunichar_id;
146  }

◆ SortByRating()

static int tesseract::BLOB_CHOICE::SortByRating ( const void *  p1,
const void *  p2 
)
inlinestatic

Definition at line 182 of file ratngs.h.

182  {
183  const BLOB_CHOICE *bc1 = *static_cast<const BLOB_CHOICE *const *>(p1);
184  const BLOB_CHOICE *bc2 = *static_cast<const BLOB_CHOICE *const *>(p2);
185  return (bc1->rating_ < bc2->rating_) ? -1 : 1;
186  }

◆ unichar_id()

UNICHAR_ID tesseract::BLOB_CHOICE::unichar_id ( ) const
inline

Definition at line 81 of file ratngs.h.

81  {
82  return unichar_id_;
83  }

◆ yshift()

float tesseract::BLOB_CHOICE::yshift ( ) const
inline

Definition at line 130 of file ratngs.h.

130  {
131  return yshift_;
132  }

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