tesseract  5.0.0-alpha-619-ge9db
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 ()
 
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 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  BLOB_CHOICE() {
54  unichar_id_ = UNICHAR_SPACE;
55  fontinfo_id_ = -1;
56  fontinfo_id2_ = -1;
57  rating_ = 10.0;
58  certainty_ = -1.0;
59  script_id_ = -1;
60  min_xheight_ = 0.0f;
61  max_xheight_ = 0.0f;
62  yshift_ = 0.0f;
63  classifier_ = BCC_FAKE;

◆ 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.

98  { // adapted match or other
99  unichar_id_ = src_unichar_id;
100  rating_ = src_rating;
101  certainty_ = src_cert;
102  fontinfo_id_ = -1;
103  fontinfo_id2_ = -1;
104  script_id_ = src_script_id;
105  min_xheight_ = min_xheight;
106  max_xheight_ = max_xheight;
107  yshift_ = yshift;
108  classifier_ = c;

◆ 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.

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

◆ ~BLOB_CHOICE()

BLOB_CHOICE::~BLOB_CHOICE ( )
default

Member Function Documentation

◆ certainty()

float BLOB_CHOICE::certainty ( ) const
inline

Definition at line 81 of file ratngs.h.

82  {
83  return certainty_;

◆ classifier()

BlobChoiceClassifier BLOB_CHOICE::classifier ( ) const
inline

Definition at line 127 of file ratngs.h.

128  {
129  return classifier_;

◆ deep_copy()

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

Definition at line 158 of file ratngs.h.

159  {
160  auto* choice = new BLOB_CHOICE;
161  *choice = *src;
162  return choice;

◆ fontinfo_id()

int16_t BLOB_CHOICE::fontinfo_id ( ) const
inline

Definition at line 84 of file ratngs.h.

85  {
86  return fontinfo_id_;

◆ fontinfo_id2()

int16_t BLOB_CHOICE::fontinfo_id2 ( ) const
inline

Definition at line 87 of file ratngs.h.

88  {
89  return fontinfo_id2_;

◆ fonts()

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

Definition at line 91 of file ratngs.h.

92  {
93  return fonts_;

◆ IsAdapted()

bool BLOB_CHOICE::IsAdapted ( ) const
inline

Definition at line 130 of file ratngs.h.

131  {
132  return classifier_ == BCC_ADAPTED_CLASSIFIER;

◆ IsClassified()

bool BLOB_CHOICE::IsClassified ( ) const
inline

Definition at line 133 of file ratngs.h.

134  {
135  return classifier_ == BCC_STATIC_CLASSIFIER ||
136  classifier_ == BCC_ADAPTED_CLASSIFIER ||
137  classifier_ == BCC_SPECKLE_CLASSIFIER;

◆ matrix_cell()

const MATRIX_COORD& BLOB_CHOICE::matrix_cell ( )
inline

Definition at line 115 of file ratngs.h.

116  {
117  return matrix_cell_;

◆ max_xheight()

float BLOB_CHOICE::max_xheight ( ) const
inline

Definition at line 121 of file ratngs.h.

122  {
123  return max_xheight_;

◆ min_xheight()

float BLOB_CHOICE::min_xheight ( ) const
inline

Definition at line 118 of file ratngs.h.

119  {
120  return min_xheight_;

◆ PosAndSizeAgree()

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

Definition at line 154 of file ratngs.cpp.

156  {
157  double baseline_diff = fabs(yshift() - other.yshift());
158  if (baseline_diff > kMaxBaselineDrift * x_height) {
159  if (debug) {
160  tprintf("Baseline diff %g for %d v %d\n",
161  baseline_diff, unichar_id_, other.unichar_id_);
162  }
163  return false;
164  }
165  double this_range = max_xheight() - min_xheight();
166  double other_range = other.max_xheight() - other.min_xheight();
167  double denominator = ClipToRange(std::min(this_range, other_range),
168  1.0, kMaxOverlapDenominator * x_height);
169  double overlap = std::min(max_xheight(), other.max_xheight()) -
170  std::max(min_xheight(), other.min_xheight());
171  overlap /= denominator;
172  if (debug) {
173  tprintf("PosAndSize for %d v %d: bl diff = %g, ranges %g, %g / %g ->%g\n",
174  unichar_id_, other.unichar_id_, baseline_diff,
175  this_range, other_range, denominator, overlap);
176  }
177 
178  return overlap >= kMinXHeightMatch;

◆ print()

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

Definition at line 168 of file ratngs.h.

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

◆ print_full()

void BLOB_CHOICE::print_full ( ) const
inline

Definition at line 175 of file ratngs.h.

176  {
177  print(nullptr);
178  tprintf(" script=%d, font1=%d, font2=%d, yshift=%g, classifier=%d\n",
179  script_id_, fontinfo_id_, fontinfo_id2_, yshift_, classifier_);

◆ rating()

float BLOB_CHOICE::rating ( ) const
inline

Definition at line 78 of file ratngs.h.

79  {
80  return rating_;

◆ script_id()

int BLOB_CHOICE::script_id ( ) const
inline

Definition at line 112 of file ratngs.h.

113  {
114  return script_id_;

◆ set_certainty()

void BLOB_CHOICE::set_certainty ( float  newrat)
inline

Definition at line 145 of file ratngs.h.

146  {
147  certainty_ = newrat;

◆ set_classifier()

void BLOB_CHOICE::set_classifier ( BlobChoiceClassifier  classifier)
inline

Definition at line 155 of file ratngs.h.

156  {
157  classifier_ = classifier;

◆ set_fonts()

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

Definition at line 94 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  }

◆ set_matrix_cell()

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

Definition at line 151 of file ratngs.h.

152  {
153  matrix_cell_.col = col;
154  matrix_cell_.row = row;

◆ set_rating()

void BLOB_CHOICE::set_rating ( float  newrat)
inline

Definition at line 142 of file ratngs.h.

143  {
144  rating_ = newrat;

◆ set_script()

void BLOB_CHOICE::set_script ( int  newscript_id)
inline

Definition at line 148 of file ratngs.h.

149  {
150  script_id_ = newscript_id;

◆ set_unichar_id()

void BLOB_CHOICE::set_unichar_id ( UNICHAR_ID  newunichar_id)
inline

Definition at line 139 of file ratngs.h.

140  {
141  unichar_id_ = newunichar_id;

◆ SortByRating()

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

Definition at line 181 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;

◆ unichar_id()

UNICHAR_ID BLOB_CHOICE::unichar_id ( ) const
inline

Definition at line 75 of file ratngs.h.

76  {
77  return unichar_id_;

◆ yshift()

float BLOB_CHOICE::yshift ( ) const
inline

Definition at line 124 of file ratngs.h.

125  {
126  return yshift_;

The documentation for this class was generated from the following files:
ClipToRange
T ClipToRange(const T &x, const T &lower_bound, const T &upper_bound)
Definition: helpers.h:106
ELIST_LINK::ELIST_LINK
ELIST_LINK()
Definition: elst.h:125
BCC_FAKE
Definition: ratngs.h:46
BLOB_CHOICE::min_xheight
float min_xheight() const
Definition: ratngs.h:118
BLOB_CHOICE::certainty
float certainty() const
Definition: ratngs.h:81
BLOB_CHOICE::print
void print(const UNICHARSET *unicharset) const
Definition: ratngs.h:168
BCC_ADAPTED_CLASSIFIER
Definition: ratngs.h:43
BLOB_CHOICE::BLOB_CHOICE
BLOB_CHOICE()
Definition: ratngs.h:52
BLOB_CHOICE::script_id
int script_id() const
Definition: ratngs.h:112
BLOB_CHOICE::unichar_id
UNICHAR_ID unichar_id() const
Definition: ratngs.h:75
UNICHARSET::debug_str
STRING debug_str(UNICHAR_ID id) const
Definition: unicharset.cpp:342
STRING::c_str
const char * c_str() const
Definition: strngs.cpp:192
BLOB_CHOICE::classifier
BlobChoiceClassifier classifier() const
Definition: ratngs.h:127
UNICHAR_SPACE
Definition: unicharset.h:34
BLOB_CHOICE::max_xheight
float max_xheight() const
Definition: ratngs.h:121
kMinXHeightMatch
const double kMinXHeightMatch
Definition: ratngs.cpp:50
BLOB_CHOICE::fonts
const GenericVector< tesseract::ScoredFont > & fonts() const
Definition: ratngs.h:91
kMaxOverlapDenominator
const double kMaxOverlapDenominator
Definition: ratngs.cpp:47
BLOB_CHOICE::rating
float rating() const
Definition: ratngs.h:78
BLOB_CHOICE::fontinfo_id
int16_t fontinfo_id() const
Definition: ratngs.h:84
BLOB_CHOICE::fontinfo_id2
int16_t fontinfo_id2() const
Definition: ratngs.h:87
BLOB_CHOICE
Definition: ratngs.h:49
BLOB_CHOICE::yshift
float yshift() const
Definition: ratngs.h:124
MATRIX_COORD::col
int col
Definition: matrix.h:632
tprintf
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:34
MATRIX_COORD::row
int row
Definition: matrix.h:633
GenericVector::size
int size() const
Definition: genericvector.h:71
BCC_SPECKLE_CLASSIFIER
Definition: ratngs.h:44
BCC_STATIC_CLASSIFIER
Definition: ratngs.h:42
kMaxBaselineDrift
const double kMaxBaselineDrift
Definition: ratngs.cpp:53