tesseract  3.03
/usr/local/google/home/jbreiden/tesseract-ocr-read-only/classify/classify.h
Go to the documentation of this file.
00001 
00002 // File:        classify.h
00003 // Description: classify class.
00004 // Author:      Samuel Charron
00005 //
00006 // (C) Copyright 2006, Google Inc.
00007 // Licensed under the Apache License, Version 2.0 (the "License");
00008 // you may not use this file except in compliance with the License.
00009 // You may obtain a copy of the License at
00010 // http://www.apache.org/licenses/LICENSE-2.0
00011 // Unless required by applicable law or agreed to in writing, software
00012 // distributed under the License is distributed on an "AS IS" BASIS,
00013 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014 // See the License for the specific language governing permissions and
00015 // limitations under the License.
00016 //
00018 
00019 #ifndef TESSERACT_CLASSIFY_CLASSIFY_H__
00020 #define TESSERACT_CLASSIFY_CLASSIFY_H__
00021 
00022 #include "adaptive.h"
00023 #include "ccstruct.h"
00024 #include "classify.h"
00025 #include "dict.h"
00026 #include "featdefs.h"
00027 #include "fontinfo.h"
00028 #include "intfx.h"
00029 #include "intmatcher.h"
00030 #include "normalis.h"
00031 #include "ratngs.h"
00032 #include "ocrfeatures.h"
00033 #include "unicity_table.h"
00034 
00035 class ScrollView;
00036 class WERD_CHOICE;
00037 class WERD_RES;
00038 struct ADAPT_RESULTS;
00039 struct NORM_PROTOS;
00040 
00041 static const int kUnknownFontinfoId = -1;
00042 static const int kBlankFontinfoId = -2;
00043 
00044 namespace tesseract {
00045 
00046 class ShapeClassifier;
00047 struct ShapeRating;
00048 class ShapeTable;
00049 struct UnicharRating;
00050 
00051 // How segmented is a blob. In this enum, character refers to a classifiable
00052 // unit, but that is too long and character is usually easier to understand.
00053 enum CharSegmentationType {
00054   CST_FRAGMENT,  // A partial character.
00055   CST_WHOLE,     // A correctly segmented character.
00056   CST_IMPROPER,  // More than one but less than 2 characters.
00057   CST_NGRAM      // Multiple characters.
00058 };
00059 
00060 class Classify : public CCStruct {
00061  public:
00062   Classify();
00063   virtual ~Classify();
00064   Dict& getDict() {
00065     return dict_;
00066   }
00067 
00068   const ShapeTable* shape_table() const {
00069     return shape_table_;
00070   }
00071 
00072   // Takes ownership of the given classifier, and uses it for future calls
00073   // to CharNormClassifier.
00074   void SetStaticClassifier(ShapeClassifier* static_classifier);
00075 
00076   // Adds a noise classification result that is a bit worse than the worst
00077   // current result, or the worst possible result if no current results.
00078   void AddLargeSpeckleTo(int blob_length, BLOB_CHOICE_LIST *choices);
00079 
00080   // Returns true if the blob is small enough to be a large speckle.
00081   bool LargeSpeckle(const TBLOB &blob);
00082 
00083   /* adaptive.cpp ************************************************************/
00084   ADAPT_TEMPLATES NewAdaptedTemplates(bool InitFromUnicharset);
00085   int GetFontinfoId(ADAPT_CLASS Class, uinT8 ConfigId);
00086   // Runs the class pruner from int_templates on the given features, returning
00087   // the number of classes output in results.
00088   //    int_templates          Class pruner tables
00089   //    num_features           Number of features in blob
00090   //    features               Array of features
00091   //    normalization_factors  (input) Array of int_templates->NumClasses fudge
00092   //                           factors from blob normalization process.
00093   //                           (Indexed by CLASS_INDEX)
00094   //    expected_num_features  (input) Array of int_templates->NumClasses
00095   //                           expected number of features for each class.
00096   //                           (Indexed by CLASS_INDEX)
00097   //    results                (output) Sorted Array of pruned classes.
00098   //                           Array must be sized to take the maximum possible
00099   //                           number of outputs : int_templates->NumClasses.
00100   int PruneClasses(const INT_TEMPLATES_STRUCT* int_templates,
00101                    int num_features,
00102                    const INT_FEATURE_STRUCT* features,
00103                    const uinT8* normalization_factors,
00104                    const uinT16* expected_num_features,
00105                    GenericVector<CP_RESULT_STRUCT>* results);
00106   void ReadNewCutoffs(FILE *CutoffFile, bool swap, inT64 end_offset,
00107                       CLASS_CUTOFF_ARRAY Cutoffs);
00108   void PrintAdaptedTemplates(FILE *File, ADAPT_TEMPLATES Templates);
00109   void WriteAdaptedTemplates(FILE *File, ADAPT_TEMPLATES Templates);
00110   ADAPT_TEMPLATES ReadAdaptedTemplates(FILE *File);
00111   /* normmatch.cpp ************************************************************/
00112   FLOAT32 ComputeNormMatch(CLASS_ID ClassId,
00113                            const FEATURE_STRUCT& feature, BOOL8 DebugMatch);
00114   void FreeNormProtos();
00115   NORM_PROTOS *ReadNormProtos(FILE *File, inT64 end_offset);
00116   /* protos.cpp ***************************************************************/
00117   void ConvertProto(PROTO Proto, int ProtoId, INT_CLASS Class);
00118   INT_TEMPLATES CreateIntTemplates(CLASSES FloatProtos,
00119                                    const UNICHARSET& target_unicharset);
00120   /* adaptmatch.cpp ***********************************************************/
00121 
00122   // Learn the given word using its chopped_word, seam_array, denorm,
00123   // box_word, best_state, and correct_text to learn both correctly and
00124   // incorrectly segmented blobs. If filename is not NULL, then LearnBlob
00125   // is called and the data will be written to a file for static training.
00126   // Otherwise AdaptToBlob is called for adaption within a document.
00127   void LearnWord(const char* filename, WERD_RES *word);
00128 
00129   // Builds a blob of length fragments, from the word, starting at start,
00130   // and then learn it, as having the given correct_text.
00131   // If filename is not NULL, then LearnBlob
00132   // is called and the data will be written to a file for static training.
00133   // Otherwise AdaptToBlob is called for adaption within a document.
00134   // threshold is a magic number required by AdaptToChar and generated by
00135   // GetAdaptThresholds.
00136   // Although it can be partly inferred from the string, segmentation is
00137   // provided to explicitly clarify the character segmentation.
00138   void LearnPieces(const char* filename, int start, int length,
00139                    float threshold, CharSegmentationType segmentation,
00140                    const char* correct_text, WERD_RES *word);
00141   void InitAdaptiveClassifier(bool load_pre_trained_templates);
00142   void InitAdaptedClass(TBLOB *Blob,
00143                         CLASS_ID ClassId,
00144                         int FontinfoId,
00145                         ADAPT_CLASS Class,
00146                         ADAPT_TEMPLATES Templates);
00147   void AmbigClassifier(const GenericVector<INT_FEATURE_STRUCT>& int_features,
00148                        const INT_FX_RESULT_STRUCT& fx_info,
00149                        const TBLOB *blob,
00150                        INT_TEMPLATES templates,
00151                        ADAPT_CLASS *classes,
00152                        UNICHAR_ID *ambiguities,
00153                        ADAPT_RESULTS *results);
00154   void MasterMatcher(INT_TEMPLATES templates,
00155                      inT16 num_features,
00156                      const INT_FEATURE_STRUCT* features,
00157                      const uinT8* norm_factors,
00158                      ADAPT_CLASS* classes,
00159                      int debug,
00160                      int matcher_multiplier,
00161                      const TBOX& blob_box,
00162                      const GenericVector<CP_RESULT_STRUCT>& results,
00163                      ADAPT_RESULTS* final_results);
00164   // Converts configs to fonts, and if the result is not adapted, and a
00165   // shape_table_ is present, the shape is expanded to include all
00166   // unichar_ids represented, before applying a set of corrections to the
00167   // distance rating in int_result, (see ComputeCorrectedRating.)
00168   // The results are added to the final_results output.
00169   void ExpandShapesAndApplyCorrections(ADAPT_CLASS* classes,
00170                                        bool debug,
00171                                        int class_id,
00172                                        int bottom, int top,
00173                                        float cp_rating,
00174                                        int blob_length,
00175                                        int matcher_multiplier,
00176                                        const uinT8* cn_factors,
00177                                        INT_RESULT_STRUCT& int_result,
00178                                        ADAPT_RESULTS* final_results);
00179   // Applies a set of corrections to the distance im_rating,
00180   // including the cn_correction, miss penalty and additional penalty
00181   // for non-alnums being vertical misfits. Returns the corrected distance.
00182   double ComputeCorrectedRating(bool debug, int unichar_id, double cp_rating,
00183                                 double im_rating, int feature_misses,
00184                                 int bottom, int top,
00185                                 int blob_length, int matcher_multiplier,
00186                                 const uinT8* cn_factors);
00187   void ConvertMatchesToChoices(const DENORM& denorm, const TBOX& box,
00188                                ADAPT_RESULTS *Results,
00189                                BLOB_CHOICE_LIST *Choices);
00190   void AddNewResult(ADAPT_RESULTS *results,
00191                     CLASS_ID class_id,
00192                     int shape_id,
00193                     FLOAT32 rating,
00194                     bool adapted,
00195                     int config,
00196                     int fontinfo_id,
00197                     int fontinfo_id2);
00198   int GetAdaptiveFeatures(TBLOB *Blob,
00199                           INT_FEATURE_ARRAY IntFeatures,
00200                           FEATURE_SET *FloatFeatures);
00201 
00202 #ifndef GRAPHICS_DISABLED
00203   void DebugAdaptiveClassifier(TBLOB *Blob,
00204                                ADAPT_RESULTS *Results);
00205 #endif
00206   PROTO_ID MakeNewTempProtos(FEATURE_SET Features,
00207                              int NumBadFeat,
00208                              FEATURE_ID BadFeat[],
00209                              INT_CLASS IClass,
00210                              ADAPT_CLASS Class,
00211                              BIT_VECTOR TempProtoMask);
00212   int MakeNewTemporaryConfig(ADAPT_TEMPLATES Templates,
00213                              CLASS_ID ClassId,
00214                              int FontinfoId,
00215                              int NumFeatures,
00216                              INT_FEATURE_ARRAY Features,
00217                              FEATURE_SET FloatFeatures);
00218   void MakePermanent(ADAPT_TEMPLATES Templates,
00219                      CLASS_ID ClassId,
00220                      int ConfigId,
00221                      TBLOB *Blob);
00222   void PrintAdaptiveMatchResults(FILE *File, ADAPT_RESULTS *Results);
00223   void RemoveExtraPuncs(ADAPT_RESULTS *Results);
00224   void RemoveBadMatches(ADAPT_RESULTS *Results);
00225   void SetAdaptiveThreshold(FLOAT32 Threshold);
00226   void ShowBestMatchFor(int shape_id,
00227                         const INT_FEATURE_STRUCT* features,
00228                         int num_features);
00229   // Returns a string for the classifier class_id: either the corresponding
00230   // unicharset debug_str or the shape_table_ debug str.
00231   STRING ClassIDToDebugStr(const INT_TEMPLATES_STRUCT* templates,
00232                            int class_id, int config_id) const;
00233   // Converts a classifier class_id index with a config ID to:
00234   // shape_table_ present: a shape_table_ index OR
00235   // No shape_table_: a font ID.
00236   // Without shape training, each class_id, config pair represents a single
00237   // unichar id/font combination, so this function looks up the corresponding
00238   // font id.
00239   // With shape training, each class_id, config pair represents a single
00240   // shape table index, so the fontset_table stores the shape table index,
00241   // and the shape_table_ must be consulted to obtain the actual unichar_id/
00242   // font combinations that the shape represents.
00243   int ClassAndConfigIDToFontOrShapeID(int class_id,
00244                                       int int_result_config) const;
00245   // Converts a shape_table_ index to a classifier class_id index (not a
00246   // unichar-id!). Uses a search, so not fast.
00247   int ShapeIDToClassID(int shape_id) const;
00248   UNICHAR_ID *BaselineClassifier(
00249       TBLOB *Blob, const GenericVector<INT_FEATURE_STRUCT>& int_features,
00250       const INT_FX_RESULT_STRUCT& fx_info,
00251       ADAPT_TEMPLATES Templates, ADAPT_RESULTS *Results);
00252   int CharNormClassifier(TBLOB *blob,
00253                          const TrainingSample& sample,
00254                          ADAPT_RESULTS *adapt_results);
00255 
00256   // As CharNormClassifier, but operates on a TrainingSample and outputs to
00257   // a GenericVector of ShapeRating without conversion to classes.
00258   int CharNormTrainingSample(bool pruner_only, int keep_this,
00259                              const TrainingSample& sample,
00260                              GenericVector<UnicharRating>* results);
00261   UNICHAR_ID *GetAmbiguities(TBLOB *Blob, CLASS_ID CorrectClass);
00262   void DoAdaptiveMatch(TBLOB *Blob, ADAPT_RESULTS *Results);
00263   void AdaptToChar(TBLOB *Blob,
00264                    CLASS_ID ClassId,
00265                    int FontinfoId,
00266                    FLOAT32 Threshold);
00267   void DisplayAdaptedChar(TBLOB* blob, INT_CLASS_STRUCT* int_class);
00268   bool AdaptableWord(WERD_RES* word);
00269   void EndAdaptiveClassifier();
00270   void SettupPass1();
00271   void SettupPass2();
00272   void AdaptiveClassifier(TBLOB *Blob, BLOB_CHOICE_LIST *Choices);
00273   void ClassifyAsNoise(ADAPT_RESULTS *Results);
00274   void ResetAdaptiveClassifierInternal();
00275 
00276   int GetCharNormFeature(const INT_FX_RESULT_STRUCT& fx_info,
00277                          INT_TEMPLATES templates,
00278                          uinT8* pruner_norm_array,
00279                          uinT8* char_norm_array);
00280   // Computes the char_norm_array for the unicharset and, if not NULL, the
00281   // pruner_array as appropriate according to the existence of the shape_table.
00282   // The norm_feature is deleted as it is almost certainly no longer needed.
00283   void ComputeCharNormArrays(FEATURE_STRUCT* norm_feature,
00284                              INT_TEMPLATES_STRUCT* templates,
00285                              uinT8* char_norm_array,
00286                              uinT8* pruner_array);
00287 
00288   bool TempConfigReliable(CLASS_ID class_id, const TEMP_CONFIG &config);
00289   void UpdateAmbigsGroup(CLASS_ID class_id, TBLOB *Blob);
00290 
00291   bool AdaptiveClassifierIsFull() { return NumAdaptationsFailed > 0; }
00292   bool LooksLikeGarbage(TBLOB *blob);
00293   void RefreshDebugWindow(ScrollView **win, const char *msg,
00294                           int y_offset, const TBOX &wbox);
00295   // intfx.cpp
00296   // Computes the DENORMS for bl(baseline) and cn(character) normalization
00297   // during feature extraction. The input denorm describes the current state
00298   // of the blob, which is usually a baseline-normalized word.
00299   // The Transforms setup are as follows:
00300   // Baseline Normalized (bl) Output:
00301   //   We center the grapheme by aligning the x-coordinate of its centroid with
00302   //   x=128 and leaving the already-baseline-normalized y as-is.
00303   //
00304   // Character Normalized (cn) Output:
00305   //   We align the grapheme's centroid at the origin and scale it
00306   //   asymmetrically in x and y so that the 2nd moments are a standard value
00307   //   (51.2) ie the result is vaguely square.
00308   // If classify_nonlinear_norm is true:
00309   //   A non-linear normalization is setup that attempts to evenly distribute
00310   //   edges across x and y.
00311   //
00312   // Some of the fields of fx_info are also setup:
00313   // Length: Total length of outline.
00314   // Rx:     Rounded y second moment. (Reversed by convention.)
00315   // Ry:     rounded x second moment.
00316   // Xmean:  Rounded x center of mass of the blob.
00317   // Ymean:  Rounded y center of mass of the blob.
00318   static void SetupBLCNDenorms(const TBLOB& blob, bool nonlinear_norm,
00319                                DENORM* bl_denorm, DENORM* cn_denorm,
00320                                INT_FX_RESULT_STRUCT* fx_info);
00321 
00322   // Extracts sets of 3-D features of length kStandardFeatureLength (=12.8), as
00323   // (x,y) position and angle as measured counterclockwise from the vector
00324   // <-1, 0>, from blob using two normalizations defined by bl_denorm and
00325   // cn_denorm. See SetpuBLCNDenorms for definitions.
00326   // If outline_cn_counts is not NULL, on return it contains the cumulative
00327   // number of cn features generated for each outline in the blob (in order).
00328   // Thus after the first outline, there were (*outline_cn_counts)[0] features,
00329   // after the second outline, there were (*outline_cn_counts)[1] features etc.
00330   static void ExtractFeatures(const TBLOB& blob,
00331                               bool nonlinear_norm,
00332                               GenericVector<INT_FEATURE_STRUCT>* bl_features,
00333                               GenericVector<INT_FEATURE_STRUCT>* cn_features,
00334                               INT_FX_RESULT_STRUCT* results,
00335                               GenericVector<int>* outline_cn_counts);
00336   /* float2int.cpp ************************************************************/
00337   void ClearCharNormArray(uinT8* char_norm_array);
00338   void ComputeIntCharNormArray(const FEATURE_STRUCT& norm_feature,
00339                                uinT8* char_norm_array);
00340   void ComputeIntFeatures(FEATURE_SET Features, INT_FEATURE_ARRAY IntFeatures);
00341   /* intproto.cpp *************************************************************/
00342   INT_TEMPLATES ReadIntTemplates(FILE *File);
00343   void WriteIntTemplates(FILE *File, INT_TEMPLATES Templates,
00344                          const UNICHARSET& target_unicharset);
00345   CLASS_ID GetClassToDebug(const char *Prompt, bool* adaptive_on,
00346                            bool* pretrained_on, int* shape_id);
00347   void ShowMatchDisplay();
00348   /* font detection ***********************************************************/
00349   UnicityTable<FontInfo>& get_fontinfo_table() {
00350     return fontinfo_table_;
00351   }
00352   const UnicityTable<FontInfo>& get_fontinfo_table() const {
00353     return fontinfo_table_;
00354   }
00355   UnicityTable<FontSet>& get_fontset_table() {
00356     return fontset_table_;
00357   }
00358   /* mfoutline.cpp ***********************************************************/
00359   void NormalizeOutlines(LIST Outlines, FLOAT32 *XScale, FLOAT32 *YScale);
00360   /* outfeat.cpp ***********************************************************/
00361   FEATURE_SET ExtractOutlineFeatures(TBLOB *Blob);
00362   /* picofeat.cpp ***********************************************************/
00363   FEATURE_SET ExtractPicoFeatures(TBLOB *Blob);
00364 
00365 
00366   // Member variables.
00367 
00368   // Parameters.
00369   BOOL_VAR_H(prioritize_division, FALSE,
00370              "Prioritize blob division over chopping");
00371   INT_VAR_H(tessedit_single_match, FALSE, "Top choice only from CP");
00372   BOOL_VAR_H(classify_enable_learning, true, "Enable adaptive classifier");
00373   INT_VAR_H(classify_debug_level, 0, "Classify debug level");
00374 
00375   /* mfoutline.cpp ***********************************************************/
00376   /* control knobs used to control normalization of outlines */
00377   INT_VAR_H(classify_norm_method, character, "Normalization Method   ...");
00378   double_VAR_H(classify_char_norm_range, 0.2,
00379              "Character Normalization Range ...");
00380   double_VAR_H(classify_min_norm_scale_x, 0.0, "Min char x-norm scale ...");
00381   double_VAR_H(classify_max_norm_scale_x, 0.325, "Max char x-norm scale ...");
00382   double_VAR_H(classify_min_norm_scale_y, 0.0, "Min char y-norm scale ...");
00383   double_VAR_H(classify_max_norm_scale_y, 0.325, "Max char y-norm scale ...");
00384   double_VAR_H(classify_max_rating_ratio, 1.5,
00385                "Veto ratio between classifier ratings");
00386   double_VAR_H(classify_max_certainty_margin, 5.5,
00387                "Veto difference between classifier certainties");
00388 
00389   /* adaptmatch.cpp ***********************************************************/
00390   BOOL_VAR_H(tess_cn_matching, 0, "Character Normalized Matching");
00391   BOOL_VAR_H(tess_bn_matching, 0, "Baseline Normalized Matching");
00392   BOOL_VAR_H(classify_enable_adaptive_matcher, 1, "Enable adaptive classifier");
00393   BOOL_VAR_H(classify_use_pre_adapted_templates, 0,
00394              "Use pre-adapted classifier templates");
00395   BOOL_VAR_H(classify_save_adapted_templates, 0,
00396              "Save adapted templates to a file");
00397   BOOL_VAR_H(classify_enable_adaptive_debugger, 0, "Enable match debugger");
00398   BOOL_VAR_H(classify_nonlinear_norm, 0,
00399              "Non-linear stroke-density normalization");
00400   INT_VAR_H(matcher_debug_level, 0, "Matcher Debug Level");
00401   INT_VAR_H(matcher_debug_flags, 0, "Matcher Debug Flags");
00402   INT_VAR_H(classify_learning_debug_level, 0, "Learning Debug Level: ");
00403   double_VAR_H(matcher_good_threshold, 0.125, "Good Match (0-1)");
00404   double_VAR_H(matcher_great_threshold, 0.0, "Great Match (0-1)");
00405   double_VAR_H(matcher_perfect_threshold, 0.02, "Perfect Match (0-1)");
00406   double_VAR_H(matcher_bad_match_pad, 0.15, "Bad Match Pad (0-1)");
00407   double_VAR_H(matcher_rating_margin, 0.1, "New template margin (0-1)");
00408   double_VAR_H(matcher_avg_noise_size, 12.0, "Avg. noise blob length: ");
00409   INT_VAR_H(matcher_permanent_classes_min, 1, "Min # of permanent classes");
00410   INT_VAR_H(matcher_min_examples_for_prototyping, 3,
00411             "Reliable Config Threshold");
00412   INT_VAR_H(matcher_sufficient_examples_for_prototyping, 5,
00413             "Enable adaption even if the ambiguities have not been seen");
00414   double_VAR_H(matcher_clustering_max_angle_delta, 0.015,
00415                "Maximum angle delta for prototype clustering");
00416   double_VAR_H(classify_misfit_junk_penalty, 0.0,
00417                "Penalty to apply when a non-alnum is vertically out of "
00418                "its expected textline position");
00419   double_VAR_H(rating_scale, 1.5, "Rating scaling factor");
00420   double_VAR_H(certainty_scale, 20.0, "Certainty scaling factor");
00421   double_VAR_H(tessedit_class_miss_scale, 0.00390625,
00422                "Scale factor for features not used");
00423   double_VAR_H(classify_adapted_pruning_factor, 2.5,
00424                "Prune poor adapted results this much worse than best result");
00425   double_VAR_H(classify_adapted_pruning_threshold, -1.0,
00426                "Threshold at which classify_adapted_pruning_factor starts");
00427   INT_VAR_H(classify_adapt_proto_threshold, 230,
00428             "Threshold for good protos during adaptive 0-255");
00429   INT_VAR_H(classify_adapt_feature_threshold, 230,
00430             "Threshold for good features during adaptive 0-255");
00431   BOOL_VAR_H(disable_character_fragments, TRUE,
00432              "Do not include character fragments in the"
00433              " results of the classifier");
00434   double_VAR_H(classify_character_fragments_garbage_certainty_threshold, -3.0,
00435                "Exclude fragments that do not match any whole character"
00436                " with at least this certainty");
00437   BOOL_VAR_H(classify_debug_character_fragments, FALSE,
00438              "Bring up graphical debugging windows for fragments training");
00439   BOOL_VAR_H(matcher_debug_separate_windows, FALSE,
00440              "Use two different windows for debugging the matching: "
00441              "One for the protos and one for the features.");
00442   STRING_VAR_H(classify_learn_debug_str, "", "Class str to debug learning");
00443 
00444   /* intmatcher.cpp **********************************************************/
00445   INT_VAR_H(classify_class_pruner_threshold, 229,
00446             "Class Pruner Threshold 0-255");
00447   INT_VAR_H(classify_class_pruner_multiplier, 15,
00448             "Class Pruner Multiplier 0-255:       ");
00449   INT_VAR_H(classify_cp_cutoff_strength, 7,
00450             "Class Pruner CutoffStrength:         ");
00451   INT_VAR_H(classify_integer_matcher_multiplier, 10,
00452             "Integer Matcher Multiplier  0-255:   ");
00453 
00454   // Use class variables to hold onto built-in templates and adapted templates.
00455   INT_TEMPLATES PreTrainedTemplates;
00456   ADAPT_TEMPLATES AdaptedTemplates;
00457 
00458   // Create dummy proto and config masks for use with the built-in templates.
00459   BIT_VECTOR AllProtosOn;
00460   BIT_VECTOR AllConfigsOn;
00461   BIT_VECTOR AllConfigsOff;
00462   BIT_VECTOR TempProtoMask;
00463   bool EnableLearning;
00464   /* normmatch.cpp */
00465   NORM_PROTOS *NormProtos;
00466   /* font detection ***********************************************************/
00467   UnicityTable<FontInfo> fontinfo_table_;
00468   // Without shape training, each class_id, config pair represents a single
00469   // unichar id/font combination, so each fontset_table_ entry holds font ids
00470   // for each config in the class.
00471   // With shape training, each class_id, config pair represents a single
00472   // shape_table_ index, so the fontset_table_ stores the shape_table_ index,
00473   // and the shape_table_ must be consulted to obtain the actual unichar_id/
00474   // font combinations that the shape represents.
00475   UnicityTable<FontSet> fontset_table_;
00476 
00477   INT_VAR_H(il1_adaption_test, 0, "Dont adapt to i/I at beginning of word");
00478   BOOL_VAR_H(classify_bln_numeric_mode, 0,
00479              "Assume the input is numbers [0-9].");
00480   double_VAR_H(speckle_large_max_size, 0.30, "Max large speckle size");
00481   double_VAR_H(speckle_rating_penalty, 10.0,
00482                "Penalty to add to worst rating for noise");
00483 
00484  protected:
00485   IntegerMatcher im_;
00486   FEATURE_DEFS_STRUCT feature_defs_;
00487   // If a shape_table_ is present, it is used to remap classifier output in
00488   // ExpandShapesAndApplyCorrections. font_ids referenced by configs actually
00489   // mean an index to the shape_table_ and the choices returned are *all* the
00490   // shape_table_ entries at that index.
00491   ShapeTable* shape_table_;
00492 
00493  private:
00494   Dict dict_;
00495   // The currently active static classifier.
00496   ShapeClassifier* static_classifier_;
00497 
00498   /* variables used to hold performance statistics */
00499   int NumAdaptationsFailed;
00500 
00501   // Expected number of features in the class pruner, used to penalize
00502   // unknowns that have too few features (like a c being classified as e) so
00503   // it doesn't recognize everything as '@' or '#'.
00504   // CharNormCutoffs is for the static classifier (with no shapetable).
00505   // BaselineCutoffs gets a copy of CharNormCutoffs as an estimate of the real
00506   // value in the adaptive classifier. Both are indexed by unichar_id.
00507   // shapetable_cutoffs_ provides a similar value for each shape in the
00508   // shape_table_
00509   uinT16* CharNormCutoffs;
00510   uinT16* BaselineCutoffs;
00511   GenericVector<uinT16> shapetable_cutoffs_;
00512   ScrollView* learn_debug_win_;
00513   ScrollView* learn_fragmented_word_debug_win_;
00514   ScrollView* learn_fragments_debug_win_;
00515 };
00516 }  // namespace tesseract
00517 
00518 #endif  // TESSERACT_CLASSIFY_CLASSIFY_H__
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines