Tesseract  3.02
tesseract-ocr/ccmain/tesseractclass.h
Go to the documentation of this file.
00001 
00002 // File:        tesseractclass.h
00003 // Description: An instance of Tesseract. For thread safety, *every*
00004 //              global variable goes in here, directly, or indirectly.
00005 // Author:      Ray Smith
00006 // Created:     Fri Mar 07 08:17:01 PST 2008
00007 //
00008 // (C) Copyright 2008, Google Inc.
00009 // Licensed under the Apache License, Version 2.0 (the "License");
00010 // you may not use this file except in compliance with the License.
00011 // You may obtain a copy of the License at
00012 // http://www.apache.org/licenses/LICENSE-2.0
00013 // Unless required by applicable law or agreed to in writing, software
00014 // distributed under the License is distributed on an "AS IS" BASIS,
00015 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00016 // See the License for the specific language governing permissions and
00017 // limitations under the License.
00018 //
00020 
00021 #ifndef TESSERACT_CCMAIN_TESSERACTCLASS_H__
00022 #define TESSERACT_CCMAIN_TESSERACTCLASS_H__
00023 
00024 #include "allheaders.h"
00025 #include "control.h"
00026 #include "docqual.h"
00027 #include "devanagari_processing.h"
00028 #include "genericvector.h"
00029 #include "params.h"
00030 #include "ocrclass.h"
00031 #include "textord.h"
00032 #include "wordrec.h"
00033 
00034 // Include automatically generated configuration file if running autoconf.
00035 #ifdef HAVE_CONFIG_H
00036 #include "config_auto.h"
00037 #endif
00038 
00039 class PAGE_RES;
00040 class PAGE_RES_IT;
00041 class BLOCK_LIST;
00042 class CharSamp;
00043 class TO_BLOCK_LIST;
00044 class IMAGE;
00045 class WERD_RES;
00046 class ROW;
00047 class TBOX;
00048 class SVMenuNode;
00049 struct Pix;
00050 class WERD_CHOICE;
00051 class WERD;
00052 class BLOB_CHOICE_LIST_CLIST;
00053 struct OSResults;
00054 
00055 
00056 // Top-level class for all tesseract global instance data.
00057 // This class either holds or points to all data used by an instance
00058 // of Tesseract, including the memory allocator. When this is
00059 // complete, Tesseract will be thread-safe. UNTIL THEN, IT IS NOT!
00060 //
00061 // NOTE to developers: Do not create cyclic dependencies through this class!
00062 // The directory dependency tree must remain a tree! The keep this clean,
00063 // lower-level code (eg in ccutil, the bottom level) must never need to
00064 // know about the content of a higher-level directory.
00065 // The following scheme will grant the easiest access to lower-level
00066 // global members without creating a cyclic dependency:
00067 //
00068 // Class Hierarchy (^ = inheritance):
00069 //
00070 //             CCUtil (ccutil/ccutil.h)
00071 //                         ^      Members include: UNICHARSET
00072 //            CUtil (cutil/cutil_class.h)
00073 //                         ^       Members include: TBLOB*, TEXTBLOCK*
00074 //           CCStruct (ccstruct/ccstruct.h)
00075 //                         ^       Members include: Image
00076 //           Classify (classify/classify.h)
00077 //                         ^       Members include: Dict
00078 //             WordRec (wordrec/wordrec.h)
00079 //                         ^       Members include: WERD*, DENORM*
00080 //        Tesseract (ccmain/tesseractclass.h)
00081 //                                 Members include: Pix*, CubeRecoContext*,
00082 //                                 TesseractCubeCombiner*
00083 //
00084 // Other important classes:
00085 //
00086 //  TessBaseAPI (api/baseapi.h)
00087 //                                 Members include: BLOCK_LIST*, PAGE_RES*,
00088 //                                 Tesseract*, ImageThresholder*
00089 //  Dict (dict/dict.h)
00090 //                                 Members include: Image* (private)
00091 //
00092 // NOTE: that each level contains members that correspond to global
00093 // data that is defined (and used) at that level, not necessarily where
00094 // the type is defined so for instance:
00095 // BOOL_VAR_H(textord_show_blobs, false, "Display unsorted blobs");
00096 // goes inside the Textord class, not the cc_util class.
00097 
00098 namespace tesseract {
00099 
00100 class ColumnFinder;
00101 class CubeLineObject;
00102 class CubeObject;
00103 class CubeRecoContext;
00104 class EquationDetect;
00105 class Tesseract;
00106 class TesseractCubeCombiner;
00107 
00108 typedef void (Tesseract::*WordRecognizer)(BLOCK* block,
00109                                           ROW *row,
00110                                           WERD_RES *word);
00111 
00112 // A collection of various variables for statistics and debugging.
00113 struct TesseractStats {
00114   TesseractStats()
00115     : adaption_word_number(0),
00116       doc_blob_quality(0),
00117       doc_outline_errs(0),
00118       doc_char_quality(0),
00119       good_char_count(0),
00120       doc_good_char_quality(0),
00121       word_count(0),
00122       dict_words(0),
00123       tilde_crunch_written(false),
00124       last_char_was_newline(true),
00125       last_char_was_tilde(false),
00126       write_results_empty_block(true) {}
00127 
00128   inT32 adaption_word_number;
00129   inT16 doc_blob_quality;
00130   inT16 doc_outline_errs;
00131   inT16 doc_char_quality;
00132   inT16 good_char_count;
00133   inT16 doc_good_char_quality;
00134   inT32 word_count;  // count of word in the document
00135   inT32 dict_words;  // number of dicitionary words in the document
00136   STRING dump_words_str;  // accumulator used by dump_words()
00137   // Flags used by write_results()
00138   bool tilde_crunch_written;
00139   bool last_char_was_newline;
00140   bool last_char_was_tilde;
00141   bool write_results_empty_block;
00142 };
00143 
00144 class Tesseract : public Wordrec {
00145  public:
00146   Tesseract();
00147   ~Tesseract();
00148 
00149   // Clear as much used memory as possible without resetting the adaptive
00150   // classifier or losing any other classifier data.
00151   void Clear();
00152   // Clear all memory of adaption for this and all subclassifiers.
00153   void ResetAdaptiveClassifier();
00154   // Clear the document dictionary for this and all subclassifiers.
00155   void ResetDocumentDictionary();
00156 
00157   // Set the equation detector.
00158   void SetEquationDetect(EquationDetect* detector);
00159 
00160   // Simple accessors.
00161   const FCOORD& reskew() const {
00162     return reskew_;
00163   }
00164   // Destroy any existing pix and return a pointer to the pointer.
00165   Pix** mutable_pix_binary() {
00166     Clear();
00167     return &pix_binary_;
00168   }
00169   Pix* pix_binary() const {
00170     return pix_binary_;
00171   }
00172   Pix* pix_grey() const {
00173     return pix_grey_;
00174   }
00175   void set_pix_grey(Pix* grey_pix) {
00176     pixDestroy(&pix_grey_);
00177     pix_grey_ = grey_pix;
00178   }
00179   // Returns a pointer to a Pix representing the best available image of the
00180   // page. The image will be 8-bit grey if the input was grey or color. Note
00181   // that in grey 0 is black and 255 is white. If the input was binary, then
00182   // the returned Pix will be binary. Note that here black is 1 and white is 0.
00183   // To tell the difference pixGetDepth() will return 8 or 1.
00184   // In either case, the return value is a borrowed Pix, and should not be
00185   // deleted or pixDestroyed.
00186   Pix* BestPix() const {
00187     return pix_grey_ != NULL ? pix_grey_ : pix_binary_;
00188   }
00189   int source_resolution() const {
00190     return source_resolution_;
00191   }
00192   void set_source_resolution(int ppi) {
00193     source_resolution_ = ppi;
00194   }
00195   int ImageWidth() const {
00196     return pixGetWidth(pix_binary_);
00197   }
00198   int ImageHeight() const {
00199     return pixGetHeight(pix_binary_);
00200   }
00201   Pix* scaled_color() const {
00202     return scaled_color_;
00203   }
00204   int scaled_factor() const {
00205     return scaled_factor_;
00206   }
00207   void SetScaledColor(int factor, Pix* color) {
00208     scaled_factor_ = factor;
00209     scaled_color_ = color;
00210   }
00211   const Textord& textord() const {
00212     return textord_;
00213   }
00214   Textord* mutable_textord() {
00215     return &textord_;
00216   }
00217 
00218   bool right_to_left() const {
00219     return right_to_left_;
00220   }
00221   int num_sub_langs() const {
00222     return sub_langs_.size();
00223   }
00224   Tesseract* get_sub_lang(int index) const {
00225     return sub_langs_[index];
00226   }
00227 
00228   void SetBlackAndWhitelist();
00229 
00230   // Perform steps to prepare underlying binary image/other data structures for
00231   // page segmentation. Uses the strategy specified in the global variable
00232   // pageseg_devanagari_split_strategy for perform splitting while preparing for
00233   // page segmentation.
00234   void PrepareForPageseg();
00235 
00236   // Perform steps to prepare underlying binary image/other data structures for
00237   // Tesseract OCR. The current segmentation is required by this method.
00238   // Uses the strategy specified in the global variable
00239   // ocr_devanagari_split_strategy for performing splitting while preparing for
00240   // Tesseract ocr.
00241   void PrepareForTessOCR(BLOCK_LIST* block_list,
00242                          Tesseract* osd_tess, OSResults* osr);
00243 
00244   int SegmentPage(const STRING* input_file, BLOCK_LIST* blocks,
00245                   Tesseract* osd_tess, OSResults* osr);
00246   void SetupWordScripts(BLOCK_LIST* blocks);
00247   int AutoPageSeg(bool single_column, bool osd, bool only_osd,
00248                   BLOCK_LIST* blocks, TO_BLOCK_LIST* to_blocks,
00249                   Tesseract* osd_tess, OSResults* osr);
00250   ColumnFinder* SetupPageSegAndDetectOrientation(
00251       bool single_column, bool osd, bool only_osd,
00252       BLOCK_LIST* blocks, Tesseract* osd_tess, OSResults* osr,
00253       TO_BLOCK_LIST* to_blocks, Pix** photo_mask_pix, Pix** music_mask_pix);
00254 
00256   bool ProcessTargetWord(const TBOX& word_box, const TBOX& target_word_box,
00257                          const char* word_config, int pass);
00258   bool recog_all_words(PAGE_RES* page_res,
00259                        ETEXT_DESC* monitor,
00260                        const TBOX* target_word_box,
00261                        const char* word_config,
00262                        int dopasses);
00263   void rejection_passes(PAGE_RES* page_res,
00264                         ETEXT_DESC* monitor,
00265                         const TBOX* target_word_box,
00266                         const char* word_config);
00267   void bigram_correction_pass(PAGE_RES *page_res);
00268   void blamer_pass(PAGE_RES* page_res);
00269   // Helper to recognize the word using the given (language-specific) tesseract.
00270   // Returns true if the result was better than previously.
00271   bool RetryWithLanguage(WERD_RES *word, BLOCK* block, ROW *row,
00272                          WordRecognizer recognizer);
00273   void classify_word_and_language(WordRecognizer recognizer,
00274                                   BLOCK* block, ROW *row, WERD_RES *word);
00275   void classify_word_pass1(BLOCK* block, ROW *row, WERD_RES *word);
00276   void recog_pseudo_word(PAGE_RES* page_res,  // blocks to check
00277                          TBOX &selection_box);
00278 
00279   void fix_rep_char(PAGE_RES_IT* page_res_it);
00280   void ExplodeRepeatedWord(BLOB_CHOICE* best_choice, PAGE_RES_IT* page_res_it);
00281 
00282   ACCEPTABLE_WERD_TYPE acceptable_word_string(const UNICHARSET& char_set,
00283                                               const char *s,
00284                                               const char *lengths);
00285   void match_word_pass2(                 //recog one word
00286                         WERD_RES *word,  //word to do
00287                         ROW *row,
00288                         BLOCK* block);
00289   void classify_word_pass2(BLOCK* block, ROW *row, WERD_RES *word);
00290   void ReportXhtFixResult(bool accept_new_word, float new_x_ht,
00291                           WERD_RES* word, WERD_RES* new_word);
00292   bool RunOldFixXht(WERD_RES *word, BLOCK* block, ROW *row);
00293   bool TrainedXheightFix(WERD_RES *word, BLOCK* block, ROW *row);
00294   BOOL8 recog_interactive(BLOCK* block, ROW* row, WERD_RES* word_res);
00295 
00296   void set_word_fonts(
00297       WERD_RES *word,  // set fonts of this word
00298       BLOB_CHOICE_LIST_CLIST *blob_choices);  // detailed results
00299   void font_recognition_pass(PAGE_RES* page_res);
00300   BOOL8 check_debug_pt(WERD_RES *word, int location);
00301 
00303   bool init_cube_objects(bool load_combiner,
00304                          TessdataManager *tessdata_manager);
00305   // Iterates through tesseract's results and calls cube on each word,
00306   // combining the results with the existing tesseract result.
00307   void run_cube_combiner(PAGE_RES *page_res);
00308   // Recognizes a single word using (only) cube. Compatible with
00309   // Tesseract's classify_word_pass1/classify_word_pass2.
00310   void cube_word_pass1(BLOCK* block, ROW *row, WERD_RES *word);
00311   // Cube recognizer to recognize a single word as with classify_word_pass1
00312   // but also returns the cube object in case the combiner is needed.
00313   CubeObject* cube_recognize_word(BLOCK* block, WERD_RES* word);
00314   // Combines the cube and tesseract results for a single word, leaving the
00315   // result in tess_word.
00316   void cube_combine_word(CubeObject* cube_obj, WERD_RES* cube_word,
00317                         WERD_RES* tess_word);
00318   // Call cube on the current word, and write the result to word.
00319   // Sets up a fake result  and returns false if something goes wrong.
00320   bool cube_recognize(CubeObject *cube_obj, BLOCK* block, WERD_RES *word);
00321   void fill_werd_res(const BoxWord& cube_box_word,
00322                      WERD_CHOICE* cube_werd_choice,
00323                      const char* cube_best_str,
00324                      WERD_RES* tess_werd_res);
00325   bool extract_cube_state(CubeObject* cube_obj, int* num_chars,
00326                           Boxa** char_boxes, CharSamp*** char_samples);
00327   bool create_cube_box_word(Boxa *char_boxes, int num_chars,
00328                             TBOX word_box, BoxWord* box_word);
00330 
00331   void output_pass(PAGE_RES_IT &page_res_it, const TBOX *target_word_box);
00332   void write_results(PAGE_RES_IT &page_res_it,  // full info
00333                      char newline_type,         // type of newline
00334                      BOOL8 force_eol            // override tilde crunch?
00335                     );
00336   void set_unlv_suspects(WERD_RES *word);
00337   UNICHAR_ID get_rep_char(WERD_RES *word);  // what char is repeated?
00338   BOOL8 acceptable_number_string(const char *s,
00339                                  const char *lengths);
00340   inT16 count_alphanums(const WERD_CHOICE &word);
00341   inT16 count_alphas(const WERD_CHOICE &word);
00343   void read_config_file(const char *filename, SetParamConstraint constraint);
00344   // Initialize for potentially a set of languages defined by the language
00345   // string and recursively any additional languages required by any language
00346   // traineddata file (via tessedit_load_sublangs in its config) that is loaded.
00347   // See init_tesseract_internal for args.
00348   int init_tesseract(const char *arg0,
00349                      const char *textbase,
00350                      const char *language,
00351                      OcrEngineMode oem,
00352                      char **configs,
00353                      int configs_size,
00354                      const GenericVector<STRING> *vars_vec,
00355                      const GenericVector<STRING> *vars_values,
00356                      bool set_only_init_params);
00357   int init_tesseract(const char *datapath,
00358                      const char *language,
00359                      OcrEngineMode oem) {
00360     return init_tesseract(datapath, NULL, language, oem,
00361                           NULL, 0, NULL, NULL, false);
00362   }
00363   // Common initialization for a single language.
00364   // arg0 is the datapath for the tessdata directory, which could be the
00365   // path of the tessdata directory with no trailing /, or (if tessdata
00366   // lives in the same directory as the executable, the path of the executable,
00367   // hence the name arg0.
00368   // textbase is an optional output file basename (used only for training)
00369   // language is the language code to load.
00370   // oem controls which engine(s) will operate on the image
00371   // configs (argv) is an array of config filenames to load variables from.
00372   // May be NULL.
00373   // configs_size (argc) is the number of elements in configs.
00374   // vars_vec is an optional vector of variables to set.
00375   // vars_values is an optional corresponding vector of values for the variables
00376   // in vars_vec.
00377   // If set_only_init_params is true, then only the initialization variables
00378   // will be set.
00379   int init_tesseract_internal(const char *arg0,
00380                               const char *textbase,
00381                               const char *language,
00382                               OcrEngineMode oem,
00383                               char **configs,
00384                               int configs_size,
00385                               const GenericVector<STRING> *vars_vec,
00386                               const GenericVector<STRING> *vars_values,
00387                               bool set_only_init_params);
00388 
00389   // Set the universal_id member of each font to be unique among all
00390   // instances of the same font loaded.
00391   void SetupUniversalFontIds();
00392 
00393   int init_tesseract_lm(const char *arg0,
00394                         const char *textbase,
00395                         const char *language);
00396 
00397   void recognize_page(STRING& image_name);
00398   void end_tesseract();
00399 
00400   bool init_tesseract_lang_data(const char *arg0,
00401                                 const char *textbase,
00402                                 const char *language,
00403                                 OcrEngineMode oem,
00404                                 char **configs,
00405                                 int configs_size,
00406                                 const GenericVector<STRING> *vars_vec,
00407                                 const GenericVector<STRING> *vars_values,
00408                                 bool set_only_init_params);
00409 
00410   void ParseLanguageString(const char* lang_str,
00411                            GenericVector<STRING>* to_load,
00412                            GenericVector<STRING>* not_to_load);
00413 
00415   SVMenuNode *build_menu_new();
00416   #ifndef GRAPHICS_DISABLED
00417   void pgeditor_main(int width, int height, PAGE_RES* page_res);
00418   #endif  // GRAPHICS_DISABLED
00419   void process_image_event( // action in image win
00420                            const SVEvent &event);
00421   BOOL8 process_cmd_win_event(                 // UI command semantics
00422                               inT32 cmd_event,  // which menu item?
00423                               char *new_value   // any prompt data
00424                              );
00425   void debug_word(PAGE_RES* page_res, const TBOX &selection_box);
00426   void do_re_display(
00427       BOOL8 (tesseract::Tesseract::*word_painter)(BLOCK* block,
00428                                                   ROW* row,
00429                                                   WERD_RES* word_res));
00430   BOOL8 word_display(BLOCK* block, ROW* row, WERD_RES* word_res);
00431   BOOL8 word_bln_display(BLOCK* block, ROW* row, WERD_RES* word_res);
00432   BOOL8 word_blank_and_set_display(BLOCK* block, ROW* row, WERD_RES* word_res);
00433   BOOL8 word_set_display(BLOCK* block, ROW* row, WERD_RES* word_res);
00434   //#ifndef GRAPHICS_DISABLED
00435   BOOL8 word_dumper(BLOCK* block, ROW* row, WERD_RES* word_res);
00436   //#endif  // GRAPHICS_DISABLED
00438   void make_reject_map(            //make rej map for wd //detailed results
00439                        WERD_RES *word,
00440                        BLOB_CHOICE_LIST_CLIST *blob_choices,
00441                        ROW *row,
00442                        inT16 pass  //1st or 2nd?
00443                       );
00444   BOOL8 one_ell_conflict(WERD_RES *word_res, BOOL8 update_map);
00445   inT16 first_alphanum_index(const char *word,
00446                              const char *word_lengths);
00447   inT16 first_alphanum_offset(const char *word,
00448                               const char *word_lengths);
00449   inT16 alpha_count(const char *word,
00450                     const char *word_lengths);
00451   BOOL8 word_contains_non_1_digit(const char *word,
00452                                   const char *word_lengths);
00453   void dont_allow_1Il(WERD_RES *word);
00454   inT16 count_alphanums(  //how many alphanums
00455                         WERD_RES *word);
00456   void flip_0O(WERD_RES *word);
00457   BOOL8 non_0_digit(const UNICHARSET& ch_set, UNICHAR_ID unichar_id);
00458   BOOL8 non_O_upper(const UNICHARSET& ch_set, UNICHAR_ID unichar_id);
00459   BOOL8 repeated_nonalphanum_wd(WERD_RES *word, ROW *row);
00460   void nn_match_word(  //Match a word
00461                      WERD_RES *word,
00462                      ROW *row);
00463   void nn_recover_rejects(WERD_RES *word, ROW *row);
00464   BOOL8 test_ambig_word(  //test for ambiguity
00465                         WERD_RES *word);
00466   void set_done(  //set done flag
00467                 WERD_RES *word,
00468                 inT16 pass);
00469   inT16 safe_dict_word(const WERD_RES *werd_res);  // is best_choice in dict?
00470   void flip_hyphens(WERD_RES *word);
00471   void reject_I_1_L(WERD_RES *word);
00472   void reject_edge_blobs(WERD_RES *word);
00473   void reject_mostly_rejects(WERD_RES *word);
00475   BOOL8 word_adaptable(  //should we adapt?
00476                        WERD_RES *word,
00477                        uinT16 mode);
00478 
00480   void recog_word_recursive(WERD_RES* word,
00481                             BLOB_CHOICE_LIST_CLIST *blob_choices);
00482   void recog_word(WERD_RES *word,
00483                   BLOB_CHOICE_LIST_CLIST *blob_choices);
00484   void split_and_recog_word(WERD_RES* word,
00485                             BLOB_CHOICE_LIST_CLIST *blob_choices);
00487   BOOL8 digit_or_numeric_punct(WERD_RES *word, int char_position);
00488   inT16 eval_word_spacing(WERD_RES_LIST &word_res_list);
00489   void match_current_words(WERD_RES_LIST &words, ROW *row, BLOCK* block);
00490   inT16 fp_eval_word_spacing(WERD_RES_LIST &word_res_list);
00491   void fix_noisy_space_list(WERD_RES_LIST &best_perm, ROW *row, BLOCK* block);
00492   void fix_fuzzy_space_list(  //space explorer
00493                             WERD_RES_LIST &best_perm,
00494                             ROW *row,
00495                             BLOCK* block);
00496   void fix_sp_fp_word(WERD_RES_IT &word_res_it, ROW *row, BLOCK* block);
00497   void fix_fuzzy_spaces(                      //find fuzzy words
00498                         ETEXT_DESC *monitor,  //progress monitor
00499                         inT32 word_count,     //count of words in doc
00500                         PAGE_RES *page_res);
00501   void dump_words(WERD_RES_LIST &perm, inT16 score,
00502                   inT16 mode, BOOL8 improved);
00503   BOOL8 uniformly_spaced(WERD_RES *word);
00504   BOOL8 fixspace_thinks_word_done(WERD_RES *word);
00505   inT16 worst_noise_blob(WERD_RES *word_res, float *worst_noise_score);
00506   float blob_noise_score(TBLOB *blob);
00507   void break_noisiest_blob_word(WERD_RES_LIST &words);
00509   GARBAGE_LEVEL garbage_word(WERD_RES *word, BOOL8 ok_dict_word);
00510   BOOL8 potential_word_crunch(WERD_RES *word,
00511                               GARBAGE_LEVEL garbage_level,
00512                               BOOL8 ok_dict_word);
00513   void tilde_crunch(PAGE_RES_IT &page_res_it);
00514   void unrej_good_quality_words(  //unreject potential
00515                                 PAGE_RES_IT &page_res_it);
00516   void doc_and_block_rejection(  //reject big chunks
00517                                PAGE_RES_IT &page_res_it,
00518                                BOOL8 good_quality_doc);
00519   void quality_based_rejection(PAGE_RES_IT &page_res_it,
00520                                BOOL8 good_quality_doc);
00521   void convert_bad_unlv_chs(WERD_RES *word_res);
00522   void tilde_delete(PAGE_RES_IT &page_res_it);
00523   inT16 word_blob_quality(WERD_RES *word, ROW *row);
00524   void word_char_quality(WERD_RES *word, ROW *row, inT16 *match_count,
00525                          inT16 *accepted_match_count);
00526   void unrej_good_chs(WERD_RES *word, ROW *row);
00527   inT16 count_outline_errs(char c, inT16 outline_count);
00528   inT16 word_outline_errs(WERD_RES *word);
00529   BOOL8 terrible_word_crunch(WERD_RES *word, GARBAGE_LEVEL garbage_level);
00530   CRUNCH_MODE word_deletable(WERD_RES *word, inT16 &delete_mode);
00531   inT16 failure_count(WERD_RES *word);
00532   BOOL8 noise_outlines(TWERD *word);
00534   void
00535   process_selected_words (
00536       PAGE_RES* page_res, // blocks to check
00537       //function to call
00538       TBOX & selection_box,
00539       BOOL8 (tesseract::Tesseract::*word_processor) (BLOCK* block,
00540                                                      ROW* row,
00541                                                      WERD_RES* word_res));
00543   void tess_add_doc_word(                          //test acceptability
00544                          WERD_CHOICE *word_choice  //after context
00545                         );
00546   void tess_segment_pass1(WERD_RES *word,
00547                           BLOB_CHOICE_LIST_CLIST *blob_choices);
00548   void tess_segment_pass2(WERD_RES *word,
00549                           BLOB_CHOICE_LIST_CLIST *blob_choices);
00550   BOOL8 tess_acceptable_word(                           //test acceptability
00551                              WERD_CHOICE *word_choice,  //after context
00552                              WERD_CHOICE *raw_choice    //before context
00553                             );
00555   // Applies the box file based on the image name fname, and resegments
00556   // the words in the block_list (page), with:
00557   // blob-mode: one blob per line in the box file, words as input.
00558   // word/line-mode: one blob per space-delimited unit after the #, and one word
00559   // per line in the box file. (See comment above for box file format.)
00560   // If find_segmentation is true, (word/line mode) then the classifier is used
00561   // to re-segment words/lines to match the space-delimited truth string for
00562   // each box. In this case, the input box may be for a word or even a whole
00563   // text line, and the output words will contain multiple blobs corresponding
00564   // to the space-delimited input string.
00565   // With find_segmentation false, no classifier is needed, but the chopper
00566   // can still be used to correctly segment touching characters with the help
00567   // of the input boxes.
00568   // In the returned PAGE_RES, the WERD_RES are setup as they would be returned
00569   // from normal classification, ie. with a word, chopped_word, rebuild_word,
00570   // seam_array, denorm, box_word, and best_state, but NO best_choice or
00571   // raw_choice, as they would require a UNICHARSET, which we aim to avoid.
00572   // Instead, the correct_text member of WERD_RES is set, and this may be later
00573   // converted to a best_choice using CorrectClassifyWords. CorrectClassifyWords
00574   // is not required before calling ApplyBoxTraining.
00575   PAGE_RES* ApplyBoxes(const STRING& fname, bool find_segmentation,
00576                        BLOCK_LIST *block_list);
00577 
00578   // Builds a PAGE_RES from the block_list in the way required for ApplyBoxes:
00579   // All fuzzy spaces are removed, and all the words are maximally chopped.
00580   PAGE_RES* SetupApplyBoxes(const GenericVector<TBOX>& boxes,
00581                             BLOCK_LIST *block_list);
00582   // Tests the chopper by exhaustively running chop_one_blob.
00583   // The word_res will contain filled chopped_word, seam_array, denorm,
00584   // box_word and best_state for the maximally chopped word.
00585   void MaximallyChopWord(const GenericVector<TBOX>& boxes,
00586                          BLOCK* block, ROW* row, WERD_RES* word_res);
00587   // Gather consecutive blobs that match the given box into the best_state
00588   // and corresponding correct_text.
00589   // Fights over which box owns which blobs are settled by pre-chopping and
00590   // applying the blobs to box or next_box with the least non-overlap.
00591   // Returns false if the box was in error, which can only be caused by
00592   // failing to find an appropriate blob for a box.
00593   // This means that occasionally, blobs may be incorrectly segmented if the
00594   // chopper fails to find a suitable chop point.
00595   bool ResegmentCharBox(PAGE_RES* page_res, const TBOX *prev_box,
00596                         const TBOX& box, const TBOX& next_box,
00597                         const char* correct_text);
00598   // Consume all source blobs that strongly overlap the given box,
00599   // putting them into a new word, with the correct_text label.
00600   // Fights over which box owns which blobs are settled by
00601   // applying the blobs to box or next_box with the least non-overlap.
00602   // Returns false if the box was in error, which can only be caused by
00603   // failing to find an overlapping blob for a box.
00604   bool ResegmentWordBox(BLOCK_LIST *block_list,
00605                         const TBOX& box, const TBOX& next_box,
00606                         const char* correct_text);
00607   // Resegments the words by running the classifier in an attempt to find the
00608   // correct segmentation that produces the required string.
00609   void ReSegmentByClassification(PAGE_RES* page_res);
00610   // Converts the space-delimited string of utf8 text to a vector of UNICHAR_ID.
00611   // Returns false if an invalid UNICHAR_ID is encountered.
00612   bool ConvertStringToUnichars(const char* utf8,
00613                                GenericVector<UNICHAR_ID>* class_ids);
00614   // Resegments the word to achieve the target_text from the classifier.
00615   // Returns false if the re-segmentation fails.
00616   // Uses brute-force combination of upto kMaxGroupSize adjacent blobs, and
00617   // applies a full search on the classifier results to find the best classified
00618   // segmentation. As a compromise to obtain better recall, 1-1 ambigiguity
00619   // substitutions ARE used.
00620   bool FindSegmentation(const GenericVector<UNICHAR_ID>& target_text,
00621                         WERD_RES* word_res);
00622   // Recursive helper to find a match to the target_text (from text_index
00623   // position) in the choices (from choices_pos position).
00624   // Choices is an array of GenericVectors, of length choices_length, with each
00625   // element representing a starting position in the word, and the
00626   // GenericVector holding classification results for a sequence of consecutive
00627   // blobs, with index 0 being a single blob, index 1 being 2 blobs etc.
00628   void SearchForText(const GenericVector<BLOB_CHOICE_LIST*>* choices,
00629                      int choices_pos, int choices_length,
00630                      const GenericVector<UNICHAR_ID>& target_text,
00631                      int text_index,
00632                      float rating, GenericVector<int>* segmentation,
00633                      float* best_rating, GenericVector<int>* best_segmentation);
00634   // Counts up the labelled words and the blobs within.
00635   // Deletes all unused or emptied words, counting the unused ones.
00636   // Resets W_BOL and W_EOL flags correctly.
00637   // Builds the rebuild_word and rebuilds the box_word.
00638   void TidyUp(PAGE_RES* page_res);
00639   // Logs a bad box by line in the box file and box coords.
00640   void ReportFailedBox(int boxfile_lineno, TBOX box, const char *box_ch,
00641                        const char *err_msg);
00642   // Creates a fake best_choice entry in each WERD_RES with the correct text.
00643   void CorrectClassifyWords(PAGE_RES* page_res);
00644   // Call LearnWord to extract features for labelled blobs within each word.
00645   // Features are written to the given filename.
00646   void ApplyBoxTraining(const STRING& filename, PAGE_RES* page_res);
00647 
00649   // Returns the number of misfit blob tops in this word.
00650   int CountMisfitTops(WERD_RES *word_res);
00651   // Returns a new x-height in pixels (original image coords) that is
00652   // maximally compatible with the result in word_res.
00653   // Returns 0.0f if no x-height is found that is better than the current
00654   // estimate.
00655   float ComputeCompatibleXheight(WERD_RES *word_res);
00657   // TODO(ocr-team): Remove obsolete parameters.
00658   BOOL_VAR_H(tessedit_resegment_from_boxes, false,
00659              "Take segmentation and labeling from box file");
00660   BOOL_VAR_H(tessedit_resegment_from_line_boxes, false,
00661               "Conversion of word/line box file to char box file");
00662   BOOL_VAR_H(tessedit_train_from_boxes, false,
00663              "Generate training data from boxed chars");
00664   BOOL_VAR_H(tessedit_make_boxes_from_boxes, false,
00665              "Generate more boxes from boxed chars");
00666   BOOL_VAR_H(tessedit_dump_pageseg_images, false,
00667              "Dump intermediate images made during page segmentation");
00668   INT_VAR_H(tessedit_pageseg_mode, PSM_SINGLE_BLOCK,
00669             "Page seg mode: 0=osd only, 1=auto+osd, 2=auto, 3=col, 4=block,"
00670             " 5=line, 6=word, 7=char"
00671             " (Values from PageSegMode enum in publictypes.h)");
00672   INT_VAR_H(tessedit_ocr_engine_mode, tesseract::OEM_TESSERACT_ONLY,
00673             "Which OCR engine(s) to run (Tesseract, Cube, both). Defaults"
00674             " to loading and running only Tesseract (no Cube, no combiner)."
00675             " (Values from OcrEngineMode enum in tesseractclass.h)");
00676   STRING_VAR_H(tessedit_char_blacklist, "",
00677                "Blacklist of chars not to recognize");
00678   STRING_VAR_H(tessedit_char_whitelist, "",
00679                "Whitelist of chars to recognize");
00680   BOOL_VAR_H(tessedit_ambigs_training, false,
00681              "Perform training for ambiguities");
00682   INT_VAR_H(pageseg_devanagari_split_strategy,
00683             tesseract::ShiroRekhaSplitter::NO_SPLIT,
00684             "Whether to use the top-line splitting process for Devanagari "
00685             "documents while performing page-segmentation.");
00686   INT_VAR_H(ocr_devanagari_split_strategy,
00687             tesseract::ShiroRekhaSplitter::NO_SPLIT,
00688             "Whether to use the top-line splitting process for Devanagari "
00689             "documents while performing ocr.");
00690   STRING_VAR_H(tessedit_write_params_to_file, "",
00691                "Write all parameters to the given file.");
00692   BOOL_VAR_H(tessedit_adapt_to_char_fragments, true,
00693              "Adapt to words that contain "
00694              " a character composed form fragments");
00695   BOOL_VAR_H(tessedit_adaption_debug, false,
00696              "Generate and print debug information for adaption");
00697   INT_VAR_H(bidi_debug, 0, "Debug level for BiDi");
00698   INT_VAR_H(applybox_debug, 1, "Debug level");
00699   INT_VAR_H(applybox_page, 0, "Page number to apply boxes from");
00700   STRING_VAR_H(applybox_exposure_pattern, ".exp",
00701                "Exposure value follows this pattern in the image"
00702                " filename. The name of the image files are expected"
00703                " to be in the form [lang].[fontname].exp[num].tif");
00704   BOOL_VAR_H(applybox_learn_chars_and_char_frags_mode, false,
00705              "Learn both character fragments (as is done in the"
00706              " special low exposure mode) as well as unfragmented"
00707              " characters.");
00708   BOOL_VAR_H(applybox_learn_ngrams_mode, false,
00709              "Each bounding box is assumed to contain ngrams. Only"
00710              " learn the ngrams whose outlines overlap horizontally.");
00711   BOOL_VAR_H(tessedit_display_outwords, false, "Draw output words");
00712   BOOL_VAR_H(tessedit_training_tess, false, "Call Tess to learn blobs");
00713   BOOL_VAR_H(tessedit_dump_choices, false, "Dump char choices");
00714   BOOL_VAR_H(tessedit_fix_fuzzy_spaces, true,
00715              "Try to improve fuzzy spaces");
00716   BOOL_VAR_H(tessedit_unrej_any_wd, false,
00717              "Dont bother with word plausibility");
00718   BOOL_VAR_H(tessedit_fix_hyphens, true, "Crunch double hyphens?");
00719   BOOL_VAR_H(tessedit_redo_xheight, true, "Check/Correct x-height");
00720   BOOL_VAR_H(tessedit_enable_doc_dict, true,
00721              "Add words to the document dictionary");
00722   BOOL_VAR_H(tessedit_debug_fonts, false, "Output font info per char");
00723   BOOL_VAR_H(tessedit_debug_block_rejection, false, "Block and Row stats");
00724   BOOL_VAR_H(tessedit_enable_bigram_correction, false,
00725              "Enable correction based on the word bigram dictionary.");
00726   INT_VAR_H(tessedit_bigram_debug, 0, "Amount of debug output for bigram "
00727             "correction.");
00728   INT_VAR_H(debug_x_ht_level, 0, "Reestimate debug");
00729   BOOL_VAR_H(debug_acceptable_wds, false, "Dump word pass/fail chk");
00730   STRING_VAR_H(chs_leading_punct, "('`\"", "Leading punctuation");
00731   STRING_VAR_H(chs_trailing_punct1, ").,;:?!", "1st Trailing punctuation");
00732   STRING_VAR_H(chs_trailing_punct2, ")'`\"", "2nd Trailing punctuation");
00733   double_VAR_H(quality_rej_pc, 0.08, "good_quality_doc lte rejection limit");
00734   double_VAR_H(quality_blob_pc, 0.0, "good_quality_doc gte good blobs limit");
00735   double_VAR_H(quality_outline_pc, 1.0,
00736                "good_quality_doc lte outline error limit");
00737   double_VAR_H(quality_char_pc, 0.95, "good_quality_doc gte good char limit");
00738   INT_VAR_H(quality_min_initial_alphas_reqd, 2, "alphas in a good word");
00739   BOOL_VAR_H(tessedit_tess_adapt_to_rejmap, false,
00740              "Use reject map to control Tesseract adaption");
00741   INT_VAR_H(tessedit_tess_adaption_mode, 0x27,
00742             "Adaptation decision algorithm for tess");
00743   BOOL_VAR_H(tessedit_minimal_rej_pass1, false,
00744              "Do minimal rejection on pass 1 output");
00745   BOOL_VAR_H(tessedit_test_adaption, false, "Test adaption criteria");
00746   BOOL_VAR_H(tessedit_matcher_log, false, "Log matcher activity");
00747   INT_VAR_H(tessedit_test_adaption_mode, 3,
00748             "Adaptation decision algorithm for tess");
00749   BOOL_VAR_H(save_blob_choices, false,
00750              "Save the results of the recognition step"
00751              " (blob_choices) within the corresponding WERD_CHOICE");
00752   BOOL_VAR_H(test_pt, false, "Test for point");
00753   double_VAR_H(test_pt_x, 99999.99, "xcoord");
00754   double_VAR_H(test_pt_y, 99999.99, "ycoord");
00755   INT_VAR_H(paragraph_debug_level, 0, "Print paragraph debug info.");
00756   INT_VAR_H(cube_debug_level, 1, "Print cube debug info.");
00757   STRING_VAR_H(outlines_odd, "%| ", "Non standard number of outlines");
00758   STRING_VAR_H(outlines_2, "ij!?%\":;", "Non standard number of outlines");
00759   BOOL_VAR_H(docqual_excuse_outline_errs, false,
00760              "Allow outline errs in unrejection?");
00761   BOOL_VAR_H(tessedit_good_quality_unrej, true,
00762              "Reduce rejection on good docs");
00763   BOOL_VAR_H(tessedit_use_reject_spaces, true, "Reject spaces?");
00764   double_VAR_H(tessedit_reject_doc_percent, 65.00,
00765                "%rej allowed before rej whole doc");
00766   double_VAR_H(tessedit_reject_block_percent, 45.00,
00767                "%rej allowed before rej whole block");
00768   double_VAR_H(tessedit_reject_row_percent, 40.00,
00769                "%rej allowed before rej whole row");
00770   double_VAR_H(tessedit_whole_wd_rej_row_percent, 70.00,
00771                "Number of row rejects in whole word rejects"
00772                "which prevents whole row rejection");
00773   BOOL_VAR_H(tessedit_preserve_blk_rej_perfect_wds, true,
00774              "Only rej partially rejected words in block rejection");
00775   BOOL_VAR_H(tessedit_preserve_row_rej_perfect_wds, true,
00776              "Only rej partially rejected words in row rejection");
00777   BOOL_VAR_H(tessedit_dont_blkrej_good_wds, false,
00778              "Use word segmentation quality metric");
00779   BOOL_VAR_H(tessedit_dont_rowrej_good_wds, false,
00780              "Use word segmentation quality metric");
00781   INT_VAR_H(tessedit_preserve_min_wd_len, 2,
00782             "Only preserve wds longer than this");
00783   BOOL_VAR_H(tessedit_row_rej_good_docs, true,
00784              "Apply row rejection to good docs");
00785   double_VAR_H(tessedit_good_doc_still_rowrej_wd, 1.1,
00786                "rej good doc wd if more than this fraction rejected");
00787   BOOL_VAR_H(tessedit_reject_bad_qual_wds, true,
00788              "Reject all bad quality wds");
00789   BOOL_VAR_H(tessedit_debug_doc_rejection, false, "Page stats");
00790   BOOL_VAR_H(tessedit_debug_quality_metrics, false,
00791              "Output data to debug file");
00792   BOOL_VAR_H(bland_unrej, false, "unrej potential with no chekcs");
00793   double_VAR_H(quality_rowrej_pc, 1.1,
00794                "good_quality_doc gte good char limit");
00795   BOOL_VAR_H(unlv_tilde_crunching, true,
00796              "Mark v.bad words for tilde crunch");
00797   BOOL_VAR_H(crunch_early_merge_tess_fails, true, "Before word crunch?");
00798   BOOL_VAR_H(crunch_early_convert_bad_unlv_chs, false, "Take out ~^ early?");
00799   double_VAR_H(crunch_terrible_rating, 80.0, "crunch rating lt this");
00800   BOOL_VAR_H(crunch_terrible_garbage, true, "As it says");
00801   double_VAR_H(crunch_poor_garbage_cert, -9.0,
00802                "crunch garbage cert lt this");
00803   double_VAR_H(crunch_poor_garbage_rate, 60, "crunch garbage rating lt this");
00804   double_VAR_H(crunch_pot_poor_rate, 40, "POTENTIAL crunch rating lt this");
00805   double_VAR_H(crunch_pot_poor_cert, -8.0, "POTENTIAL crunch cert lt this");
00806   BOOL_VAR_H(crunch_pot_garbage, true, "POTENTIAL crunch garbage");
00807   double_VAR_H(crunch_del_rating, 60, "POTENTIAL crunch rating lt this");
00808   double_VAR_H(crunch_del_cert, -10.0, "POTENTIAL crunch cert lt this");
00809   double_VAR_H(crunch_del_min_ht, 0.7, "Del if word ht lt xht x this");
00810   double_VAR_H(crunch_del_max_ht, 3.0, "Del if word ht gt xht x this");
00811   double_VAR_H(crunch_del_min_width, 3.0, "Del if word width lt xht x this");
00812   double_VAR_H(crunch_del_high_word, 1.5,
00813                "Del if word gt xht x this above bl");
00814   double_VAR_H(crunch_del_low_word, 0.5, "Del if word gt xht x this below bl");
00815   double_VAR_H(crunch_small_outlines_size, 0.6, "Small if lt xht x this");
00816   INT_VAR_H(crunch_rating_max, 10, "For adj length in rating per ch");
00817   INT_VAR_H(crunch_pot_indicators, 1, "How many potential indicators needed");
00818   BOOL_VAR_H(crunch_leave_ok_strings, true, "Dont touch sensible strings");
00819   BOOL_VAR_H(crunch_accept_ok, true, "Use acceptability in okstring");
00820   BOOL_VAR_H(crunch_leave_accept_strings, false,
00821              "Dont pot crunch sensible strings");
00822   BOOL_VAR_H(crunch_include_numerals, false, "Fiddle alpha figures");
00823   INT_VAR_H(crunch_leave_lc_strings, 4,
00824             "Dont crunch words with long lower case strings");
00825   INT_VAR_H(crunch_leave_uc_strings, 4,
00826             "Dont crunch words with long lower case strings");
00827   INT_VAR_H(crunch_long_repetitions, 3, "Crunch words with long repetitions");
00828   INT_VAR_H(crunch_debug, 0, "As it says");
00829   INT_VAR_H(fixsp_non_noise_limit, 1,
00830             "How many non-noise blbs either side?");
00831   double_VAR_H(fixsp_small_outlines_size, 0.28, "Small if lt xht x this");
00832   BOOL_VAR_H(tessedit_prefer_joined_punct, false, "Reward punctation joins");
00833   INT_VAR_H(fixsp_done_mode, 1, "What constitues done for spacing");
00834   INT_VAR_H(debug_fix_space_level, 0, "Contextual fixspace debug");
00835   STRING_VAR_H(numeric_punctuation, ".,",
00836                "Punct. chs expected WITHIN numbers");
00837   INT_VAR_H(x_ht_acceptance_tolerance, 8,
00838             "Max allowed deviation of blob top outside of font data");
00839   INT_VAR_H(x_ht_min_change, 8, "Min change in xht before actually trying it");
00840   BOOL_VAR_H(tessedit_write_block_separators, false,
00841              "Write block separators in output");
00842   BOOL_VAR_H(tessedit_write_rep_codes, false,
00843              "Write repetition char code");
00844   BOOL_VAR_H(tessedit_write_unlv, false, "Write .unlv output file");
00845   BOOL_VAR_H(tessedit_create_hocr, false, "Write .html hOCR output file");
00846   STRING_VAR_H(unrecognised_char, "|",
00847                "Output char for unidentified blobs");
00848   INT_VAR_H(suspect_level, 99, "Suspect marker level");
00849   INT_VAR_H(suspect_space_level, 100,
00850             "Min suspect level for rejecting spaces");
00851   INT_VAR_H(suspect_short_words, 2,
00852             "Dont Suspect dict wds longer than this");
00853   BOOL_VAR_H(suspect_constrain_1Il, false, "UNLV keep 1Il chars rejected");
00854   double_VAR_H(suspect_rating_per_ch, 999.9, "Dont touch bad rating limit");
00855   double_VAR_H(suspect_accept_rating, -999.9, "Accept good rating limit");
00856   BOOL_VAR_H(tessedit_minimal_rejection, false, "Only reject tess failures");
00857   BOOL_VAR_H(tessedit_zero_rejection, false, "Dont reject ANYTHING");
00858   BOOL_VAR_H(tessedit_word_for_word, false,
00859              "Make output have exactly one word per WERD");
00860   BOOL_VAR_H(tessedit_zero_kelvin_rejection, false,
00861              "Dont reject ANYTHING AT ALL");
00862   BOOL_VAR_H(tessedit_consistent_reps, true, "Force all rep chars the same");
00863   INT_VAR_H(tessedit_reject_mode, 0, "Rejection algorithm");
00864   INT_VAR_H(tessedit_ok_mode, 5, "Acceptance decision algorithm");
00865   BOOL_VAR_H(tessedit_rejection_debug, false, "Adaption debug");
00866   BOOL_VAR_H(tessedit_flip_0O, true, "Contextual 0O O0 flips");
00867   double_VAR_H(tessedit_lower_flip_hyphen, 1.5,
00868                "Aspect ratio dot/hyphen test");
00869   double_VAR_H(tessedit_upper_flip_hyphen, 1.8,
00870                "Aspect ratio dot/hyphen test");
00871   BOOL_VAR_H(rej_trust_doc_dawg, false, "Use DOC dawg in 11l conf. detector");
00872   BOOL_VAR_H(rej_1Il_use_dict_word, false, "Use dictword test");
00873   BOOL_VAR_H(rej_1Il_trust_permuter_type, true, "Dont double check");
00874   BOOL_VAR_H(rej_use_tess_accepted, true, "Individual rejection control");
00875   BOOL_VAR_H(rej_use_tess_blanks, true, "Individual rejection control");
00876   BOOL_VAR_H(rej_use_good_perm, true, "Individual rejection control");
00877   BOOL_VAR_H(rej_use_sensible_wd, false, "Extend permuter check");
00878   BOOL_VAR_H(rej_alphas_in_number_perm, false, "Extend permuter check");
00879   double_VAR_H(rej_whole_of_mostly_reject_word_fract, 0.85, "if >this fract");
00880   INT_VAR_H(tessedit_image_border, 2, "Rej blbs near image edge limit");
00881   STRING_VAR_H(ok_repeated_ch_non_alphanum_wds, "-?*\075",
00882                "Allow NN to unrej");
00883   STRING_VAR_H(conflict_set_I_l_1, "Il1[]", "Il1 conflict set");
00884   INT_VAR_H(min_sane_x_ht_pixels, 8, "Reject any x-ht lt or eq than this");
00885   BOOL_VAR_H(tessedit_create_boxfile, false, "Output text with boxes");
00886   INT_VAR_H(tessedit_page_number, -1,
00887             "-1 -> All pages, else specifc page to process");
00888   BOOL_VAR_H(tessedit_write_images, false, "Capture the image from the IPE");
00889   BOOL_VAR_H(interactive_display_mode, false, "Run interactively?");
00890   STRING_VAR_H(file_type, ".tif", "Filename extension");
00891   BOOL_VAR_H(tessedit_override_permuter, true, "According to dict_word");
00892   INT_VAR_H(tessdata_manager_debug_level, 0,
00893             "Debug level for TessdataManager functions.");
00894   STRING_VAR_H(tessedit_load_sublangs, "",
00895                "List of languages to load with this one");
00896   // Min acceptable orientation margin (difference in scores between top and 2nd
00897   // choice in OSResults::orientations) to believe the page orientation.
00898   double_VAR_H(min_orientation_margin, 7.0,
00899                "Min acceptable orientation margin");
00900   BOOL_VAR_H(textord_tabfind_show_vlines, false, "Debug line finding");
00901   BOOL_VAR_H(textord_use_cjk_fp_model, FALSE, "Use CJK fixed pitch model");
00902   BOOL_VAR_H(tessedit_init_config_only, false,
00903              "Only initialize with the config file. Useful if the instance is "
00904              "not going to be used for OCR but say only for layout analysis.");
00905   BOOL_VAR_H(textord_equation_detect, false, "Turn on equation detector");
00906 
00908   FILE *init_recog_training(const STRING &fname);
00909   void recog_training_segmented(const STRING &fname,
00910                                 PAGE_RES *page_res,
00911                                 volatile ETEXT_DESC *monitor,
00912                                 FILE *output_file);
00913   void ambigs_classify_and_output(WERD_RES *werd_res,
00914                                   ROW_RES *row_res,
00915                                   BLOCK_RES *block_res,
00916                                   const char *label,
00917                                   FILE *output_file);
00918 
00919   inline CubeRecoContext *GetCubeRecoContext() { return cube_cntxt_; }
00920 
00921  private:
00922   // The filename of a backup config file. If not null, then we currently
00923   // have a temporary debug config file loaded, and backup_config_file_
00924   // will be loaded, and set to null when debug is complete.
00925   const char* backup_config_file_;
00926   // The filename of a config file to read when processing a debug word.
00927   STRING word_config_;
00928   // Image used for input to layout analysis and tesseract recognition.
00929   // May be modified by the ShiroRekhaSplitter to eliminate the top-line.
00930   Pix* pix_binary_;
00931   // Unmodified image used for input to cube. Always valid.
00932   Pix* cube_binary_;
00933   // Grey-level input image if the input was not binary, otherwise NULL.
00934   Pix* pix_grey_;
00935   // Input image resolution after any scaling. The resolution is not well
00936   // transmitted by operations on Pix, so we keep an independent record here.
00937   int source_resolution_;
00938   // The shiro-rekha splitter object which is used to split top-lines in
00939   // Devanagari words to provide a better word and grapheme segmentation.
00940   ShiroRekhaSplitter splitter_;
00941   // Page segmentation/layout
00942   Textord textord_;
00943   // True if the primary language uses right_to_left reading order.
00944   bool right_to_left_;
00945   Pix* scaled_color_;
00946   int scaled_factor_;
00947   FCOORD deskew_;
00948   FCOORD reskew_;
00949   TesseractStats stats_;
00950   // Sub-languages to be tried in addition to this.
00951   GenericVector<Tesseract*> sub_langs_;
00952   // Most recently used Tesseract out of this and sub_langs_. The default
00953   // language for the next word.
00954   Tesseract* most_recently_used_;
00955   // The size of the font table, ie max possible font id + 1.
00956   int font_table_size_;
00957   // Cube objects.
00958   CubeRecoContext* cube_cntxt_;
00959   TesseractCubeCombiner *tess_cube_combiner_;
00960   // Equation detector. Note: this pointer is NOT owned by the class.
00961   EquationDetect* equ_detect_;
00962 };
00963 
00964 }  // namespace tesseract
00965 
00966 
00967 #endif  // TESSERACT_CCMAIN_TESSERACTCLASS_H__