66 #define ADAPT_TEMPLATE_SUFFIX ".a" 68 #define MAX_MATCHES 10 69 #define UNLIKELY_NUM_FEAT 200 71 #define MAX_ADAPTABLE_WERD_SIZE 40 73 #define ADAPTABLE_WERD_ADJUSTMENT (0.05) 75 #define Y_DIM_OFFSET (Y_SHIFT - BASELINE_Y_SHIFT) 77 #define WORST_POSSIBLE_RATING (0.0f) 122 inline bool MarginalMatch(
float confidence,
float matcher_great_threshold) {
123 return (1.0f - confidence) > matcher_great_threshold;
132 for (
int i = 0; i < results.
match.
size(); i++) {
133 if (results.
match[i].unichar_id ==
id)
142 int index = FindScoredUnichar(
id, results);
144 return results.
match[index].rating;
186 assert(Choices != NULL);
210 #ifndef GRAPHICS_DISABLED 221 int y_offset,
const TBOX &wbox) {
222 #ifndef GRAPHICS_DISABLED 223 const int kSampleSpaceWidth = 500;
225 *win =
new ScrollView(msg, 100, y_offset, kSampleSpaceWidth * 2, 200,
226 kSampleSpaceWidth * 2, 200,
true);
229 (*win)->Pen(64, 64, 64);
234 (*win)->ZoomToRectangle(wbox.
left(), wbox.
top(),
236 #endif // GRAPHICS_DISABLED 246 if (word_len == 0)
return;
248 float* thresholds = NULL;
249 if (fontname == NULL) {
255 tprintf(
"\n\nAdapting to word = %s\n",
257 thresholds =
new float[word_len];
265 #ifndef GRAPHICS_DISABLED 267 if (learn_fragmented_word_debug_win_ != NULL) {
277 #endif // GRAPHICS_DISABLED 279 for (
int ch = 0; ch < word_len; ++ch) {
284 float threshold = thresholds != NULL ? thresholds[ch] : 0.0f;
293 bool garbage =
false;
295 for (frag = 0; frag < word->
best_state[ch]; ++frag) {
306 for (frag = 0; frag < word->
best_state[ch]; ++frag) {
311 tokens[0].
string(), frag, word->
best_state[ch],
315 for (
int i = 0; i < tokens.
size(); i++) {
316 full_string += tokens[i];
317 if (i != tokens.
size() - 1)
320 LearnPieces(fontname, start_blob + frag, 1, threshold,
356 delete [] thresholds;
370 const char* correct_text,
WERD_RES* word) {
384 if (rotated_blob == NULL)
387 #ifndef GRAPHICS_DISABLED 393 learn_debug_win_->
Update();
398 blob->
plot(learn_fragments_debug_win_,
400 learn_fragments_debug_win_->
Update();
402 #endif // GRAPHICS_DISABLED 404 if (fontname != NULL) {
408 DENORM bl_denorm, cn_denorm;
411 &bl_denorm, &cn_denorm, &fx_info);
412 LearnBlob(fontname, rotated_blob, cn_denorm, fx_info, correct_text);
415 int font_id = word->
fontinfo != NULL
419 tprintf(
"Adapting to char = %s, thr= %g font_id= %d\n",
427 AdaptToChar(rotated_blob, class_id, font_id, threshold,
431 tprintf(
"Can't adapt to %s not in unicharset\n", correct_text);
433 if (rotated_blob != blob) {
465 cprintf (
"Unable to save adapted templates to %s!\n", Filename.
string());
467 cprintf (
"\nSaving adapted templates to %s ...", Filename.
string());
502 if (static_classifier_ != NULL) {
503 delete static_classifier_;
504 static_classifier_ = NULL;
536 load_pre_trained_templates) {
546 tprintf(
"Error loading shape table!\n");
550 tprintf(
"Successfully loaded shape table!\n");
581 BaselineCutoffs[i] = 0;
594 cprintf(
"\nReading pre-adapted templates from %s ...\n",
603 BaselineCutoffs[i] = CharNormCutoffs[i];
615 tprintf(
"Resetting adaptive classifier (NumAdaptationsFailed=%d)\n",
616 NumAdaptationsFailed);
623 NumAdaptationsFailed = 0;
634 tprintf(
"Switch to backup adaptive classifier (NumAdaptationsFailed=%d)\n",
635 NumAdaptationsFailed);
640 NumAdaptationsFailed = 0;
744 BaselineCutoffs[ClassId] = CharNormCutoffs[ClassId];
748 for (Fid = 0; Fid < Features->
NumFeatures; Fid++) {
754 Proto = &(TempProto->
Proto);
780 tprintf(
"Added new class '%s' with class id %d and %d protos.\n",
828 *FloatFeatures = Features;
853 float adaptable_score =
856 BestChoiceLength > 0 &&
902 Class = adaptive_templates->
Class[ClassId];
903 assert(Class != NULL);
910 if (NumFeatures <= 0) {
916 for (
int cfg = 0; cfg < IClass->
NumConfigs; ++cfg) {
918 SET_BIT(MatchingFontConfigs, cfg);
924 NumFeatures, IntFeatures,
931 if (1.0f - int_result.
rating <= Threshold) {
934 tprintf(
"Found good match to perm config %d = %4.1f%%.\n",
946 tprintf(
"Increasing reliability of temp config %d to %d.\n",
955 tprintf(
"Found poor match to temp config %d = %4.1f%%.\n",
962 NumFeatures, IntFeatures, FloatFeatures);
963 if (NewTempConfigId >= 0 &&
965 MakePermanent(adaptive_templates, ClassId, NewTempConfigId, Blob);
969 #ifndef GRAPHICS_DISABLED 980 #ifndef GRAPHICS_DISABLED 986 if (
sample == NULL)
return;
990 bl_features.
size(), &bl_features[0],
993 tprintf(
"Best match to temp config %d = %4.1f%%.\n",
994 int_result.config, int_result.rating * 100.0);
997 ConfigMask = 1 << int_result.config;
1000 bl_features.
size(), &bl_features[0],
1032 int old_match = FindScoredUnichar(new_result.
unichar_id, *results);
1034 if (new_result.
rating + matcher_bad_match_pad < results->best_rating ||
1035 (old_match < results->match.size() &&
1036 new_result.
rating <= results->
match[old_match].rating))
1042 if (old_match < results->match.size()) {
1043 results->
match[old_match].rating = new_result.
rating;
1092 if (int_features.
empty())
return;
1104 while (*ambiguities >= 0) {
1110 int_features.
size(), &int_features[0],
1118 CharNormArray, &int_result, results);
1121 delete [] CharNormArray;
1130 const uinT8* norm_factors,
1133 int matcher_multiplier,
1134 const TBOX& blob_box,
1137 int top = blob_box.
top();
1138 int bottom = blob_box.
bottom();
1140 for (
int c = 0; c < results.
size(); c++) {
1141 CLASS_ID class_id = results[c].Class;
1150 num_features, features,
1157 matcher_multiplier, norm_factors,
1158 &int_result, final_results);
1168 ADAPT_CLASS* classes,
bool debug,
int class_id,
int bottom,
int top,
1169 float cp_rating,
int blob_length,
int matcher_multiplier,
1170 const uinT8* cn_factors,
1172 if (classes != NULL) {
1175 for (
int f = 0; f < int_result->
fonts.size(); ++f) {
1176 int_result->
fonts[f].fontinfo_id =
1182 for (
int f = 0; f < int_result->
fonts.size(); ++f) {
1183 int_result->
fonts[f].fontinfo_id =
1185 int_result->
fonts[f].fontinfo_id);
1196 for (
int f = 0; f < int_result->
fonts.size(); ++f) {
1197 int shape_id = int_result->
fonts[f].fontinfo_id;
1199 for (
int c = 0; c < shape.
size(); ++c) {
1200 int unichar_id = shape[c].unichar_id;
1204 for (r = 0; r < mapped_results.
size() &&
1205 mapped_results[r].unichar_id != unichar_id; ++r) {}
1206 if (r == mapped_results.
size()) {
1208 mapped_results[r].unichar_id = unichar_id;
1209 mapped_results[r].fonts.
truncate(0);
1211 for (
int i = 0; i < shape[c].font_ids.
size(); ++i) {
1217 for (
int m = 0; m < mapped_results.
size(); ++m) {
1218 mapped_results[m].rating =
1220 cp_rating, int_result->
rating,
1222 blob_length, matcher_multiplier, cn_factors);
1232 bottom, top, blob_length,
1233 matcher_multiplier, cn_factors);
1242 double cp_rating,
double im_rating,
1244 int bottom,
int top,
1245 int blob_length,
int matcher_multiplier,
1246 const uinT8* cn_factors) {
1249 cn_factors[unichar_id],
1250 matcher_multiplier);
1252 double vertical_penalty = 0.0;
1257 int min_bottom, max_bottom, min_top, max_top;
1259 &min_top, &max_top);
1261 tprintf(
"top=%d, vs [%d, %d], bottom=%d, vs [%d, %d]\n",
1262 top, min_top, max_top, bottom, min_bottom, max_bottom);
1264 if (top < min_top || top > max_top ||
1265 bottom < min_bottom || bottom > max_bottom) {
1269 double result = 1.0 - (cn_corrected + miss_penalty + vertical_penalty);
1273 tprintf(
"%s: %2.1f%%(CP%2.1f, IM%2.1f + CN%.2f(%d) + MP%2.1f + VP%2.1f)\n",
1277 (1.0 - im_rating) * 100.0,
1278 (cn_corrected - (1.0 - im_rating)) * 100.0,
1279 cn_factors[unichar_id],
1280 miss_penalty * 100.0,
1281 vertical_penalty * 100.0);
1310 if (int_features.
empty())
return NULL;
1316 CharNormArray, BaselineCutoffs, &Results->
CPResults);
1326 delete [] CharNormArray;
1331 return Templates->
Class[ClassId]->
1363 -1, &unichar_results);
1365 for (
int r = 0; r < unichar_results.size(); ++r) {
1368 return sample.num_features();
1381 int num_features =
sample.num_features();
1391 uinT8* pruner_norm_array =
new uinT8[num_pruner_classes];
1399 shape_table_ != NULL ? &shapetable_cutoffs_[0] : CharNormCutoffs,
1401 delete [] pruner_norm_array;
1402 if (keep_this >= 0) {
1403 adapt_results->
CPResults[0].Class = keep_this;
1409 int class_id = adapt_results->
CPResults[i].Class;
1418 blob_box, adapt_results->
CPResults, adapt_results);
1420 for (
int i = 0; i < adapt_results->
match.
size(); i++) {
1425 delete [] char_norm_array;
1426 delete adapt_results;
1427 return num_features;
1449 rating /= 1.0 + rating;
1462 BLOB_CHOICE_LIST *Choices) {
1463 assert(Choices != NULL);
1466 BLOB_CHOICE_IT temp_it;
1467 bool contains_nonfrag =
false;
1468 temp_it.set_to_list(Choices);
1469 int choices_length = 0;
1483 for (
int i = 0; i < Results->
match.
size(); i++) {
1485 bool adapted = result.
adapted;
1487 if (temp_it.length()+1 == max_matches &&
1488 !contains_nonfrag && current_is_frag) {
1500 Rating = Certainty = (1.0f - result.
rating);
1509 if (Certainty > best_certainty) {
1511 }
else if (adapted &&
1516 float min_xheight, max_xheight, yshift;
1518 &min_xheight, &max_xheight, &yshift);
1522 min_xheight, max_xheight, yshift,
1526 temp_it.add_to_end(choice);
1527 contains_nonfrag |= !current_is_frag;
1529 if (choices_length >= max_matches)
break;
1536 #ifndef GRAPHICS_DISABLED 1549 if (static_classifier_ == NULL)
return;
1554 if (
sample == NULL)
return;
1591 if (
sample == NULL)
return;
1667 Results->
match[0].unichar_id != CorrectClass)) {
1668 for (i = 0; i < Results->
match.
size(); i++)
1669 Ambiguities[i] = Results->
match[i].unichar_id;
1670 Ambiguities[i] = -1;
1672 Ambiguities[0] = -1;
1682 BLOB_CHOICE_LIST *ratings =
new BLOB_CHOICE_LIST();
1684 BLOB_CHOICE_IT ratings_it(ratings);
1690 for (ratings_it.mark_cycle_pt(); !ratings_it.cycled_list();
1691 ratings_it.forward()) {
1695 float certainty = ratings_it.data()->certainty();
1730 uinT8* pruner_norm_array,
1731 uinT8* char_norm_array) {
1750 uinT8* char_norm_array,
1751 uinT8* pruner_array) {
1753 if (pruner_array != NULL) {
1758 templates->
NumClasses *
sizeof(pruner_array[0]));
1761 for (
int id = 0;
id < templates->
NumClasses; ++id) {
1764 for (
int config = 0; config < fs.
size; ++config) {
1766 for (
int c = 0; c < shape.
size(); ++c) {
1767 if (char_norm_array[shape[c].unichar_id] < pruner_array[
id])
1768 pruner_array[id] = char_norm_array[shape[c].unichar_id];
1804 int MaxProtoId, OldMaxProtoId;
1817 Class = Templates->
Class[ClassId];
1820 ++NumAdaptationsFailed;
1822 cprintf(
"Cannot make new temporary config: maximum number exceeded.\n");
1829 BlobLength, NumFeatures, Features,
1835 for (i = 0; i < NumOldProtos; i++)
1839 BlobLength, NumFeatures, Features,
1847 ++NumAdaptationsFailed;
1849 cprintf(
"Cannot make new temp protos: maximum number exceeded.\n");
1860 cprintf(
"Making new temp config %d fontinfo id %d" 1861 " using %d old and %d new protos.\n",
1862 ConfigId,
Config->FontinfoId,
1863 NumOldProtos, MaxProtoId - OldMaxProtoId);
1906 for (ProtoStart = BadFeat, LastBad = ProtoStart + NumBadFeat;
1907 ProtoStart < LastBad; ProtoStart = ProtoEnd) {
1908 F1 = Features->
Features[*ProtoStart];
1913 for (ProtoEnd = ProtoStart + 1,
1917 F2 = Features->
Features[*ProtoEnd];
1922 AngleDelta = fabs(A1 - A2);
1923 if (AngleDelta > 0.5)
1924 AngleDelta = 1.0 - AngleDelta;
1927 fabs(X1 - X2) > SegmentLength ||
1928 fabs(Y1 - Y2) > SegmentLength)
1932 F2 = Features->
Features[*(ProtoEnd - 1)];
1942 Proto = &(TempProto->
Proto);
1947 Proto->
Length = SegmentLength;
1949 Proto->
X = (X1 + X2) / 2.0;
1987 Class = Templates->
Class[ClassId];
1998 "PERM_CONFIG_STRUCT");
2014 tprintf(
"Making config %d for %s (ClassId %d) permanent:" 2015 " fontinfo id %d, ambiguities '",
2016 ConfigId,
getDict().getUnicharset().debug_str(ClassId).
string(),
2019 *AmbigsPointer >= 0; ++AmbigsPointer)
2078 for (
int i = 0; i < results.
match.
size(); ++i) {
2080 results.
match[i].Print();
2103 static const char* romans =
"i v x I V X";
2111 float scored_one = ScoredUnichar(unichar_id_one, *Results);
2112 float scored_zero = ScoredUnichar(unichar_id_zero, *Results);
2114 for (Next = NextGood = 0; Next < Results->
match.
size(); Next++) {
2116 if (match.
rating >= BadMatchThreshold) {
2121 scored_one < BadMatchThreshold) {
2122 Results->
match[Next].unichar_id = unichar_id_one;
2124 scored_zero < BadMatchThreshold) {
2125 Results->
match[Next].unichar_id = unichar_id_zero;
2127 Results->
match[Next].unichar_id = INVALID_UNICHAR_ID;
2129 if (Results->
match[Next].unichar_id != INVALID_UNICHAR_ID) {
2130 if (NextGood == Next) {
2133 Results->
match[NextGood++] = Results->
match[Next];
2139 for (Next = NextGood = 0; Next < Results->
match.
size(); Next++) {
2140 if (Results->
match[Next].rating >= BadMatchThreshold) {
2141 if (NextGood == Next) {
2144 Results->
match[NextGood++] = Results->
match[Next];
2167 static char punc_chars[] =
". , ; : / ` ~ ' - = \\ | \" ! _ ^";
2168 static char digit_chars[] =
"0 1 2 3 4 5 6 7 8 9";
2172 for (Next = NextGood = 0; Next < Results->
match.
size(); Next++) {
2175 if (strstr(punc_chars,
2177 if (punc_count >= 2)
2181 if (strstr(digit_chars,
2183 if (digit_count >= 1)
2189 if (NextGood == Next) {
2192 Results->
match[NextGood++] = match;
2216 ClipToRange<int>(255 * Threshold, 0, 255));
2218 ClipToRange<int>(255 * Threshold, 0, 255));
2237 #ifndef GRAPHICS_DISABLED 2240 tprintf(
"No built-in templates for class/shape %d\n", shape_id);
2243 if (num_features <= 0) {
2244 tprintf(
"Illegal blob (char norm features)!\n");
2251 num_features, features, &cn_result,
2255 config_mask = 1 << cn_result.
config;
2257 tprintf(
"Static Shape ID: %d\n", shape_id);
2260 AllProtosOn, reinterpret_cast<BIT_VECTOR>(&config_mask),
2261 num_features, features, &cn_result,
2266 #endif // GRAPHICS_DISABLED 2272 int class_id,
int config_id)
const {
2280 return class_string;
2285 int int_result_config)
const {
2288 if (font_set_id < 0)
2289 return kBlankFontinfoId;
2292 return fs.
configs[int_result_config];
2302 for (
int config = 0; config < fs.
size; ++config) {
2303 if (fs.
configs[config] == shape_id)
2307 tprintf(
"Shape %d not found\n", shape_id);
2316 tprintf(
"NumTimesSeen for config of %s is %d\n",
2317 getDict().getUnicharset().debug_str(class_id).
string(),
2329 int ambigs_size = (ambigs == NULL) ? 0 : ambigs->
size();
2330 for (
int ambig = 0; ambig < ambigs_size; ++ambig) {
2332 assert(ambig_class != NULL);
2337 tprintf(
"Ambig %s has not been seen enough times," 2338 " not making config for %s permanent\n",
2339 getDict().getUnicharset().debug_str(
2340 (*ambigs)[ambig]).
string(),
2341 getDict().getUnicharset().debug_str(class_id).
string());
2353 int ambigs_size = (ambigs == NULL) ? 0 : ambigs->
size();
2355 tprintf(
"Running UpdateAmbigsGroup for %s class_id=%d\n",
2356 getDict().getUnicharset().debug_str(class_id).
string(), class_id);
2358 for (
int ambig = 0; ambig < ambigs_size; ++ambig) {
2359 CLASS_ID ambig_class_id = (*ambigs)[ambig];
2367 tprintf(
"Making config %d of %s permanent\n", cfg,
2368 getDict().getUnicharset().debug_str(
2369 ambig_class_id).
string());
double matcher_rating_margin
void free_adapted_templates(ADAPT_TEMPLATES templates)
bool PiecesAllNatural(int start, int count) const
int FindGoodProtos(INT_CLASS ClassTemplate, BIT_VECTOR ProtoMask, BIT_VECTOR ConfigMask, uinT16 BlobLength, inT16 NumFeatures, INT_FEATURE_ARRAY Features, PROTO_ID *ProtoArray, int AdaptProtoThreshold, int Debug)
void AddProtoToProtoPruner(PROTO Proto, int ProtoId, INT_CLASS Class, bool debug)
UnicityTable< FontSet > fontset_table_
bool classify_enable_adaptive_debugger
inT64 GetEndOffset(TessdataType tessdata_type) const
INT_TEMPLATES ReadIntTemplates(FILE *File)
FILE * GetDataFilePtr() const
#define copy_all_bits(source, dest, length)
int MakeNewTemporaryConfig(ADAPT_TEMPLATES Templates, CLASS_ID ClassId, int FontinfoId, int NumFeatures, INT_FEATURE_ARRAY Features, FEATURE_SET FloatFeatures)
double matcher_good_threshold
TEMP_CONFIG NewTempConfig(int MaxProtoId, int FontinfoId)
double classify_character_fragments_garbage_certainty_threshold
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)
double matcher_clustering_max_angle_delta
void cprintf(const char *format,...)
bool DeSerialize(bool swap, FILE *fp)
bool eq(UNICHAR_ID unichar_id, const char *const unichar_repr) const
const int kBlnBaselineOffset
void ComputeCharNormArrays(FEATURE_STRUCT *norm_feature, INT_TEMPLATES_STRUCT *templates, uinT8 *char_norm_array, uinT8 *pruner_array)
#define TempConfigFor(Class, ConfigId)
bool get_isalpha(UNICHAR_ID unichar_id) const
void StartBackupAdaptiveClassifier()
int IntCastRounded(double x)
void SettupStopperPass1()
Sets up stopper variables in preparation for the first pass.
GenericVector< TBLOB * > blobs
static void BreakPieces(const GenericVector< SEAM *> &seams, const GenericVector< TBLOB *> &blobs, int first, int last)
bool classify_enable_learning
int GetFontinfoId(ADAPT_CLASS Class, uinT8 ConfigId)
LIST delete_d(LIST list, void *key, int_compare is_equal)
bool LargeSpeckle(const TBLOB &blob)
bool classify_enable_adaptive_matcher
ADAPT_TEMPLATES AdaptedTemplates
#define IncreaseConfidence(TempConfig)
#define LENGTH_COMPRESSION
bool TESS_API contains_unichar(const char *const unichar_repr) const
void Init(tesseract::IntParam *classify_debug_level)
#define PRINT_PROTO_MATCHES
float adjust_factor() const
PROTO_ID MakeNewTempProtos(FEATURE_SET Features, int NumBadFeat, FEATURE_ID BadFeat[], INT_CLASS IClass, ADAPT_CLASS Class, BIT_VECTOR TempProtoMask)
void FreeFeature(FEATURE Feature)
void get_top_bottom(UNICHAR_ID unichar_id, int *min_bottom, int *max_bottom, int *min_top, int *max_top) const
bool use_ambigs_for_adaption
void LearnPieces(const char *fontname, int start, int length, float threshold, CharSegmentationType segmentation, const char *correct_text, WERD_RES *word)
INT_FEATURE_STRUCT INT_FEATURE_ARRAY[MAX_NUM_INT_FEATURES]
void AddProtoToClassPruner(PROTO Proto, CLASS_ID ClassId, INT_TEMPLATES Templates)
void ClearCharNormArray(uinT8 *char_norm_array)
#define MAX_ADAPTABLE_WERD_SIZE
#define UnusedClassIdIn(T, c)
void DoAdaptiveMatch(TBLOB *Blob, ADAPT_RESULTS *Results)
static void JoinPieces(const GenericVector< SEAM *> &seams, const GenericVector< TBLOB *> &blobs, int first, int last)
void Match(INT_CLASS ClassTemplate, BIT_VECTOR ProtoMask, BIT_VECTOR ConfigMask, inT16 NumFeatures, const INT_FEATURE_STRUCT *Features, tesseract::UnicharRating *Result, int AdaptFeatureThreshold, int Debug, bool SeparateDebugWindows)
static void SetupBLCNDenorms(const TBLOB &blob, bool nonlinear_norm, DENORM *bl_denorm, DENORM *cn_denorm, INT_FX_RESULT_STRUCT *fx_info)
double matcher_bad_match_pad
void set_fonts(const GenericVector< tesseract::ScoredFont > &fonts)
void PrintAdaptedTemplates(FILE *File, ADAPT_TEMPLATES Templates)
GenericVector< ScoredFont > fonts
void SettupStopperPass2()
Sets up stopper variables in preparation for the second pass.
void FreeTempConfig(TEMP_CONFIG Config)
void RefreshDebugWindow(ScrollView **win, const char *msg, int y_offset, const TBOX &wbox)
const UNICHARSET & getUnicharset() const
INT_TEMPLATES PreTrainedTemplates
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)
void ResetAdaptiveClassifierInternal()
void LearnWord(const char *fontname, WERD_RES *word)
char * classify_learn_debug_str
double tessedit_class_miss_scale
#define IsEmptyAdaptedClass(Class)
int ShapeIDToClassID(int shape_id) const
void ReadNewCutoffs(FILE *CutoffFile, bool swap, inT64 end_offset, CLASS_CUTOFF_ARRAY Cutoffs)
void EndDangerousAmbigs()
WERD_CHOICE * best_choice
TBOX bounding_box() const
BIT_VECTOR NewBitVector(int NumBits)
int classify_adapt_feature_threshold
PERM_CONFIG_STRUCT * PERM_CONFIG
#define set_all_bits(array, length)
int matcher_permanent_classes_min
const double kStandardFeatureLength
bool classify_use_pre_adapted_templates
#define WordsInVectorOfSize(NumBits)
virtual void DebugDisplay(const TrainingSample &sample, Pix *page_pix, UNICHAR_ID unichar_id)
GenericVector< SEAM * > seam_array
TrainingSample * BlobToTrainingSample(const TBLOB &blob, bool nonlinear_norm, INT_FX_RESULT_STRUCT *fx_info, GenericVector< INT_FEATURE_STRUCT > *bl_features)
void UpdateMatchDisplay()
double matcher_perfect_threshold
void MakePermanent(ADAPT_TEMPLATES Templates, CLASS_ID ClassId, int ConfigId, TBLOB *Blob)
int AddIntProto(INT_CLASS Class)
UnicityTable< FontInfo > fontinfo_table_
TessdataManager tessdata_manager
bool LooksLikeGarbage(TBLOB *blob)
#define ClassForClassId(T, c)
void RemoveExtraPuncs(ADAPT_RESULTS *Results)
bool classify_debug_character_fragments
#define UNLIKELY_NUM_FEAT
int matcher_sufficient_examples_for_prototyping
TEMP_PROTO_STRUCT * TEMP_PROTO
const char * string() const
int GetCharNormFeature(const INT_FX_RESULT_STRUCT &fx_info, INT_TEMPLATES templates, uinT8 *pruner_norm_array, uinT8 *char_norm_array)
void FillABC(PROTO Proto)
#define SET_BIT(array, bit)
const FontInfo * fontinfo
NORM_PROTOS * ReadNormProtos(FILE *File, inT64 end_offset)
TEMP_PROTO NewTempProto()
ADAPT_TEMPLATES ReadAdaptedTemplates(FILE *File)
#define PermConfigFor(Class, ConfigId)
void AddNewResult(const UnicharRating &new_result, ADAPT_RESULTS *results)
#define MAX_NUM_INT_FEATURES
FEATURE_SET ExtractOutlineFeatures(TBLOB *Blob)
void plot(ScrollView *window)
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)
void InitMatcherRatings(register FLOAT32 *Rating)
GenericVector< CP_RESULT_STRUCT > CPResults
void FreeBitVector(BIT_VECTOR BitVector)
#define MakeProtoPermanent(Class, ProtoId)
void plot(ScrollView *window, ScrollView::Color color, ScrollView::Color child_color)
void RemoveBadMatches(ADAPT_RESULTS *Results)
const UnicharIdVector * AmbigsForAdaption(UNICHAR_ID unichar_id) const
void UpdateAmbigsGroup(CLASS_ID class_id, TBLOB *Blob)
bool matcher_debug_separate_windows
void LearnBlob(const STRING &fontname, TBLOB *Blob, const DENORM &cn_denorm, const INT_FX_RESULT_STRUCT &fx_info, const char *blob_text)
UNICHAR_ID best_unichar_id
double classify_adapted_pruning_factor
const UnicharAmbigs & getUnicharAmbigs() const
void AdaptiveClassifier(TBLOB *Blob, BLOB_CHOICE_LIST *Choices)
STRING debug_str(UNICHAR_ID id) const
void free_int_templates(INT_TEMPLATES templates)
void print_ratings_list(const char *msg, BLOB_CHOICE_LIST *ratings, const UNICHARSET ¤t_unicharset)
int CharNormClassifier(TBLOB *blob, const TrainingSample &sample, ADAPT_RESULTS *adapt_results)
float ApplyCNCorrection(float rating, int blob_length, int normalization_factor, int matcher_multiplier)
double classify_misfit_junk_penalty
TBOX bounding_box() const
const DENORM & denorm() const
int AddIntConfig(INT_CLASS Class)
FEATURE_SET ExtractPicoFeatures(TBLOB *Blob)
FLOAT32 ActualOutlineLength(FEATURE Feature)
TBLOB * ClassifyNormalizeIfNeeded() const
bool classify_nonlinear_norm
int ClassAndConfigIDToFontOrShapeID(int class_id, int int_result_config) const
void SetAdaptiveThreshold(FLOAT32 Threshold)
ADAPT_TEMPLATES Templates
int classify_adapt_proto_threshold
bool AlternativeChoiceAdjustmentsWorseThan(float threshold) const
LIST push(LIST list, void *element)
int get_script(UNICHAR_ID unichar_id) const
const UnicharIdVector * ReverseAmbigsForAdaption(UNICHAR_ID unichar_id) const
int matcher_min_examples_for_prototyping
UNICHAR_ID TESS_API unichar_to_id(const char *const unichar_repr) const
GenericVector< STRING > correct_text
void ConvertProto(PROTO Proto, int ProtoId, INT_CLASS Class)
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)
int classify_learning_debug_level
double segment_penalty_dict_case_ok
ShapeTable * shape_table_
int CharNormTrainingSample(bool pruner_only, int keep_this, const TrainingSample &sample, GenericVector< UnicharRating > *results)
bool disable_character_fragments
double classify_adapted_pruning_threshold
void AddLargeSpeckleTo(int blob_length, BLOB_CHOICE_LIST *choices)
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)
int classify_integer_matcher_multiplier
#define PRINT_MATCH_SUMMARY
void DisplayAdaptedChar(TBLOB *blob, INT_CLASS_STRUCT *int_class)
FEATURE NewFeature(const FEATURE_DESC_STRUCT *FeatureDesc)
const Shape & GetShape(int shape_id) const
int FindBadFeatures(INT_CLASS ClassTemplate, BIT_VECTOR ProtoMask, BIT_VECTOR ConfigMask, uinT16 BlobLength, inT16 NumFeatures, INT_FEATURE_ARRAY Features, FEATURE_ID *FeatureArray, int AdaptFeatureThreshold, int Debug)
void FreeTempProto(void *arg)
void EndAdaptiveClassifier()
STRING language_data_path_prefix
int GetAdaptiveFeatures(TBLOB *Blob, INT_FEATURE_ARRAY IntFeatures, FEATURE_SET *FloatFeatures)
#define test_bit(array, bit)
bool TempConfigReliable(CLASS_ID class_id, const TEMP_CONFIG &config)
void ConvertConfig(BIT_VECTOR Config, int ConfigId, INT_CLASS Class)
bool SeekToStart(TessdataType tessdata_type)
void DebugAdaptiveClassifier(TBLOB *Blob, ADAPT_RESULTS *Results)
#define ADAPT_TEMPLATE_SUFFIX
void PrintAdaptiveMatchResults(const ADAPT_RESULTS &results)
#define MakeConfigPermanent(Class, ConfigId)
UNICHAR_ID * GetAmbiguities(TBLOB *Blob, CLASS_ID CorrectClass)
#define PRINT_FEATURE_MATCHES
void * alloc_struct(inT32 count, const char *)
void ShowBestMatchFor(int shape_id, const INT_FEATURE_STRUCT *features, int num_features)
int MakeTempProtoPerm(void *item1, void *item2)
void SetAdaptiveThreshold(FLOAT32 Threshold)
bool classify_bln_numeric_mode
const FEATURE_DESC_STRUCT CharNormDesc
void ComputeIntFeatures(FEATURE_SET Features, INT_FEATURE_ARRAY IntFeatures)
#define reset_bit(array, bit)
bool get_isdigit(UNICHAR_ID unichar_id) const
void ConvertMatchesToChoices(const DENORM &denorm, const TBOX &box, ADAPT_RESULTS *Results, BLOB_CHOICE_LIST *Choices)
void AdaptToChar(TBLOB *Blob, CLASS_ID ClassId, int FontinfoId, FLOAT32 Threshold, ADAPT_TEMPLATES adaptive_templates)
double matcher_reliable_adaptive_result
void FreeFeatureSet(FEATURE_SET FeatureSet)
void XHeightRange(int unichar_id, const UNICHARSET &unicharset, const TBOX &bbox, float *min_xht, float *max_xht, float *yshift) const
GenericVector< int > best_state
void InitAdaptiveClassifier(bool load_pre_trained_templates)
char window_wait(ScrollView *win)
#define zero_all_bits(array, length)
const char * id_to_unichar(UNICHAR_ID id) const
static int SortDescendingRating(const void *t1, const void *t2)
bool get_enabled(UNICHAR_ID unichar_id) const
bool classify_save_adapted_templates
#define ADAPTABLE_WERD_ADJUSTMENT
GenericVector< UnicharRating > match
const STRING debug_string() const
ADAPT_TEMPLATES BackupAdaptedTemplates
#define WORST_POSSIBLE_RATING
STRING DebugStr(int shape_id) const
virtual int UnicharClassifySample(const TrainingSample &sample, Pix *page_pix, int debug, UNICHAR_ID keep_this, GenericVector< UnicharRating > *results)
int MaxNumUnichars() const
void ComputeAdaptionThresholds(float certainty_scale, float min_rating, float max_rating, float rating_margin, float *thresholds)
ADAPT_TEMPLATES NewAdaptedTemplates(bool InitFromUnicharset)
const CHAR_FRAGMENT * get_fragment(UNICHAR_ID unichar_id) const
void ClassifyAsNoise(ADAPT_RESULTS *Results)
void ComputeIntCharNormArray(const FEATURE_STRUCT &norm_feature, uinT8 *char_norm_array)
void SwitchAdaptiveClassifier()
INT_CLASS Class[MAX_NUM_CLASSES]
#define ConfigIsPermanent(Class, ConfigId)
bool MarginalMatch(float confidence, float matcher_great_threshold)
#define GetPicoFeatureLength()
void WriteAdaptedTemplates(FILE *File, ADAPT_TEMPLATES Templates)
void InitAdaptedClass(TBLOB *Blob, CLASS_ID ClassId, int FontinfoId, ADAPT_CLASS Class, ADAPT_TEMPLATES Templates)
double matcher_avg_noise_size
bool AdaptableWord(WERD_RES *word)
ADAPT_CLASS Class[MAX_NUM_CLASSES]
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)
STRING ClassIDToDebugStr(const INT_TEMPLATES_STRUCT *templates, int class_id, int config_id) const