00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00019
00020 #ifndef TESSERACT_CCMAIN_OSDETECT_H__
00021 #define TESSERACT_CCMAIN_OSDETECT_H__
00022
00023 #include "strngs.h"
00024 #include "unicharset.h"
00025
00026 class TO_BLOCK_LIST;
00027 class BLOBNBOX;
00028 class BLOB_CHOICE_LIST;
00029 class BLOBNBOX_CLIST;
00030
00031 namespace tesseract {
00032 class Tesseract;
00033 }
00034
00035
00036 const int kMaxNumberOfScripts = 116 + 1 + 2 + 1;
00037
00038 struct OSBestResult {
00039 OSBestResult() : orientation_id(0), script_id(0), sconfidence(0.0),
00040 oconfidence(0.0) {}
00041 int orientation_id;
00042 int script_id;
00043 float sconfidence;
00044 float oconfidence;
00045 };
00046
00047 struct OSResults {
00048 OSResults() : unicharset(NULL) {
00049 for (int i = 0; i < 4; ++i) {
00050 for (int j = 0; j < kMaxNumberOfScripts; ++j)
00051 scripts_na[i][j] = 0;
00052 orientations[i] = 0;
00053 }
00054 }
00055 void update_best_orientation();
00056
00057 void set_best_orientation(int orientation_id);
00058
00059
00060 void update_best_script(int orientation_id);
00061
00062 int get_best_script(int orientation_id) const;
00063
00064 void accumulate(const OSResults& osr);
00065
00066
00067 void print_scores(void) const;
00068 void print_scores(int orientation_id) const;
00069
00070
00071
00072
00073
00074 float orientations[4];
00075
00076 float scripts_na[4][kMaxNumberOfScripts];
00077
00078 UNICHARSET* unicharset;
00079 OSBestResult best_result;
00080 };
00081
00082 class OrientationDetector {
00083 public:
00084 OrientationDetector(OSResults*);
00085 bool detect_blob(BLOB_CHOICE_LIST* scores);
00086 int get_orientation();
00087 private:
00088 OSResults* osr_;
00089 };
00090
00091 class ScriptDetector {
00092 public:
00093 ScriptDetector(OSResults*, tesseract::Tesseract* tess);
00094 void detect_blob(BLOB_CHOICE_LIST* scores);
00095 void get_script() ;
00096 bool must_stop(int orientation);
00097 private:
00098 OSResults* osr_;
00099 static const char* korean_script_;
00100 static const char* japanese_script_;
00101 static const char* fraktur_script_;
00102 int korean_id_;
00103 int japanese_id_;
00104 int katakana_id_;
00105 int hiragana_id_;
00106 int han_id_;
00107 int hangul_id_;
00108 int latin_id_;
00109 int fraktur_id_;
00110 tesseract::Tesseract* tess_;
00111 };
00112
00113 int orientation_and_script_detection(STRING& filename,
00114 OSResults*,
00115 tesseract::Tesseract*);
00116
00117 int os_detect(TO_BLOCK_LIST* port_blocks,
00118 OSResults* osr,
00119 tesseract::Tesseract* tess);
00120
00121 int os_detect_blobs(BLOBNBOX_CLIST* blob_list,
00122 OSResults* osr,
00123 tesseract::Tesseract* tess);
00124
00125 bool os_detect_blob(BLOBNBOX* bbox, OrientationDetector* o,
00126 ScriptDetector* s, OSResults*,
00127 tesseract::Tesseract* tess);
00128
00129
00130
00131
00132 const int OrientationIdToValue(const int& id);
00133
00134 #endif // TESSERACT_CCMAIN_OSDETECT_H__