Constructs the font_id_map_ which maps real font_ids (sparse) to a compact index for the font_class_array_.
| 638 | // Constructs the font_id_map_ which maps real font_ids (sparse) to a compact |
| 639 | // index for the font_class_array_. |
| 640 | void TrainingSampleSet::SetupFontIdMap() { |
| 641 | // Number of samples for each font_id. |
| 642 | GenericVector<int> font_counts; |
| 643 | for (int s = 0; s < samples_.size(); ++s) { |
| 644 | int font_id = samples_[s]->font_id(); |
| 645 | while (font_id >= font_counts.size()) |
| 646 | font_counts.push_back(0); |
| 647 | ++font_counts[font_id]; |
| 648 | } |
| 649 | font_id_map_.Init(font_counts.size(), false); |
| 650 | for (int f = 0; f < font_counts.size(); ++f) { |
| 651 | font_id_map_.SetMap(f, font_counts[f] > 0); |
| 652 | } |
| 653 | font_id_map_.Setup(); |
| 654 | } |
| 655 | |
| 656 | |
| 657 | // Finds the sample for each font, class pair that has least maximum |