22 #include "config_auto.h" 76 #define ADAPT_TEMPLATE_SUFFIX ".a" 78 #define MAX_MATCHES 10 79 #define UNLIKELY_NUM_FEAT 200 81 #define MAX_ADAPTABLE_WERD_SIZE 40 83 #define ADAPTABLE_WERD_ADJUSTMENT (0.05) 85 #define Y_DIM_OFFSET (Y_SHIFT - BASELINE_Y_SHIFT) 87 #define WORST_POSSIBLE_RATING (0.0f) 132 inline bool MarginalMatch(
float confidence,
float matcher_great_threshold) {
133 return (1.0f - confidence) > matcher_great_threshold;
142 for (
int i = 0; i < results.
match.
size(); i++) {
143 if (results.
match[i].unichar_id ==
id)
152 int index = FindScoredUnichar(
id, results);
154 return results.
match[index].rating;
193 assert(Choices !=
nullptr);
217 #ifndef GRAPHICS_DISABLED 228 int y_offset,
const TBOX &wbox) {
229 #ifndef GRAPHICS_DISABLED 230 const int kSampleSpaceWidth = 500;
231 if (*win ==
nullptr) {
232 *win =
new ScrollView(msg, 100, y_offset, kSampleSpaceWidth * 2, 200,
233 kSampleSpaceWidth * 2, 200,
true);
236 (*win)->Pen(64, 64, 64);
241 (*win)->ZoomToRectangle(wbox.
left(), wbox.
top(),
243 #endif // GRAPHICS_DISABLED 253 if (word_len == 0)
return;
255 float* thresholds =
nullptr;
256 if (fontname ==
nullptr) {
262 tprintf(
"\n\nAdapting to word = %s\n",
264 thresholds =
new float[word_len];
272 #ifndef GRAPHICS_DISABLED 274 if (learn_fragmented_word_debug_win_ !=
nullptr) {
284 #endif // GRAPHICS_DISABLED 286 for (
int ch = 0; ch < word_len; ++ch) {
291 float threshold = thresholds !=
nullptr ? thresholds[ch] : 0.0f;
300 bool garbage =
false;
302 for (frag = 0; frag < word->
best_state[ch]; ++frag) {
313 for (frag = 0; frag < word->
best_state[ch]; ++frag) {
318 tokens[0].
string(), frag, word->
best_state[ch],
322 for (
int i = 0; i < tokens.
size(); i++) {
323 full_string += tokens[i];
324 if (i != tokens.
size() - 1)
327 LearnPieces(fontname, start_blob + frag, 1, threshold,
363 delete [] thresholds;
377 const char* correct_text,
WERD_RES* word) {
391 if (rotated_blob ==
nullptr)
394 #ifndef GRAPHICS_DISABLED 400 learn_debug_win_->
Update();
404 ASSERT_HOST(learn_fragments_debug_win_ !=
nullptr);
405 blob->
plot(learn_fragments_debug_win_,
407 learn_fragments_debug_win_->
Update();
409 #endif // GRAPHICS_DISABLED 411 if (fontname !=
nullptr) {
415 DENORM bl_denorm, cn_denorm;
418 &bl_denorm, &cn_denorm, &fx_info);
419 LearnBlob(fontname, rotated_blob, cn_denorm, fx_info, correct_text);
422 int font_id = word->
fontinfo !=
nullptr 426 tprintf(
"Adapting to char = %s, thr= %g font_id= %d\n",
434 AdaptToChar(rotated_blob, class_id, font_id, threshold,
438 tprintf(
"Can't adapt to %s not in unicharset\n", correct_text);
440 if (rotated_blob != blob) {
469 cprintf (
"Unable to save adapted templates to %s!\n", Filename.
string());
471 cprintf (
"\nSaving adapted templates to %s ...", Filename.
string());
506 delete static_classifier_;
507 static_classifier_ =
nullptr;
544 tprintf(
"Error loading shape table!\n");
569 BaselineCutoffs[i] = 0;
581 cprintf(
"\nReading pre-adapted templates from %s ...\n",
589 BaselineCutoffs[i] = CharNormCutoffs[i];
601 tprintf(
"Resetting adaptive classifier (NumAdaptationsFailed=%d)\n",
602 NumAdaptationsFailed);
609 NumAdaptationsFailed = 0;
620 tprintf(
"Switch to backup adaptive classifier (NumAdaptationsFailed=%d)\n",
621 NumAdaptationsFailed);
626 NumAdaptationsFailed = 0;
721 BaselineCutoffs[ClassId] = CharNormCutoffs[ClassId];
725 for (Fid = 0; Fid < Features->
NumFeatures; Fid++) {
731 Proto = &(TempProto->
Proto);
757 tprintf(
"Added new class '%s' with class id %d and %d protos.\n",
803 *FloatFeatures = Features;
826 float adaptable_score =
829 BestChoiceLength > 0 &&
873 Class = adaptive_templates->
Class[ClassId];
874 assert(Class !=
nullptr);
881 if (NumFeatures <= 0) {
887 for (
int cfg = 0; cfg < IClass->
NumConfigs; ++cfg) {
889 SET_BIT(MatchingFontConfigs, cfg);
895 NumFeatures, IntFeatures,
902 if (1.0f - int_result.
rating <= Threshold) {
905 tprintf(
"Found good match to perm config %d = %4.1f%%.\n",
917 tprintf(
"Increasing reliability of temp config %d to %d.\n",
926 tprintf(
"Found poor match to temp config %d = %4.1f%%.\n",
933 NumFeatures, IntFeatures, FloatFeatures);
934 if (NewTempConfigId >= 0 &&
936 MakePermanent(adaptive_templates, ClassId, NewTempConfigId, Blob);
940 #ifndef GRAPHICS_DISABLED 951 #ifndef GRAPHICS_DISABLED 957 if (
sample ==
nullptr)
return;
961 bl_features.
size(), &bl_features[0],
964 tprintf(
"Best match to temp config %d = %4.1f%%.\n",
965 int_result.config, int_result.rating * 100.0);
968 ConfigMask = 1 << int_result.config;
971 bl_features.
size(), &bl_features[0],
1000 int old_match = FindScoredUnichar(new_result.
unichar_id, *results);
1002 if (new_result.
rating + matcher_bad_match_pad < results->best_rating ||
1003 (old_match < results->match.size() &&
1004 new_result.
rating <= results->
match[old_match].rating))
1010 if (old_match < results->match.size()) {
1011 results->
match[old_match].rating = new_result.
rating;
1057 if (int_features.
empty())
return;
1069 while (*ambiguities >= 0) {
1075 int_features.
size(), &int_features[0],
1083 CharNormArray, &int_result, results);
1086 delete [] CharNormArray;
1093 int16_t num_features,
1095 const uint8_t* norm_factors,
1098 int matcher_multiplier,
1099 const TBOX& blob_box,
1102 int top = blob_box.
top();
1103 int bottom = blob_box.
bottom();
1105 for (
int c = 0; c < results.
size(); c++) {
1106 CLASS_ID class_id = results[c].Class;
1115 num_features, features,
1122 matcher_multiplier, norm_factors,
1123 &int_result, final_results);
1133 ADAPT_CLASS* classes,
bool debug,
int class_id,
int bottom,
int top,
1134 float cp_rating,
int blob_length,
int matcher_multiplier,
1135 const uint8_t* cn_factors,
1137 if (classes !=
nullptr) {
1140 for (
int f = 0; f < int_result->
fonts.size(); ++f) {
1141 int_result->
fonts[f].fontinfo_id =
1147 for (
int f = 0; f < int_result->
fonts.size(); ++f) {
1148 int_result->
fonts[f].fontinfo_id =
1150 int_result->
fonts[f].fontinfo_id);
1161 for (
int f = 0; f < int_result->
fonts.size(); ++f) {
1162 int shape_id = int_result->
fonts[f].fontinfo_id;
1164 for (
int c = 0; c < shape.
size(); ++c) {
1165 int unichar_id = shape[c].unichar_id;
1169 for (r = 0; r < mapped_results.
size() &&
1170 mapped_results[r].unichar_id != unichar_id; ++r) {}
1171 if (r == mapped_results.
size()) {
1173 mapped_results[r].unichar_id = unichar_id;
1174 mapped_results[r].fonts.
truncate(0);
1176 for (
int i = 0; i < shape[c].font_ids.
size(); ++i) {
1182 for (
int m = 0; m < mapped_results.
size(); ++m) {
1183 mapped_results[m].rating =
1185 cp_rating, int_result->
rating,
1187 blob_length, matcher_multiplier, cn_factors);
1197 bottom, top, blob_length,
1198 matcher_multiplier, cn_factors);
1207 double cp_rating,
double im_rating,
1209 int bottom,
int top,
1210 int blob_length,
int matcher_multiplier,
1211 const uint8_t* cn_factors) {
1214 cn_factors[unichar_id],
1215 matcher_multiplier);
1217 double vertical_penalty = 0.0;
1222 int min_bottom, max_bottom, min_top, max_top;
1224 &min_top, &max_top);
1226 tprintf(
"top=%d, vs [%d, %d], bottom=%d, vs [%d, %d]\n",
1227 top, min_top, max_top, bottom, min_bottom, max_bottom);
1229 if (top < min_top || top > max_top ||
1230 bottom < min_bottom || bottom > max_bottom) {
1234 double result = 1.0 - (cn_corrected + miss_penalty + vertical_penalty);
1238 tprintf(
"%s: %2.1f%%(CP%2.1f, IM%2.1f + CN%.2f(%d) + MP%2.1f + VP%2.1f)\n",
1242 (1.0 - im_rating) * 100.0,
1243 (cn_corrected - (1.0 - im_rating)) * 100.0,
1244 cn_factors[unichar_id],
1245 miss_penalty * 100.0,
1246 vertical_penalty * 100.0);
1273 if (int_features.
empty())
return nullptr;
1279 CharNormArray, BaselineCutoffs, &Results->
CPResults);
1289 delete [] CharNormArray;
1294 return Templates->
Class[ClassId]->
1323 -1, &unichar_results);
1325 for (
int r = 0; r < unichar_results.size(); ++r) {
1328 return sample.num_features();
1341 uint32_t num_features =
sample.num_features();
1351 uint8_t* pruner_norm_array =
new uint8_t[num_pruner_classes];
1359 shape_table_ !=
nullptr ? &shapetable_cutoffs_[0] : CharNormCutoffs,
1361 delete [] pruner_norm_array;
1362 if (keep_this >= 0) {
1363 adapt_results->
CPResults[0].Class = keep_this;
1369 int class_id = adapt_results->
CPResults[i].Class;
1378 blob_box, adapt_results->
CPResults, adapt_results);
1380 for (
int i = 0; i < adapt_results->
match.
size(); i++) {
1385 delete [] char_norm_array;
1386 delete adapt_results;
1387 return num_features;
1406 rating /= 1.0 + rating;
1419 BLOB_CHOICE_LIST *Choices) {
1420 assert(Choices !=
nullptr);
1423 BLOB_CHOICE_IT temp_it;
1424 bool contains_nonfrag =
false;
1425 temp_it.set_to_list(Choices);
1426 int choices_length = 0;
1439 float best_certainty = -FLT_MAX;
1440 for (
int i = 0; i < Results->
match.
size(); i++) {
1442 bool adapted = result.
adapted;
1444 if (temp_it.length()+1 == max_matches &&
1445 !contains_nonfrag && current_is_frag) {
1457 Rating = Certainty = (1.0f - result.
rating);
1466 if (Certainty > best_certainty) {
1468 }
else if (adapted &&
1473 float min_xheight, max_xheight, yshift;
1475 &min_xheight, &max_xheight, &yshift);
1479 min_xheight, max_xheight, yshift,
1483 temp_it.add_to_end(choice);
1484 contains_nonfrag |= !current_is_frag;
1486 if (choices_length >= max_matches)
break;
1493 #ifndef GRAPHICS_DISABLED 1503 if (static_classifier_ ==
nullptr)
return;
1508 if (
sample ==
nullptr)
return;
1542 if (
sample ==
nullptr)
return;
1546 if (static_classifier_ ==
nullptr) {
1623 Results->
match[0].unichar_id != CorrectClass)) {
1624 for (i = 0; i < Results->
match.
size(); i++)
1625 Ambiguities[i] = Results->
match[i].unichar_id;
1626 Ambiguities[i] = -1;
1628 Ambiguities[0] = -1;
1638 BLOB_CHOICE_LIST *ratings =
new BLOB_CHOICE_LIST();
1640 BLOB_CHOICE_IT ratings_it(ratings);
1646 for (ratings_it.mark_cycle_pt(); !ratings_it.cycled_list();
1647 ratings_it.forward()) {
1651 float certainty = ratings_it.data()->certainty();
1684 uint8_t* pruner_norm_array,
1685 uint8_t* char_norm_array) {
1704 uint8_t* char_norm_array,
1705 uint8_t* pruner_array) {
1707 if (pruner_array !=
nullptr) {
1711 memset(pruner_array, UINT8_MAX,
1712 templates->
NumClasses *
sizeof(pruner_array[0]));
1715 for (
int id = 0;
id < templates->
NumClasses; ++id) {
1718 for (
int config = 0; config < fs.
size; ++config) {
1720 for (
int c = 0; c < shape.
size(); ++c) {
1721 if (char_norm_array[shape[c].unichar_id] < pruner_array[
id])
1722 pruner_array[id] = char_norm_array[shape[c].unichar_id];
1756 int MaxProtoId, OldMaxProtoId;
1769 Class = Templates->
Class[ClassId];
1772 ++NumAdaptationsFailed;
1774 cprintf(
"Cannot make new temporary config: maximum number exceeded.\n");
1781 BlobLength, NumFeatures, Features,
1787 for (i = 0; i < NumOldProtos; i++)
1791 BlobLength, NumFeatures, Features,
1799 ++NumAdaptationsFailed;
1801 cprintf(
"Cannot make new temp protos: maximum number exceeded.\n");
1812 cprintf(
"Making new temp config %d fontinfo id %d" 1813 " using %d old and %d new protos.\n",
1814 ConfigId,
Config->FontinfoId,
1815 NumOldProtos, MaxProtoId - OldMaxProtoId);
1851 float X1, X2, Y1, Y2;
1852 float A1, A2, AngleDelta;
1853 float SegmentLength;
1856 for (ProtoStart = BadFeat, LastBad = ProtoStart + NumBadFeat;
1857 ProtoStart < LastBad; ProtoStart = ProtoEnd) {
1858 F1 = Features->
Features[*ProtoStart];
1863 for (ProtoEnd = ProtoStart + 1,
1867 F2 = Features->
Features[*ProtoEnd];
1872 AngleDelta = fabs(A1 - A2);
1873 if (AngleDelta > 0.5)
1874 AngleDelta = 1.0 - AngleDelta;
1877 fabs(X1 - X2) > SegmentLength ||
1878 fabs(Y1 - Y2) > SegmentLength)
1882 F2 = Features->
Features[*(ProtoEnd - 1)];
1892 Proto = &(TempProto->
Proto);
1897 Proto->
Length = SegmentLength;
1899 Proto->
X = (X1 + X2) / 2.0;
1934 Class = Templates->
Class[ClassId];
1960 tprintf(
"Making config %d for %s (ClassId %d) permanent:" 1961 " fontinfo id %d, ambiguities '",
1962 ConfigId,
getDict().getUnicharset().debug_str(ClassId).
string(),
1965 *AmbigsPointer >= 0; ++AmbigsPointer)
2019 for (
int i = 0; i < results.
match.
size(); ++i) {
2021 results.
match[i].Print();
2040 float BadMatchThreshold;
2041 static const char* romans =
"i v x I V X";
2049 float scored_one = ScoredUnichar(unichar_id_one, *Results);
2050 float scored_zero = ScoredUnichar(unichar_id_zero, *Results);
2052 for (Next = NextGood = 0; Next < Results->
match.
size(); Next++) {
2054 if (match.
rating >= BadMatchThreshold) {
2059 scored_one < BadMatchThreshold) {
2060 Results->
match[Next].unichar_id = unichar_id_one;
2062 scored_zero < BadMatchThreshold) {
2063 Results->
match[Next].unichar_id = unichar_id_zero;
2065 Results->
match[Next].unichar_id = INVALID_UNICHAR_ID;
2067 if (Results->
match[Next].unichar_id != INVALID_UNICHAR_ID) {
2068 if (NextGood == Next) {
2071 Results->
match[NextGood++] = Results->
match[Next];
2077 for (Next = NextGood = 0; Next < Results->
match.
size(); Next++) {
2078 if (Results->
match[Next].rating >= BadMatchThreshold) {
2079 if (NextGood == Next) {
2082 Results->
match[NextGood++] = Results->
match[Next];
2103 static char punc_chars[] =
". , ; : / ` ~ ' - = \\ | \" ! _ ^";
2104 static char digit_chars[] =
"0 1 2 3 4 5 6 7 8 9";
2108 for (Next = NextGood = 0; Next < Results->
match.
size(); Next++) {
2111 if (strstr(punc_chars,
2113 if (punc_count >= 2)
2117 if (strstr(digit_chars,
2119 if (digit_count >= 1)
2125 if (NextGood == Next) {
2128 Results->
match[NextGood++] = match;
2149 ClipToRange<int>(255 * Threshold, 0, 255));
2151 ClipToRange<int>(255 * Threshold, 0, 255));
2167 #ifndef GRAPHICS_DISABLED 2168 uint32_t config_mask;
2170 tprintf(
"No built-in templates for class/shape %d\n", shape_id);
2173 if (num_features <= 0) {
2174 tprintf(
"Illegal blob (char norm features)!\n");
2181 num_features, features, &cn_result,
2185 config_mask = 1 << cn_result.
config;
2187 tprintf(
"Static Shape ID: %d\n", shape_id);
2190 &config_mask, num_features, features, &cn_result,
2194 #endif // GRAPHICS_DISABLED 2200 int class_id,
int config_id)
const {
2208 return class_string;
2213 int int_result_config)
const {
2216 if (font_set_id < 0)
2217 return kBlankFontinfoId;
2220 return fs.
configs[int_result_config];
2230 for (
int config = 0; config < fs.
size; ++config) {
2231 if (fs.
configs[config] == shape_id)
2235 tprintf(
"Shape %d not found\n", shape_id);
2244 tprintf(
"NumTimesSeen for config of %s is %d\n",
2245 getDict().getUnicharset().debug_str(class_id).
string(),
2257 int ambigs_size = (ambigs ==
nullptr) ? 0 : ambigs->
size();
2258 for (
int ambig = 0; ambig < ambigs_size; ++ambig) {
2260 assert(ambig_class !=
nullptr);
2265 tprintf(
"Ambig %s has not been seen enough times," 2266 " not making config for %s permanent\n",
2267 getDict().getUnicharset().debug_str(
2268 (*ambigs)[ambig]).
string(),
2269 getDict().getUnicharset().debug_str(class_id).
string());
2281 int ambigs_size = (ambigs ==
nullptr) ? 0 : ambigs->
size();
2283 tprintf(
"Running UpdateAmbigsGroup for %s class_id=%d\n",
2284 getDict().getUnicharset().debug_str(class_id).
string(), class_id);
2286 for (
int ambig = 0; ambig < ambigs_size; ++ambig) {
2287 CLASS_ID ambig_class_id = (*ambigs)[ambig];
2295 tprintf(
"Making config %d of %s permanent\n", cfg,
2296 getDict().getUnicharset().debug_str(
2297 ambig_class_id).
string());
void InitMatcherRatings(float *Rating)
bool PiecesAllNatural(int start, int count) const
TrainingSample * BlobToTrainingSample(const TBLOB &blob, bool nonlinear_norm, INT_FX_RESULT_STRUCT *fx_info, GenericVector< INT_FEATURE_STRUCT > *bl_features)
void ClassifyAsNoise(ADAPT_RESULTS *Results)
bool LargeSpeckle(const TBLOB &blob)
static void SetupBLCNDenorms(const TBLOB &blob, bool nonlinear_norm, DENORM *bl_denorm, DENORM *cn_denorm, INT_FX_RESULT_STRUCT *fx_info)
double tessedit_class_miss_scale
ADAPT_TEMPLATES ReadAdaptedTemplates(TFile *File)
void InitAdaptiveClassifier(TessdataManager *mgr)
void ComputeIntFeatures(FEATURE_SET Features, INT_FEATURE_ARRAY IntFeatures)
double segment_penalty_dict_case_ok
int matcher_permanent_classes_min
void RefreshDebugWindow(ScrollView **win, const char *msg, int y_offset, const TBOX &wbox)
int GetCharNormFeature(const INT_FX_RESULT_STRUCT &fx_info, INT_TEMPLATES templates, uint8_t *pruner_norm_array, uint8_t *char_norm_array)
bool GetComponent(TessdataType type, TFile *fp)
void UpdateMatchDisplay()
void cprintf(const char *format,...)
void LearnPieces(const char *fontname, int start, int length, float threshold, CharSegmentationType segmentation, const char *correct_text, WERD_RES *word)
void FreeFeature(FEATURE Feature)
bool classify_enable_adaptive_debugger
void DisplayAdaptedChar(TBLOB *blob, INT_CLASS_STRUCT *int_class)
void free_int_templates(INT_TEMPLATES templates)
#define WordsInVectorOfSize(NumBits)
void SettupStopperPass1()
Sets up stopper variables in preparation for the first pass.
INT_CLASS Class[MAX_NUM_CLASSES]
const UnicharAmbigs & getUnicharAmbigs() const
bool eq(UNICHAR_ID unichar_id, const char *const unichar_repr) const
void ComputeAdaptionThresholds(float certainty_scale, float min_rating, float max_rating, float rating_margin, float *thresholds)
UNICHAR_ID best_unichar_id
STRING DebugStr(int shape_id) const
const char * string() const
void set_fonts(const GenericVector< tesseract::ScoredFont > &fonts)
void DebugAdaptiveClassifier(TBLOB *Blob, ADAPT_RESULTS *Results)
int FindGoodProtos(INT_CLASS ClassTemplate, BIT_VECTOR ProtoMask, BIT_VECTOR ConfigMask, uint16_t BlobLength, int16_t NumFeatures, INT_FEATURE_ARRAY Features, PROTO_ID *ProtoArray, int AdaptProtoThreshold, int Debug)
void ConvertProto(PROTO Proto, int ProtoId, INT_CLASS Class)
void AdaptiveClassifier(TBLOB *Blob, BLOB_CHOICE_LIST *Choices)
bool use_ambigs_for_adaption
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)
bool classify_bln_numeric_mode
void plot(ScrollView *window, ScrollView::Color color, ScrollView::Color child_color)
STRING language_data_path_prefix
TBOX bounding_box() const
bool TempConfigReliable(CLASS_ID class_id, const TEMP_CONFIG &config)
int GetFontinfoId(ADAPT_CLASS Class, uint8_t ConfigId)
virtual void DebugDisplay(const TrainingSample &sample, Pix *page_pix, UNICHAR_ID unichar_id)
static void JoinPieces(const GenericVector< SEAM *> &seams, const GenericVector< TBLOB *> &blobs, int first, int last)
static void BreakPieces(const GenericVector< SEAM *> &seams, const GenericVector< TBLOB *> &blobs, int first, int last)
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 AdaptableWord(WERD_RES *word)
LIST push(LIST list, void *element)
bool AlternativeChoiceAdjustmentsWorseThan(float threshold) const
bool matcher_debug_separate_windows
const UnicharIdVector * AmbigsForAdaption(UNICHAR_ID unichar_id) const
const FontInfo * fontinfo
void SetAdaptiveThreshold(float Threshold)
UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
void ClearCharNormArray(uint8_t *char_norm_array)
double matcher_rating_margin
#define PRINT_FEATURE_MATCHES
bool DeSerialize(TFile *fp)
void AddNewResult(const UnicharRating &new_result, ADAPT_RESULTS *results)
int MakeNewTemporaryConfig(ADAPT_TEMPLATES Templates, CLASS_ID ClassId, int FontinfoId, int NumFeatures, INT_FEATURE_ARRAY Features, FEATURE_SET FloatFeatures)
const int kBlnBaselineOffset
#define zero_all_bits(array, length)
ADAPT_TEMPLATES NewAdaptedTemplates(bool InitFromUnicharset)
void UpdateAmbigsGroup(CLASS_ID class_id, TBLOB *Blob)
#define UnusedClassIdIn(T, c)
void ShowBestMatchFor(int shape_id, const INT_FEATURE_STRUCT *features, int num_features)
bool get_isalpha(UNICHAR_ID unichar_id) const
#define WORST_POSSIBLE_RATING
void EndDangerousAmbigs()
GenericVector< UnicharRating > match
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)
int AddIntProto(INT_CLASS Class)
void FreeBitVector(BIT_VECTOR BitVector)
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)
void AddLargeSpeckleTo(int blob_length, BLOB_CHOICE_LIST *choices)
bool classify_nonlinear_norm
#define copy_all_bits(source, dest, length)
int MakeTempProtoPerm(void *item1, void *item2)
int classify_adapt_proto_threshold
GenericVector< STRING > correct_text
void free_adapted_templates(ADAPT_TEMPLATES templates)
#define GetPicoFeatureLength()
void XHeightRange(int unichar_id, const UNICHARSET &unicharset, const TBOX &bbox, float *min_xht, float *max_xht, float *yshift) const
#define TempConfigFor(Class, ConfigId)
NORM_PROTOS * ReadNormProtos(TFile *fp)
double classify_character_fragments_garbage_certainty_threshold
void ComputeCharNormArrays(FEATURE_STRUCT *norm_feature, INT_TEMPLATES_STRUCT *templates, uint8_t *char_norm_array, uint8_t *pruner_array)
static int SortDescendingRating(const void *t1, const void *t2)
void FreeTempConfig(TEMP_CONFIG Config)
bool classify_debug_character_fragments
double classify_adapted_pruning_threshold
ADAPT_CLASS Class[MAX_NUM_CLASSES]
bool get_isdigit(UNICHAR_ID unichar_id) const
#define PermConfigFor(Class, ConfigId)
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)
BIT_VECTOR NewBitVector(int NumBits)
int classify_learning_debug_level
#define MakeProtoPermanent(Class, ProtoId)
float ApplyCNCorrection(float rating, int blob_length, int normalization_factor, int matcher_multiplier)
INT_TEMPLATES PreTrainedTemplates
float ActualOutlineLength(FEATURE Feature)
void get_top_bottom(UNICHAR_ID unichar_id, int *min_bottom, int *max_bottom, int *min_top, int *max_top) const
bool contains_unichar(const char *const unichar_repr) const
int ClassAndConfigIDToFontOrShapeID(int class_id, int int_result_config) const
double matcher_good_threshold
#define IncreaseConfidence(TempConfig)
TEMP_PROTO NewTempProto()
STRING debug_str(UNICHAR_ID id) const
#define MAX_NUM_INT_FEATURES
bool MarginalMatch(float confidence, float matcher_great_threshold)
ADAPT_TEMPLATES Templates
int IntCastRounded(double x)
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 SetAdaptiveThreshold(float Threshold)
double matcher_reliable_adaptive_result
double classify_adapted_pruning_factor
#define LENGTH_COMPRESSION
void plot(ScrollView *window)
STRING ClassIDToDebugStr(const INT_TEMPLATES_STRUCT *templates, int class_id, int config_id) const
GenericVector< int > best_state
int MaxNumUnichars() const
double matcher_clustering_max_angle_delta
double classify_misfit_junk_penalty
bool get_enabled(UNICHAR_ID unichar_id) const
#define set_all_bits(array, length)
ShapeTable * shape_table_
PROTO_ID MakeNewTempProtos(FEATURE_SET Features, int NumBadFeat, FEATURE_ID BadFeat[], INT_CLASS IClass, ADAPT_CLASS Class, BIT_VECTOR TempProtoMask)
bool LooksLikeGarbage(TBLOB *blob)
ADAPT_TEMPLATES BackupAdaptedTemplates
ADAPT_TEMPLATES AdaptedTemplates
void MakePermanent(ADAPT_TEMPLATES Templates, CLASS_ID ClassId, int ConfigId, TBLOB *Blob)
DLLSYM void tprintf(const char *format,...)
void PrintAdaptiveMatchResults(const ADAPT_RESULTS &results)
TBOX bounding_box() const
float adjust_factor() const
TBLOB * ClassifyNormalizeIfNeeded() const
void PrintAdaptedTemplates(FILE *File, ADAPT_TEMPLATES Templates)
void ResetAdaptiveClassifierInternal()
GenericVector< SEAM * > seam_array
INT_FEATURE_STRUCT INT_FEATURE_ARRAY[MAX_NUM_INT_FEATURES]
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)
void ConvertMatchesToChoices(const DENORM &denorm, const TBOX &box, ADAPT_RESULTS *Results, BLOB_CHOICE_LIST *Choices)
int CharNormClassifier(TBLOB *blob, const TrainingSample &sample, ADAPT_RESULTS *adapt_results)
bool Open(const STRING &filename, FileReader reader)
TEMP_CONFIG NewTempConfig(int MaxProtoId, int FontinfoId)
void EndAdaptiveClassifier()
GenericVector< TBLOB * > blobs
double matcher_perfect_threshold
FEATURE NewFeature(const FEATURE_DESC_STRUCT *FeatureDesc)
const Shape & GetShape(int shape_id) const
double matcher_avg_noise_size
int AddIntConfig(INT_CLASS Class)
int matcher_sufficient_examples_for_prototyping
#define ConfigIsPermanent(Class, ConfigId)
FEATURE_SET ExtractOutlineFeatures(TBLOB *Blob)
bool disable_character_fragments
void FillABC(PROTO Proto)
void RemoveExtraPuncs(ADAPT_RESULTS *Results)
bool classify_enable_adaptive_matcher
GenericVector< CP_RESULT_STRUCT > CPResults
PERM_CONFIG_STRUCT * PERM_CONFIG
#define IsEmptyAdaptedClass(Class)
int classify_adapt_feature_threshold
#define reset_bit(array, bit)
void FreeFeatureSet(FEATURE_SET FeatureSet)
const CHAR_FRAGMENT * get_fragment(UNICHAR_ID unichar_id) const
void SwitchAdaptiveClassifier()
int classify_integer_matcher_multiplier
UnicityTable< FontInfo > fontinfo_table_
void AddProtoToProtoPruner(PROTO Proto, int ProtoId, INT_CLASS Class, bool debug)
const UnicharIdVector * ReverseAmbigsForAdaption(UNICHAR_ID unichar_id) const
void WriteAdaptedTemplates(FILE *File, ADAPT_TEMPLATES Templates)
virtual int UnicharClassifySample(const TrainingSample &sample, Pix *page_pix, int debug, UNICHAR_ID keep_this, GenericVector< UnicharRating > *results)
const STRING debug_string() const
int matcher_min_examples_for_prototyping
double matcher_bad_match_pad
#define MakeConfigPermanent(Class, ConfigId)
INT_TEMPLATES ReadIntTemplates(TFile *fp)
#define PRINT_MATCH_SUMMARY
#define MAX_ADAPTABLE_WERD_SIZE
const DENORM & denorm() const
const FEATURE_DESC_STRUCT CharNormDesc
const char * id_to_unichar(UNICHAR_ID id) const
int CharNormTrainingSample(bool pruner_only, int keep_this, const TrainingSample &sample, GenericVector< UnicharRating > *results)
const UNICHARSET & getUnicharset() const
void InitAdaptedClass(TBLOB *Blob, CLASS_ID ClassId, int FontinfoId, ADAPT_CLASS Class, ADAPT_TEMPLATES Templates)
char * classify_learn_debug_str
int FindBadFeatures(INT_CLASS ClassTemplate, BIT_VECTOR ProtoMask, BIT_VECTOR ConfigMask, uint16_t BlobLength, int16_t NumFeatures, INT_FEATURE_ARRAY Features, FEATURE_ID *FeatureArray, int AdaptFeatureThreshold, int Debug)
const double kStandardFeatureLength
UNICHAR_ID * GetAmbiguities(TBLOB *Blob, CLASS_ID CorrectClass)
TEMP_PROTO_STRUCT * TEMP_PROTO
#define ADAPTABLE_WERD_ADJUSTMENT
void StartBackupAdaptiveClassifier()
void ComputeIntCharNormArray(const FEATURE_STRUCT &norm_feature, uint8_t *char_norm_array)
void print_ratings_list(const char *msg, BLOB_CHOICE_LIST *ratings, const UNICHARSET ¤t_unicharset)
void LearnBlob(const STRING &fontname, TBLOB *Blob, const DENORM &cn_denorm, const INT_FX_RESULT_STRUCT &fx_info, const char *blob_text)
void DoAdaptiveMatch(TBLOB *Blob, ADAPT_RESULTS *Results)
#define ADAPT_TEMPLATE_SUFFIX
char window_wait(ScrollView *win)
int GetAdaptiveFeatures(TBLOB *Blob, INT_FEATURE_ARRAY IntFeatures, FEATURE_SET *FloatFeatures)
void RemoveBadMatches(ADAPT_RESULTS *Results)
void AdaptToChar(TBLOB *Blob, CLASS_ID ClassId, int FontinfoId, float Threshold, ADAPT_TEMPLATES adaptive_templates)
#define PRINT_PROTO_MATCHES
void SettupStopperPass2()
Sets up stopper variables in preparation for the second pass.
void ReadNewCutoffs(TFile *fp, CLASS_CUTOFF_ARRAY Cutoffs)
#define ClassForClassId(T, c)
#define UNLIKELY_NUM_FEAT
void FreeTempProto(void *arg)
bool classify_enable_learning
void AddProtoToClassPruner(PROTO Proto, CLASS_ID ClassId, INT_TEMPLATES Templates)
WERD_CHOICE * best_choice
#define test_bit(array, bit)
UnicityTable< FontSet > fontset_table_
#define SET_BIT(array, bit)
void LearnWord(const char *fontname, WERD_RES *word)
void ConvertConfig(BIT_VECTOR Config, int ConfigId, INT_CLASS Class)
int get_script(UNICHAR_ID unichar_id) const
int ShapeIDToClassID(int shape_id) const
bool classify_use_pre_adapted_templates
FEATURE_SET ExtractPicoFeatures(TBLOB *Blob)
GenericVector< ScoredFont > fonts
bool classify_save_adapted_templates
LIST delete_d(LIST list, void *key, int_compare is_equal)