tesseract 4.1.1
Loading...
Searching...
No Matches
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 "platform.h" // for TESS_API
24
25class BLOBNBOX;
26class BLOBNBOX_CLIST;
27class BLOB_CHOICE_LIST;
28class STRING;
29class TO_BLOCK_LIST;
30class UNICHARSET;
31template <typename T> class GenericVector;
32
33namespace tesseract {
34class Tesseract;
35}
36
37// Max number of scripts in ICU + "NULL" + Japanese and Korean + Fraktur
38const int kMaxNumberOfScripts = 116 + 1 + 2 + 1;
39
42 oconfidence(0.0) {}
47};
48
49struct OSResults {
50 OSResults() : 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 }
58 // Set the estimate of the orientation to the given id.
59 void set_best_orientation(int orientation_id);
60 // Update/Compute the best estimate of the script assuming the given
61 // orientation id.
62 void update_best_script(int orientation_id);
63 // Return the index of the script with the highest score for this orientation.
64 TESS_API int get_best_script(int orientation_id) const;
65 // Accumulate scores with given OSResults instance and update the best script.
66 void accumulate(const OSResults& osr);
67
68 // Print statistics.
69 void print_scores(void) const;
70 void print_scores(int orientation_id) const;
71
72 // Array holding scores for each orientation id [0,3].
73 // Orientation ids [0..3] map to [0, 270, 180, 90] degree orientations of the
74 // page respectively, where the values refer to the amount of clockwise
75 // rotation to be applied to the page for the text to be upright and readable.
76 float orientations[4];
77 // Script confidence scores for each of 4 possible orientations.
79
82};
83
85 public:
86 OrientationDetector(const GenericVector<int>* allowed_scripts,
87 OSResults* results);
88 bool detect_blob(BLOB_CHOICE_LIST* scores);
89 int get_orientation();
90 private:
91 OSResults* osr_;
92 const GenericVector<int>* allowed_scripts_;
93};
94
96 public:
97 ScriptDetector(const GenericVector<int>* allowed_scripts,
99 void detect_blob(BLOB_CHOICE_LIST* scores);
100 bool must_stop(int orientation);
101 private:
102 OSResults* osr_;
103 static const char* korean_script_;
104 static const char* japanese_script_;
105 static const char* fraktur_script_;
106 int korean_id_;
107 int japanese_id_;
108 int katakana_id_;
109 int hiragana_id_;
110 int han_id_;
111 int hangul_id_;
112 int latin_id_;
113 int fraktur_id_;
115 const GenericVector<int>* allowed_scripts_;
116};
117
119 OSResults*,
121
122int os_detect(TO_BLOCK_LIST* port_blocks,
123 OSResults* osr,
125
126int os_detect_blobs(const GenericVector<int>* allowed_scripts,
127 BLOBNBOX_CLIST* blob_list,
128 OSResults* osr,
130
134
135// Helper method to convert an orientation index to its value in degrees.
136// The value represents the amount of clockwise rotation in degrees that must be
137// applied for the text to be upright (readable).
138TESS_API int OrientationIdToValue(const int& id);
139
140#endif // TESSERACT_CCMAIN_OSDETECT_H_
TESS_API int OrientationIdToValue(const int &id)
Definition: osdetect.cpp:566
int os_detect(TO_BLOCK_LIST *port_blocks, OSResults *osr, tesseract::Tesseract *tess)
Definition: osdetect.cpp:233
const int kMaxNumberOfScripts
Definition: osdetect.h:38
bool os_detect_blob(BLOBNBOX *bbox, OrientationDetector *o, ScriptDetector *s, OSResults *, tesseract::Tesseract *tess)
Definition: osdetect.cpp:329
int os_detect_blobs(const GenericVector< int > *allowed_scripts, BLOBNBOX_CLIST *blob_list, OSResults *osr, tesseract::Tesseract *tess)
Definition: osdetect.cpp:278
int orientation_and_script_detection(STRING &filename, OSResults *, tesseract::Tesseract *)
Definition: osdetect.cpp:190
#define TESS_API
Definition: platform.h:54
int script_id
Definition: osdetect.h:44
OSBestResult()
Definition: osdetect.h:41
float oconfidence
Definition: osdetect.h:46
int orientation_id
Definition: osdetect.h:43
float sconfidence
Definition: osdetect.h:45
OSResults()
Definition: osdetect.h:50
void accumulate(const OSResults &osr)
Definition: osdetect.cpp:144
OSBestResult best_result
Definition: osdetect.h:81
float orientations[4]
Definition: osdetect.h:76
UNICHARSET * unicharset
Definition: osdetect.h:80
void set_best_orientation(int orientation_id)
Definition: osdetect.cpp:84
void update_best_script(int orientation_id)
Definition: osdetect.cpp:89
TESS_API int get_best_script(int orientation_id) const
Definition: osdetect.cpp:112
void print_scores(void) const
Definition: osdetect.cpp:126
float scripts_na[4][kMaxNumberOfScripts]
Definition: osdetect.h:78
void update_best_orientation()
Definition: osdetect.cpp:62
bool detect_blob(BLOB_CHOICE_LIST *scores)
Definition: osdetect.cpp:382
bool must_stop(int orientation)
Definition: osdetect.cpp:558
void detect_blob(BLOB_CHOICE_LIST *scores)
Definition: osdetect.cpp:471
Definition: strngs.h:45