tesseract 4.1.1
Loading...
Searching...
No Matches
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 }
const int kMaxNumberOfScripts
Definition: osdetect.h:38
float orientations[4]
Definition: osdetect.h:76
UNICHARSET * unicharset
Definition: osdetect.h:80
float scripts_na[4][kMaxNumberOfScripts]
Definition: osdetect.h:78

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 }
153}
int orientation_id
Definition: osdetect.h:43
OSBestResult best_result
Definition: osdetect.h:81
void update_best_script(int orientation_id)
Definition: osdetect.cpp:89
void update_best_orientation()
Definition: osdetect.cpp:62

◆ 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}
const char * get_script_from_script_id(int id) const
Definition: unicharset.h:854

◆ 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}
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:35

◆ 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}
void print_scores(void) const
Definition: osdetect.cpp:126

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

◆ 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}
const float kScriptAcceptRatio
Definition: osdetect.cpp:43
int script_id
Definition: osdetect.h:44
float sconfidence
Definition: osdetect.h:45

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: