tesseract  4.00.00dev
osdetect.h
Go to the documentation of this file.
1 // File: osdetect.h
3 // Description: Orientation and script detection.
4 // Author: Samuel Charron
5 // Ranjith Unnikrishnan
6 //
7 // (C) Copyright 2008, Google Inc.
8 // Licensed under the Apache License, Version 2.0 (the "License");
9 // you may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
12 // Unless required by applicable law or agreed to in writing, software
13 // distributed under the License is distributed on an "AS IS" BASIS,
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 // See the License for the specific language governing permissions and
16 // limitations under the License.
17 //
19 
20 #ifndef TESSERACT_CCMAIN_OSDETECT_H_
21 #define TESSERACT_CCMAIN_OSDETECT_H_
22 
23 #include "strngs.h"
24 #include "unicharset.h"
25 
26 class TO_BLOCK_LIST;
27 class BLOBNBOX;
28 class BLOB_CHOICE_LIST;
29 class BLOBNBOX_CLIST;
30 
31 namespace tesseract {
32 class Tesseract;
33 }
34 
35 // Max number of scripts in ICU + "NULL" + Japanese and Korean + Fraktur
36 const int kMaxNumberOfScripts = 116 + 1 + 2 + 1;
37 
38 struct OSBestResult {
39  OSBestResult() : orientation_id(0), script_id(0), sconfidence(0.0),
40  oconfidence(0.0) {}
42  int script_id;
43  float sconfidence;
44  float oconfidence;
45 };
46 
47 struct OSResults {
48  OSResults() : 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  }
55  void update_best_orientation();
56  // Set the estimate of the orientation to the given id.
57  void set_best_orientation(int orientation_id);
58  // Update/Compute the best estimate of the script assuming the given
59  // orientation id.
60  void update_best_script(int orientation_id);
61  // Return the index of the script with the highest score for this orientation.
62  TESS_API int get_best_script(int orientation_id) const;
63  // Accumulate scores with given OSResults instance and update the best script.
64  void accumulate(const OSResults& osr);
65 
66  // Print statistics.
67  void print_scores(void) const;
68  void print_scores(int orientation_id) const;
69 
70  // Array holding scores for each orientation id [0,3].
71  // Orientation ids [0..3] map to [0, 270, 180, 90] degree orientations of the
72  // page respectively, where the values refer to the amount of clockwise
73  // rotation to be applied to the page for the text to be upright and readable.
74  float orientations[4];
75  // Script confidence scores for each of 4 possible orientations.
76  float scripts_na[4][kMaxNumberOfScripts];
77 
80 };
81 
83  public:
84  OrientationDetector(const GenericVector<int>* allowed_scripts,
85  OSResults* results);
86  bool detect_blob(BLOB_CHOICE_LIST* scores);
87  int get_orientation();
88  private:
89  OSResults* osr_;
90  const GenericVector<int>* allowed_scripts_;
91 };
92 
94  public:
95  ScriptDetector(const GenericVector<int>* allowed_scripts,
96  OSResults* osr, tesseract::Tesseract* tess);
97  void detect_blob(BLOB_CHOICE_LIST* scores);
98  bool must_stop(int orientation);
99  private:
100  OSResults* osr_;
101  static const char* korean_script_;
102  static const char* japanese_script_;
103  static const char* fraktur_script_;
104  int korean_id_;
105  int japanese_id_;
106  int katakana_id_;
107  int hiragana_id_;
108  int han_id_;
109  int hangul_id_;
110  int latin_id_;
111  int fraktur_id_;
112  tesseract::Tesseract* tess_;
113  const GenericVector<int>* allowed_scripts_;
114 };
115 
117  OSResults*,
119 
120 int os_detect(TO_BLOCK_LIST* port_blocks,
121  OSResults* osr,
122  tesseract::Tesseract* tess);
123 
124 int os_detect_blobs(const GenericVector<int>* allowed_scripts,
125  BLOBNBOX_CLIST* blob_list,
126  OSResults* osr,
127  tesseract::Tesseract* tess);
128 
131  tesseract::Tesseract* tess);
132 
133 // Helper method to convert an orientation index to its value in degrees.
134 // The value represents the amount of clockwise rotation in degrees that must be
135 // applied for the text to be upright (readable).
136 TESS_API int OrientationIdToValue(const int& id);
137 
138 #endif // TESSERACT_CCMAIN_OSDETECT_H_
#define TESS_API
Definition: platform.h:81
int orientation_id
Definition: osdetect.h:41
UNICHARSET * unicharset
Definition: osdetect.h:78
int os_detect_blobs(const GenericVector< int > *allowed_scripts, BLOBNBOX_CLIST *blob_list, OSResults *osr, tesseract::Tesseract *tess)
Definition: osdetect.cpp:276
int os_detect(TO_BLOCK_LIST *port_blocks, OSResults *osr, tesseract::Tesseract *tess)
Definition: osdetect.cpp:234
TESS_API int OrientationIdToValue(const int &id)
Definition: osdetect.cpp:565
float oconfidence
Definition: osdetect.h:44
float sconfidence
Definition: osdetect.h:43
Definition: strngs.h:45
OSBestResult best_result
Definition: osdetect.h:79
int orientation_and_script_detection(STRING &filename, OSResults *, tesseract::Tesseract *)
Definition: osdetect.cpp:191
const char * filename
Definition: ioapi.h:38
OSBestResult()
Definition: osdetect.h:39
bool os_detect_blob(BLOBNBOX *bbox, OrientationDetector *o, ScriptDetector *s, OSResults *, tesseract::Tesseract *tess)
Definition: osdetect.cpp:325
int script_id
Definition: osdetect.h:42
const int kMaxNumberOfScripts
Definition: osdetect.h:36
OSResults()
Definition: osdetect.h:48