tesseract  4.0.0-1-g2a2b
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 49 of file osdetect.h.

Constructor & Destructor Documentation

◆ OSResults()

OSResults::OSResults ( )
inline

Definition at line 50 of file osdetect.h.

50  : unicharset(nullptr) {
51  for (int i = 0; i < 4; ++i) {
52  for (int j = 0; j < kMaxNumberOfScripts; ++j)
53  scripts_na[i][j] = 0;
54  orientations[i] = 0;
55  }
56  }
UNICHARSET * unicharset
Definition: osdetect.h:80
float scripts_na[4][kMaxNumberOfScripts]
Definition: osdetect.h:78
float orientations[4]
Definition: osdetect.h:76
const int kMaxNumberOfScripts
Definition: osdetect.h:38

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 }
UNICHARSET * unicharset
Definition: osdetect.h:80
void update_best_orientation()
Definition: osdetect.cpp:62
float scripts_na[4][kMaxNumberOfScripts]
Definition: osdetect.h:78
float orientations[4]
Definition: osdetect.h:76
OSBestResult best_result
Definition: osdetect.h:81
int orientation_id
Definition: osdetect.h:43
void update_best_script(int orientation_id)
Definition: osdetect.cpp:89
const int kMaxNumberOfScripts
Definition: osdetect.h:38

◆ 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 }
UNICHARSET * unicharset
Definition: osdetect.h:80
const char * get_script_from_script_id(int id) const
Definition: unicharset.h:849
float scripts_na[4][kMaxNumberOfScripts]
Definition: osdetect.h:78
const int kMaxNumberOfScripts
Definition: osdetect.h:38

◆ print_scores() [1/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 }
void print_scores(void) const
Definition: osdetect.cpp:126
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:37

◆ print_scores() [2/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 }
UNICHARSET * unicharset
Definition: osdetect.h:80
const char * get_script_from_script_id(int id) const
Definition: unicharset.h:849
float scripts_na[4][kMaxNumberOfScripts]
Definition: osdetect.h:78
const int kMaxNumberOfScripts
Definition: osdetect.h:38
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:37

◆ 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 }
OSBestResult best_result
Definition: osdetect.h:81
int orientation_id
Definition: osdetect.h:43
float oconfidence
Definition: osdetect.h:46

◆ 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 }
float orientations[4]
Definition: osdetect.h:76
OSBestResult best_result
Definition: osdetect.h:81
int orientation_id
Definition: osdetect.h:43
float oconfidence
Definition: osdetect.h:46

◆ 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  }
109  (first / second - 1.0) / (kScriptAcceptRatio - 1.0);
110 }
int script_id
Definition: osdetect.h:44
const float kScriptAcceptRatio
Definition: osdetect.cpp:43
float scripts_na[4][kMaxNumberOfScripts]
Definition: osdetect.h:78
float sconfidence
Definition: osdetect.h:45
OSBestResult best_result
Definition: osdetect.h:81
const int kMaxNumberOfScripts
Definition: osdetect.h:38

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: