tesseract  4.00.00dev
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 ()
 
UNICHAR_ID unichar_id () const
 
float rating () const
 
float certainty () const
 
inT16 fontinfo_id () const
 
inT16 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 xgap_before () const
 
inT16 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 gap)
 
void set_xgap_after (inT16 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 48 of file ratngs.h.

Constructor & Destructor Documentation

◆ BLOB_CHOICE() [1/3]

BLOB_CHOICE::BLOB_CHOICE ( )
inline

Definition at line 51 of file ratngs.h.

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

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

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

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

115  : ELIST_LINK(other) {
116  unichar_id_ = other.unichar_id();
117  rating_ = other.rating();
118  certainty_ = other.certainty();
119  fontinfo_id_ = other.fontinfo_id();
120  fontinfo_id2_ = other.fontinfo_id2();
121  script_id_ = other.script_id();
122  matrix_cell_ = other.matrix_cell_;
123  min_xheight_ = other.min_xheight_;
124  max_xheight_ = other.max_xheight_;
125  yshift_ = other.yshift();
126  classifier_ = other.classifier_;
127  fonts_ = other.fonts_;
128 }
float yshift() const
Definition: ratngs.h:129
inT16 fontinfo_id2() const
Definition: ratngs.h:88
float rating() const
Definition: ratngs.h:79
float certainty() const
Definition: ratngs.h:82
inT16 fontinfo_id() const
Definition: ratngs.h:85
ELIST_LINK()
Definition: elst.h:92
int script_id() const
Definition: ratngs.h:111
UNICHAR_ID unichar_id() const
Definition: ratngs.h:76

◆ ~BLOB_CHOICE()

BLOB_CHOICE::~BLOB_CHOICE ( )
inline

Definition at line 74 of file ratngs.h.

74 {}

Member Function Documentation

◆ certainty()

float BLOB_CHOICE::certainty ( ) const
inline

Definition at line 82 of file ratngs.h.

82  {
83  return certainty_;
84  }

◆ classifier()

BlobChoiceClassifier BLOB_CHOICE::classifier ( ) const
inline

Definition at line 132 of file ratngs.h.

132  {
133  return classifier_;
134  }

◆ deep_copy()

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

Definition at line 169 of file ratngs.h.

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

◆ fontinfo_id()

inT16 BLOB_CHOICE::fontinfo_id ( ) const
inline

Definition at line 85 of file ratngs.h.

85  {
86  return fontinfo_id_;
87  }

◆ fontinfo_id2()

inT16 BLOB_CHOICE::fontinfo_id2 ( ) const
inline

Definition at line 88 of file ratngs.h.

88  {
89  return fontinfo_id2_;
90  }

◆ fonts()

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

Definition at line 91 of file ratngs.h.

91  {
92  return fonts_;
93  }

◆ IsAdapted()

bool BLOB_CHOICE::IsAdapted ( ) const
inline

Definition at line 135 of file ratngs.h.

135  {
136  return classifier_ == BCC_ADAPTED_CLASSIFIER;
137  }

◆ IsClassified()

bool BLOB_CHOICE::IsClassified ( ) const
inline

Definition at line 138 of file ratngs.h.

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

◆ matrix_cell()

const MATRIX_COORD& BLOB_CHOICE::matrix_cell ( )
inline

Definition at line 114 of file ratngs.h.

114  {
115  return matrix_cell_;
116  }

◆ max_xheight()

float BLOB_CHOICE::max_xheight ( ) const
inline

Definition at line 126 of file ratngs.h.

126  {
127  return max_xheight_;
128  }

◆ min_xheight()

float BLOB_CHOICE::min_xheight ( ) const
inline

Definition at line 123 of file ratngs.h.

123  {
124  return min_xheight_;
125  }

◆ PosAndSizeAgree()

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

Definition at line 132 of file ratngs.cpp.

133  {
134  double baseline_diff = fabs(yshift() - other.yshift());
135  if (baseline_diff > kMaxBaselineDrift * x_height) {
136  if (debug) {
137  tprintf("Baseline diff %g for %d v %d\n",
138  baseline_diff, unichar_id_, other.unichar_id_);
139  }
140  return false;
141  }
142  double this_range = max_xheight() - min_xheight();
143  double other_range = other.max_xheight() - other.min_xheight();
144  double denominator = ClipToRange(MIN(this_range, other_range),
145  1.0, kMaxOverlapDenominator * x_height);
146  double overlap = MIN(max_xheight(), other.max_xheight()) -
147  MAX(min_xheight(), other.min_xheight());
148  overlap /= denominator;
149  if (debug) {
150  tprintf("PosAndSize for %d v %d: bl diff = %g, ranges %g, %g / %g ->%g\n",
151  unichar_id_, other.unichar_id_, baseline_diff,
152  this_range, other_range, denominator, overlap);
153  }
154 
155  return overlap >= kMinXHeightMatch;
156 }
float yshift() const
Definition: ratngs.h:129
const double kMaxOverlapDenominator
Definition: ratngs.cpp:47
#define tprintf(...)
Definition: tprintf.h:31
const double kMaxBaselineDrift
Definition: ratngs.cpp:53
T ClipToRange(const T &x, const T &lower_bound, const T &upper_bound)
Definition: helpers.h:122
const double kMinXHeightMatch
Definition: ratngs.cpp:50
float min_xheight() const
Definition: ratngs.h:123
#define MAX(x, y)
Definition: ndminx.h:24
#define MIN(x, y)
Definition: ndminx.h:28
float max_xheight() const
Definition: ratngs.h:126

◆ print()

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

Definition at line 179 of file ratngs.h.

179  {
180  tprintf("r%.2f c%.2f x[%g,%g]: %d %s",
181  rating_, certainty_,
182  min_xheight_, max_xheight_, unichar_id_,
183  (unicharset == NULL) ? "" :
184  unicharset->debug_str(unichar_id_).string());
185  }
#define tprintf(...)
Definition: tprintf.h:31
const char * string() const
Definition: strngs.cpp:198
STRING debug_str(UNICHAR_ID id) const
Definition: unicharset.cpp:318

◆ print_full()

void BLOB_CHOICE::print_full ( ) const
inline

Definition at line 186 of file ratngs.h.

186  {
187  print(NULL);
188  tprintf(" script=%d, font1=%d, font2=%d, yshift=%g, classifier=%d\n",
189  script_id_, fontinfo_id_, fontinfo_id2_, yshift_, classifier_);
190  }
#define tprintf(...)
Definition: tprintf.h:31
void print(const UNICHARSET *unicharset) const
Definition: ratngs.h:179

◆ rating()

float BLOB_CHOICE::rating ( ) const
inline

Definition at line 79 of file ratngs.h.

79  {
80  return rating_;
81  }

◆ script_id()

int BLOB_CHOICE::script_id ( ) const
inline

Definition at line 111 of file ratngs.h.

111  {
112  return script_id_;
113  }

◆ set_certainty()

void BLOB_CHOICE::set_certainty ( float  newrat)
inline

Definition at line 150 of file ratngs.h.

150  {
151  certainty_ = newrat;
152  }

◆ set_classifier()

void BLOB_CHOICE::set_classifier ( BlobChoiceClassifier  classifier)
inline

Definition at line 166 of file ratngs.h.

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

◆ set_fonts()

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

Definition at line 94 of file ratngs.h.

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

◆ set_matrix_cell()

void 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 BLOB_CHOICE::set_rating ( float  newrat)
inline

Definition at line 147 of file ratngs.h.

147  {
148  rating_ = newrat;
149  }

◆ set_script()

void 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 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  }

◆ set_xgap_after()

void BLOB_CHOICE::set_xgap_after ( inT16  gap)
inline

Definition at line 163 of file ratngs.h.

163  {
164  xgap_after_ = gap;
165  }

◆ set_xgap_before()

void BLOB_CHOICE::set_xgap_before ( inT16  gap)
inline

Definition at line 160 of file ratngs.h.

160  {
161  xgap_before_ = gap;
162  }

◆ SortByRating()

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

Definition at line 192 of file ratngs.h.

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

◆ unichar_id()

UNICHAR_ID BLOB_CHOICE::unichar_id ( ) const
inline

Definition at line 76 of file ratngs.h.

76  {
77  return unichar_id_;
78  }

◆ xgap_after()

inT16 BLOB_CHOICE::xgap_after ( ) const
inline

Definition at line 120 of file ratngs.h.

120  {
121  return xgap_after_;
122  }

◆ xgap_before()

inT16 BLOB_CHOICE::xgap_before ( ) const
inline

Definition at line 117 of file ratngs.h.

117  {
118  return xgap_before_;
119  }

◆ yshift()

float BLOB_CHOICE::yshift ( ) const
inline

Definition at line 129 of file ratngs.h.

129  {
130  return yshift_;
131  }

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