tesseract  5.0.0
tesseract::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()

tesseract::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  }
55  orientations[i] = 0;
56  }
57  }
const int kMaxNumberOfScripts
Definition: osdetect.h:38
UNICHARSET * unicharset
Definition: osdetect.h:81
float scripts_na[4][kMaxNumberOfScripts]
Definition: osdetect.h:79
float orientations[4]
Definition: osdetect.h:77

Member Function Documentation

◆ accumulate()

void tesseract::OSResults::accumulate ( const OSResults osr)

Definition at line 145 of file osdetect.cpp.

145  {
146  for (int i = 0; i < 4; ++i) {
147  orientations[i] += osr.orientations[i];
148  for (int j = 0; j < kMaxNumberOfScripts; ++j) {
149  scripts_na[i][j] += osr.scripts_na[i][j];
150  }
151  }
152  unicharset = osr.unicharset;
155 }
OSBestResult best_result
Definition: osdetect.h:82
void update_best_orientation()
Definition: osdetect.cpp:63
void update_best_script(int orientation_id)
Definition: osdetect.cpp:90

◆ get_best_script()

int tesseract::OSResults::get_best_script ( int  orientation_id) const

Definition at line 113 of file osdetect.cpp.

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

◆ print_scores() [1/2]

void tesseract::OSResults::print_scores ( int  orientation_id) const

Definition at line 135 of file osdetect.cpp.

135  {
136  for (int j = 0; j < kMaxNumberOfScripts; ++j) {
137  if (scripts_na[orientation_id][j]) {
138  tprintf("%12s\t: %f\n", unicharset->get_script_from_script_id(j),
139  scripts_na[orientation_id][j]);
140  }
141  }
142 }
void tprintf(const char *format,...)
Definition: tprintf.cpp:41

◆ print_scores() [2/2]

void tesseract::OSResults::print_scores ( void  ) const

Definition at line 127 of file osdetect.cpp.

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

◆ set_best_orientation()

void tesseract::OSResults::set_best_orientation ( int  orientation_id)

Definition at line 85 of file osdetect.cpp.

85  {
86  best_result.orientation_id = orientation_id;
88 }

◆ update_best_orientation()

void tesseract::OSResults::update_best_orientation ( )

Definition at line 63 of file osdetect.cpp.

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

◆ update_best_script()

void tesseract::OSResults::update_best_script ( int  orientation_id)

Definition at line 90 of file osdetect.cpp.

90  {
91  // We skip index 0 to ignore the "Common" script.
92  float first = scripts_na[orientation][1];
93  float second = scripts_na[orientation][2];
95  if (scripts_na[orientation][1] < scripts_na[orientation][2]) {
96  first = scripts_na[orientation][2];
97  second = scripts_na[orientation][1];
99  }
100  for (int i = 3; i < kMaxNumberOfScripts; ++i) {
101  if (scripts_na[orientation][i] > first) {
103  second = first;
104  first = scripts_na[orientation][i];
105  } else if (scripts_na[orientation][i] > second) {
106  second = scripts_na[orientation][i];
107  }
108  }
110  (second == 0.0f) ? 2.0f : (first / second - 1.0) / (kScriptAcceptRatio - 1.0);
111 }
const float kScriptAcceptRatio
Definition: osdetect.cpp:44

Member Data Documentation

◆ best_result

OSBestResult tesseract::OSResults::best_result

Definition at line 82 of file osdetect.h.

◆ orientations

float tesseract::OSResults::orientations[4]

Definition at line 77 of file osdetect.h.

◆ scripts_na

float tesseract::OSResults::scripts_na[4][kMaxNumberOfScripts]

Definition at line 79 of file osdetect.h.

◆ unicharset

UNICHARSET* tesseract::OSResults::unicharset

Definition at line 81 of file osdetect.h.


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