tesseract  4.00.00dev
classify.h
Go to the documentation of this file.
1 // File: classify.h
3 // Description: classify class.
4 // Author: Samuel Charron
5 //
6 // (C) Copyright 2006, Google Inc.
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
18 
19 #ifndef TESSERACT_CLASSIFY_CLASSIFY_H_
20 #define TESSERACT_CLASSIFY_CLASSIFY_H_
21 
22 #include "adaptive.h"
23 #include "ccstruct.h"
24 #include "classify.h"
25 #include "dict.h"
26 #include "featdefs.h"
27 #include "fontinfo.h"
28 #include "imagedata.h"
29 #include "intfx.h"
30 #include "intmatcher.h"
31 #include "normalis.h"
32 #include "ratngs.h"
33 #include "ocrfeatures.h"
34 #include "unicity_table.h"
35 
36 class ScrollView;
37 class WERD_CHOICE;
38 class WERD_RES;
39 struct ADAPT_RESULTS;
40 struct NORM_PROTOS;
41 
42 static const int kUnknownFontinfoId = -1;
43 static const int kBlankFontinfoId = -2;
44 
45 namespace tesseract {
46 
47 class ShapeClassifier;
48 struct ShapeRating;
49 class ShapeTable;
50 struct UnicharRating;
51 
52 // How segmented is a blob. In this enum, character refers to a classifiable
53 // unit, but that is too long and character is usually easier to understand.
55  CST_FRAGMENT, // A partial character.
56  CST_WHOLE, // A correctly segmented character.
57  CST_IMPROPER, // More than one but less than 2 characters.
58  CST_NGRAM // Multiple characters.
59 };
60 
61 class Classify : public CCStruct {
62  public:
63  Classify();
64  virtual ~Classify();
66  return dict_;
67  }
68 
69  const ShapeTable* shape_table() const {
70  return shape_table_;
71  }
72 
73  // Takes ownership of the given classifier, and uses it for future calls
74  // to CharNormClassifier.
75  void SetStaticClassifier(ShapeClassifier* static_classifier);
76 
77  // Adds a noise classification result that is a bit worse than the worst
78  // current result, or the worst possible result if no current results.
79  void AddLargeSpeckleTo(int blob_length, BLOB_CHOICE_LIST *choices);
80 
81  // Returns true if the blob is small enough to be a large speckle.
82  bool LargeSpeckle(const TBLOB &blob);
83 
84  /* adaptive.cpp ************************************************************/
85  ADAPT_TEMPLATES NewAdaptedTemplates(bool InitFromUnicharset);
86  int GetFontinfoId(ADAPT_CLASS Class, uinT8 ConfigId);
87  // Runs the class pruner from int_templates on the given features, returning
88  // the number of classes output in results.
89  // int_templates Class pruner tables
90  // num_features Number of features in blob
91  // features Array of features
92  // normalization_factors (input) Array of int_templates->NumClasses fudge
93  // factors from blob normalization process.
94  // (Indexed by CLASS_INDEX)
95  // expected_num_features (input) Array of int_templates->NumClasses
96  // expected number of features for each class.
97  // (Indexed by CLASS_INDEX)
98  // results (output) Sorted Array of pruned classes.
99  // Array must be sized to take the maximum possible
100  // number of outputs : int_templates->NumClasses.
101  int PruneClasses(const INT_TEMPLATES_STRUCT* int_templates, int num_features,
102  int keep_this, const INT_FEATURE_STRUCT* features,
103  const uinT8* normalization_factors,
104  const uinT16* expected_num_features,
106  void ReadNewCutoffs(TFile* fp, CLASS_CUTOFF_ARRAY Cutoffs);
107  void PrintAdaptedTemplates(FILE *File, ADAPT_TEMPLATES Templates);
108  void WriteAdaptedTemplates(FILE *File, ADAPT_TEMPLATES Templates);
110  /* normmatch.cpp ************************************************************/
112  const FEATURE_STRUCT& feature, BOOL8 DebugMatch);
113  void FreeNormProtos();
115  /* protos.cpp ***************************************************************/
116  void ConvertProto(PROTO Proto, int ProtoId, INT_CLASS Class);
118  const UNICHARSET& target_unicharset);
119  /* adaptmatch.cpp ***********************************************************/
120 
121  // Learns the given word using its chopped_word, seam_array, denorm,
122  // box_word, best_state, and correct_text to learn both correctly and
123  // incorrectly segmented blobs. If fontname is not NULL, then LearnBlob
124  // is called and the data will be saved in an internal buffer.
125  // Otherwise AdaptToBlob is called for adaption within a document.
126  void LearnWord(const char* fontname, WERD_RES* word);
127 
128  // Builds a blob of length fragments, from the word, starting at start,
129  // and then learns it, as having the given correct_text.
130  // If fontname is not NULL, then LearnBlob is called and the data will be
131  // saved in an internal buffer for static training.
132  // Otherwise AdaptToBlob is called for adaption within a document.
133  // threshold is a magic number required by AdaptToChar and generated by
134  // ComputeAdaptionThresholds.
135  // Although it can be partly inferred from the string, segmentation is
136  // provided to explicitly clarify the character segmentation.
137  void LearnPieces(const char* fontname, int start, int length, float threshold,
138  CharSegmentationType segmentation, const char* correct_text,
139  WERD_RES* word);
141  void InitAdaptedClass(TBLOB *Blob,
142  CLASS_ID ClassId,
143  int FontinfoId,
144  ADAPT_CLASS Class,
145  ADAPT_TEMPLATES Templates);
146  void AmbigClassifier(const GenericVector<INT_FEATURE_STRUCT>& int_features,
147  const INT_FX_RESULT_STRUCT& fx_info,
148  const TBLOB *blob,
149  INT_TEMPLATES templates,
150  ADAPT_CLASS *classes,
151  UNICHAR_ID *ambiguities,
152  ADAPT_RESULTS *results);
153  void MasterMatcher(INT_TEMPLATES templates,
154  inT16 num_features,
155  const INT_FEATURE_STRUCT* features,
156  const uinT8* norm_factors,
157  ADAPT_CLASS* classes,
158  int debug,
159  int matcher_multiplier,
160  const TBOX& blob_box,
161  const GenericVector<CP_RESULT_STRUCT>& results,
162  ADAPT_RESULTS* final_results);
163  // Converts configs to fonts, and if the result is not adapted, and a
164  // shape_table_ is present, the shape is expanded to include all
165  // unichar_ids represented, before applying a set of corrections to the
166  // distance rating in int_result, (see ComputeCorrectedRating.)
167  // The results are added to the final_results output.
169  bool debug,
170  int class_id,
171  int bottom, int top,
172  float cp_rating,
173  int blob_length,
174  int matcher_multiplier,
175  const uinT8* cn_factors,
176  UnicharRating* int_result,
177  ADAPT_RESULTS* final_results);
178  // Applies a set of corrections to the distance im_rating,
179  // including the cn_correction, miss penalty and additional penalty
180  // for non-alnums being vertical misfits. Returns the corrected distance.
181  double ComputeCorrectedRating(bool debug, int unichar_id, double cp_rating,
182  double im_rating, int feature_misses,
183  int bottom, int top,
184  int blob_length, int matcher_multiplier,
185  const uinT8* cn_factors);
186  void ConvertMatchesToChoices(const DENORM& denorm, const TBOX& box,
187  ADAPT_RESULTS *Results,
188  BLOB_CHOICE_LIST *Choices);
189  void AddNewResult(const UnicharRating& new_result, ADAPT_RESULTS *results);
190  int GetAdaptiveFeatures(TBLOB *Blob,
191  INT_FEATURE_ARRAY IntFeatures,
192  FEATURE_SET *FloatFeatures);
193 
194 #ifndef GRAPHICS_DISABLED
195  void DebugAdaptiveClassifier(TBLOB *Blob,
196  ADAPT_RESULTS *Results);
197 #endif
199  int NumBadFeat,
200  FEATURE_ID BadFeat[],
201  INT_CLASS IClass,
202  ADAPT_CLASS Class,
205  CLASS_ID ClassId,
206  int FontinfoId,
207  int NumFeatures,
208  INT_FEATURE_ARRAY Features,
209  FEATURE_SET FloatFeatures);
210  void MakePermanent(ADAPT_TEMPLATES Templates,
211  CLASS_ID ClassId,
212  int ConfigId,
213  TBLOB *Blob);
214  void PrintAdaptiveMatchResults(const ADAPT_RESULTS& results);
215  void RemoveExtraPuncs(ADAPT_RESULTS *Results);
216  void RemoveBadMatches(ADAPT_RESULTS *Results);
217  void SetAdaptiveThreshold(FLOAT32 Threshold);
218  void ShowBestMatchFor(int shape_id,
219  const INT_FEATURE_STRUCT* features,
220  int num_features);
221  // Returns a string for the classifier class_id: either the corresponding
222  // unicharset debug_str or the shape_table_ debug str.
224  int class_id, int config_id) const;
225  // Converts a classifier class_id index with a config ID to:
226  // shape_table_ present: a shape_table_ index OR
227  // No shape_table_: a font ID.
228  // Without shape training, each class_id, config pair represents a single
229  // unichar id/font combination, so this function looks up the corresponding
230  // font id.
231  // With shape training, each class_id, config pair represents a single
232  // shape table index, so the fontset_table stores the shape table index,
233  // and the shape_table_ must be consulted to obtain the actual unichar_id/
234  // font combinations that the shape represents.
235  int ClassAndConfigIDToFontOrShapeID(int class_id,
236  int int_result_config) const;
237  // Converts a shape_table_ index to a classifier class_id index (not a
238  // unichar-id!). Uses a search, so not fast.
239  int ShapeIDToClassID(int shape_id) const;
241  TBLOB *Blob, const GenericVector<INT_FEATURE_STRUCT>& int_features,
242  const INT_FX_RESULT_STRUCT& fx_info,
243  ADAPT_TEMPLATES Templates, ADAPT_RESULTS *Results);
244  int CharNormClassifier(TBLOB *blob,
245  const TrainingSample& sample,
246  ADAPT_RESULTS *adapt_results);
247 
248  // As CharNormClassifier, but operates on a TrainingSample and outputs to
249  // a GenericVector of ShapeRating without conversion to classes.
250  int CharNormTrainingSample(bool pruner_only, int keep_this,
251  const TrainingSample& sample,
253  UNICHAR_ID *GetAmbiguities(TBLOB *Blob, CLASS_ID CorrectClass);
254  void DoAdaptiveMatch(TBLOB *Blob, ADAPT_RESULTS *Results);
255  void AdaptToChar(TBLOB* Blob, CLASS_ID ClassId, int FontinfoId,
256  FLOAT32 Threshold, ADAPT_TEMPLATES adaptive_templates);
257  void DisplayAdaptedChar(TBLOB* blob, INT_CLASS_STRUCT* int_class);
258  bool AdaptableWord(WERD_RES* word);
259  void EndAdaptiveClassifier();
260  void SettupPass1();
261  void SettupPass2();
262  void AdaptiveClassifier(TBLOB *Blob, BLOB_CHOICE_LIST *Choices);
263  void ClassifyAsNoise(ADAPT_RESULTS *Results);
267 
268  int GetCharNormFeature(const INT_FX_RESULT_STRUCT& fx_info,
269  INT_TEMPLATES templates,
270  uinT8* pruner_norm_array,
271  uinT8* char_norm_array);
272  // Computes the char_norm_array for the unicharset and, if not NULL, the
273  // pruner_array as appropriate according to the existence of the shape_table.
274  // The norm_feature is deleted as it is almost certainly no longer needed.
275  void ComputeCharNormArrays(FEATURE_STRUCT* norm_feature,
276  INT_TEMPLATES_STRUCT* templates,
277  uinT8* char_norm_array,
278  uinT8* pruner_array);
279 
280  bool TempConfigReliable(CLASS_ID class_id, const TEMP_CONFIG &config);
281  void UpdateAmbigsGroup(CLASS_ID class_id, TBLOB *Blob);
282 
283  bool AdaptiveClassifierIsFull() const { return NumAdaptationsFailed > 0; }
285  return AdaptedTemplates->NumPermClasses == 0;
286  }
287  bool LooksLikeGarbage(TBLOB *blob);
288  void RefreshDebugWindow(ScrollView **win, const char *msg,
289  int y_offset, const TBOX &wbox);
290  // intfx.cpp
291  // Computes the DENORMS for bl(baseline) and cn(character) normalization
292  // during feature extraction. The input denorm describes the current state
293  // of the blob, which is usually a baseline-normalized word.
294  // The Transforms setup are as follows:
295  // Baseline Normalized (bl) Output:
296  // We center the grapheme by aligning the x-coordinate of its centroid with
297  // x=128 and leaving the already-baseline-normalized y as-is.
298  //
299  // Character Normalized (cn) Output:
300  // We align the grapheme's centroid at the origin and scale it
301  // asymmetrically in x and y so that the 2nd moments are a standard value
302  // (51.2) ie the result is vaguely square.
303  // If classify_nonlinear_norm is true:
304  // A non-linear normalization is setup that attempts to evenly distribute
305  // edges across x and y.
306  //
307  // Some of the fields of fx_info are also setup:
308  // Length: Total length of outline.
309  // Rx: Rounded y second moment. (Reversed by convention.)
310  // Ry: rounded x second moment.
311  // Xmean: Rounded x center of mass of the blob.
312  // Ymean: Rounded y center of mass of the blob.
313  static void SetupBLCNDenorms(const TBLOB& blob, bool nonlinear_norm,
314  DENORM* bl_denorm, DENORM* cn_denorm,
315  INT_FX_RESULT_STRUCT* fx_info);
316 
317  // Extracts sets of 3-D features of length kStandardFeatureLength (=12.8), as
318  // (x,y) position and angle as measured counterclockwise from the vector
319  // <-1, 0>, from blob using two normalizations defined by bl_denorm and
320  // cn_denorm. See SetpuBLCNDenorms for definitions.
321  // If outline_cn_counts is not NULL, on return it contains the cumulative
322  // number of cn features generated for each outline in the blob (in order).
323  // Thus after the first outline, there were (*outline_cn_counts)[0] features,
324  // after the second outline, there were (*outline_cn_counts)[1] features etc.
325  static void ExtractFeatures(const TBLOB& blob,
326  bool nonlinear_norm,
329  INT_FX_RESULT_STRUCT* results,
330  GenericVector<int>* outline_cn_counts);
331  /* float2int.cpp ************************************************************/
332  void ClearCharNormArray(uinT8* char_norm_array);
333  void ComputeIntCharNormArray(const FEATURE_STRUCT& norm_feature,
334  uinT8* char_norm_array);
335  void ComputeIntFeatures(FEATURE_SET Features, INT_FEATURE_ARRAY IntFeatures);
336  /* intproto.cpp *************************************************************/
338  void WriteIntTemplates(FILE *File, INT_TEMPLATES Templates,
339  const UNICHARSET& target_unicharset);
340  CLASS_ID GetClassToDebug(const char *Prompt, bool* adaptive_on,
341  bool* pretrained_on, int* shape_id);
342  void ShowMatchDisplay();
343  /* font detection ***********************************************************/
345  return fontinfo_table_;
346  }
348  return fontinfo_table_;
349  }
351  return fontset_table_;
352  }
353  /* mfoutline.cpp ***********************************************************/
354  void NormalizeOutlines(LIST Outlines, FLOAT32 *XScale, FLOAT32 *YScale);
355  /* outfeat.cpp ***********************************************************/
357  /* picofeat.cpp ***********************************************************/
360  const INT_FX_RESULT_STRUCT& fx_info);
362  const INT_FX_RESULT_STRUCT& fx_info);
363  /* blobclass.cpp ***********************************************************/
364  // Extracts features from the given blob and saves them in the tr_file_data_
365  // member variable.
366  // fontname: Name of font that this blob was printed in.
367  // cn_denorm: Character normalization transformation to apply to the blob.
368  // fx_info: Character normalization parameters computed with cn_denorm.
369  // blob_text: Ground truth text for the blob.
370  void LearnBlob(const STRING& fontname, TBLOB* Blob, const DENORM& cn_denorm,
371  const INT_FX_RESULT_STRUCT& fx_info, const char* blob_text);
372  // Writes stored training data to a .tr file based on the given filename.
373  // Returns false on error.
374  bool WriteTRFile(const STRING& filename);
375 
376  // Member variables.
377 
378  // Parameters.
379  // Set during training (in lang.config) to indicate whether the divisible
380  // blobs chopper should be used (true for latin script.)
381  BOOL_VAR_H(allow_blob_division, true, "Use divisible blobs chopping");
382  // Set during training (in lang.config) to indicate whether the divisible
383  // blobs chopper should be used in preference to chopping. Set to true for
384  // southern Indic scripts.
386  "Prioritize blob division over chopping");
387  INT_VAR_H(tessedit_single_match, FALSE, "Top choice only from CP");
388  BOOL_VAR_H(classify_enable_learning, true, "Enable adaptive classifier");
389  INT_VAR_H(classify_debug_level, 0, "Classify debug level");
390 
391  /* mfoutline.cpp ***********************************************************/
392  /* control knobs used to control normalization of outlines */
393  INT_VAR_H(classify_norm_method, character, "Normalization Method ...");
395  "Character Normalization Range ...");
396  double_VAR_H(classify_min_norm_scale_x, 0.0, "Min char x-norm scale ...");
397  double_VAR_H(classify_max_norm_scale_x, 0.325, "Max char x-norm scale ...");
398  double_VAR_H(classify_min_norm_scale_y, 0.0, "Min char y-norm scale ...");
399  double_VAR_H(classify_max_norm_scale_y, 0.325, "Max char y-norm scale ...");
401  "Veto ratio between classifier ratings");
403  "Veto difference between classifier certainties");
404 
405  /* adaptmatch.cpp ***********************************************************/
406  BOOL_VAR_H(tess_cn_matching, 0, "Character Normalized Matching");
407  BOOL_VAR_H(tess_bn_matching, 0, "Baseline Normalized Matching");
408  BOOL_VAR_H(classify_enable_adaptive_matcher, 1, "Enable adaptive classifier");
410  "Use pre-adapted classifier templates");
412  "Save adapted templates to a file");
413  BOOL_VAR_H(classify_enable_adaptive_debugger, 0, "Enable match debugger");
415  "Non-linear stroke-density normalization");
416  INT_VAR_H(matcher_debug_level, 0, "Matcher Debug Level");
417  INT_VAR_H(matcher_debug_flags, 0, "Matcher Debug Flags");
418  INT_VAR_H(classify_learning_debug_level, 0, "Learning Debug Level: ");
419  double_VAR_H(matcher_good_threshold, 0.125, "Good Match (0-1)");
420  double_VAR_H(matcher_reliable_adaptive_result, 0.0, "Great Match (0-1)");
421  double_VAR_H(matcher_perfect_threshold, 0.02, "Perfect Match (0-1)");
422  double_VAR_H(matcher_bad_match_pad, 0.15, "Bad Match Pad (0-1)");
423  double_VAR_H(matcher_rating_margin, 0.1, "New template margin (0-1)");
424  double_VAR_H(matcher_avg_noise_size, 12.0, "Avg. noise blob length: ");
425  INT_VAR_H(matcher_permanent_classes_min, 1, "Min # of permanent classes");
427  "Reliable Config Threshold");
429  "Enable adaption even if the ambiguities have not been seen");
431  "Maximum angle delta for prototype clustering");
433  "Penalty to apply when a non-alnum is vertically out of "
434  "its expected textline position");
435  double_VAR_H(rating_scale, 1.5, "Rating scaling factor");
436  double_VAR_H(certainty_scale, 20.0, "Certainty scaling factor");
438  "Scale factor for features not used");
440  "Prune poor adapted results this much worse than best result");
442  "Threshold at which classify_adapted_pruning_factor starts");
444  "Threshold for good protos during adaptive 0-255");
446  "Threshold for good features during adaptive 0-255");
448  "Do not include character fragments in the"
449  " results of the classifier");
451  "Exclude fragments that do not match any whole character"
452  " with at least this certainty");
454  "Bring up graphical debugging windows for fragments training");
456  "Use two different windows for debugging the matching: "
457  "One for the protos and one for the features.");
458  STRING_VAR_H(classify_learn_debug_str, "", "Class str to debug learning");
459 
460  /* intmatcher.cpp **********************************************************/
462  "Class Pruner Threshold 0-255");
464  "Class Pruner Multiplier 0-255: ");
466  "Class Pruner CutoffStrength: ");
468  "Integer Matcher Multiplier 0-255: ");
469 
470  // Use class variables to hold onto built-in templates and adapted templates.
473  // The backup adapted templates are created from the previous page (only)
474  // so they are always ready and reasonably well trained if the primary
475  // adapted templates become full.
477 
478  // Create dummy proto and config masks for use with the built-in templates.
484  /* normmatch.cpp */
486  /* font detection ***********************************************************/
488  // Without shape training, each class_id, config pair represents a single
489  // unichar id/font combination, so each fontset_table_ entry holds font ids
490  // for each config in the class.
491  // With shape training, each class_id, config pair represents a single
492  // shape_table_ index, so the fontset_table_ stores the shape_table_ index,
493  // and the shape_table_ must be consulted to obtain the actual unichar_id/
494  // font combinations that the shape represents.
496 
497  INT_VAR_H(il1_adaption_test, 0, "Don't adapt to i/I at beginning of word");
499  "Assume the input is numbers [0-9].");
500  double_VAR_H(speckle_large_max_size, 0.30, "Max large speckle size");
502  "Penalty to add to worst rating for noise");
503 
504  protected:
507  // If a shape_table_ is present, it is used to remap classifier output in
508  // ExpandShapesAndApplyCorrections. font_ids referenced by configs actually
509  // mean an index to the shape_table_ and the choices returned are *all* the
510  // shape_table_ entries at that index.
512 
513  private:
514  Dict dict_;
515  // The currently active static classifier.
516  ShapeClassifier* static_classifier_;
517 
518  /* variables used to hold performance statistics */
519  int NumAdaptationsFailed;
520 
521  // Training data gathered here for all the images in a document.
522  STRING tr_file_data_;
523 
524  // Expected number of features in the class pruner, used to penalize
525  // unknowns that have too few features (like a c being classified as e) so
526  // it doesn't recognize everything as '@' or '#'.
527  // CharNormCutoffs is for the static classifier (with no shapetable).
528  // BaselineCutoffs gets a copy of CharNormCutoffs as an estimate of the real
529  // value in the adaptive classifier. Both are indexed by unichar_id.
530  // shapetable_cutoffs_ provides a similar value for each shape in the
531  // shape_table_
532  uinT16 CharNormCutoffs[MAX_NUM_CLASSES];
533  uinT16 BaselineCutoffs[MAX_NUM_CLASSES];
534  GenericVector<uinT16> shapetable_cutoffs_;
535  ScrollView* learn_debug_win_;
536  ScrollView* learn_fragmented_word_debug_win_;
537  ScrollView* learn_fragments_debug_win_;
538 };
539 } // namespace tesseract
540 
541 #endif // TESSERACT_CLASSIFY_CLASSIFY_H_
bool LargeSpeckle(const TBLOB &blob)
Definition: classify.cpp:230
BIT_VECTOR TempProtoMask
Definition: classify.h:482
UnicityTable< FontSet > & get_fontset_table()
Definition: classify.h:350
void ResetAdaptiveClassifierInternal()
Definition: adaptmatch.cpp:599
bool classify_enable_adaptive_matcher
Definition: classify.h:408
void InitAdaptedClass(TBLOB *Blob, CLASS_ID ClassId, int FontinfoId, ADAPT_CLASS Class, ADAPT_TEMPLATES Templates)
Definition: adaptmatch.cpp:703
double matcher_good_threshold
Definition: classify.h:419
void RemoveBadMatches(ADAPT_RESULTS *Results)
double matcher_avg_noise_size
Definition: classify.h:424
bool classify_nonlinear_norm
Definition: classify.h:415
bool matcher_debug_separate_windows
Definition: classify.h:457
#define TRUE
Definition: capi.h:45
int GetCharNormFeature(const INT_FX_RESULT_STRUCT &fx_info, INT_TEMPLATES templates, uinT8 *pruner_norm_array, uinT8 *char_norm_array)
void WriteIntTemplates(FILE *File, INT_TEMPLATES Templates, const UNICHARSET &target_unicharset)
Definition: intproto.cpp:1067
bool classify_bln_numeric_mode
Definition: classify.h:499
int UNICHAR_ID
Definition: unichar.h:33
UnicityTable< FontSet > fontset_table_
Definition: classify.h:495
PROTO_ID MakeNewTempProtos(FEATURE_SET Features, int NumBadFeat, FEATURE_ID BadFeat[], INT_CLASS IClass, ADAPT_CLASS Class, BIT_VECTOR TempProtoMask)
Dict & getDict()
Definition: classify.h:65
void RefreshDebugWindow(ScrollView **win, const char *msg, int y_offset, const TBOX &wbox)
Definition: adaptmatch.cpp:220
UNICHAR_ID CLASS_ID
Definition: matchdefs.h:35
FEATURE_SET ExtractIntCNFeatures(const TBLOB &blob, const INT_FX_RESULT_STRUCT &fx_info)
Definition: picofeat.cpp:230
void ConvertProto(PROTO Proto, int ProtoId, INT_CLASS Class)
Definition: intproto.cpp:516
bool classify_save_adapted_templates
Definition: classify.h:412
bool allow_blob_division
Definition: classify.h:381
int classify_cp_cutoff_strength
Definition: classify.h:466
uinT16 CLASS_CUTOFF_ARRAY[MAX_NUM_CLASSES]
Definition: cutoffs.h:26
void DisplayAdaptedChar(TBLOB *blob, INT_CLASS_STRUCT *int_class)
Definition: adaptmatch.cpp:965
double tessedit_class_miss_scale
Definition: classify.h:438
ADAPT_TEMPLATES NewAdaptedTemplates(bool InitFromUnicharset)
Definition: adaptive.cpp:165
int classify_adapt_feature_threshold
Definition: classify.h:446
CLASS_ID GetClassToDebug(const char *Prompt, bool *adaptive_on, bool *pretrained_on, int *shape_id)
Definition: intproto.cpp:1329
NORM_PROTOS * ReadNormProtos(TFile *fp)
Definition: normmatch.cpp:245
FEATURE_DEFS_STRUCT feature_defs_
Definition: classify.h:506
int classify_integer_matcher_multiplier
Definition: classify.h:468
BIT_VECTOR AllProtosOn
Definition: classify.h:479
bool AdaptableWord(WERD_RES *word)
Definition: adaptmatch.cpp:836
bool LooksLikeGarbage(TBLOB *blob)
uinT32 * BIT_VECTOR
Definition: bitvec.h:28
bool AdaptiveClassifierIsFull() const
Definition: classify.h:283
void ReadNewCutoffs(TFile *fp, CLASS_CUTOFF_ARRAY Cutoffs)
Definition: cutoffs.cpp:52
void DoAdaptiveMatch(TBLOB *Blob, ADAPT_RESULTS *Results)
void ShowBestMatchFor(int shape_id, const INT_FEATURE_STRUCT *features, int num_features)
ADAPT_TEMPLATES ReadAdaptedTemplates(TFile *File)
Definition: adaptive.cpp:359
void NormalizeOutlines(LIST Outlines, FLOAT32 *XScale, FLOAT32 *YScale)
Definition: mfoutline.cpp:301
UnicityTable< FontInfo > & get_fontinfo_table()
Definition: classify.h:344
char * classify_learn_debug_str
Definition: classify.h:458
void ClearCharNormArray(uinT8 *char_norm_array)
Definition: float2int.cpp:48
double classify_max_norm_scale_y
Definition: classify.h:399
bool classify_debug_character_fragments
Definition: classify.h:454
void AddNewResult(const UnicharRating &new_result, ADAPT_RESULTS *results)
bool disable_character_fragments
Definition: classify.h:449
void PrintAdaptedTemplates(FILE *File, ADAPT_TEMPLATES Templates)
Definition: adaptive.cpp:266
double matcher_clustering_max_angle_delta
Definition: classify.h:431
int16_t inT16
Definition: host.h:36
void ExpandShapesAndApplyCorrections(ADAPT_CLASS *classes, bool debug, int class_id, int bottom, int top, float cp_rating, int blob_length, int matcher_multiplier, const uinT8 *cn_factors, UnicharRating *int_result, ADAPT_RESULTS *final_results)
bool classify_enable_adaptive_debugger
Definition: classify.h:413
double classify_char_norm_range
Definition: classify.h:395
double matcher_reliable_adaptive_result
Definition: classify.h:420
ShapeTable * shape_table_
Definition: classify.h:511
int classify_learning_debug_level
Definition: classify.h:418
int classify_class_pruner_multiplier
Definition: classify.h:464
double classify_min_norm_scale_x
Definition: classify.h:396
bool classify_use_pre_adapted_templates
Definition: classify.h:410
ADAPT_TEMPLATES BackupAdaptedTemplates
Definition: classify.h:476
double speckle_rating_penalty
Definition: classify.h:502
static void SetupBLCNDenorms(const TBLOB &blob, bool nonlinear_norm, DENORM *bl_denorm, DENORM *cn_denorm, INT_FX_RESULT_STRUCT *fx_info)
Definition: intfx.cpp:133
double certainty_scale
Definition: classify.h:436
void ComputeIntCharNormArray(const FEATURE_STRUCT &norm_feature, uinT8 *char_norm_array)
Definition: float2int.cpp:69
int GetAdaptiveFeatures(TBLOB *Blob, INT_FEATURE_ARRAY IntFeatures, FEATURE_SET *FloatFeatures)
Definition: adaptmatch.cpp:798
void LearnPieces(const char *fontname, int start, int length, float threshold, CharSegmentationType segmentation, const char *correct_text, WERD_RES *word)
Definition: adaptmatch.cpp:368
int ShapeIDToClassID(int shape_id) const
void UpdateAmbigsGroup(CLASS_ID class_id, TBLOB *Blob)
void PrintAdaptiveMatchResults(const ADAPT_RESULTS &results)
void MasterMatcher(INT_TEMPLATES templates, inT16 num_features, const INT_FEATURE_STRUCT *features, const uinT8 *norm_factors, ADAPT_CLASS *classes, int debug, int matcher_multiplier, const TBOX &blob_box, const GenericVector< CP_RESULT_STRUCT > &results, ADAPT_RESULTS *final_results)
bool AdaptiveClassifierIsEmpty() const
Definition: classify.h:284
BIT_VECTOR AllConfigsOff
Definition: classify.h:481
FEATURE_SET ExtractIntGeoFeatures(const TBLOB &blob, const INT_FX_RESULT_STRUCT &fx_info)
Definition: picofeat.cpp:262
void AmbigClassifier(const GenericVector< INT_FEATURE_STRUCT > &int_features, const INT_FX_RESULT_STRUCT &fx_info, const TBLOB *blob, INT_TEMPLATES templates, ADAPT_CLASS *classes, UNICHAR_ID *ambiguities, ADAPT_RESULTS *results)
double matcher_perfect_threshold
Definition: classify.h:421
const ShapeTable * shape_table() const
Definition: classify.h:69
INT_TEMPLATES ReadIntTemplates(TFile *fp)
Definition: intproto.cpp:761
unsigned char BOOL8
Definition: host.h:44
Definition: strngs.h:45
#define FALSE
Definition: capi.h:46
#define double_VAR_H(name, val, comment)
Definition: params.h:273
void ComputeCharNormArrays(FEATURE_STRUCT *norm_feature, INT_TEMPLATES_STRUCT *templates, uinT8 *char_norm_array, uinT8 *pruner_array)
double matcher_bad_match_pad
Definition: classify.h:422
int classify_adapt_proto_threshold
Definition: classify.h:444
double classify_min_norm_scale_y
Definition: classify.h:398
void StartBackupAdaptiveClassifier()
Definition: adaptmatch.cpp:630
void AdaptToChar(TBLOB *Blob, CLASS_ID ClassId, int FontinfoId, FLOAT32 Threshold, ADAPT_TEMPLATES adaptive_templates)
Definition: adaptmatch.cpp:872
int MakeNewTemporaryConfig(ADAPT_TEMPLATES Templates, CLASS_ID ClassId, int FontinfoId, int NumFeatures, INT_FEATURE_ARRAY Features, FEATURE_SET FloatFeatures)
IntegerMatcher im_
Definition: classify.h:502
int GetFontinfoId(ADAPT_CLASS Class, uinT8 ConfigId)
Definition: adaptive.cpp:188
ADAPT_TEMPLATES AdaptedTemplates
Definition: classify.h:472
FLOAT32 ComputeNormMatch(CLASS_ID ClassId, const FEATURE_STRUCT &feature, BOOL8 DebugMatch)
Definition: normmatch.cpp:88
double ComputeCorrectedRating(bool debug, int unichar_id, double cp_rating, double im_rating, int feature_misses, int bottom, int top, int blob_length, int matcher_multiplier, const uinT8 *cn_factors)
double classify_adapted_pruning_threshold
Definition: classify.h:442
void AddLargeSpeckleTo(int blob_length, BLOB_CHOICE_LIST *choices)
Definition: classify.cpp:207
void MakePermanent(ADAPT_TEMPLATES Templates, CLASS_ID ClassId, int ConfigId, TBLOB *Blob)
void WriteAdaptedTemplates(FILE *File, ADAPT_TEMPLATES Templates)
Definition: adaptive.cpp:489
static void ExtractFeatures(const TBLOB &blob, bool nonlinear_norm, GenericVector< INT_FEATURE_STRUCT > *bl_features, GenericVector< INT_FEATURE_STRUCT > *cn_features, INT_FX_RESULT_STRUCT *results, GenericVector< int > *outline_cn_counts)
Definition: intfx.cpp:445
double classify_max_norm_scale_x
Definition: classify.h:397
int CharNormClassifier(TBLOB *blob, const TrainingSample &sample, ADAPT_RESULTS *adapt_results)
void EndAdaptiveClassifier()
Definition: adaptmatch.cpp:456
float FLOAT32
Definition: host.h:42
void SwitchAdaptiveClassifier()
Definition: adaptmatch.cpp:614
Definition: rect.h:30
int classify_class_pruner_threshold
Definition: classify.h:462
double classify_character_fragments_garbage_certainty_threshold
Definition: classify.h:452
int matcher_permanent_classes_min
Definition: classify.h:425
#define STRING_VAR_H(name, val, comment)
Definition: params.h:270
virtual ~Classify()
Definition: classify.cpp:189
double classify_misfit_junk_penalty
Definition: classify.h:434
int ClassAndConfigIDToFontOrShapeID(int class_id, int int_result_config) const
Definition: blobs.h:261
double classify_adapted_pruning_factor
Definition: classify.h:440
void SetStaticClassifier(ShapeClassifier *static_classifier)
Definition: classify.cpp:199
int matcher_sufficient_examples_for_prototyping
Definition: classify.h:429
void SetAdaptiveThreshold(FLOAT32 Threshold)
void RemoveExtraPuncs(ADAPT_RESULTS *Results)
BIT_VECTOR AllConfigsOn
Definition: classify.h:480
double classify_max_rating_ratio
Definition: classify.h:401
const char * filename
Definition: ioapi.h:38
void AdaptiveClassifier(TBLOB *Blob, BLOB_CHOICE_LIST *Choices)
Definition: adaptmatch.cpp:185
uint8_t uinT8
Definition: host.h:35
int matcher_min_examples_for_prototyping
Definition: classify.h:427
void ConvertMatchesToChoices(const DENORM &denorm, const TBOX &box, ADAPT_RESULTS *Results, BLOB_CHOICE_LIST *Choices)
int PruneClasses(const INT_TEMPLATES_STRUCT *int_templates, int num_features, int keep_this, const INT_FEATURE_STRUCT *features, const uinT8 *normalization_factors, const uinT16 *expected_num_features, GenericVector< CP_RESULT_STRUCT > *results)
Definition: intmatcher.cpp:412
void LearnBlob(const STRING &fontname, TBLOB *Blob, const DENORM &cn_denorm, const INT_FX_RESULT_STRUCT &fx_info, const char *blob_text)
Definition: blobclass.cpp:69
void InitAdaptiveClassifier(TessdataManager *mgr)
Definition: adaptmatch.cpp:527
bool WriteTRFile(const STRING &filename)
Definition: blobclass.cpp:97
void ComputeIntFeatures(FEATURE_SET Features, INT_FEATURE_ARRAY IntFeatures)
Definition: float2int.cpp:100
#define INT_VAR_H(name, val, comment)
Definition: params.h:264
NORM_PROTOS * NormProtos
Definition: classify.h:485
void DebugAdaptiveClassifier(TBLOB *Blob, ADAPT_RESULTS *Results)
double matcher_rating_margin
Definition: classify.h:423
CharSegmentationType
Definition: classify.h:54
INT_TEMPLATES CreateIntTemplates(CLASSES FloatProtos, const UNICHARSET &target_unicharset)
Definition: intproto.cpp:557
#define BOOL_VAR_H(name, val, comment)
Definition: params.h:267
Definition: cluster.h:32
void ClassifyAsNoise(ADAPT_RESULTS *Results)
bool TempConfigReliable(CLASS_ID class_id, const TEMP_CONFIG &config)
FEATURE_SET ExtractPicoFeatures(TBLOB *Blob)
Definition: picofeat.cpp:67
#define MAX_NUM_CLASSES
Definition: matchdefs.h:31
double classify_max_certainty_margin
Definition: classify.h:403
uinT8 FEATURE_ID
Definition: matchdefs.h:47
void LearnWord(const char *fontname, WERD_RES *word)
Definition: adaptmatch.cpp:244
INT_FEATURE_STRUCT INT_FEATURE_ARRAY[MAX_NUM_INT_FEATURES]
Definition: intproto.h:155
bool classify_enable_learning
Definition: classify.h:388
UNICHAR_ID * GetAmbiguities(TBLOB *Blob, CLASS_ID CorrectClass)
UnicityTable< FontInfo > fontinfo_table_
Definition: classify.h:487
uint16_t uinT16
Definition: host.h:37
double speckle_large_max_size
Definition: classify.h:500
STRING ClassIDToDebugStr(const INT_TEMPLATES_STRUCT *templates, int class_id, int config_id) const
const char features[]
Definition: feature_tests.c:2
inT16 PROTO_ID
Definition: matchdefs.h:41
UNICHAR_ID * BaselineClassifier(TBLOB *Blob, const GenericVector< INT_FEATURE_STRUCT > &int_features, const INT_FX_RESULT_STRUCT &fx_info, ADAPT_TEMPLATES Templates, ADAPT_RESULTS *Results)
const UnicityTable< FontInfo > & get_fontinfo_table() const
Definition: classify.h:347
FEATURE_SET ExtractOutlineFeatures(TBLOB *Blob)
Definition: outfeat.cpp:47
INT_TEMPLATES PreTrainedTemplates
Definition: classify.h:468
bool prioritize_division
Definition: classify.h:386
int CharNormTrainingSample(bool pruner_only, int keep_this, const TrainingSample &sample, GenericVector< UnicharRating > *results)