tesseract  4.00.00dev
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 47 of file osdetect.h.

Constructor & Destructor Documentation

◆ OSResults()

OSResults::OSResults ( )
inline

Definition at line 48 of file osdetect.h.

48  : unicharset(NULL) {
49  for (int i = 0; i < 4; ++i) {
50  for (int j = 0; j < kMaxNumberOfScripts; ++j)
51  scripts_na[i][j] = 0;
52  orientations[i] = 0;
53  }
54  }
float scripts_na[4][kMaxNumberOfScripts]
Definition: osdetect.h:76
UNICHARSET * unicharset
Definition: osdetect.h:78
float orientations[4]
Definition: osdetect.h:74
const int kMaxNumberOfScripts
Definition: osdetect.h:36

Member Function Documentation

◆ accumulate()

void OSResults::accumulate ( const OSResults osr)

Definition at line 146 of file osdetect.cpp.

146  {
147  for (int i = 0; i < 4; ++i) {
148  orientations[i] += osr.orientations[i];
149  for (int j = 0; j < kMaxNumberOfScripts; ++j)
150  scripts_na[i][j] += osr.scripts_na[i][j];
151  }
152  unicharset = osr.unicharset;
155 }
void update_best_orientation()
Definition: osdetect.cpp:64
float scripts_na[4][kMaxNumberOfScripts]
Definition: osdetect.h:76
int orientation_id
Definition: osdetect.h:41
UNICHARSET * unicharset
Definition: osdetect.h:78
void update_best_script(int orientation_id)
Definition: osdetect.cpp:91
float orientations[4]
Definition: osdetect.h:74
OSBestResult best_result
Definition: osdetect.h:79
const int kMaxNumberOfScripts
Definition: osdetect.h:36

◆ get_best_script()

int OSResults::get_best_script ( int  orientation_id) const

Definition at line 114 of file osdetect.cpp.

114  {
115  int max_id = -1;
116  for (int j = 0; j < kMaxNumberOfScripts; ++j) {
117  const char *script = unicharset->get_script_from_script_id(j);
118  if (strcmp(script, "Common") && strcmp(script, "NULL")) {
119  if (max_id == -1 ||
120  scripts_na[orientation_id][j] > scripts_na[orientation_id][max_id])
121  max_id = j;
122  }
123  }
124  return max_id;
125 }
float scripts_na[4][kMaxNumberOfScripts]
Definition: osdetect.h:76
const char * get_script_from_script_id(int id) const
Definition: unicharset.h:814
UNICHARSET * unicharset
Definition: osdetect.h:78
const int kMaxNumberOfScripts
Definition: osdetect.h:36

◆ print_scores() [1/2]

void OSResults::print_scores ( void  ) const

Definition at line 128 of file osdetect.cpp.

128  {
129  for (int i = 0; i < 4; ++i) {
130  tprintf("Orientation id #%d", i);
131  print_scores(i);
132  }
133 }
#define tprintf(...)
Definition: tprintf.h:31
void print_scores(void) const
Definition: osdetect.cpp:128

◆ print_scores() [2/2]

void OSResults::print_scores ( int  orientation_id) const

Definition at line 136 of file osdetect.cpp.

136  {
137  for (int j = 0; j < kMaxNumberOfScripts; ++j) {
138  if (scripts_na[orientation_id][j]) {
139  tprintf("%12s\t: %f\n", unicharset->get_script_from_script_id(j),
140  scripts_na[orientation_id][j]);
141  }
142  }
143 }
float scripts_na[4][kMaxNumberOfScripts]
Definition: osdetect.h:76
const char * get_script_from_script_id(int id) const
Definition: unicharset.h:814
UNICHARSET * unicharset
Definition: osdetect.h:78
#define tprintf(...)
Definition: tprintf.h:31
const int kMaxNumberOfScripts
Definition: osdetect.h:36

◆ set_best_orientation()

void OSResults::set_best_orientation ( int  orientation_id)

Definition at line 86 of file osdetect.cpp.

86  {
87  best_result.orientation_id = orientation_id;
89 }
int orientation_id
Definition: osdetect.h:41
float oconfidence
Definition: osdetect.h:44
OSBestResult best_result
Definition: osdetect.h:79

◆ update_best_orientation()

void OSResults::update_best_orientation ( )

Definition at line 64 of file osdetect.cpp.

64  {
65  float first = orientations[0];
66  float second = orientations[1];
68  if (orientations[0] < orientations[1]) {
69  first = orientations[1];
70  second = orientations[0];
72  }
73  for (int i = 2; i < 4; ++i) {
74  if (orientations[i] > first) {
75  second = first;
76  first = orientations[i];
78  } else if (orientations[i] > second) {
79  second = orientations[i];
80  }
81  }
82  // Store difference of top two orientation scores.
83  best_result.oconfidence = first - second;
84 }
int orientation_id
Definition: osdetect.h:41
float oconfidence
Definition: osdetect.h:44
float orientations[4]
Definition: osdetect.h:74
OSBestResult best_result
Definition: osdetect.h:79

◆ update_best_script()

void OSResults::update_best_script ( int  orientation_id)

Definition at line 91 of file osdetect.cpp.

91  {
92  // We skip index 0 to ignore the "Common" script.
93  float first = scripts_na[orientation][1];
94  float second = scripts_na[orientation][2];
96  if (scripts_na[orientation][1] < scripts_na[orientation][2]) {
97  first = scripts_na[orientation][2];
98  second = scripts_na[orientation][1];
100  }
101  for (int i = 3; i < kMaxNumberOfScripts; ++i) {
102  if (scripts_na[orientation][i] > first) {
104  second = first;
105  first = scripts_na[orientation][i];
106  } else if (scripts_na[orientation][i] > second) {
107  second = scripts_na[orientation][i];
108  }
109  }
111  (first / second - 1.0) / (kScriptAcceptRatio - 1.0);
112 }
float scripts_na[4][kMaxNumberOfScripts]
Definition: osdetect.h:76
float sconfidence
Definition: osdetect.h:43
OSBestResult best_result
Definition: osdetect.h:79
const float kScriptAcceptRatio
Definition: osdetect.cpp:42
int script_id
Definition: osdetect.h:42
const int kMaxNumberOfScripts
Definition: osdetect.h:36

Member Data Documentation

◆ best_result

OSBestResult OSResults::best_result

Definition at line 79 of file osdetect.h.

◆ orientations

float OSResults::orientations[4]

Definition at line 74 of file osdetect.h.

◆ scripts_na

float OSResults::scripts_na[4][kMaxNumberOfScripts]

Definition at line 76 of file osdetect.h.

◆ unicharset

UNICHARSET* OSResults::unicharset

Definition at line 78 of file osdetect.h.


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