tesseract
5.0.0-alpha-619-ge9db
|
Go to the documentation of this file.
22 #include "config_auto.h"
75 #define ADAPT_TEMPLATE_SUFFIX ".a"
77 #define MAX_MATCHES 10
78 #define UNLIKELY_NUM_FEAT 200
80 #define MAX_ADAPTABLE_WERD_SIZE 40
82 #define ADAPTABLE_WERD_ADJUSTMENT (0.05)
84 #define Y_DIM_OFFSET (Y_SHIFT - BASELINE_Y_SHIFT)
86 #define WORST_POSSIBLE_RATING (0.0f)
131 inline bool MarginalMatch(
float confidence,
float matcher_great_threshold) {
132 return (1.0f - confidence) > matcher_great_threshold;
141 for (
int i = 0; i < results.
match.
size(); i++) {
142 if (results.
match[i].unichar_id ==
id)
151 int index = FindScoredUnichar(
id, results);
153 return results.
match[index].rating;
192 assert(Choices !=
nullptr);
203 Results->ComputeBest();
216 #ifndef GRAPHICS_DISABLED
227 int y_offset,
const TBOX &wbox) {
228 #ifndef GRAPHICS_DISABLED
229 const int kSampleSpaceWidth = 500;
230 if (*win ==
nullptr) {
231 *win =
new ScrollView(msg, 100, y_offset, kSampleSpaceWidth * 2, 200,
232 kSampleSpaceWidth * 2, 200,
true);
235 (*win)->Pen(64, 64, 64);
240 (*win)->ZoomToRectangle(wbox.
left(), wbox.
top(),
242 #endif // GRAPHICS_DISABLED
252 if (word_len == 0)
return;
254 float* thresholds =
nullptr;
255 if (fontname ==
nullptr) {
261 tprintf(
"\n\nAdapting to word = %s\n",
263 thresholds =
new float[word_len];
271 #ifndef GRAPHICS_DISABLED
273 if (learn_fragmented_word_debug_win_ !=
nullptr) {
283 #endif // GRAPHICS_DISABLED
285 for (
int ch = 0; ch < word_len; ++ch) {
290 float threshold = thresholds !=
nullptr ? thresholds[ch] : 0.0f;
299 bool garbage =
false;
301 for (frag = 0; frag < word->
best_state[ch]; ++frag) {
312 for (frag = 0; frag < word->
best_state[ch]; ++frag) {
317 tokens[0].c_str(), frag, word->
best_state[ch],
321 for (
int i = 0; i < tokens.
size(); i++) {
322 full_string += tokens[i];
323 if (i != tokens.
size() - 1)
326 LearnPieces(fontname, start_blob + frag, 1, threshold,
362 delete [] thresholds;
376 const char* correct_text,
WERD_RES* word) {
390 if (rotated_blob ==
nullptr)
393 #ifndef GRAPHICS_DISABLED
399 learn_debug_win_->
Update();
403 ASSERT_HOST(learn_fragments_debug_win_ !=
nullptr);
404 blob->
plot(learn_fragments_debug_win_,
406 learn_fragments_debug_win_->
Update();
408 #endif // GRAPHICS_DISABLED
410 if (fontname !=
nullptr) {
414 DENORM bl_denorm, cn_denorm;
417 &bl_denorm, &cn_denorm, &fx_info);
418 LearnBlob(fontname, rotated_blob, cn_denorm, fx_info, correct_text);
421 int font_id = word->
fontinfo !=
nullptr
425 tprintf(
"Adapting to char = %s, thr= %g font_id= %d\n",
433 AdaptToChar(rotated_blob, class_id, font_id, threshold,
437 tprintf(
"Can't adapt to %s not in unicharset\n", correct_text);
439 if (rotated_blob != blob) {
468 cprintf (
"Unable to save adapted templates to %s!\n", Filename.
c_str());
470 cprintf (
"\nSaving adapted templates to %s ...", Filename.
c_str());
505 delete static_classifier_;
506 static_classifier_ =
nullptr;
543 tprintf(
"Error loading shape table!\n");
567 for (uint16_t& BaselineCutoff : BaselineCutoffs) {
577 if (!fp.
Open(Filename.
c_str(),
nullptr)) {
580 cprintf(
"\nReading pre-adapted templates from %s ...\n",
588 BaselineCutoffs[i] = CharNormCutoffs[i];
600 tprintf(
"Resetting adaptive classifier (NumAdaptationsFailed=%d)\n",
601 NumAdaptationsFailed);
608 NumAdaptationsFailed = 0;
619 tprintf(
"Switch to backup adaptive classifier (NumAdaptationsFailed=%d)\n",
620 NumAdaptationsFailed);
625 NumAdaptationsFailed = 0;
720 BaselineCutoffs[ClassId] = CharNormCutoffs[ClassId];
724 for (Fid = 0; Fid < Features->
NumFeatures; Fid++) {
730 Proto = &(TempProto->
Proto);
756 tprintf(
"Added new class '%s' with class id %d and %d protos.\n",
802 *FloatFeatures = Features;
824 float adaptable_score =
827 BestChoiceLength > 0 &&
869 Class = adaptive_templates->
Class[ClassId];
870 assert(Class !=
nullptr);
877 if (NumFeatures <= 0) {
883 for (
int cfg = 0; cfg < IClass->
NumConfigs; ++cfg) {
885 SET_BIT(MatchingFontConfigs, cfg);
891 NumFeatures, IntFeatures,
894 FreeBitVector(MatchingFontConfigs);
898 if (1.0f - int_result.
rating <= Threshold) {
901 tprintf(
"Found good match to perm config %d = %4.1f%%.\n",
913 tprintf(
"Increasing reliability of temp config %d to %d.\n",
922 tprintf(
"Found poor match to temp config %d = %4.1f%%.\n",
929 NumFeatures, IntFeatures, FloatFeatures);
930 if (NewTempConfigId >= 0 &&
932 MakePermanent(adaptive_templates, ClassId, NewTempConfigId, Blob);
936 #ifndef GRAPHICS_DISABLED
947 #ifndef GRAPHICS_DISABLED
953 if (
sample ==
nullptr)
return;
957 bl_features.
size(), &bl_features[0],
960 tprintf(
"Best match to temp config %d = %4.1f%%.\n",
961 int_result.config, int_result.rating * 100.0);
964 ConfigMask = 1 << int_result.config;
967 bl_features.
size(), &bl_features[0],
996 int old_match = FindScoredUnichar(new_result.
unichar_id, *results);
998 if (new_result.
rating + matcher_bad_match_pad < results->best_rating ||
999 (old_match < results->match.size() &&
1000 new_result.
rating <= results->
match[old_match].rating))
1006 if (old_match < results->match.size()) {
1007 results->
match[old_match].rating = new_result.
rating;
1053 if (int_features.
empty())
return;
1065 while (*ambiguities >= 0) {
1071 int_features.
size(), &int_features[0],
1079 CharNormArray, &int_result, results);
1082 delete [] CharNormArray;
1089 int16_t num_features,
1091 const uint8_t* norm_factors,
1094 int matcher_multiplier,
1095 const TBOX& blob_box,
1098 int top = blob_box.
top();
1099 int bottom = blob_box.
bottom();
1101 for (
int c = 0; c < results.
size(); c++) {
1102 CLASS_ID class_id = results[c].Class;
1111 num_features, features,
1118 matcher_multiplier, norm_factors,
1119 &int_result, final_results);
1129 ADAPT_CLASS* classes,
bool debug,
int class_id,
int bottom,
int top,
1130 float cp_rating,
int blob_length,
int matcher_multiplier,
1131 const uint8_t* cn_factors,
1133 if (classes !=
nullptr) {
1136 for (
int f = 0; f < int_result->
fonts.size(); ++f) {
1137 int_result->
fonts[f].fontinfo_id =
1143 for (
int f = 0; f < int_result->
fonts.size(); ++f) {
1144 int_result->
fonts[f].fontinfo_id =
1146 int_result->
fonts[f].fontinfo_id);
1157 for (
int f = 0; f < int_result->
fonts.size(); ++f) {
1158 int shape_id = int_result->
fonts[f].fontinfo_id;
1160 for (
int c = 0; c < shape.
size(); ++c) {
1161 int unichar_id = shape[c].unichar_id;
1165 for (r = 0; r < mapped_results.
size() &&
1166 mapped_results[r].unichar_id != unichar_id; ++r) {}
1167 if (r == mapped_results.
size()) {
1169 mapped_results[r].unichar_id = unichar_id;
1170 mapped_results[r].fonts.
truncate(0);
1172 for (
int i = 0; i < shape[c].font_ids.
size(); ++i) {
1178 for (
int m = 0; m < mapped_results.
size(); ++m) {
1179 mapped_results[m].rating =
1181 cp_rating, int_result->
rating,
1183 blob_length, matcher_multiplier, cn_factors);
1193 bottom, top, blob_length,
1194 matcher_multiplier, cn_factors);
1203 double cp_rating,
double im_rating,
1205 int bottom,
int top,
1206 int blob_length,
int matcher_multiplier,
1207 const uint8_t* cn_factors) {
1210 cn_factors[unichar_id],
1211 matcher_multiplier);
1213 double vertical_penalty = 0.0;
1218 int min_bottom, max_bottom, min_top, max_top;
1220 &min_top, &max_top);
1222 tprintf(
"top=%d, vs [%d, %d], bottom=%d, vs [%d, %d]\n",
1223 top, min_top, max_top, bottom, min_bottom, max_bottom);
1225 if (top < min_top || top > max_top ||
1226 bottom < min_bottom || bottom > max_bottom) {
1230 double result = 1.0 - (cn_corrected + miss_penalty + vertical_penalty);
1234 tprintf(
"%s: %2.1f%%(CP%2.1f, IM%2.1f + CN%.2f(%d) + MP%2.1f + VP%2.1f)\n",
1238 (1.0 - im_rating) * 100.0,
1239 (cn_corrected - (1.0 - im_rating)) * 100.0,
1240 cn_factors[unichar_id],
1241 miss_penalty * 100.0,
1242 vertical_penalty * 100.0);
1269 if (int_features.
empty())
return nullptr;
1275 CharNormArray, BaselineCutoffs, &Results->
CPResults);
1285 delete [] CharNormArray;
1290 return Templates->
Class[ClassId]->
1319 -1, &unichar_results);
1321 for (
int r = 0; r < unichar_results.size(); ++r) {
1324 return sample.num_features();
1335 adapt_results->Initialize();
1337 uint32_t num_features =
sample.num_features();
1347 auto* pruner_norm_array =
new uint8_t[num_pruner_classes];
1348 adapt_results->BlobLength =
1355 shape_table_ !=
nullptr ? &shapetable_cutoffs_[0] : CharNormCutoffs,
1356 &adapt_results->CPResults);
1357 delete [] pruner_norm_array;
1358 if (keep_this >= 0) {
1359 adapt_results->CPResults[0].Class = keep_this;
1360 adapt_results->CPResults.truncate(1);
1364 for (
int i = 0; i < adapt_results->CPResults.size(); ++i) {
1365 int class_id = adapt_results->CPResults[i].Class;
1367 UnicharRating(class_id, 1.0f - adapt_results->CPResults[i].Rating));
1374 blob_box, adapt_results->CPResults, adapt_results);
1376 for (
int i = 0; i < adapt_results->match.size(); i++) {
1377 results->
push_back(adapt_results->match[i]);
1381 delete [] char_norm_array;
1382 delete adapt_results;
1383 return num_features;
1402 rating /= 1.0 + rating;
1415 BLOB_CHOICE_LIST *Choices) {
1416 assert(Choices !=
nullptr);
1419 BLOB_CHOICE_IT temp_it;
1420 bool contains_nonfrag =
false;
1421 temp_it.set_to_list(Choices);
1422 int choices_length = 0;
1435 float best_certainty = -FLT_MAX;
1436 for (
int i = 0; i < Results->
match.
size(); i++) {
1438 bool adapted = result.
adapted;
1440 if (temp_it.length()+1 == max_matches &&
1441 !contains_nonfrag && current_is_frag) {
1453 Rating = Certainty = (1.0f - result.
rating);
1462 if (Certainty > best_certainty) {
1464 }
else if (adapted &&
1469 float min_xheight, max_xheight, yshift;
1471 &min_xheight, &max_xheight, &yshift);
1475 min_xheight, max_xheight, yshift,
1479 temp_it.add_to_end(choice);
1480 contains_nonfrag |= !current_is_frag;
1482 if (choices_length >= max_matches)
break;
1489 #ifndef GRAPHICS_DISABLED
1499 if (static_classifier_ ==
nullptr)
return;
1504 if (
sample ==
nullptr)
return;
1538 if (
sample ==
nullptr)
return;
1542 if (static_classifier_ ==
nullptr) {
1598 Results->Initialize();
1616 Ambiguities =
new UNICHAR_ID[Results->match.size() + 1];
1617 if (Results->match.size() > 1 ||
1618 (Results->match.size() == 1 &&
1619 Results->match[0].unichar_id != CorrectClass)) {
1620 for (i = 0; i < Results->match.size(); i++)
1621 Ambiguities[i] = Results->match[i].unichar_id;
1622 Ambiguities[i] = -1;
1624 Ambiguities[0] = -1;
1634 auto *ratings =
new BLOB_CHOICE_LIST();
1636 BLOB_CHOICE_IT ratings_it(ratings);
1642 for (ratings_it.mark_cycle_pt(); !ratings_it.cycled_list();
1643 ratings_it.forward()) {
1647 float certainty = ratings_it.data()->certainty();
1680 uint8_t* pruner_norm_array,
1681 uint8_t* char_norm_array) {
1700 uint8_t* char_norm_array,
1701 uint8_t* pruner_array) {
1703 if (pruner_array !=
nullptr) {
1707 memset(pruner_array, UINT8_MAX,
1708 templates->
NumClasses *
sizeof(pruner_array[0]));
1711 for (
int id = 0;
id < templates->
NumClasses; ++id) {
1714 for (
int config = 0; config < fs.
size; ++config) {
1716 for (
int c = 0; c < shape.
size(); ++c) {
1717 if (char_norm_array[shape[c].unichar_id] < pruner_array[
id])
1718 pruner_array[id] = char_norm_array[shape[c].unichar_id];
1752 int MaxProtoId, OldMaxProtoId;
1764 Class = Templates->
Class[ClassId];
1767 ++NumAdaptationsFailed;
1769 cprintf(
"Cannot make new temporary config: maximum number exceeded.\n");
1776 NumFeatures, Features,
1782 for (i = 0; i < NumOldProtos; i++)
1786 NumFeatures, Features,
1794 ++NumAdaptationsFailed;
1796 cprintf(
"Cannot make new temp protos: maximum number exceeded.\n");
1807 cprintf(
"Making new temp config %d fontinfo id %d"
1808 " using %d old and %d new protos.\n",
1809 ConfigId,
Config->FontinfoId,
1810 NumOldProtos, MaxProtoId - OldMaxProtoId);
1846 float X1, X2, Y1, Y2;
1847 float A1, A2, AngleDelta;
1848 float SegmentLength;
1851 for (ProtoStart = BadFeat, LastBad = ProtoStart + NumBadFeat;
1852 ProtoStart < LastBad; ProtoStart = ProtoEnd) {
1853 F1 = Features->
Features[*ProtoStart];
1858 for (ProtoEnd = ProtoStart + 1,
1862 F2 = Features->
Features[*ProtoEnd];
1867 AngleDelta = fabs(A1 - A2);
1868 if (AngleDelta > 0.5)
1869 AngleDelta = 1.0 - AngleDelta;
1872 fabs(X1 - X2) > SegmentLength ||
1873 fabs(Y1 - Y2) > SegmentLength)
1877 F2 = Features->
Features[*(ProtoEnd - 1)];
1887 Proto = &(TempProto->
Proto);
1892 Proto->
Length = SegmentLength;
1894 Proto->
X = (X1 + X2) / 2.0;
1929 Class = Templates->
Class[ClassId];
1940 Perm->Ambigs = Ambigs;
1941 Perm->FontinfoId =
Config->FontinfoId;
1955 tprintf(
"Making config %d for %s (ClassId %d) permanent:"
1956 " fontinfo id %d, ambiguities '",
1957 ConfigId,
getDict().getUnicharset().debug_str(ClassId).c_str(),
1960 *AmbigsPointer >= 0; ++AmbigsPointer)
1986 TempProto = static_cast<TEMP_PROTO>(item1);
1987 ProtoKey = static_cast<PROTO_KEY *>(item2);
2014 for (
int i = 0; i < results.
match.
size(); ++i) {
2016 results.
match[i].Print();
2035 float BadMatchThreshold;
2036 static const char* romans =
"i v x I V X";
2044 float scored_one = ScoredUnichar(unichar_id_one, *Results);
2045 float scored_zero = ScoredUnichar(unichar_id_zero, *Results);
2047 for (Next = NextGood = 0; Next < Results->
match.
size(); Next++) {
2049 if (match.
rating >= BadMatchThreshold) {
2054 scored_one < BadMatchThreshold) {
2055 Results->
match[Next].unichar_id = unichar_id_one;
2057 scored_zero < BadMatchThreshold) {
2058 Results->
match[Next].unichar_id = unichar_id_zero;
2060 Results->
match[Next].unichar_id = INVALID_UNICHAR_ID;
2062 if (Results->
match[Next].unichar_id != INVALID_UNICHAR_ID) {
2063 if (NextGood == Next) {
2066 Results->
match[NextGood++] = Results->
match[Next];
2072 for (Next = NextGood = 0; Next < Results->
match.
size(); Next++) {
2073 if (Results->
match[Next].rating >= BadMatchThreshold) {
2074 if (NextGood == Next) {
2077 Results->
match[NextGood++] = Results->
match[Next];
2098 static char punc_chars[] =
". , ; : / ` ~ ' - = \\ | \" ! _ ^";
2099 static char digit_chars[] =
"0 1 2 3 4 5 6 7 8 9";
2103 for (Next = NextGood = 0; Next < Results->
match.
size(); Next++) {
2106 if (strstr(punc_chars,
2108 if (punc_count >= 2)
2112 if (strstr(digit_chars,
2114 if (digit_count >= 1)
2120 if (NextGood == Next) {
2123 Results->
match[NextGood++] = match;
2144 ClipToRange<int>(255 * Threshold, 0, 255));
2146 ClipToRange<int>(255 * Threshold, 0, 255));
2162 #ifndef GRAPHICS_DISABLED
2163 uint32_t config_mask;
2165 tprintf(
"No built-in templates for class/shape %d\n", shape_id);
2168 if (num_features <= 0) {
2169 tprintf(
"Illegal blob (char norm features)!\n");
2176 num_features, features, &cn_result,
2180 config_mask = 1 << cn_result.
config;
2182 tprintf(
"Static Shape ID: %d\n", shape_id);
2185 &config_mask, num_features, features, &cn_result,
2189 #endif // GRAPHICS_DISABLED
2195 int class_id,
int config_id)
const {
2203 return class_string;
2208 int int_result_config)
const {
2211 if (font_set_id < 0)
2212 return kBlankFontinfoId;
2215 return fs.
configs[int_result_config];
2225 for (
int config = 0; config < fs.
size; ++config) {
2226 if (fs.
configs[config] == shape_id)
2230 tprintf(
"Shape %d not found\n", shape_id);
2239 tprintf(
"NumTimesSeen for config of %s is %d\n",
2240 getDict().getUnicharset().debug_str(class_id).c_str(),
2252 int ambigs_size = (ambigs ==
nullptr) ? 0 : ambigs->
size();
2253 for (
int ambig = 0; ambig < ambigs_size; ++ambig) {
2255 assert(ambig_class !=
nullptr);
2260 tprintf(
"Ambig %s has not been seen enough times,"
2261 " not making config for %s permanent\n",
2262 getDict().getUnicharset().debug_str(
2263 (*ambigs)[ambig]).c_str(),
2264 getDict().getUnicharset().debug_str(class_id).c_str());
2276 int ambigs_size = (ambigs ==
nullptr) ? 0 : ambigs->
size();
2278 tprintf(
"Running UpdateAmbigsGroup for %s class_id=%d\n",
2279 getDict().getUnicharset().debug_str(class_id).c_str(), class_id);
2281 for (
int ambig = 0; ambig < ambigs_size; ++ambig) {
2282 CLASS_ID ambig_class_id = (*ambigs)[ambig];
2290 tprintf(
"Making config %d of %s permanent\n", cfg,
2291 getDict().getUnicharset().debug_str(
2292 ambig_class_id).c_str());
void Match(INT_CLASS ClassTemplate, BIT_VECTOR ProtoMask, BIT_VECTOR ConfigMask, int16_t NumFeatures, const INT_FEATURE_STRUCT *Features, tesseract::UnicharRating *Result, int AdaptFeatureThreshold, int Debug, bool SeparateDebugWindows)
double tessedit_class_miss_scale
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)
TBLOB * ClassifyNormalizeIfNeeded() const
bool classify_enable_adaptive_matcher
virtual void DebugDisplay(const TrainingSample &sample, Pix *page_pix, UNICHAR_ID unichar_id)
void ComputeAdaptionThresholds(float certainty_scale, float min_rating, float max_rating, float rating_margin, float *thresholds)
void ClearCharNormArray(uint8_t *char_norm_array)
void SetAdaptiveThreshold(float Threshold)
bool use_ambigs_for_adaption
double matcher_clustering_max_angle_delta
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)
TrainingSample * BlobToTrainingSample(const TBLOB &blob, bool nonlinear_norm, INT_FX_RESULT_STRUCT *fx_info, GenericVector< INT_FEATURE_STRUCT > *bl_features)
bool PiecesAllNatural(int start, int count) const
#define TempConfigFor(Class, ConfigId)
bool AlternativeChoiceAdjustmentsWorseThan(float threshold) const
bool get_isdigit(UNICHAR_ID unichar_id) const
UnicityTable< FontInfo > fontinfo_table_
bool get_isalpha(UNICHAR_ID unichar_id) const
int classify_adapt_proto_threshold
float ApplyCNCorrection(float rating, int blob_length, int normalization_factor, int matcher_multiplier)
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)
int MakeNewTemporaryConfig(ADAPT_TEMPLATES Templates, CLASS_ID ClassId, int FontinfoId, int NumFeatures, INT_FEATURE_ARRAY Features, FEATURE_SET FloatFeatures)
bool classify_enable_learning
GenericVector< ScoredFont > fonts
const DENORM & denorm() const
const UnicharAmbigs & getUnicharAmbigs() const
int CharNormClassifier(TBLOB *blob, const TrainingSample &sample, ADAPT_RESULTS *adapt_results)
bool classify_enable_adaptive_debugger
void EndAdaptiveClassifier()
void plot(ScrollView *window, ScrollView::Color color, ScrollView::Color child_color)
const double kStandardFeatureLength
bool AdaptableWord(WERD_RES *word)
double matcher_good_threshold
double classify_adapted_pruning_threshold
int matcher_permanent_classes_min
#define test_bit(array, bit)
void PrintAdaptedTemplates(FILE *File, ADAPT_TEMPLATES Templates)
const UnicharIdVector * ReverseAmbigsForAdaption(UNICHAR_ID unichar_id) const
const FontInfo * fontinfo
void UpdateAmbigsGroup(CLASS_ID class_id, TBLOB *Blob)
void cprintf(const char *format,...)
void EndDangerousAmbigs()
void ConvertProto(PROTO Proto, int ProtoId, INT_CLASS Class)
void ConvertMatchesToChoices(const DENORM &denorm, const TBOX &box, ADAPT_RESULTS *Results, BLOB_CHOICE_LIST *Choices)
void LearnWord(const char *fontname, WERD_RES *word)
int classify_learning_debug_level
int IntCastRounded(double x)
const float MF_SCALE_FACTOR
void SettupStopperPass1()
Sets up stopper variables in preparation for the first pass.
static void SetupBLCNDenorms(const TBLOB &blob, bool nonlinear_norm, DENORM *bl_denorm, DENORM *cn_denorm, INT_FX_RESULT_STRUCT *fx_info)
GenericVector< int > best_state
bool LooksLikeGarbage(TBLOB *blob)
void RemoveBadMatches(ADAPT_RESULTS *Results)
bool eq(UNICHAR_ID unichar_id, const char *const unichar_repr) const
#define PRINT_FEATURE_MATCHES
STRING language_data_path_prefix
void ComputeIntFeatures(FEATURE_SET Features, INT_FEATURE_ARRAY IntFeatures)
void InitAdaptedClass(TBLOB *Blob, CLASS_ID ClassId, int FontinfoId, ADAPT_CLASS Class, ADAPT_TEMPLATES Templates)
void PrintAdaptiveMatchResults(const ADAPT_RESULTS &results)
virtual int UnicharClassifySample(const TrainingSample &sample, Pix *page_pix, int debug, UNICHAR_ID keep_this, GenericVector< UnicharRating > *results)
int FindGoodProtos(INT_CLASS ClassTemplate, BIT_VECTOR ProtoMask, BIT_VECTOR ConfigMask, int16_t NumFeatures, INT_FEATURE_ARRAY Features, PROTO_ID *ProtoArray, int AdaptProtoThreshold, int Debug)
bool DeSerialize(TFile *fp)
void SetAdaptiveThreshold(float Threshold)
bool Open(const STRING &filename, FileReader reader)
double matcher_reliable_adaptive_result
int get_script(UNICHAR_ID unichar_id) const
const UnicharIdVector * AmbigsForAdaption(UNICHAR_ID unichar_id) const
int AddIntProto(INT_CLASS Class)
void DisplayAdaptedChar(TBLOB *blob, INT_CLASS_STRUCT *int_class)
void ClassifyAsNoise(ADAPT_RESULTS *Results)
double matcher_avg_noise_size
void AddProtoToProtoPruner(PROTO Proto, int ProtoId, INT_CLASS Class, bool debug)
#define reset_bit(array, bit)
GenericVector< CP_RESULT_STRUCT > CPResults
void free_adapted_templates(ADAPT_TEMPLATES templates)
#define ADAPTABLE_WERD_ADJUSTMENT
void ConvertConfig(BIT_VECTOR Config, int ConfigId, INT_CLASS Class)
int matcher_min_examples_for_prototyping
void XHeightRange(int unichar_id, const UNICHARSET &unicharset, const TBOX &bbox, float *min_xht, float *max_xht, float *yshift) const
STRING debug_str(UNICHAR_ID id) const
WERD_CHOICE * best_choice
const char * c_str() const
void get_top_bottom(UNICHAR_ID unichar_id, int *min_bottom, int *max_bottom, int *min_top, int *max_top) const
bool get_enabled(UNICHAR_ID unichar_id) const
double matcher_perfect_threshold
#define ADAPT_TEMPLATE_SUFFIX
#define MakeConfigPermanent(Class, ConfigId)
ADAPT_TEMPLATES ReadAdaptedTemplates(TFile *File)
LIST delete_d(LIST list, void *key, int_compare is_equal)
ShapeTable * shape_table_
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)
bool disable_character_fragments
void MakePermanent(ADAPT_TEMPLATES Templates, CLASS_ID ClassId, int ConfigId, TBLOB *Blob)
void FreeFeature(FEATURE Feature)
void FreeTempConfig(TEMP_CONFIG Config)
int ShapeIDToClassID(int shape_id) const
#define LENGTH_COMPRESSION
ADAPT_TEMPLATES BackupAdaptedTemplates
bool classify_save_adapted_templates
bool classify_nonlinear_norm
bool GetComponent(TessdataType type, TFile *fp)
UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
void StartBackupAdaptiveClassifier()
void AdaptiveClassifier(TBLOB *Blob, BLOB_CHOICE_LIST *Choices)
double segment_penalty_dict_case_ok
GenericVector< TBLOB * > blobs
#define IncreaseConfidence(TempConfig)
#define MAX_NUM_INT_FEATURES
float adjust_factor() const
STRING DebugStr(int shape_id) const
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)
NORM_PROTOS * ReadNormProtos(TFile *fp)
const Shape & GetShape(int shape_id) const
ADAPT_TEMPLATES AdaptedTemplates
int matcher_sufficient_examples_for_prototyping
char * classify_learn_debug_str
FEATURE_SET ExtractOutlineFeatures(TBLOB *Blob)
int AddIntConfig(INT_CLASS Class)
static void BreakPieces(const GenericVector< SEAM * > &seams, const GenericVector< TBLOB * > &blobs, int first, int last)
void AddLargeSpeckleTo(int blob_length, BLOB_CHOICE_LIST *choices)
void InitAdaptiveClassifier(TessdataManager *mgr)
const STRING debug_string() const
ADAPT_TEMPLATES Templates
#define ConfigIsPermanent(Class, ConfigId)
LIST push(LIST list, void *element)
void FillABC(PROTO Proto)
void LearnPieces(const char *fontname, int start, int length, float threshold, CharSegmentationType segmentation, const char *correct_text, WERD_RES *word)
int GetCharNormFeature(const INT_FX_RESULT_STRUCT &fx_info, INT_TEMPLATES templates, uint8_t *pruner_norm_array, uint8_t *char_norm_array)
void DoAdaptiveMatch(TBLOB *Blob, ADAPT_RESULTS *Results)
int GetFontinfoId(ADAPT_CLASS Class, uint8_t ConfigId)
FEATURE NewFeature(const FEATURE_DESC_STRUCT *FeatureDesc)
GenericVector< SEAM * > seam_array
TEMP_CONFIG NewTempConfig(int MaxProtoId, int FontinfoId)
void ComputeCharNormArrays(FEATURE_STRUCT *norm_feature, INT_TEMPLATES_STRUCT *templates, uint8_t *char_norm_array, uint8_t *pruner_array)
INT_FEATURE_STRUCT INT_FEATURE_ARRAY[MAX_NUM_INT_FEATURES]
TBOX bounding_box() const
bool classify_use_pre_adapted_templates
ADAPT_CLASS Class[MAX_NUM_CLASSES]
FEATURE_SET ExtractPicoFeatures(TBLOB *Blob)
int classify_adapt_feature_threshold
void ReadNewCutoffs(TFile *fp, uint16_t *Cutoffs)
TEMP_PROTO NewTempProto()
#define UNLIKELY_NUM_FEAT
#define SET_BIT(array, bit)
double classify_adapted_pruning_factor
const FEATURE_DESC_STRUCT CharNormDesc
static int SortDescendingRating(const void *t1, const void *t2)
#define WORST_POSSIBLE_RATING
INT_CLASS Class[MAX_NUM_CLASSES]
void ComputeIntCharNormArray(const FEATURE_STRUCT &norm_feature, uint8_t *char_norm_array)
void LearnBlob(const STRING &fontname, TBLOB *Blob, const DENORM &cn_denorm, const INT_FX_RESULT_STRUCT &fx_info, const char *blob_text)
double classify_misfit_junk_penalty
int CharNormTrainingSample(bool pruner_only, int keep_this, const TrainingSample &sample, GenericVector< UnicharRating > *results)
void RemoveExtraPuncs(ADAPT_RESULTS *Results)
int GetAdaptiveFeatures(TBLOB *Blob, INT_FEATURE_ARRAY IntFeatures, FEATURE_SET *FloatFeatures)
bool contains_unichar(const char *const unichar_repr) const
int MakeTempProtoPerm(void *item1, void *item2)
bool MarginalMatch(float confidence, float matcher_great_threshold)
void FreeFeatureSet(FEATURE_SET FeatureSet)
void DebugAdaptiveClassifier(TBLOB *Blob, ADAPT_RESULTS *Results)
void UpdateMatchDisplay()
UNICHAR_ID best_unichar_id
void AddNewResult(const UnicharRating &new_result, ADAPT_RESULTS *results)
void print_ratings_list(const char *msg, BLOB_CHOICE_LIST *ratings, const UNICHARSET ¤t_unicharset)
#define PRINT_MATCH_SUMMARY
GenericVector< STRING > correct_text
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)
void set_fonts(const GenericVector< tesseract::ScoredFont > &fonts)
void InitMatcherRatings(float *Rating)
int FindBadFeatures(INT_CLASS ClassTemplate, BIT_VECTOR ProtoMask, BIT_VECTOR ConfigMask, int16_t NumFeatures, INT_FEATURE_ARRAY Features, FEATURE_ID *FeatureArray, int AdaptFeatureThreshold, int Debug)
bool TempConfigReliable(CLASS_ID class_id, const TEMP_CONFIG &config)
DLLSYM void tprintf(const char *format,...)
bool LargeSpeckle(const TBLOB &blob)
const UNICHARSET & getUnicharset() const
const CHAR_FRAGMENT * get_fragment(UNICHAR_ID unichar_id) const
INT_TEMPLATES ReadIntTemplates(TFile *fp)
INT_TEMPLATES PreTrainedTemplates
void free_int_templates(INT_TEMPLATES templates)
bool matcher_debug_separate_windows
void plot(ScrollView *window)
GenericVector< UnicharRating > match
void AddProtoToClassPruner(PROTO Proto, CLASS_ID ClassId, INT_TEMPLATES Templates)
TBOX bounding_box() const
UNICHAR_ID * GetAmbiguities(TBLOB *Blob, CLASS_ID CorrectClass)
static void JoinPieces(const GenericVector< SEAM * > &seams, const GenericVector< TBLOB * > &blobs, int first, int last)
int classify_integer_matcher_multiplier
const char * id_to_unichar(UNICHAR_ID id) const
bool classify_debug_character_fragments
double matcher_rating_margin
#define PermConfigFor(Class, ConfigId)
void ResetAdaptiveClassifierInternal()
void WriteAdaptedTemplates(FILE *File, ADAPT_TEMPLATES Templates)
#define MakeProtoPermanent(Class, ProtoId)
bool classify_bln_numeric_mode
double matcher_bad_match_pad
UnicityTable< FontSet > fontset_table_
void ShowBestMatchFor(int shape_id, const INT_FEATURE_STRUCT *features, int num_features)
#define UnusedClassIdIn(T, c)
#define PRINT_PROTO_MATCHES
float ActualOutlineLength(FEATURE Feature)
double classify_character_fragments_garbage_certainty_threshold
char window_wait(ScrollView *win)
#define ClassForClassId(T, c)
void AdaptToChar(TBLOB *Blob, CLASS_ID ClassId, int FontinfoId, float Threshold, ADAPT_TEMPLATES adaptive_templates)
void SettupStopperPass2()
Sets up stopper variables in preparation for the second pass.
int ClassAndConfigIDToFontOrShapeID(int class_id, int int_result_config) const
PROTO_ID MakeNewTempProtos(FEATURE_SET Features, int NumBadFeat, FEATURE_ID BadFeat[], INT_CLASS IClass, ADAPT_CLASS Class, BIT_VECTOR TempProtoMask)
void SwitchAdaptiveClassifier()
int MaxNumUnichars() const
const int kBlnBaselineOffset
void FreeTempProto(void *arg)
void RefreshDebugWindow(ScrollView **win, const char *msg, int y_offset, const TBOX &wbox)
#define IsEmptyAdaptedClass(Class)
#define MAX_ADAPTABLE_WERD_SIZE
ADAPT_TEMPLATES NewAdaptedTemplates(bool InitFromUnicharset)
STRING ClassIDToDebugStr(const INT_TEMPLATES_STRUCT *templates, int class_id, int config_id) const
#define GetPicoFeatureLength()