tesseract  5.0.0-alpha-619-ge9db
OSResults Struct Reference

#include <osdetect.h>

Public Member Functions

 OSResults ()
 
void update_best_orientation ()
 
void set_best_orientation (int orientation_id)
 
void update_best_script (int orientation_id)
 
TESS_API int get_best_script (int orientation_id) const
 
void accumulate (const OSResults &osr)
 
void print_scores (void) const
 
void print_scores (int orientation_id) const
 

Public Attributes

float orientations [4]
 
float scripts_na [4][kMaxNumberOfScripts]
 
UNICHARSETunicharset
 
OSBestResult best_result
 

Detailed Description

Definition at line 50 of file osdetect.h.

Constructor & Destructor Documentation

◆ OSResults()

OSResults::OSResults ( )
inline

Definition at line 51 of file osdetect.h.

51  : unicharset(nullptr) {
52  for (int i = 0; i < 4; ++i) {
53  for (int j = 0; j < kMaxNumberOfScripts; ++j) scripts_na[i][j] = 0;
54  orientations[i] = 0;
55  }
56  }

Member Function Documentation

◆ accumulate()

void OSResults::accumulate ( const OSResults osr)

Definition at line 144 of file osdetect.cpp.

144  {
145  for (int i = 0; i < 4; ++i) {
146  orientations[i] += osr.orientations[i];
147  for (int j = 0; j < kMaxNumberOfScripts; ++j)
148  scripts_na[i][j] += osr.scripts_na[i][j];
149  }
150  unicharset = osr.unicharset;
153 }

◆ get_best_script()

int OSResults::get_best_script ( int  orientation_id) const

Definition at line 112 of file osdetect.cpp.

112  {
113  int max_id = -1;
114  for (int j = 0; j < kMaxNumberOfScripts; ++j) {
115  const char *script = unicharset->get_script_from_script_id(j);
116  if (strcmp(script, "Common") && strcmp(script, "NULL")) {
117  if (max_id == -1 ||
118  scripts_na[orientation_id][j] > scripts_na[orientation_id][max_id])
119  max_id = j;
120  }
121  }
122  return max_id;
123 }

◆ print_scores() [1/2]

void OSResults::print_scores ( int  orientation_id) const

Definition at line 134 of file osdetect.cpp.

134  {
135  for (int j = 0; j < kMaxNumberOfScripts; ++j) {
136  if (scripts_na[orientation_id][j]) {
137  tprintf("%12s\t: %f\n", unicharset->get_script_from_script_id(j),
138  scripts_na[orientation_id][j]);
139  }
140  }
141 }

◆ print_scores() [2/2]

void OSResults::print_scores ( void  ) const

Definition at line 126 of file osdetect.cpp.

126  {
127  for (int i = 0; i < 4; ++i) {
128  tprintf("Orientation id #%d", i);
129  print_scores(i);
130  }
131 }

◆ set_best_orientation()

void OSResults::set_best_orientation ( int  orientation_id)

Definition at line 84 of file osdetect.cpp.

84  {
85  best_result.orientation_id = orientation_id;
87 }

◆ update_best_orientation()

void OSResults::update_best_orientation ( )

Definition at line 62 of file osdetect.cpp.

62  {
63  float first = orientations[0];
64  float second = orientations[1];
66  if (orientations[0] < orientations[1]) {
67  first = orientations[1];
68  second = orientations[0];
70  }
71  for (int i = 2; i < 4; ++i) {
72  if (orientations[i] > first) {
73  second = first;
74  first = orientations[i];
76  } else if (orientations[i] > second) {
77  second = orientations[i];
78  }
79  }
80  // Store difference of top two orientation scores.
81  best_result.oconfidence = first - second;
82 }

◆ update_best_script()

void OSResults::update_best_script ( int  orientation_id)

Definition at line 89 of file osdetect.cpp.

89  {
90  // We skip index 0 to ignore the "Common" script.
91  float first = scripts_na[orientation][1];
92  float second = scripts_na[orientation][2];
94  if (scripts_na[orientation][1] < scripts_na[orientation][2]) {
95  first = scripts_na[orientation][2];
96  second = scripts_na[orientation][1];
98  }
99  for (int i = 3; i < kMaxNumberOfScripts; ++i) {
100  if (scripts_na[orientation][i] > first) {
102  second = first;
103  first = scripts_na[orientation][i];
104  } else if (scripts_na[orientation][i] > second) {
105  second = scripts_na[orientation][i];
106  }
107  }
108  best_result.sconfidence = (second == 0.0f) ? 2.0f :
109  (first / second - 1.0) / (kScriptAcceptRatio - 1.0);
110 }

Member Data Documentation

◆ best_result

OSBestResult OSResults::best_result

Definition at line 81 of file osdetect.h.

◆ orientations

float OSResults::orientations[4]

Definition at line 76 of file osdetect.h.

◆ scripts_na

float OSResults::scripts_na[4][kMaxNumberOfScripts]

Definition at line 78 of file osdetect.h.

◆ unicharset

UNICHARSET* OSResults::unicharset

Definition at line 80 of file osdetect.h.


The documentation for this struct was generated from the following files:
OSResults::best_result
OSBestResult best_result
Definition: osdetect.h:81
OSBestResult::script_id
int script_id
Definition: osdetect.h:45
OSResults::update_best_orientation
void update_best_orientation()
Definition: osdetect.cpp:62
UNICHARSET::get_script_from_script_id
const char * get_script_from_script_id(int id) const
Definition: unicharset.h:844
kMaxNumberOfScripts
const int kMaxNumberOfScripts
Definition: osdetect.h:39
OSResults::unicharset
UNICHARSET * unicharset
Definition: osdetect.h:80
OSResults::print_scores
void print_scores(void) const
Definition: osdetect.cpp:126
OSBestResult::orientation_id
int orientation_id
Definition: osdetect.h:44
OSResults::scripts_na
float scripts_na[4][kMaxNumberOfScripts]
Definition: osdetect.h:78
OSBestResult::oconfidence
float oconfidence
Definition: osdetect.h:47
OSResults::orientations
float orientations[4]
Definition: osdetect.h:76
OSResults::update_best_script
void update_best_script(int orientation_id)
Definition: osdetect.cpp:89
kScriptAcceptRatio
const float kScriptAcceptRatio
Definition: osdetect.cpp:43
tprintf
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:34
OSBestResult::sconfidence
float sconfidence
Definition: osdetect.h:46