tesseract  4.0.0-1-g2a2b
BLOB_CHOICE Class Reference

#include <ratngs.h>

Inheritance diagram for BLOB_CHOICE:
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 GenericVector< tesseract::ScoredFont > & fonts () const
 
void set_fonts (const GenericVector< tesseract::ScoredFont > &fonts)
 
int script_id () const
 
const MATRIX_COORDmatrix_cell ()
 
int16_t xgap_before () const
 
int16_t xgap_after () const
 
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_xgap_before (int16_t gap)
 
void set_xgap_after (int16_t gap)
 
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 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 49 of file ratngs.h.

Constructor & Destructor Documentation

◆ BLOB_CHOICE() [1/3]

BLOB_CHOICE::BLOB_CHOICE ( )
inline

Definition at line 52 of file ratngs.h.

52  {
53  unichar_id_ = UNICHAR_SPACE;
54  fontinfo_id_ = -1;
55  fontinfo_id2_ = -1;
56  rating_ = 10.0;
57  certainty_ = -1.0;
58  script_id_ = -1;
59  xgap_before_ = 0;
60  xgap_after_ = 0;
61  min_xheight_ = 0.0f;
62  max_xheight_ = 0.0f;
63  yshift_ = 0.0f;
64  classifier_ = BCC_FAKE;
65  }

◆ BLOB_CHOICE() [2/3]

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 92 of file ratngs.cpp.

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

◆ BLOB_CHOICE() [3/3]

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 117 of file ratngs.cpp.

117  : ELIST_LINK(other) {
118  unichar_id_ = other.unichar_id();
119  rating_ = other.rating();
120  certainty_ = other.certainty();
121  fontinfo_id_ = other.fontinfo_id();
122  fontinfo_id2_ = other.fontinfo_id2();
123  script_id_ = other.script_id();
124  matrix_cell_ = other.matrix_cell_;
125  min_xheight_ = other.min_xheight_;
126  max_xheight_ = other.max_xheight_;
127  yshift_ = other.yshift();
128  classifier_ = other.classifier_;
129  fonts_ = other.fonts_;
130 }
float certainty() const
Definition: ratngs.h:83
int16_t fontinfo_id() const
Definition: ratngs.h:86
float yshift() const
Definition: ratngs.h:130
int16_t fontinfo_id2() const
Definition: ratngs.h:89
float rating() const
Definition: ratngs.h:80
int script_id() const
Definition: ratngs.h:112
UNICHAR_ID unichar_id() const
Definition: ratngs.h:77
ELIST_LINK()
Definition: elst.h:92

◆ ~BLOB_CHOICE()

BLOB_CHOICE::~BLOB_CHOICE ( )
default

Member Function Documentation

◆ certainty()

float BLOB_CHOICE::certainty ( ) const
inline

Definition at line 83 of file ratngs.h.

83  {
84  return certainty_;
85  }

◆ classifier()

BlobChoiceClassifier BLOB_CHOICE::classifier ( ) const
inline

Definition at line 133 of file ratngs.h.

133  {
134  return classifier_;
135  }

◆ deep_copy()

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

Definition at line 170 of file ratngs.h.

170  {
171  BLOB_CHOICE* choice = new BLOB_CHOICE;
172  *choice = *src;
173  return choice;
174  }
BLOB_CHOICE()
Definition: ratngs.h:52

◆ fontinfo_id()

int16_t BLOB_CHOICE::fontinfo_id ( ) const
inline

Definition at line 86 of file ratngs.h.

86  {
87  return fontinfo_id_;
88  }

◆ fontinfo_id2()

int16_t BLOB_CHOICE::fontinfo_id2 ( ) const
inline

Definition at line 89 of file ratngs.h.

89  {
90  return fontinfo_id2_;
91  }

◆ fonts()

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

Definition at line 92 of file ratngs.h.

92  {
93  return fonts_;
94  }

◆ IsAdapted()

bool BLOB_CHOICE::IsAdapted ( ) const
inline

Definition at line 136 of file ratngs.h.

136  {
137  return classifier_ == BCC_ADAPTED_CLASSIFIER;
138  }

◆ IsClassified()

bool BLOB_CHOICE::IsClassified ( ) const
inline

Definition at line 139 of file ratngs.h.

139  {
140  return classifier_ == BCC_STATIC_CLASSIFIER ||
141  classifier_ == BCC_ADAPTED_CLASSIFIER ||
142  classifier_ == BCC_SPECKLE_CLASSIFIER;
143  }

◆ matrix_cell()

const MATRIX_COORD& BLOB_CHOICE::matrix_cell ( )
inline

Definition at line 115 of file ratngs.h.

115  {
116  return matrix_cell_;
117  }

◆ max_xheight()

float BLOB_CHOICE::max_xheight ( ) const
inline

Definition at line 127 of file ratngs.h.

127  {
128  return max_xheight_;
129  }

◆ min_xheight()

float BLOB_CHOICE::min_xheight ( ) const
inline

Definition at line 124 of file ratngs.h.

124  {
125  return min_xheight_;
126  }

◆ PosAndSizeAgree()

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

Definition at line 152 of file ratngs.cpp.

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

◆ print()

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

Definition at line 180 of file ratngs.h.

180  {
181  tprintf("r%.2f c%.2f x[%g,%g]: %d %s",
182  rating_, certainty_,
183  min_xheight_, max_xheight_, unichar_id_,
184  (unicharset == nullptr) ? "" :
185  unicharset->debug_str(unichar_id_).string());
186  }
const char * string() const
Definition: strngs.cpp:196
STRING debug_str(UNICHAR_ID id) const
Definition: unicharset.cpp:342
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:37

◆ print_full()

void BLOB_CHOICE::print_full ( ) const
inline

Definition at line 187 of file ratngs.h.

187  {
188  print(nullptr);
189  tprintf(" script=%d, font1=%d, font2=%d, yshift=%g, classifier=%d\n",
190  script_id_, fontinfo_id_, fontinfo_id2_, yshift_, classifier_);
191  }
void print(const UNICHARSET *unicharset) const
Definition: ratngs.h:180
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:37

◆ rating()

float BLOB_CHOICE::rating ( ) const
inline

Definition at line 80 of file ratngs.h.

80  {
81  return rating_;
82  }

◆ script_id()

int BLOB_CHOICE::script_id ( ) const
inline

Definition at line 112 of file ratngs.h.

112  {
113  return script_id_;
114  }

◆ set_certainty()

void BLOB_CHOICE::set_certainty ( float  newrat)
inline

Definition at line 151 of file ratngs.h.

151  {
152  certainty_ = newrat;
153  }

◆ set_classifier()

void BLOB_CHOICE::set_classifier ( BlobChoiceClassifier  classifier)
inline

Definition at line 167 of file ratngs.h.

167  {
168  classifier_ = classifier;
169  }
BlobChoiceClassifier classifier() const
Definition: ratngs.h:133

◆ set_fonts()

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

Definition at line 95 of file ratngs.h.

95  {
96  fonts_ = fonts;
97  int score1 = 0, score2 = 0;
98  fontinfo_id_ = -1;
99  fontinfo_id2_ = -1;
100  for (int f = 0; f < fonts_.size(); ++f) {
101  if (fonts_[f].score > score1) {
102  score2 = score1;
103  fontinfo_id2_ = fontinfo_id_;
104  score1 = fonts_[f].score;
105  fontinfo_id_ = fonts_[f].fontinfo_id;
106  } else if (fonts_[f].score > score2) {
107  score2 = fonts_[f].score;
108  fontinfo_id2_ = fonts_[f].fontinfo_id;
109  }
110  }
111  }
int size() const
Definition: genericvector.h:71
const GenericVector< tesseract::ScoredFont > & fonts() const
Definition: ratngs.h:92

◆ set_matrix_cell()

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

Definition at line 157 of file ratngs.h.

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

◆ set_rating()

void BLOB_CHOICE::set_rating ( float  newrat)
inline

Definition at line 148 of file ratngs.h.

148  {
149  rating_ = newrat;
150  }

◆ set_script()

void BLOB_CHOICE::set_script ( int  newscript_id)
inline

Definition at line 154 of file ratngs.h.

154  {
155  script_id_ = newscript_id;
156  }

◆ set_unichar_id()

void BLOB_CHOICE::set_unichar_id ( UNICHAR_ID  newunichar_id)
inline

Definition at line 145 of file ratngs.h.

145  {
146  unichar_id_ = newunichar_id;
147  }

◆ set_xgap_after()

void BLOB_CHOICE::set_xgap_after ( int16_t  gap)
inline

Definition at line 164 of file ratngs.h.

164  {
165  xgap_after_ = gap;
166  }

◆ set_xgap_before()

void BLOB_CHOICE::set_xgap_before ( int16_t  gap)
inline

Definition at line 161 of file ratngs.h.

161  {
162  xgap_before_ = gap;
163  }

◆ SortByRating()

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

Definition at line 193 of file ratngs.h.

193  {
194  const BLOB_CHOICE *bc1 = *static_cast<const BLOB_CHOICE *const *>(p1);
195  const BLOB_CHOICE *bc2 = *static_cast<const BLOB_CHOICE *const *>(p2);
196  return (bc1->rating_ < bc2->rating_) ? -1 : 1;
197  }

◆ unichar_id()

UNICHAR_ID BLOB_CHOICE::unichar_id ( ) const
inline

Definition at line 77 of file ratngs.h.

77  {
78  return unichar_id_;
79  }

◆ xgap_after()

int16_t BLOB_CHOICE::xgap_after ( ) const
inline

Definition at line 121 of file ratngs.h.

121  {
122  return xgap_after_;
123  }

◆ xgap_before()

int16_t BLOB_CHOICE::xgap_before ( ) const
inline

Definition at line 118 of file ratngs.h.

118  {
119  return xgap_before_;
120  }

◆ yshift()

float 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: