tesseract  5.0.0-alpha-619-ge9db
tesseract::MasterTrainer Class Reference

#include <mastertrainer.h>

Public Member Functions

 MasterTrainer (NormalizationMode norm_mode, bool shape_analysis, bool replicate_samples, int debug_level)
 
 ~MasterTrainer ()
 
bool Serialize (FILE *fp) const
 
void LoadUnicharset (const char *filename)
 
void SetFeatureSpace (const IntFeatureSpace &fs)
 
void ReadTrainingSamples (const char *page_name, const FEATURE_DEFS_STRUCT &feature_defs, bool verification)
 
void AddSample (bool verification, const char *unichar_str, TrainingSample *sample)
 
void LoadPageImages (const char *filename)
 
void PostLoadCleanup ()
 
void PreTrainingSetup ()
 
void SetupMasterShapes ()
 
void IncludeJunk ()
 
void ReplicateAndRandomizeSamplesIfRequired ()
 
bool LoadFontInfo (const char *filename)
 
bool LoadXHeights (const char *filename)
 
bool AddSpacingInfo (const char *filename)
 
int GetFontInfoId (const char *font_name)
 
int GetBestMatchingFontInfoId (const char *filename)
 
const STRINGGetTRFileName (int index) const
 
void SetupFlatShapeTable (ShapeTable *shape_table)
 
CLUSTERERSetupForClustering (const ShapeTable &shape_table, const FEATURE_DEFS_STRUCT &feature_defs, int shape_id, int *num_samples)
 
void WriteInttempAndPFFMTable (const UNICHARSET &unicharset, const UNICHARSET &shape_set, const ShapeTable &shape_table, CLASS_STRUCT *float_classes, const char *inttemp_file, const char *pffmtable_file)
 
const UNICHARSETunicharset () const
 
TrainingSampleSetGetSamples ()
 
const ShapeTablemaster_shapes () const
 
void DebugCanonical (const char *unichar_str1, const char *unichar_str2)
 
void DisplaySamples (const char *unichar_str1, int cloud_font, const char *unichar_str2, int canonical_font)
 
void TestClassifierVOld (bool replicate_samples, ShapeClassifier *test_classifier, ShapeClassifier *old_classifier)
 
void TestClassifierOnSamples (CountTypes error_mode, int report_level, bool replicate_samples, ShapeClassifier *test_classifier, STRING *report_string)
 
double TestClassifier (CountTypes error_mode, int report_level, bool replicate_samples, TrainingSampleSet *samples, ShapeClassifier *test_classifier, STRING *report_string)
 
float ShapeDistance (const ShapeTable &shapes, int s1, int s2)
 

Detailed Description

Definition at line 69 of file mastertrainer.h.

Constructor & Destructor Documentation

◆ MasterTrainer()

tesseract::MasterTrainer::MasterTrainer ( NormalizationMode  norm_mode,
bool  shape_analysis,
bool  replicate_samples,
int  debug_level 
)

Definition at line 50 of file mastertrainer.cpp.

54  : norm_mode_(norm_mode), samples_(fontinfo_table_),
55  junk_samples_(fontinfo_table_), verify_samples_(fontinfo_table_),
56  charsetsize_(0),
57  enable_shape_analysis_(shape_analysis),
58  enable_replication_(replicate_samples),
59  fragments_(nullptr), prev_unichar_id_(-1), debug_level_(debug_level) {
60 }

◆ ~MasterTrainer()

tesseract::MasterTrainer::~MasterTrainer ( )

Definition at line 62 of file mastertrainer.cpp.

62  {
63  delete [] fragments_;
64  for (int p = 0; p < page_images_.size(); ++p)
65  pixDestroy(&page_images_[p]);
66 }

Member Function Documentation

◆ AddSample()

void tesseract::MasterTrainer::AddSample ( bool  verification,
const char *  unichar_str,
TrainingSample sample 
)

Definition at line 162 of file mastertrainer.cpp.

163  {
164  if (verification) {
165  verify_samples_.AddSample(unichar, sample);
166  prev_unichar_id_ = -1;
167  } else if (unicharset_.contains_unichar(unichar)) {
168  if (prev_unichar_id_ >= 0)
169  fragments_[prev_unichar_id_] = -1;
170  prev_unichar_id_ = samples_.AddSample(unichar, sample);
171  if (flat_shapes_.FindShape(prev_unichar_id_, sample->font_id()) < 0)
172  flat_shapes_.AddShape(prev_unichar_id_, sample->font_id());
173  } else {
174  const int junk_id = junk_samples_.AddSample(unichar, sample);
175  if (prev_unichar_id_ >= 0) {
177  if (frag != nullptr && frag->is_natural()) {
178  if (fragments_[prev_unichar_id_] == 0)
179  fragments_[prev_unichar_id_] = junk_id;
180  else if (fragments_[prev_unichar_id_] != junk_id)
181  fragments_[prev_unichar_id_] = -1;
182  }
183  delete frag;
184  }
185  prev_unichar_id_ = -1;
186  }
187 }

◆ AddSpacingInfo()

bool tesseract::MasterTrainer::AddSpacingInfo ( const char *  filename)

Definition at line 411 of file mastertrainer.cpp.

411  {
412  FILE* fontinfo_file = fopen(filename, "rb");
413  if (fontinfo_file == nullptr)
414  return true; // We silently ignore missing files!
415  // Find the fontinfo_id.
416  int fontinfo_id = GetBestMatchingFontInfoId(filename);
417  if (fontinfo_id < 0) {
418  tprintf("No font found matching fontinfo filename %s\n", filename);
419  fclose(fontinfo_file);
420  return false;
421  }
422  tprintf("Reading spacing from %s for font %d...\n", filename, fontinfo_id);
423  // TODO(rays) scale should probably be a double, but keep as an int for now
424  // to duplicate current behavior.
425  int scale = kBlnXHeight / xheights_[fontinfo_id];
426  int num_unichars;
427  char uch[UNICHAR_LEN];
428  char kerned_uch[UNICHAR_LEN];
429  int x_gap, x_gap_before, x_gap_after, num_kerned;
430  ASSERT_HOST(tfscanf(fontinfo_file, "%d\n", &num_unichars) == 1);
431  FontInfo *fi = &fontinfo_table_.get(fontinfo_id);
432  fi->init_spacing(unicharset_.size());
433  FontSpacingInfo *spacing = nullptr;
434  for (int l = 0; l < num_unichars; ++l) {
435  if (tfscanf(fontinfo_file, "%s %d %d %d",
436  uch, &x_gap_before, &x_gap_after, &num_kerned) != 4) {
437  tprintf("Bad format of font spacing file %s\n", filename);
438  fclose(fontinfo_file);
439  return false;
440  }
441  bool valid = unicharset_.contains_unichar(uch);
442  if (valid) {
443  spacing = new FontSpacingInfo();
444  spacing->x_gap_before = static_cast<int16_t>(x_gap_before * scale);
445  spacing->x_gap_after = static_cast<int16_t>(x_gap_after * scale);
446  }
447  for (int k = 0; k < num_kerned; ++k) {
448  if (tfscanf(fontinfo_file, "%s %d", kerned_uch, &x_gap) != 2) {
449  tprintf("Bad format of font spacing file %s\n", filename);
450  fclose(fontinfo_file);
451  delete spacing;
452  return false;
453  }
454  if (!valid || !unicharset_.contains_unichar(kerned_uch)) continue;
455  spacing->kerned_unichar_ids.push_back(
456  unicharset_.unichar_to_id(kerned_uch));
457  spacing->kerned_x_gaps.push_back(static_cast<int16_t>(x_gap * scale));
458  }
459  if (valid) fi->add_spacing(unicharset_.unichar_to_id(uch), spacing);
460  }
461  fclose(fontinfo_file);
462  return true;
463 }

◆ DebugCanonical()

void tesseract::MasterTrainer::DebugCanonical ( const char *  unichar_str1,
const char *  unichar_str2 
)

Definition at line 635 of file mastertrainer.cpp.

636  {
637  int class_id1 = unicharset_.unichar_to_id(unichar_str1);
638  int class_id2 = unicharset_.unichar_to_id(unichar_str2);
639  if (class_id2 == INVALID_UNICHAR_ID)
640  class_id2 = class_id1;
641  if (class_id1 == INVALID_UNICHAR_ID) {
642  tprintf("No unicharset entry found for %s\n", unichar_str1);
643  return;
644  } else {
645  tprintf("Font ambiguities for unichar %d = %s and %d = %s\n",
646  class_id1, unichar_str1, class_id2, unichar_str2);
647  }
648  int num_fonts = samples_.NumFonts();
649  const IntFeatureMap& feature_map = feature_map_;
650  // Iterate the fonts to get the similarity with other fonst of the same
651  // class.
652  tprintf(" ");
653  for (int f = 0; f < num_fonts; ++f) {
654  if (samples_.NumClassSamples(f, class_id2, false) == 0)
655  continue;
656  tprintf("%6d", f);
657  }
658  tprintf("\n");
659  for (int f1 = 0; f1 < num_fonts; ++f1) {
660  // Map the features of the canonical_sample.
661  if (samples_.NumClassSamples(f1, class_id1, false) == 0)
662  continue;
663  tprintf("%4d ", f1);
664  for (int f2 = 0; f2 < num_fonts; ++f2) {
665  if (samples_.NumClassSamples(f2, class_id2, false) == 0)
666  continue;
667  float dist = samples_.ClusterDistance(f1, class_id1, f2, class_id2,
668  feature_map);
669  tprintf(" %5.3f", dist);
670  }
671  tprintf("\n");
672  }
673  // Build a fake ShapeTable containing all the sample types.
674  ShapeTable shapes(unicharset_);
675  for (int f = 0; f < num_fonts; ++f) {
676  if (samples_.NumClassSamples(f, class_id1, true) > 0)
677  shapes.AddShape(class_id1, f);
678  if (class_id1 != class_id2 &&
679  samples_.NumClassSamples(f, class_id2, true) > 0)
680  shapes.AddShape(class_id2, f);
681  }
682 }

◆ DisplaySamples()

void tesseract::MasterTrainer::DisplaySamples ( const char *  unichar_str1,
int  cloud_font,
const char *  unichar_str2,
int  canonical_font 
)

Definition at line 695 of file mastertrainer.cpp.

697  {
698  const IntFeatureMap& feature_map = feature_map_;
699  const IntFeatureSpace& feature_space = feature_map.feature_space();
700  ScrollView* f_window = CreateFeatureSpaceWindow("Features", 100, 500);
702  f_window);
703  int class_id2 = samples_.unicharset().unichar_to_id(unichar_str2);
704  if (class_id2 != INVALID_UNICHAR_ID && canonical_font >= 0) {
705  const TrainingSample* sample = samples_.GetCanonicalSample(canonical_font,
706  class_id2);
707  for (uint32_t f = 0; f < sample->num_features(); ++f) {
708  RenderIntFeature(f_window, &sample->features()[f], ScrollView::RED);
709  }
710  }
711  int class_id1 = samples_.unicharset().unichar_to_id(unichar_str1);
712  if (class_id1 != INVALID_UNICHAR_ID && cloud_font >= 0) {
713  const BitVector& cloud = samples_.GetCloudFeatures(cloud_font, class_id1);
714  for (int f = 0; f < cloud.size(); ++f) {
715  if (cloud[f]) {
716  INT_FEATURE_STRUCT feature =
717  feature_map.InverseIndexFeature(f);
718  RenderIntFeature(f_window, &feature, ScrollView::GREEN);
719  }
720  }
721  }
722  f_window->Update();
723  ScrollView* s_window = CreateFeatureSpaceWindow("Samples", 100, 500);
724  SVEventType ev_type;
725  do {
726  SVEvent* ev;
727  // Wait until a click or popup event.
728  ev = f_window->AwaitEvent(SVET_ANY);
729  ev_type = ev->type;
730  if (ev_type == SVET_CLICK) {
731  int feature_index = feature_space.XYToFeatureIndex(ev->x, ev->y);
732  if (feature_index >= 0) {
733  // Iterate samples and display those with the feature.
734  Shape shape;
735  shape.AddToShape(class_id1, cloud_font);
736  s_window->Clear();
737  samples_.DisplaySamplesWithFeature(feature_index, shape,
738  feature_space, ScrollView::GREEN,
739  s_window);
740  s_window->Update();
741  }
742  }
743  delete ev;
744  } while (ev_type != SVET_DESTROY);
745 }

◆ GetBestMatchingFontInfoId()

int tesseract::MasterTrainer::GetBestMatchingFontInfoId ( const char *  filename)

Definition at line 478 of file mastertrainer.cpp.

478  {
479  int fontinfo_id = -1;
480  int best_len = 0;
481  for (int f = 0; f < fontinfo_table_.size(); ++f) {
482  if (strstr(filename, fontinfo_table_.get(f).name) != nullptr) {
483  int len = strlen(fontinfo_table_.get(f).name);
484  // Use the longest matching length in case a substring of a font matched.
485  if (len > best_len) {
486  best_len = len;
487  fontinfo_id = f;
488  }
489  }
490  }
491  return fontinfo_id;
492 }

◆ GetFontInfoId()

int tesseract::MasterTrainer::GetFontInfoId ( const char *  font_name)

Definition at line 467 of file mastertrainer.cpp.

467  {
468  FontInfo fontinfo;
469  // We are only borrowing the string, so it is OK to const cast it.
470  fontinfo.name = const_cast<char*>(font_name);
471  fontinfo.properties = 0; // Not used to lookup in the table
472  fontinfo.universal_id = 0;
473  return fontinfo_table_.get_index(fontinfo);
474 }

◆ GetSamples()

TrainingSampleSet* tesseract::MasterTrainer::GetSamples ( )
inline

Definition at line 189 of file mastertrainer.h.

189  {
190  return &samples_;
191  }

◆ GetTRFileName()

const STRING& tesseract::MasterTrainer::GetTRFileName ( int  index) const
inline

Definition at line 162 of file mastertrainer.h.

162  {
163  return tr_filenames_[index];
164  }

◆ IncludeJunk()

void tesseract::MasterTrainer::IncludeJunk ( )

Definition at line 294 of file mastertrainer.cpp.

294  {
295  // Get ids of fragments in junk_samples_ that replace the dead chars.
296  const UNICHARSET& junk_set = junk_samples_.unicharset();
297  const UNICHARSET& sample_set = samples_.unicharset();
298  int num_junks = junk_samples_.num_samples();
299  tprintf("Moving %d junk samples to master sample set.\n", num_junks);
300  for (int s = 0; s < num_junks; ++s) {
301  TrainingSample* sample = junk_samples_.mutable_sample(s);
302  int junk_id = sample->class_id();
303  const char* junk_utf8 = junk_set.id_to_unichar(junk_id);
304  int sample_id = sample_set.unichar_to_id(junk_utf8);
305  if (sample_id == INVALID_UNICHAR_ID)
306  sample_id = 0;
307  sample->set_class_id(sample_id);
308  junk_samples_.extract_sample(s);
309  samples_.AddSample(sample_id, sample);
310  }
311  junk_samples_.DeleteDeadSamples();
312  samples_.OrganizeByFontAndClass();
313 }

◆ LoadFontInfo()

bool tesseract::MasterTrainer::LoadFontInfo ( const char *  filename)

Definition at line 332 of file mastertrainer.cpp.

332  {
333  FILE* fp = fopen(filename, "rb");
334  if (fp == nullptr) {
335  fprintf(stderr, "Failed to load font_properties from %s\n", filename);
336  return false;
337  }
338  int italic, bold, fixed, serif, fraktur;
339  while (!feof(fp)) {
340  FontInfo fontinfo;
341  char* font_name = new char[1024];
342  fontinfo.name = font_name;
343  fontinfo.properties = 0;
344  fontinfo.universal_id = 0;
345  if (tfscanf(fp, "%1024s %i %i %i %i %i\n", font_name, &italic, &bold,
346  &fixed, &serif, &fraktur) != 6) {
347  delete[] font_name;
348  continue;
349  }
350  fontinfo.properties =
351  (italic << 0) +
352  (bold << 1) +
353  (fixed << 2) +
354  (serif << 3) +
355  (fraktur << 4);
356  if (!fontinfo_table_.contains(fontinfo)) {
357  fontinfo_table_.push_back(fontinfo);
358  } else {
359  delete[] font_name;
360  }
361  }
362  fclose(fp);
363  return true;
364 }

◆ LoadPageImages()

void tesseract::MasterTrainer::LoadPageImages ( const char *  filename)

Definition at line 192 of file mastertrainer.cpp.

192  {
193  size_t offset = 0;
194  int page;
195  Pix* pix;
196  for (page = 0;; page++) {
197  pix = pixReadFromMultipageTiff(filename, &offset);
198  if (!pix) break;
199  page_images_.push_back(pix);
200  if (!offset) break;
201  }
202  tprintf("Loaded %d page images from %s\n", page, filename);
203 }

◆ LoadUnicharset()

void tesseract::MasterTrainer::LoadUnicharset ( const char *  filename)

Definition at line 87 of file mastertrainer.cpp.

87  {
88  if (!unicharset_.load_from_file(filename)) {
89  tprintf("Failed to load unicharset from file %s\n"
90  "Building unicharset for training from scratch...\n",
91  filename);
93  UNICHARSET initialized;
94  // Add special characters, as they were removed by the clear, but the
95  // default constructor puts them in.
97  }
98  charsetsize_ = unicharset_.size();
99  delete [] fragments_;
100  fragments_ = new int[charsetsize_];
101  memset(fragments_, 0, sizeof(*fragments_) * charsetsize_);
102  samples_.LoadUnicharset(filename);
103  junk_samples_.LoadUnicharset(filename);
104  verify_samples_.LoadUnicharset(filename);
105 }

◆ LoadXHeights()

bool tesseract::MasterTrainer::LoadXHeights ( const char *  filename)

Definition at line 368 of file mastertrainer.cpp.

368  {
369  tprintf("fontinfo table is of size %d\n", fontinfo_table_.size());
370  xheights_.init_to_size(fontinfo_table_.size(), -1);
371  if (filename == nullptr) return true;
372  FILE *f = fopen(filename, "rb");
373  if (f == nullptr) {
374  fprintf(stderr, "Failed to load font xheights from %s\n", filename);
375  return false;
376  }
377  tprintf("Reading x-heights from %s ...\n", filename);
378  FontInfo fontinfo;
379  fontinfo.properties = 0; // Not used to lookup in the table.
380  fontinfo.universal_id = 0;
381  char buffer[1024];
382  int xht;
383  int total_xheight = 0;
384  int xheight_count = 0;
385  while (!feof(f)) {
386  if (tfscanf(f, "%1023s %d\n", buffer, &xht) != 2)
387  continue;
388  buffer[1023] = '\0';
389  fontinfo.name = buffer;
390  if (!fontinfo_table_.contains(fontinfo)) continue;
391  int fontinfo_id = fontinfo_table_.get_index(fontinfo);
392  xheights_[fontinfo_id] = xht;
393  total_xheight += xht;
394  ++xheight_count;
395  }
396  if (xheight_count == 0) {
397  fprintf(stderr, "No valid xheights in %s!\n", filename);
398  fclose(f);
399  return false;
400  }
401  int mean_xheight = DivRounded(total_xheight, xheight_count);
402  for (int i = 0; i < fontinfo_table_.size(); ++i) {
403  if (xheights_[i] < 0)
404  xheights_[i] = mean_xheight;
405  }
406  fclose(f);
407  return true;
408 } // LoadXHeights

◆ master_shapes()

const ShapeTable& tesseract::MasterTrainer::master_shapes ( ) const
inline

Definition at line 192 of file mastertrainer.h.

192  {
193  return master_shapes_;
194  }

◆ PostLoadCleanup()

void tesseract::MasterTrainer::PostLoadCleanup ( )

Definition at line 210 of file mastertrainer.cpp.

210  {
211  if (debug_level_ > 0)
212  tprintf("PostLoadCleanup...\n");
213  if (enable_shape_analysis_)
214  ReplaceFragmentedSamples();
215  SampleIterator sample_it;
216  sample_it.Init(nullptr, nullptr, true, &verify_samples_);
217  sample_it.NormalizeSamples();
218  verify_samples_.OrganizeByFontAndClass();
219 
220  samples_.IndexFeatures(feature_space_);
221  // TODO(rays) DeleteOutliers is currently turned off to prove NOP-ness
222  // against current training.
223  // samples_.DeleteOutliers(feature_space_, debug_level_ > 0);
224  samples_.OrganizeByFontAndClass();
225  if (debug_level_ > 0)
226  tprintf("ComputeCanonicalSamples...\n");
227  samples_.ComputeCanonicalSamples(feature_map_, debug_level_ > 0);
228 }

◆ PreTrainingSetup()

void tesseract::MasterTrainer::PreTrainingSetup ( )

Definition at line 233 of file mastertrainer.cpp.

233  {
234  if (debug_level_ > 0)
235  tprintf("PreTrainingSetup...\n");
236  samples_.IndexFeatures(feature_space_);
237  samples_.ComputeCanonicalFeatures();
238  if (debug_level_ > 0)
239  tprintf("ComputeCloudFeatures...\n");
240  samples_.ComputeCloudFeatures(feature_space_.Size());
241 }

◆ ReadTrainingSamples()

void tesseract::MasterTrainer::ReadTrainingSamples ( const char *  page_name,
const FEATURE_DEFS_STRUCT feature_defs,
bool  verification 
)

Definition at line 111 of file mastertrainer.cpp.

113  {
114  char buffer[2048];
115  const int int_feature_type = ShortNameToFeatureType(feature_defs, kIntFeatureType);
116  const int micro_feature_type = ShortNameToFeatureType(feature_defs,
118  const int cn_feature_type = ShortNameToFeatureType(feature_defs, kCNFeatureType);
119  const int geo_feature_type = ShortNameToFeatureType(feature_defs, kGeoFeatureType);
120 
121  FILE* fp = fopen(page_name, "rb");
122  if (fp == nullptr) {
123  tprintf("Failed to open tr file: %s\n", page_name);
124  return;
125  }
126  tr_filenames_.push_back(STRING(page_name));
127  while (fgets(buffer, sizeof(buffer), fp) != nullptr) {
128  if (buffer[0] == '\n')
129  continue;
130 
131  char* space = strchr(buffer, ' ');
132  if (space == nullptr) {
133  tprintf("Bad format in tr file, reading fontname, unichar\n");
134  continue;
135  }
136  *space++ = '\0';
137  int font_id = GetFontInfoId(buffer);
138  if (font_id < 0) font_id = 0;
139  int page_number;
140  STRING unichar;
141  TBOX bounding_box;
142  if (!ParseBoxFileStr(space, &page_number, &unichar, &bounding_box)) {
143  tprintf("Bad format in tr file, reading box coords\n");
144  continue;
145  }
146  CHAR_DESC char_desc = ReadCharDescription(feature_defs, fp);
147  auto* sample = new TrainingSample;
148  sample->set_font_id(font_id);
149  sample->set_page_num(page_number + page_images_.size());
150  sample->set_bounding_box(bounding_box);
151  sample->ExtractCharDesc(int_feature_type, micro_feature_type,
152  cn_feature_type, geo_feature_type, char_desc);
153  AddSample(verification, unichar.c_str(), sample);
154  FreeCharDescription(char_desc);
155  }
156  charsetsize_ = unicharset_.size();
157  fclose(fp);
158 }

◆ ReplicateAndRandomizeSamplesIfRequired()

void tesseract::MasterTrainer::ReplicateAndRandomizeSamplesIfRequired ( )

Definition at line 320 of file mastertrainer.cpp.

320  {
321  if (enable_replication_) {
322  if (debug_level_ > 0)
323  tprintf("ReplicateAndRandomize...\n");
324  verify_samples_.ReplicateAndRandomizeSamples();
325  samples_.ReplicateAndRandomizeSamples();
326  samples_.IndexFeatures(feature_space_);
327  }
328 }

◆ Serialize()

bool tesseract::MasterTrainer::Serialize ( FILE *  fp) const

Definition at line 71 of file mastertrainer.cpp.

71  {
72  uint32_t value = norm_mode_;
73  if (!tesseract::Serialize(fp, &value)) return false;
74  if (!unicharset_.save_to_file(fp)) return false;
75  if (!feature_space_.Serialize(fp)) return false;
76  if (!samples_.Serialize(fp)) return false;
77  if (!junk_samples_.Serialize(fp)) return false;
78  if (!verify_samples_.Serialize(fp)) return false;
79  if (!master_shapes_.Serialize(fp)) return false;
80  if (!flat_shapes_.Serialize(fp)) return false;
81  if (!fontinfo_table_.Serialize(fp)) return false;
82  if (!xheights_.Serialize(fp)) return false;
83  return true;
84 }

◆ SetFeatureSpace()

void tesseract::MasterTrainer::SetFeatureSpace ( const IntFeatureSpace fs)
inline

Definition at line 82 of file mastertrainer.h.

82  {
83  feature_space_ = fs;
84  feature_map_.Init(fs);
85  }

◆ SetupFlatShapeTable()

void tesseract::MasterTrainer::SetupFlatShapeTable ( ShapeTable shape_table)

Definition at line 495 of file mastertrainer.cpp.

495  {
496  // To exactly mimic the results of the previous implementation, the shapes
497  // must be clustered in order the fonts arrived, and reverse order of the
498  // characters within each font.
499  // Get a list of the fonts in the order they appeared.
500  GenericVector<int> active_fonts;
501  int num_shapes = flat_shapes_.NumShapes();
502  for (int s = 0; s < num_shapes; ++s) {
503  int font = flat_shapes_.GetShape(s)[0].font_ids[0];
504  int f = 0;
505  for (f = 0; f < active_fonts.size(); ++f) {
506  if (active_fonts[f] == font)
507  break;
508  }
509  if (f == active_fonts.size())
510  active_fonts.push_back(font);
511  }
512  // For each font in order, add all the shapes with that font in reverse order.
513  int num_fonts = active_fonts.size();
514  for (int f = 0; f < num_fonts; ++f) {
515  for (int s = num_shapes - 1; s >= 0; --s) {
516  int font = flat_shapes_.GetShape(s)[0].font_ids[0];
517  if (font == active_fonts[f]) {
518  shape_table->AddShape(flat_shapes_.GetShape(s));
519  }
520  }
521  }
522 }

◆ SetupForClustering()

CLUSTERER * tesseract::MasterTrainer::SetupForClustering ( const ShapeTable shape_table,
const FEATURE_DEFS_STRUCT feature_defs,
int  shape_id,
int *  num_samples 
)

Definition at line 526 of file mastertrainer.cpp.

530  {
531 
533  int num_params = feature_defs.FeatureDesc[desc_index]->NumParams;
534  ASSERT_HOST(num_params == MFCount);
535  CLUSTERER* clusterer = MakeClusterer(
536  num_params, feature_defs.FeatureDesc[desc_index]->ParamDesc);
537 
538  // We want to iterate over the samples of just the one shape.
539  IndexMapBiDi shape_map;
540  shape_map.Init(shape_table.NumShapes(), false);
541  shape_map.SetMap(shape_id, true);
542  shape_map.Setup();
543  // Reverse the order of the samples to match the previous behavior.
545  SampleIterator it;
546  it.Init(&shape_map, &shape_table, false, &samples_);
547  for (it.Begin(); !it.AtEnd(); it.Next()) {
548  sample_ptrs.push_back(&it.GetSample());
549  }
550  int sample_id = 0;
551  for (int i = sample_ptrs.size() - 1; i >= 0; --i) {
552  const TrainingSample* sample = sample_ptrs[i];
553  uint32_t num_features = sample->num_micro_features();
554  for (uint32_t f = 0; f < num_features; ++f)
555  MakeSample(clusterer, sample->micro_features()[f], sample_id);
556  ++sample_id;
557  }
558  *num_samples = sample_id;
559  return clusterer;
560 }

◆ SetupMasterShapes()

void tesseract::MasterTrainer::SetupMasterShapes ( )

Definition at line 245 of file mastertrainer.cpp.

245  {
246  tprintf("Building master shape table\n");
247  const int num_fonts = samples_.NumFonts();
248 
249  ShapeTable char_shapes_begin_fragment(samples_.unicharset());
250  ShapeTable char_shapes_end_fragment(samples_.unicharset());
251  ShapeTable char_shapes(samples_.unicharset());
252  for (int c = 0; c < samples_.charsetsize(); ++c) {
253  ShapeTable shapes(samples_.unicharset());
254  for (int f = 0; f < num_fonts; ++f) {
255  if (samples_.NumClassSamples(f, c, true) > 0)
256  shapes.AddShape(c, f);
257  }
258  ClusterShapes(kMinClusteredShapes, 1, kFontMergeDistance, &shapes);
259 
260  const CHAR_FRAGMENT *fragment = samples_.unicharset().get_fragment(c);
261 
262  if (fragment == nullptr)
263  char_shapes.AppendMasterShapes(shapes, nullptr);
264  else if (fragment->is_beginning())
265  char_shapes_begin_fragment.AppendMasterShapes(shapes, nullptr);
266  else if (fragment->is_ending())
267  char_shapes_end_fragment.AppendMasterShapes(shapes, nullptr);
268  else
269  char_shapes.AppendMasterShapes(shapes, nullptr);
270  }
272  kFontMergeDistance, &char_shapes_begin_fragment);
273  char_shapes.AppendMasterShapes(char_shapes_begin_fragment, nullptr);
275  kFontMergeDistance, &char_shapes_end_fragment);
276  char_shapes.AppendMasterShapes(char_shapes_end_fragment, nullptr);
278  kFontMergeDistance, &char_shapes);
279  master_shapes_.AppendMasterShapes(char_shapes, nullptr);
280  tprintf("Master shape_table:%s\n", master_shapes_.SummaryStr().c_str());
281 }

◆ ShapeDistance()

float tesseract::MasterTrainer::ShapeDistance ( const ShapeTable shapes,
int  s1,
int  s2 
)

Definition at line 809 of file mastertrainer.cpp.

809  {
810  const IntFeatureMap& feature_map = feature_map_;
811  const Shape& shape1 = shapes.GetShape(s1);
812  const Shape& shape2 = shapes.GetShape(s2);
813  int num_chars1 = shape1.size();
814  int num_chars2 = shape2.size();
815  float dist_sum = 0.0f;
816  int dist_count = 0;
817  if (num_chars1 > 1 || num_chars2 > 1) {
818  // In the multi-char case try to optimize the calculation by computing
819  // distances between characters of matching font where possible.
820  for (int c1 = 0; c1 < num_chars1; ++c1) {
821  for (int c2 = 0; c2 < num_chars2; ++c2) {
822  dist_sum += samples_.UnicharDistance(shape1[c1], shape2[c2],
823  true, feature_map);
824  ++dist_count;
825  }
826  }
827  } else {
828  // In the single unichar case, there is little alternative, but to compute
829  // the squared-order distance between pairs of fonts.
830  dist_sum = samples_.UnicharDistance(shape1[0], shape2[0],
831  false, feature_map);
832  ++dist_count;
833  }
834  return dist_sum / dist_count;
835 }

◆ TestClassifier()

double tesseract::MasterTrainer::TestClassifier ( CountTypes  error_mode,
int  report_level,
bool  replicate_samples,
TrainingSampleSet samples,
ShapeClassifier test_classifier,
STRING report_string 
)

Definition at line 782 of file mastertrainer.cpp.

787  {
788  SampleIterator sample_it;
789  sample_it.Init(nullptr, nullptr, replicate_samples, samples);
790  if (report_level > 0) {
791  int num_samples = 0;
792  for (sample_it.Begin(); !sample_it.AtEnd(); sample_it.Next())
793  ++num_samples;
794  tprintf("Iterator has charset size of %d/%d, %d shapes, %d samples\n",
795  sample_it.SparseCharsetSize(), sample_it.CompactCharsetSize(),
796  test_classifier->GetShapeTable()->NumShapes(), num_samples);
797  tprintf("Testing %sREPLICATED:\n", replicate_samples ? "" : "NON-");
798  }
799  double unichar_error = 0.0;
800  ErrorCounter::ComputeErrorRate(test_classifier, report_level,
801  error_mode, fontinfo_table_,
802  page_images_, &sample_it, &unichar_error,
803  nullptr, report_string);
804  return unichar_error;
805 }

◆ TestClassifierOnSamples()

void tesseract::MasterTrainer::TestClassifierOnSamples ( CountTypes  error_mode,
int  report_level,
bool  replicate_samples,
ShapeClassifier test_classifier,
STRING report_string 
)

Definition at line 760 of file mastertrainer.cpp.

764  {
765  TestClassifier(error_mode, report_level, replicate_samples, &samples_,
766  test_classifier, report_string);
767 }

◆ TestClassifierVOld()

void tesseract::MasterTrainer::TestClassifierVOld ( bool  replicate_samples,
ShapeClassifier test_classifier,
ShapeClassifier old_classifier 
)

Definition at line 748 of file mastertrainer.cpp.

750  {
751  SampleIterator sample_it;
752  sample_it.Init(nullptr, nullptr, replicate_samples, &samples_);
753  ErrorCounter::DebugNewErrors(test_classifier, old_classifier,
754  CT_UNICHAR_TOPN_ERR, fontinfo_table_,
755  page_images_, &sample_it);
756 }

◆ unicharset()

const UNICHARSET& tesseract::MasterTrainer::unicharset ( ) const
inline

Definition at line 186 of file mastertrainer.h.

186  {
187  return samples_.unicharset();
188  }

◆ WriteInttempAndPFFMTable()

void tesseract::MasterTrainer::WriteInttempAndPFFMTable ( const UNICHARSET unicharset,
const UNICHARSET shape_set,
const ShapeTable shape_table,
CLASS_STRUCT float_classes,
const char *  inttemp_file,
const char *  pffmtable_file 
)

Definition at line 566 of file mastertrainer.cpp.

571  {
572  auto *classify = new tesseract::Classify();
573  // Move the fontinfo table to classify.
574  fontinfo_table_.MoveTo(&classify->get_fontinfo_table());
575  INT_TEMPLATES int_templates = classify->CreateIntTemplates(float_classes,
576  shape_set);
577  FILE* fp = fopen(inttemp_file, "wb");
578  if (fp == nullptr) {
579  tprintf("Error, failed to open file \"%s\"\n", inttemp_file);
580  } else {
581  classify->WriteIntTemplates(fp, int_templates, shape_set);
582  fclose(fp);
583  }
584  // Now write pffmtable. This is complicated by the fact that the adaptive
585  // classifier still wants one indexed by unichar-id, but the static
586  // classifier needs one indexed by its shape class id.
587  // We put the shapetable_cutoffs in a GenericVector, and compute the
588  // unicharset cutoffs along the way.
589  GenericVector<uint16_t> shapetable_cutoffs;
590  GenericVector<uint16_t> unichar_cutoffs;
591  for (int c = 0; c < unicharset.size(); ++c)
592  unichar_cutoffs.push_back(0);
593  /* then write out each class */
594  for (int i = 0; i < int_templates->NumClasses; ++i) {
595  INT_CLASS Class = ClassForClassId(int_templates, i);
596  // Todo: Test with min instead of max
597  // int MaxLength = LengthForConfigId(Class, 0);
598  uint16_t max_length = 0;
599  for (int config_id = 0; config_id < Class->NumConfigs; config_id++) {
600  // Todo: Test with min instead of max
601  // if (LengthForConfigId (Class, config_id) < MaxLength)
602  uint16_t length = Class->ConfigLengths[config_id];
603  if (length > max_length)
604  max_length = Class->ConfigLengths[config_id];
605  int shape_id = float_classes[i].font_set.get(config_id);
606  const Shape& shape = shape_table.GetShape(shape_id);
607  for (int c = 0; c < shape.size(); ++c) {
608  int unichar_id = shape[c].unichar_id;
609  if (length > unichar_cutoffs[unichar_id])
610  unichar_cutoffs[unichar_id] = length;
611  }
612  }
613  shapetable_cutoffs.push_back(max_length);
614  }
615  fp = fopen(pffmtable_file, "wb");
616  if (fp == nullptr) {
617  tprintf("Error, failed to open file \"%s\"\n", pffmtable_file);
618  } else {
619  shapetable_cutoffs.Serialize(fp);
620  for (int c = 0; c < unicharset.size(); ++c) {
621  const char *unichar = unicharset.id_to_unichar(c);
622  if (strcmp(unichar, " ") == 0) {
623  unichar = "NULL";
624  }
625  fprintf(fp, "%s %d\n", unichar, unichar_cutoffs[c]);
626  }
627  fclose(fp);
628  }
629  free_int_templates(int_templates);
630  delete classify;
631 }

The documentation for this class was generated from the following files:
UNICHARSET::load_from_file
bool load_from_file(const char *const filename, bool skip_fragments)
Definition: unicharset.h:378
INT_TEMPLATES_STRUCT
Definition: intproto.h:117
MFCount
Definition: mf.h:43
INT_CLASS_STRUCT::ConfigLengths
uint16_t ConfigLengths[MAX_NUM_CONFIGS]
Definition: intproto.h:110
ScrollView
Definition: scrollview.h:97
tesseract::ShapeTable::Serialize
bool Serialize(FILE *fp) const
Definition: shapetable.cpp:241
tesseract::TrainingSampleSet::extract_sample
TrainingSample * extract_sample(int index)
Definition: trainingsampleset.h:165
SVET_DESTROY
Definition: scrollview.h:45
SVEventType
SVEventType
Definition: scrollview.h:44
tesseract::TrainingSampleSet::ClusterDistance
float ClusterDistance(int font_id1, int class_id1, int font_id2, int class_id2, const IntFeatureMap &feature_map)
Definition: trainingsampleset.cpp:296
UNICHARSET::AppendOtherUnicharset
void AppendOtherUnicharset(const UNICHARSET &src)
Definition: unicharset.cpp:463
SVET_CLICK
Definition: scrollview.h:47
kGeoFeatureType
const char *const kGeoFeatureType
Definition: featdefs.cpp:34
kBlnXHeight
const int kBlnXHeight
Definition: normalis.h:23
tfscanf
int tfscanf(FILE *stream, const char *format,...)
Definition: scanutils.cpp:181
tesseract::ErrorCounter::DebugNewErrors
static void DebugNewErrors(ShapeClassifier *new_classifier, ShapeClassifier *old_classifier, CountTypes boosting_mode, const FontInfoTable &fontinfo_table, const GenericVector< Pix * > &page_images, SampleIterator *it)
Definition: errorcounter.cpp:106
tesseract::NM_BASELINE
Definition: normalis.h:42
ShortNameToFeatureType
uint32_t ShortNameToFeatureType(const FEATURE_DEFS_STRUCT &FeatureDefs, const char *ShortName)
Definition: featdefs.cpp:269
ASSERT_HOST
#define ASSERT_HOST(x)
Definition: errcode.h:87
INT_CLASS_STRUCT
Definition: intproto.h:104
baseline
Definition: mfoutline.h:62
tesseract::MasterTrainer::AddSample
void AddSample(bool verification, const char *unichar_str, TrainingSample *sample)
Definition: mastertrainer.cpp:162
tesseract::ShapeTable::AppendMasterShapes
void AppendMasterShapes(const ShapeTable &other, GenericVector< int > *shape_map)
Definition: shapetable.cpp:656
tesseract::TrainingSampleSet::mutable_sample
TrainingSample * mutable_sample(int index)
Definition: trainingsampleset.h:161
tesseract::ShapeTable::NumShapes
int NumShapes() const
Definition: shapetable.h:274
tesseract::TrainingSampleSet::LoadUnicharset
void LoadUnicharset(const char *filename)
Definition: trainingsampleset.cpp:113
tesseract::IntFeatureMap::Init
void Init(const IntFeatureSpace &feature_space)
Definition: intfeaturemap.cpp:73
tesseract::TrainingSampleSet::NumClassSamples
int NumClassSamples(int font_id, int class_id, bool randomize) const
Definition: trainingsampleset.cpp:156
STRING
Definition: strngs.h:45
tesseract::Classify
Definition: classify.h:103
ScrollView::Clear
void Clear()
Definition: scrollview.cpp:588
tesseract::Shape::AddShape
void AddShape(const Shape &other)
Definition: shapetable.cpp:120
GenericVector::contains
bool contains(const T &object) const
Definition: genericvector.h:793
GenericVector::Serialize
bool Serialize(FILE *fp) const
Definition: genericvector.h:929
tesseract::FontInfoTable::Serialize
bool Serialize(FILE *fp) const
Definition: fontinfo.cpp:49
tesseract::kMinClusteredShapes
const int kMinClusteredShapes
Definition: mastertrainer.cpp:44
tesseract::IntFeatureSpace::Size
int Size() const
Definition: intfeaturespace.h:51
tesseract::TrainingSampleSet::Serialize
bool Serialize(FILE *fp) const
Definition: trainingsampleset.cpp:80
tesseract::CT_UNICHAR_TOPN_ERR
Definition: errorcounter.h:76
CHAR_FRAGMENT::is_natural
bool is_natural() const
Definition: unicharset.h:113
UNICHARSET::clear
void clear()
Definition: unicharset.h:306
kIntFeatureType
const char *const kIntFeatureType
Definition: featdefs.cpp:33
UNICHARSET::save_to_file
bool save_to_file(const char *const filename) const
Definition: unicharset.h:350
tesseract::TrainingSampleSet::DeleteDeadSamples
void DeleteDeadSamples()
Definition: trainingsampleset.cpp:497
tesseract::TrainingSampleSet::num_samples
int num_samples() const
Definition: trainingsampleset.h:55
SVEvent::y
int y
Definition: scrollview.h:67
tesseract::TrainingSampleSet::GetCloudFeatures
const BitVector & GetCloudFeatures(int font_id, int class_id) const
Definition: trainingsampleset.cpp:211
FEATURE_DEFS_STRUCT::FeatureDesc
const FEATURE_DESC_STRUCT * FeatureDesc[NUM_FEATURE_TYPES]
Definition: featdefs.h:46
tesseract::MasterTrainer::TestClassifier
double TestClassifier(CountTypes error_mode, int report_level, bool replicate_samples, TrainingSampleSet *samples, ShapeClassifier *test_classifier, STRING *report_string)
Definition: mastertrainer.cpp:782
CHAR_FRAGMENT::parse_from_string
static CHAR_FRAGMENT * parse_from_string(const char *str)
Definition: unicharset.cpp:1057
GenericVector::push_back
int push_back(T object)
Definition: genericvector.h:799
ParseBoxFileStr
bool ParseBoxFileStr(const char *boxfile_str, int *page_number, STRING *utf8_str, TBOX *bounding_box)
Definition: boxread.cpp:181
tesseract::MasterTrainer::GetFontInfoId
int GetFontInfoId(const char *font_name)
Definition: mastertrainer.cpp:467
tesseract::TrainingSampleSet::ComputeCanonicalFeatures
void ComputeCanonicalFeatures()
Definition: trainingsampleset.cpp:694
STRING::c_str
const char * c_str() const
Definition: strngs.cpp:192
tesseract::TrainingSampleSet::UnicharDistance
float UnicharDistance(const UnicharAndFonts &uf1, const UnicharAndFonts &uf2, bool matched_fonts, const IntFeatureMap &feature_map)
Definition: trainingsampleset.cpp:230
tesseract::MasterTrainer::unicharset
const UNICHARSET & unicharset() const
Definition: mastertrainer.h:186
UNICHARSET::unichar_to_id
UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:209
tesseract::MasterTrainer::GetBestMatchingFontInfoId
int GetBestMatchingFontInfoId(const char *filename)
Definition: mastertrainer.cpp:478
tesseract::FontInfoTable::MoveTo
void MoveTo(UnicityTable< FontInfo > *target)
Definition: fontinfo.cpp:107
UNICHARSET
Definition: unicharset.h:145
CHAR_FRAGMENT::is_ending
bool is_ending() const
Definition: unicharset.h:108
INT_TEMPLATES_STRUCT::NumClasses
int NumClasses
Definition: intproto.h:118
FEATURE_DESC_STRUCT::NumParams
uint16_t NumParams
Definition: ocrfeatures.h:52
CLASS_STRUCT::font_set
UnicityTableEqEq< int > font_set
Definition: protos.h:59
tesseract::ShapeTable::GetShape
const Shape & GetShape(int shape_id) const
Definition: shapetable.h:319
feature_defs
FEATURE_DEFS_STRUCT feature_defs
Definition: commontraining.cpp:89
CreateFeatureSpaceWindow
ScrollView * CreateFeatureSpaceWindow(const char *name, int xpos, int ypos)
Definition: intproto.cpp:1764
MakeClusterer
CLUSTERER * MakeClusterer(int16_t SampleSize, const PARAM_DESC ParamDesc[])
Definition: cluster.cpp:376
GenericVector::get_index
int get_index(const T &object) const
Definition: genericvector.h:781
UnicityTable::get
const T & get(int id) const
Return the object from an id.
Definition: unicity_table.h:140
character
Definition: mfoutline.h:62
tesseract::TrainingSampleSet::OrganizeByFontAndClass
void OrganizeByFontAndClass()
Definition: trainingsampleset.cpp:511
DivRounded
int DivRounded(int a, int b)
Definition: helpers.h:165
FEATURE_DESC_STRUCT::ParamDesc
const PARAM_DESC * ParamDesc
Definition: ocrfeatures.h:54
tesseract::ErrorCounter::ComputeErrorRate
static double ComputeErrorRate(ShapeClassifier *classifier, int report_level, CountTypes boosting_mode, const FontInfoTable &fontinfo_table, const GenericVector< Pix * > &page_images, SampleIterator *it, double *unichar_error, double *scaled_error, STRING *fonts_report)
Definition: errorcounter.cpp:39
kMicroFeatureType
const char *const kMicroFeatureType
Definition: featdefs.cpp:31
SVEvent::type
SVEventType type
Definition: scrollview.h:63
ScrollView::RED
Definition: scrollview.h:104
unicharset_
UNICHARSET unicharset_
Definition: unicharcompress_test.cc:167
tesseract::TrainingSampleSet::ComputeCloudFeatures
void ComputeCloudFeatures(int feature_space_size)
Definition: trainingsampleset.cpp:712
sample
Definition: cluster.h:31
GenericVector< int >
tesseract::IntFeatureMap::feature_space
const IntFeatureSpace & feature_space() const
Definition: intfeaturemap.h:60
SVET_ANY
Definition: scrollview.h:55
CHAR_DESC_STRUCT
Definition: featdefs.h:38
CHAR_FRAGMENT
Definition: unicharset.h:48
tesseract::kMaxUnicharsPerCluster
const int kMaxUnicharsPerCluster
Definition: mastertrainer.cpp:46
ScrollView::AwaitEvent
SVEvent * AwaitEvent(SVEventType type)
Definition: scrollview.cpp:443
UNICHAR_LEN
#define UNICHAR_LEN
Definition: unichar.h:32
tesseract::TrainingSampleSet::AddSample
int AddSample(const char *unichar, TrainingSample *sample)
Definition: trainingsampleset.cpp:129
tesseract::kFontMergeDistance
const float kFontMergeDistance
Definition: mastertrainer.cpp:48
INT_FEATURE_STRUCT
Definition: intproto.h:131
CLUSTERER
Definition: cluster.h:81
GenericVector::get
T & get(int index) const
Definition: genericvector.h:716
SVEvent
Definition: scrollview.h:60
UNICHARSET::contains_unichar
bool contains_unichar(const char *const unichar_repr) const
Definition: unicharset.cpp:670
ScrollView::GREEN
Definition: scrollview.h:106
tesseract::TrainingSampleSet::NumFonts
int NumFonts() const
Definition: trainingsampleset.h:61
kCNFeatureType
const char *const kCNFeatureType
Definition: featdefs.cpp:32
GenericVector::init_to_size
void init_to_size(int size, const T &t)
Definition: genericvector.h:706
tesseract::ShapeTable::FindShape
int FindShape(int unichar_id, int font_id) const
Definition: shapetable.cpp:386
tprintf
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:34
tesseract::TrainingSampleSet::charsetsize
int charsetsize() const
Definition: trainingsampleset.h:67
UNICHARSET::get_fragment
const CHAR_FRAGMENT * get_fragment(UNICHAR_ID unichar_id) const
Definition: unicharset.h:724
SVEvent::x
int x
Definition: scrollview.h:66
tesseract::ShapeTable::SummaryStr
STRING SummaryStr() const
Definition: shapetable.cpp:313
free_int_templates
void free_int_templates(INT_TEMPLATES templates)
Definition: intproto.cpp:697
ScrollView::Update
static void Update()
Definition: scrollview.cpp:708
tesseract::ShapeTable::AddShape
int AddShape(int unichar_id, int font_id)
Definition: shapetable.cpp:336
tesseract::TrainingSampleSet::IndexFeatures
void IndexFeatures(const IntFeatureSpace &feature_space)
Definition: trainingsampleset.cpp:485
UNICHARSET::id_to_unichar
const char * id_to_unichar(UNICHAR_ID id) const
Definition: unicharset.cpp:290
CHAR_FRAGMENT::is_beginning
bool is_beginning() const
Definition: unicharset.h:105
tesseract::TrainingSampleSet::DisplaySamplesWithFeature
void DisplaySamplesWithFeature(int f_index, const Shape &shape, const IntFeatureSpace &feature_space, ScrollView::Color color, ScrollView *window) const
Definition: trainingsampleset.cpp:743
INT_CLASS_STRUCT::NumConfigs
uint8_t NumConfigs
Definition: intproto.h:107
tesseract::IntFeatureSpace::Serialize
bool Serialize(FILE *fp) const
Definition: intfeaturespace.cpp:38
tesseract::TrainingSampleSet::ReplicateAndRandomizeSamples
void ReplicateAndRandomizeSamples()
Definition: trainingsampleset.cpp:665
GenericVector::size
int size() const
Definition: genericvector.h:71
tesseract::Serialize
bool Serialize(FILE *fp, const char *data, size_t n=1)
Definition: serialis.cpp:73
ClassForClassId
#define ClassForClassId(T, c)
Definition: intproto.h:177
tesseract::TrainingSampleSet::unicharset
const UNICHARSET & unicharset() const
Definition: trainingsampleset.h:64
tesseract::ClearFeatureSpaceWindow
void ClearFeatureSpaceWindow(NORM_METHOD norm_method, ScrollView *window)
Definition: intproto.cpp:987
MakeSample
SAMPLE * MakeSample(CLUSTERER *Clusterer, const float *Feature, int32_t CharID)
Definition: cluster.cpp:429
ReadCharDescription
CHAR_DESC ReadCharDescription(const FEATURE_DEFS_STRUCT &FeatureDefs, FILE *File)
Definition: featdefs.cpp:235
UNICHARSET::size
int size() const
Definition: unicharset.h:341
RenderIntFeature
void RenderIntFeature(ScrollView *window, const INT_FEATURE_STRUCT *Feature, ScrollView::Color color)
Definition: intproto.cpp:1603
FreeCharDescription
void FreeCharDescription(CHAR_DESC CharDesc)
Definition: featdefs.cpp:128
TBOX
Definition: rect.h:33
tesseract::TrainingSampleSet::GetCanonicalSample
const TrainingSample * GetCanonicalSample(int font_id, int class_id) const
Definition: trainingsampleset.cpp:462
tesseract::TrainingSampleSet::ComputeCanonicalSamples
void ComputeCanonicalSamples(const IntFeatureMap &map, bool debug)
Definition: trainingsampleset.cpp:568