Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
osdetect.h
Go to the documentation of this file.
1 
2 // 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 {
40  oconfidence(0.0) {}
42  int script_id;
43  float sconfidence;
44  float oconfidence;
45 };
46 
47 struct OSResults {
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  }
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  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.
77 
80 };
81 
83  public:
85  bool detect_blob(BLOB_CHOICE_LIST* scores);
86  int get_orientation();
87  private:
88  OSResults* osr_;
89 };
90 
92  public:
94  void detect_blob(BLOB_CHOICE_LIST* scores);
95  void get_script() ;
96  bool must_stop(int orientation);
97  private:
98  OSResults* osr_;
99  static const char* korean_script_;
100  static const char* japanese_script_;
101  static const char* fraktur_script_;
102  int korean_id_;
103  int japanese_id_;
104  int katakana_id_;
105  int hiragana_id_;
106  int han_id_;
107  int hangul_id_;
108  int latin_id_;
109  int fraktur_id_;
110  tesseract::Tesseract* tess_;
111 };
112 
114  OSResults*,
116 
117 int os_detect(TO_BLOCK_LIST* port_blocks,
118  OSResults* osr,
119  tesseract::Tesseract* tess);
120 
121 int os_detect_blobs(BLOBNBOX_CLIST* blob_list,
122  OSResults* osr,
123  tesseract::Tesseract* tess);
124 
127  tesseract::Tesseract* tess);
128 
129 // Helper method to convert an orientation index to its value in degrees.
130 // The value represents the amount of clockwise rotation in degrees that must be
131 // applied for the text to be upright (readable).
132 const int OrientationIdToValue(const int& id);
133 
134 #endif // TESSERACT_CCMAIN_OSDETECT_H__