tesseract 3.04.01

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 "imagedata.h"
00029 #include "intfx.h"
00030 #include "intmatcher.h"
00031 #include "normalis.h"
00032 #include "ratngs.h"
00033 #include "ocrfeatures.h"
00034 #include "unicity_table.h"
00035 
00036 class ScrollView;
00037 class WERD_CHOICE;
00038 class WERD_RES;
00039 struct ADAPT_RESULTS;
00040 struct NORM_PROTOS;
00041 
00042 static const int kUnknownFontinfoId = -1;
00043 static const int kBlankFontinfoId = -2;
00044 
00045 namespace tesseract {
00046 
00047 class ShapeClassifier;
00048 struct ShapeRating;
00049 class ShapeTable;
00050 struct UnicharRating;
00051 
00052 // How segmented is a blob. In this enum, character refers to a classifiable
00053 // unit, but that is too long and character is usually easier to understand.
00054 enum CharSegmentationType {
00055   CST_FRAGMENT,  // A partial character.
00056   CST_WHOLE,     // A correctly segmented character.
00057   CST_IMPROPER,  // More than one but less than 2 characters.
00058   CST_NGRAM      // Multiple characters.
00059 };
00060 
00061 class Classify : public CCStruct {
00062  public:
00063   Classify();
00064   virtual ~Classify();
00065   Dict& getDict() {
00066     return dict_;
00067   }
00068 
00069   const ShapeTable* shape_table() const {
00070     return shape_table_;
00071   }
00072 
00073   // Takes ownership of the given classifier, and uses it for future calls
00074   // to CharNormClassifier.
00075   void SetStaticClassifier(ShapeClassifier* static_classifier);
00076 
00077   // Adds a noise classification result that is a bit worse than the worst
00078   // current result, or the worst possible result if no current results.
00079   void AddLargeSpeckleTo(int blob_length, BLOB_CHOICE_LIST *choices);
00080 
00081   // Returns true if the blob is small enough to be a large speckle.
00082   bool LargeSpeckle(const TBLOB &blob);
00083 
00084   /* adaptive.cpp ************************************************************/
00085   ADAPT_TEMPLATES NewAdaptedTemplates(bool InitFromUnicharset);
00086   int GetFontinfoId(ADAPT_CLASS Class, uinT8 ConfigId);
00087   // Runs the class pruner from int_templates on the given features, returning
00088   // the number of classes output in results.
00089   //    int_templates          Class pruner tables
00090   //    num_features           Number of features in blob
00091   //    features               Array of features
00092   //    normalization_factors  (input) Array of int_templates->NumClasses fudge
00093   //                           factors from blob normalization process.
00094   //                           (Indexed by CLASS_INDEX)
00095   //    expected_num_features  (input) Array of int_templates->NumClasses
00096   //                           expected number of features for each class.
00097   //                           (Indexed by CLASS_INDEX)
00098   //    results                (output) Sorted Array of pruned classes.
00099   //                           Array must be sized to take the maximum possible
00100   //                           number of outputs : int_templates->NumClasses.
00101   int PruneClasses(const INT_TEMPLATES_STRUCT* int_templates, int num_features,
00102                    int keep_this, 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   // Learns 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 fontname is not NULL, then LearnBlob
00125   // is called and the data will be saved in an internal buffer.
00126   // Otherwise AdaptToBlob is called for adaption within a document.
00127   void LearnWord(const char* fontname, WERD_RES* word);
00128 
00129   // Builds a blob of length fragments, from the word, starting at start,
00130   // and then learns it, as having the given correct_text.
00131   // If fontname is not NULL, then LearnBlob is called and the data will be
00132   // saved in an internal buffer 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   // ComputeAdaptionThresholds.
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* fontname, int start, int length, float threshold,
00139                    CharSegmentationType segmentation, const char* correct_text,
00140                    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                                        UnicharRating* 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(const UnicharRating& new_result, ADAPT_RESULTS *results);
00191   int GetAdaptiveFeatures(TBLOB *Blob,
00192                           INT_FEATURE_ARRAY IntFeatures,
00193                           FEATURE_SET *FloatFeatures);
00194 
00195 #ifndef GRAPHICS_DISABLED
00196   void DebugAdaptiveClassifier(TBLOB *Blob,
00197                                ADAPT_RESULTS *Results);
00198 #endif
00199   PROTO_ID MakeNewTempProtos(FEATURE_SET Features,
00200                              int NumBadFeat,
00201                              FEATURE_ID BadFeat[],
00202                              INT_CLASS IClass,
00203                              ADAPT_CLASS Class,
00204                              BIT_VECTOR TempProtoMask);
00205   int MakeNewTemporaryConfig(ADAPT_TEMPLATES Templates,
00206                              CLASS_ID ClassId,
00207                              int FontinfoId,
00208                              int NumFeatures,
00209                              INT_FEATURE_ARRAY Features,
00210                              FEATURE_SET FloatFeatures);
00211   void MakePermanent(ADAPT_TEMPLATES Templates,
00212                      CLASS_ID ClassId,
00213                      int ConfigId,
00214                      TBLOB *Blob);
00215   void PrintAdaptiveMatchResults(const ADAPT_RESULTS& results);
00216   void RemoveExtraPuncs(ADAPT_RESULTS *Results);
00217   void RemoveBadMatches(ADAPT_RESULTS *Results);
00218   void SetAdaptiveThreshold(FLOAT32 Threshold);
00219   void ShowBestMatchFor(int shape_id,
00220                         const INT_FEATURE_STRUCT* features,
00221                         int num_features);
00222   // Returns a string for the classifier class_id: either the corresponding
00223   // unicharset debug_str or the shape_table_ debug str.
00224   STRING ClassIDToDebugStr(const INT_TEMPLATES_STRUCT* templates,
00225                            int class_id, int config_id) const;
00226   // Converts a classifier class_id index with a config ID to:
00227   // shape_table_ present: a shape_table_ index OR
00228   // No shape_table_: a font ID.
00229   // Without shape training, each class_id, config pair represents a single
00230   // unichar id/font combination, so this function looks up the corresponding
00231   // font id.
00232   // With shape training, each class_id, config pair represents a single
00233   // shape table index, so the fontset_table stores the shape table index,
00234   // and the shape_table_ must be consulted to obtain the actual unichar_id/
00235   // font combinations that the shape represents.
00236   int ClassAndConfigIDToFontOrShapeID(int class_id,
00237                                       int int_result_config) const;
00238   // Converts a shape_table_ index to a classifier class_id index (not a
00239   // unichar-id!). Uses a search, so not fast.
00240   int ShapeIDToClassID(int shape_id) const;
00241   UNICHAR_ID *BaselineClassifier(
00242       TBLOB *Blob, const GenericVector<INT_FEATURE_STRUCT>& int_features,
00243       const INT_FX_RESULT_STRUCT& fx_info,
00244       ADAPT_TEMPLATES Templates, ADAPT_RESULTS *Results);
00245   int CharNormClassifier(TBLOB *blob,
00246                          const TrainingSample& sample,
00247                          ADAPT_RESULTS *adapt_results);
00248 
00249   // As CharNormClassifier, but operates on a TrainingSample and outputs to
00250   // a GenericVector of ShapeRating without conversion to classes.
00251   int CharNormTrainingSample(bool pruner_only, int keep_this,
00252                              const TrainingSample& sample,
00253                              GenericVector<UnicharRating>* results);
00254   UNICHAR_ID *GetAmbiguities(TBLOB *Blob, CLASS_ID CorrectClass);
00255   void DoAdaptiveMatch(TBLOB *Blob, ADAPT_RESULTS *Results);
00256   void AdaptToChar(TBLOB* Blob, CLASS_ID ClassId, int FontinfoId,
00257                    FLOAT32 Threshold, ADAPT_TEMPLATES adaptive_templates);
00258   void DisplayAdaptedChar(TBLOB* blob, INT_CLASS_STRUCT* int_class);
00259   bool AdaptableWord(WERD_RES* word);
00260   void EndAdaptiveClassifier();
00261   void SettupPass1();
00262   void SettupPass2();
00263   void AdaptiveClassifier(TBLOB *Blob, BLOB_CHOICE_LIST *Choices);
00264   void ClassifyAsNoise(ADAPT_RESULTS *Results);
00265   void ResetAdaptiveClassifierInternal();
00266   void SwitchAdaptiveClassifier();
00267   void StartBackupAdaptiveClassifier();
00268 
00269   int GetCharNormFeature(const INT_FX_RESULT_STRUCT& fx_info,
00270                          INT_TEMPLATES templates,
00271                          uinT8* pruner_norm_array,
00272                          uinT8* char_norm_array);
00273   // Computes the char_norm_array for the unicharset and, if not NULL, the
00274   // pruner_array as appropriate according to the existence of the shape_table.
00275   // The norm_feature is deleted as it is almost certainly no longer needed.
00276   void ComputeCharNormArrays(FEATURE_STRUCT* norm_feature,
00277                              INT_TEMPLATES_STRUCT* templates,
00278                              uinT8* char_norm_array,
00279                              uinT8* pruner_array);
00280 
00281   bool TempConfigReliable(CLASS_ID class_id, const TEMP_CONFIG &config);
00282   void UpdateAmbigsGroup(CLASS_ID class_id, TBLOB *Blob);
00283 
00284   bool AdaptiveClassifierIsFull() const { return NumAdaptationsFailed > 0; }
00285   bool AdaptiveClassifierIsEmpty() const {
00286     return AdaptedTemplates->NumPermClasses == 0;
00287   }
00288   bool LooksLikeGarbage(TBLOB *blob);
00289   void RefreshDebugWindow(ScrollView **win, const char *msg,
00290                           int y_offset, const TBOX &wbox);
00291   // intfx.cpp
00292   // Computes the DENORMS for bl(baseline) and cn(character) normalization
00293   // during feature extraction. The input denorm describes the current state
00294   // of the blob, which is usually a baseline-normalized word.
00295   // The Transforms setup are as follows:
00296   // Baseline Normalized (bl) Output:
00297   //   We center the grapheme by aligning the x-coordinate of its centroid with
00298   //   x=128 and leaving the already-baseline-normalized y as-is.
00299   //
00300   // Character Normalized (cn) Output:
00301   //   We align the grapheme's centroid at the origin and scale it
00302   //   asymmetrically in x and y so that the 2nd moments are a standard value
00303   //   (51.2) ie the result is vaguely square.
00304   // If classify_nonlinear_norm is true:
00305   //   A non-linear normalization is setup that attempts to evenly distribute
00306   //   edges across x and y.
00307   //
00308   // Some of the fields of fx_info are also setup:
00309   // Length: Total length of outline.
00310   // Rx:     Rounded y second moment. (Reversed by convention.)
00311   // Ry:     rounded x second moment.
00312   // Xmean:  Rounded x center of mass of the blob.
00313   // Ymean:  Rounded y center of mass of the blob.
00314   static void SetupBLCNDenorms(const TBLOB& blob, bool nonlinear_norm,
00315                                DENORM* bl_denorm, DENORM* cn_denorm,
00316                                INT_FX_RESULT_STRUCT* fx_info);
00317 
00318   // Extracts sets of 3-D features of length kStandardFeatureLength (=12.8), as
00319   // (x,y) position and angle as measured counterclockwise from the vector
00320   // <-1, 0>, from blob using two normalizations defined by bl_denorm and
00321   // cn_denorm. See SetpuBLCNDenorms for definitions.
00322   // If outline_cn_counts is not NULL, on return it contains the cumulative
00323   // number of cn features generated for each outline in the blob (in order).
00324   // Thus after the first outline, there were (*outline_cn_counts)[0] features,
00325   // after the second outline, there were (*outline_cn_counts)[1] features etc.
00326   static void ExtractFeatures(const TBLOB& blob,
00327                               bool nonlinear_norm,
00328                               GenericVector<INT_FEATURE_STRUCT>* bl_features,
00329                               GenericVector<INT_FEATURE_STRUCT>* cn_features,
00330                               INT_FX_RESULT_STRUCT* results,
00331                               GenericVector<int>* outline_cn_counts);
00332   /* float2int.cpp ************************************************************/
00333   void ClearCharNormArray(uinT8* char_norm_array);
00334   void ComputeIntCharNormArray(const FEATURE_STRUCT& norm_feature,
00335                                uinT8* char_norm_array);
00336   void ComputeIntFeatures(FEATURE_SET Features, INT_FEATURE_ARRAY IntFeatures);
00337   /* intproto.cpp *************************************************************/
00338   INT_TEMPLATES ReadIntTemplates(FILE *File);
00339   void WriteIntTemplates(FILE *File, INT_TEMPLATES Templates,
00340                          const UNICHARSET& target_unicharset);
00341   CLASS_ID GetClassToDebug(const char *Prompt, bool* adaptive_on,
00342                            bool* pretrained_on, int* shape_id);
00343   void ShowMatchDisplay();
00344   /* font detection ***********************************************************/
00345   UnicityTable<FontInfo>& get_fontinfo_table() {
00346     return fontinfo_table_;
00347   }
00348   const UnicityTable<FontInfo>& get_fontinfo_table() const {
00349     return fontinfo_table_;
00350   }
00351   UnicityTable<FontSet>& get_fontset_table() {
00352     return fontset_table_;
00353   }
00354   /* mfoutline.cpp ***********************************************************/
00355   void NormalizeOutlines(LIST Outlines, FLOAT32 *XScale, FLOAT32 *YScale);
00356   /* outfeat.cpp ***********************************************************/
00357   FEATURE_SET ExtractOutlineFeatures(TBLOB *Blob);
00358   /* picofeat.cpp ***********************************************************/
00359   FEATURE_SET ExtractPicoFeatures(TBLOB *Blob);
00360   FEATURE_SET ExtractIntCNFeatures(const TBLOB& blob,
00361                                    const INT_FX_RESULT_STRUCT& fx_info);
00362   FEATURE_SET ExtractIntGeoFeatures(const TBLOB& blob,
00363                                     const INT_FX_RESULT_STRUCT& fx_info);
00364   /* blobclass.cpp ***********************************************************/
00365   // Extracts features from the given blob and saves them in the tr_file_data_
00366   // member variable.
00367   // fontname:  Name of font that this blob was printed in.
00368   // cn_denorm: Character normalization transformation to apply to the blob.
00369   // fx_info:   Character normalization parameters computed with cn_denorm.
00370   // blob_text: Ground truth text for the blob.
00371   void LearnBlob(const STRING& fontname, TBLOB* Blob, const DENORM& cn_denorm,
00372                  const INT_FX_RESULT_STRUCT& fx_info, const char* blob_text);
00373   // Writes stored training data to a .tr file based on the given filename.
00374   // Returns false on error.
00375   bool WriteTRFile(const STRING& filename);
00376 
00377   // Member variables.
00378 
00379   // Parameters.
00380   // Set during training (in lang.config) to indicate whether the divisible
00381   // blobs chopper should be used (true for latin script.)
00382   BOOL_VAR_H(allow_blob_division, true, "Use divisible blobs chopping");
00383   // Set during training (in lang.config) to indicate whether the divisible
00384   // blobs chopper should be used in preference to chopping. Set to true for
00385   // southern Indic scripts.
00386   BOOL_VAR_H(prioritize_division, FALSE,
00387              "Prioritize blob division over chopping");
00388   INT_VAR_H(tessedit_single_match, FALSE, "Top choice only from CP");
00389   BOOL_VAR_H(classify_enable_learning, true, "Enable adaptive classifier");
00390   INT_VAR_H(classify_debug_level, 0, "Classify debug level");
00391 
00392   /* mfoutline.cpp ***********************************************************/
00393   /* control knobs used to control normalization of outlines */
00394   INT_VAR_H(classify_norm_method, character, "Normalization Method   ...");
00395   double_VAR_H(classify_char_norm_range, 0.2,
00396              "Character Normalization Range ...");
00397   double_VAR_H(classify_min_norm_scale_x, 0.0, "Min char x-norm scale ...");
00398   double_VAR_H(classify_max_norm_scale_x, 0.325, "Max char x-norm scale ...");
00399   double_VAR_H(classify_min_norm_scale_y, 0.0, "Min char y-norm scale ...");
00400   double_VAR_H(classify_max_norm_scale_y, 0.325, "Max char y-norm scale ...");
00401   double_VAR_H(classify_max_rating_ratio, 1.5,
00402                "Veto ratio between classifier ratings");
00403   double_VAR_H(classify_max_certainty_margin, 5.5,
00404                "Veto difference between classifier certainties");
00405 
00406   /* adaptmatch.cpp ***********************************************************/
00407   BOOL_VAR_H(tess_cn_matching, 0, "Character Normalized Matching");
00408   BOOL_VAR_H(tess_bn_matching, 0, "Baseline Normalized Matching");
00409   BOOL_VAR_H(classify_enable_adaptive_matcher, 1, "Enable adaptive classifier");
00410   BOOL_VAR_H(classify_use_pre_adapted_templates, 0,
00411              "Use pre-adapted classifier templates");
00412   BOOL_VAR_H(classify_save_adapted_templates, 0,
00413              "Save adapted templates to a file");
00414   BOOL_VAR_H(classify_enable_adaptive_debugger, 0, "Enable match debugger");
00415   BOOL_VAR_H(classify_nonlinear_norm, 0,
00416              "Non-linear stroke-density normalization");
00417   INT_VAR_H(matcher_debug_level, 0, "Matcher Debug Level");
00418   INT_VAR_H(matcher_debug_flags, 0, "Matcher Debug Flags");
00419   INT_VAR_H(classify_learning_debug_level, 0, "Learning Debug Level: ");
00420   double_VAR_H(matcher_good_threshold, 0.125, "Good Match (0-1)");
00421   double_VAR_H(matcher_reliable_adaptive_result, 0.0, "Great Match (0-1)");
00422   double_VAR_H(matcher_perfect_threshold, 0.02, "Perfect Match (0-1)");
00423   double_VAR_H(matcher_bad_match_pad, 0.15, "Bad Match Pad (0-1)");
00424   double_VAR_H(matcher_rating_margin, 0.1, "New template margin (0-1)");
00425   double_VAR_H(matcher_avg_noise_size, 12.0, "Avg. noise blob length: ");
00426   INT_VAR_H(matcher_permanent_classes_min, 1, "Min # of permanent classes");
00427   INT_VAR_H(matcher_min_examples_for_prototyping, 3,
00428             "Reliable Config Threshold");
00429   INT_VAR_H(matcher_sufficient_examples_for_prototyping, 5,
00430             "Enable adaption even if the ambiguities have not been seen");
00431   double_VAR_H(matcher_clustering_max_angle_delta, 0.015,
00432                "Maximum angle delta for prototype clustering");
00433   double_VAR_H(classify_misfit_junk_penalty, 0.0,
00434                "Penalty to apply when a non-alnum is vertically out of "
00435                "its expected textline position");
00436   double_VAR_H(rating_scale, 1.5, "Rating scaling factor");
00437   double_VAR_H(certainty_scale, 20.0, "Certainty scaling factor");
00438   double_VAR_H(tessedit_class_miss_scale, 0.00390625,
00439                "Scale factor for features not used");
00440   double_VAR_H(classify_adapted_pruning_factor, 2.5,
00441                "Prune poor adapted results this much worse than best result");
00442   double_VAR_H(classify_adapted_pruning_threshold, -1.0,
00443                "Threshold at which classify_adapted_pruning_factor starts");
00444   INT_VAR_H(classify_adapt_proto_threshold, 230,
00445             "Threshold for good protos during adaptive 0-255");
00446   INT_VAR_H(classify_adapt_feature_threshold, 230,
00447             "Threshold for good features during adaptive 0-255");
00448   BOOL_VAR_H(disable_character_fragments, TRUE,
00449              "Do not include character fragments in the"
00450              " results of the classifier");
00451   double_VAR_H(classify_character_fragments_garbage_certainty_threshold, -3.0,
00452                "Exclude fragments that do not match any whole character"
00453                " with at least this certainty");
00454   BOOL_VAR_H(classify_debug_character_fragments, FALSE,
00455              "Bring up graphical debugging windows for fragments training");
00456   BOOL_VAR_H(matcher_debug_separate_windows, FALSE,
00457              "Use two different windows for debugging the matching: "
00458              "One for the protos and one for the features.");
00459   STRING_VAR_H(classify_learn_debug_str, "", "Class str to debug learning");
00460 
00461   /* intmatcher.cpp **********************************************************/
00462   INT_VAR_H(classify_class_pruner_threshold, 229,
00463             "Class Pruner Threshold 0-255");
00464   INT_VAR_H(classify_class_pruner_multiplier, 15,
00465             "Class Pruner Multiplier 0-255:       ");
00466   INT_VAR_H(classify_cp_cutoff_strength, 7,
00467             "Class Pruner CutoffStrength:         ");
00468   INT_VAR_H(classify_integer_matcher_multiplier, 10,
00469             "Integer Matcher Multiplier  0-255:   ");
00470 
00471   // Use class variables to hold onto built-in templates and adapted templates.
00472   INT_TEMPLATES PreTrainedTemplates;
00473   ADAPT_TEMPLATES AdaptedTemplates;
00474   // The backup adapted templates are created from the previous page (only)
00475   // so they are always ready and reasonably well trained if the primary
00476   // adapted templates become full.
00477   ADAPT_TEMPLATES BackupAdaptedTemplates;
00478 
00479   // Create dummy proto and config masks for use with the built-in templates.
00480   BIT_VECTOR AllProtosOn;
00481   BIT_VECTOR AllConfigsOn;
00482   BIT_VECTOR AllConfigsOff;
00483   BIT_VECTOR TempProtoMask;
00484   bool EnableLearning;
00485   /* normmatch.cpp */
00486   NORM_PROTOS *NormProtos;
00487   /* font detection ***********************************************************/
00488   UnicityTable<FontInfo> fontinfo_table_;
00489   // Without shape training, each class_id, config pair represents a single
00490   // unichar id/font combination, so each fontset_table_ entry holds font ids
00491   // for each config in the class.
00492   // With shape training, each class_id, config pair represents a single
00493   // shape_table_ index, so the fontset_table_ stores the shape_table_ index,
00494   // and the shape_table_ must be consulted to obtain the actual unichar_id/
00495   // font combinations that the shape represents.
00496   UnicityTable<FontSet> fontset_table_;
00497 
00498   INT_VAR_H(il1_adaption_test, 0, "Don't adapt to i/I at beginning of word");
00499   BOOL_VAR_H(classify_bln_numeric_mode, 0,
00500              "Assume the input is numbers [0-9].");
00501   double_VAR_H(speckle_large_max_size, 0.30, "Max large speckle size");
00502   double_VAR_H(speckle_rating_penalty, 10.0,
00503                "Penalty to add to worst rating for noise");
00504 
00505  protected:
00506   IntegerMatcher im_;
00507   FEATURE_DEFS_STRUCT feature_defs_;
00508   // If a shape_table_ is present, it is used to remap classifier output in
00509   // ExpandShapesAndApplyCorrections. font_ids referenced by configs actually
00510   // mean an index to the shape_table_ and the choices returned are *all* the
00511   // shape_table_ entries at that index.
00512   ShapeTable* shape_table_;
00513 
00514  private:
00515   Dict dict_;
00516   // The currently active static classifier.
00517   ShapeClassifier* static_classifier_;
00518 
00519   /* variables used to hold performance statistics */
00520   int NumAdaptationsFailed;
00521 
00522   // Training data gathered here for all the images in a document.
00523   STRING tr_file_data_;
00524 
00525   // Expected number of features in the class pruner, used to penalize
00526   // unknowns that have too few features (like a c being classified as e) so
00527   // it doesn't recognize everything as '@' or '#'.
00528   // CharNormCutoffs is for the static classifier (with no shapetable).
00529   // BaselineCutoffs gets a copy of CharNormCutoffs as an estimate of the real
00530   // value in the adaptive classifier. Both are indexed by unichar_id.
00531   // shapetable_cutoffs_ provides a similar value for each shape in the
00532   // shape_table_
00533   uinT16* CharNormCutoffs;
00534   uinT16* BaselineCutoffs;
00535   GenericVector<uinT16> shapetable_cutoffs_;
00536   ScrollView* learn_debug_win_;
00537   ScrollView* learn_fragmented_word_debug_win_;
00538   ScrollView* learn_fragments_debug_win_;
00539 };
00540 }  // namespace tesseract
00541 
00542 #endif  // TESSERACT_CLASSIFY_CLASSIFY_H__
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines