19 #ifndef TESSERACT_CLASSIFY_CLASSIFY_H_
20 #define TESSERACT_CLASSIFY_CLASSIFY_H_
24 #include "config_auto.h"
28 #ifdef DISABLED_LEGACY_ENGINE
35 class Classify :
public CCStruct {
48 "Assume the input is numbers [0-9].");
51 "Veto ratio between classifier ratings");
54 "Veto difference between classifier certainties");
84 static const int kUnknownFontinfoId = -1;
85 static const int kBlankFontinfoId = -2;
89 class ShapeClassifier;
145 const uint8_t* normalization_factors,
146 const uint16_t* expected_num_features,
179 void LearnPieces(
const char* fontname,
int start,
int length,
float threshold,
196 int16_t num_features,
198 const uint8_t* norm_factors,
201 int matcher_multiplier,
202 const TBOX& blob_box,
216 int matcher_multiplier,
217 const uint8_t* cn_factors,
224 double im_rating,
int feature_misses,
226 int blob_length,
int matcher_multiplier,
227 const uint8_t* cn_factors);
230 BLOB_CHOICE_LIST *Choices);
236 #ifndef GRAPHICS_DISABLED
266 int class_id,
int config_id)
const;
278 int int_result_config)
const;
312 uint8_t* pruner_norm_array,
313 uint8_t* char_norm_array);
319 uint8_t* char_norm_array,
320 uint8_t* pruner_array);
331 int y_offset,
const TBOX &wbox);
376 uint8_t* char_norm_array);
383 bool* pretrained_on,
int* shape_id);
428 "Prioritize blob division over chopping");
436 "Character Normalization Range ...");
438 "Veto ratio between classifier ratings");
440 "Veto difference between classifier certainties");
447 "Use pre-adapted classifier templates");
449 "Save adapted templates to a file");
452 "Non-linear stroke-density normalization");
464 "Reliable Config Threshold");
466 "Enable adaption even if the ambiguities have not been seen");
468 "Maximum angle delta for prototype clustering");
470 "Penalty to apply when a non-alnum is vertically out of "
471 "its expected textline position");
475 "Scale factor for features not used");
477 "Prune poor adapted results this much worse than best result");
479 "Threshold at which classify_adapted_pruning_factor starts");
481 "Threshold for good protos during adaptive 0-255");
483 "Threshold for good features during adaptive 0-255");
485 "Do not include character fragments in the"
486 " results of the classifier");
488 "Exclude fragments that do not match any whole character"
489 " with at least this certainty");
491 "Bring up graphical debugging windows for fragments training");
493 "Use two different windows for debugging the matching: "
494 "One for the protos and one for the features.");
499 "Class Pruner Threshold 0-255");
501 "Class Pruner Multiplier 0-255: ");
503 "Class Pruner CutoffStrength: ");
505 "Integer Matcher Multiplier 0-255: ");
508 "Assume the input is numbers [0-9].");
511 "Penalty to add to worst rating for noise");
563 int NumAdaptationsFailed;
#define BOOL_VAR_H(name, val, comment)
#define STRING_VAR_H(name, val, comment)
#define INT_VAR_H(name, val, comment)
#define double_VAR_H(name, val, comment)
INT_FEATURE_STRUCT INT_FEATURE_ARRAY[MAX_NUM_INT_FEATURES]
double speckle_rating_penalty
double classify_adapted_pruning_factor
double classify_max_rating_ratio
bool matcher_debug_separate_windows
bool AdaptiveClassifierIsEmpty() const
double tessedit_class_miss_scale
bool classify_debug_character_fragments
bool AdaptableWord(WERD_RES *word)
void DisplayAdaptedChar(TBLOB *blob, INT_CLASS_STRUCT *int_class)
void RemoveBadMatches(ADAPT_RESULTS *Results)
double matcher_bad_match_pad
void PrintAdaptedTemplates(FILE *File, ADAPT_TEMPLATES Templates)
void WriteAdaptedTemplates(FILE *File, ADAPT_TEMPLATES Templates)
bool LooksLikeGarbage(TBLOB *blob)
STRING ClassIDToDebugStr(const INT_TEMPLATES_STRUCT *templates, int class_id, int config_id) const
int GetAdaptiveFeatures(TBLOB *Blob, INT_FEATURE_ARRAY IntFeatures, FEATURE_SET *FloatFeatures)
void UpdateAmbigsGroup(CLASS_ID class_id, TBLOB *Blob)
bool classify_enable_adaptive_debugger
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)
bool classify_save_adapted_templates
ADAPT_TEMPLATES NewAdaptedTemplates(bool InitFromUnicharset)
void AddNewResult(const UnicharRating &new_result, ADAPT_RESULTS *results)
double classify_adapted_pruning_threshold
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)
int classify_cp_cutoff_strength
void LearnWord(const char *fontname, WERD_RES *word)
int matcher_min_examples_for_prototyping
double classify_character_fragments_garbage_certainty_threshold
void ResetAdaptiveClassifierInternal()
void StartBackupAdaptiveClassifier()
int classify_adapt_proto_threshold
double matcher_perfect_threshold
bool classify_nonlinear_norm
int classify_class_pruner_multiplier
int PruneClasses(const INT_TEMPLATES_STRUCT *int_templates, int num_features, int keep_this, const INT_FEATURE_STRUCT *features, const uint8_t *normalization_factors, const uint16_t *expected_num_features, GenericVector< CP_RESULT_STRUCT > *results)
ShapeTable * shape_table_
double speckle_large_max_size
ADAPT_TEMPLATES AdaptedTemplates
void ShowBestMatchFor(int shape_id, const INT_FEATURE_STRUCT *features, int num_features)
int ClassAndConfigIDToFontOrShapeID(int class_id, int int_result_config) const
bool classify_use_pre_adapted_templates
int GetCharNormFeature(const INT_FX_RESULT_STRUCT &fx_info, INT_TEMPLATES templates, uint8_t *pruner_norm_array, uint8_t *char_norm_array)
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_t *cn_factors, UnicharRating *int_result, ADAPT_RESULTS *final_results)
bool classify_bln_numeric_mode
int MakeNewTemporaryConfig(ADAPT_TEMPLATES Templates, CLASS_ID ClassId, int FontinfoId, int NumFeatures, INT_FEATURE_ARRAY Features, FEATURE_SET FloatFeatures)
static void SetupBLCNDenorms(const TBLOB &blob, bool nonlinear_norm, DENORM *bl_denorm, DENORM *cn_denorm, INT_FX_RESULT_STRUCT *fx_info)
void ClearCharNormArray(uint8_t *char_norm_array)
bool LargeSpeckle(const TBLOB &blob)
UnicityTable< FontInfo > & get_fontinfo_table()
INT_TEMPLATES PreTrainedTemplates
double classify_misfit_junk_penalty
float ComputeNormMatch(CLASS_ID ClassId, const FEATURE_STRUCT &feature, bool DebugMatch)
int classify_class_pruner_threshold
void RefreshDebugWindow(ScrollView **win, const char *msg, int y_offset, const TBOX &wbox)
FEATURE_DEFS_STRUCT feature_defs_
int matcher_permanent_classes_min
UnicityTable< FontSet > fontset_table_
int CharNormClassifier(TBLOB *blob, const TrainingSample &sample, ADAPT_RESULTS *adapt_results)
bool classify_enable_learning
double matcher_clustering_max_angle_delta
CLASS_ID GetClassToDebug(const char *Prompt, bool *adaptive_on, bool *pretrained_on, int *shape_id)
bool TempConfigReliable(CLASS_ID class_id, const TEMP_CONFIG &config)
double matcher_rating_margin
double classify_char_norm_range
int CharNormTrainingSample(bool pruner_only, int keep_this, const TrainingSample &sample, GenericVector< UnicharRating > *results)
void MasterMatcher(INT_TEMPLATES templates, int16_t num_features, const INT_FEATURE_STRUCT *features, const uint8_t *norm_factors, ADAPT_CLASS *classes, int debug, int matcher_multiplier, const TBOX &blob_box, const GenericVector< CP_RESULT_STRUCT > &results, ADAPT_RESULTS *final_results)
void WriteIntTemplates(FILE *File, INT_TEMPLATES Templates, const UNICHARSET &target_unicharset)
bool WriteTRFile(const STRING &filename)
UnicityTable< FontSet > & get_fontset_table()
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_t *cn_factors)
double classify_max_certainty_margin
void ClassifyAsNoise(ADAPT_RESULTS *Results)
void DoAdaptiveMatch(TBLOB *Blob, ADAPT_RESULTS *Results)
int GetFontinfoId(ADAPT_CLASS Class, uint8_t ConfigId)
NORM_PROTOS * ReadNormProtos(TFile *fp)
const UnicityTable< FontInfo > & get_fontinfo_table() const
double matcher_avg_noise_size
UNICHAR_ID * GetAmbiguities(TBLOB *Blob, CLASS_ID CorrectClass)
void InitAdaptedClass(TBLOB *Blob, CLASS_ID ClassId, int FontinfoId, ADAPT_CLASS Class, ADAPT_TEMPLATES Templates)
void SwitchAdaptiveClassifier()
void AdaptiveClassifier(TBLOB *Blob, BLOB_CHOICE_LIST *Choices)
bool AdaptiveClassifierIsFull() const
double matcher_reliable_adaptive_result
FEATURE_SET ExtractIntCNFeatures(const TBLOB &blob, const INT_FX_RESULT_STRUCT &fx_info)
bool disable_character_fragments
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)
char * classify_learn_debug_str
void ComputeIntCharNormArray(const FEATURE_STRUCT &norm_feature, uint8_t *char_norm_array)
void ComputeCharNormArrays(FEATURE_STRUCT *norm_feature, INT_TEMPLATES_STRUCT *templates, uint8_t *char_norm_array, uint8_t *pruner_array)
int classify_integer_matcher_multiplier
INT_TEMPLATES ReadIntTemplates(TFile *fp)
void InitAdaptiveClassifier(TessdataManager *mgr)
void LearnPieces(const char *fontname, int start, int length, float threshold, CharSegmentationType segmentation, const char *correct_text, WERD_RES *word)
int matcher_sufficient_examples_for_prototyping
FEATURE_SET ExtractPicoFeatures(TBLOB *Blob)
void SetAdaptiveThreshold(float Threshold)
bool classify_enable_adaptive_matcher
void SetStaticClassifier(ShapeClassifier *static_classifier)
ADAPT_TEMPLATES ReadAdaptedTemplates(TFile *File)
PROTO_ID MakeNewTempProtos(FEATURE_SET Features, int NumBadFeat, FEATURE_ID BadFeat[], INT_CLASS IClass, ADAPT_CLASS Class, BIT_VECTOR TempProtoMask)
double matcher_good_threshold
void ReadNewCutoffs(TFile *fp, uint16_t *Cutoffs)
void ComputeIntFeatures(FEATURE_SET Features, INT_FEATURE_ARRAY IntFeatures)
int ShapeIDToClassID(int shape_id) const
void EndAdaptiveClassifier()
UnicityTable< FontInfo > fontinfo_table_
ADAPT_TEMPLATES BackupAdaptedTemplates
void MakePermanent(ADAPT_TEMPLATES Templates, CLASS_ID ClassId, int ConfigId, TBLOB *Blob)
void AdaptToChar(TBLOB *Blob, CLASS_ID ClassId, int FontinfoId, float Threshold, ADAPT_TEMPLATES adaptive_templates)
void NormalizeOutlines(LIST Outlines, float *XScale, float *YScale)
void LearnBlob(const STRING &fontname, TBLOB *Blob, const DENORM &cn_denorm, const INT_FX_RESULT_STRUCT &fx_info, const char *blob_text)
const ShapeTable * shape_table() const
FEATURE_SET ExtractIntGeoFeatures(const TBLOB &blob, const INT_FX_RESULT_STRUCT &fx_info)
void RemoveExtraPuncs(ADAPT_RESULTS *Results)
FEATURE_SET ExtractOutlineFeatures(TBLOB *Blob)
void ConvertMatchesToChoices(const DENORM &denorm, const TBOX &box, ADAPT_RESULTS *Results, BLOB_CHOICE_LIST *Choices)
void ConvertProto(PROTO Proto, int ProtoId, INT_CLASS Class)
INT_TEMPLATES CreateIntTemplates(CLASSES FloatProtos, const UNICHARSET &target_unicharset)
void DebugAdaptiveClassifier(TBLOB *Blob, ADAPT_RESULTS *Results)
int classify_adapt_feature_threshold
int classify_learning_debug_level
void AddLargeSpeckleTo(int blob_length, BLOB_CHOICE_LIST *choices)
void PrintAdaptiveMatchResults(const ADAPT_RESULTS &results)