#include <sampleiterator.h>
Definition at line 91 of file sampleiterator.h.
◆ SampleIterator()
tesseract::SampleIterator::SampleIterator |
( |
| ) |
|
Definition at line 29 of file sampleiterator.cpp.
30 : charset_map_(
nullptr)
31 , shape_table_(
nullptr)
32 , sample_set_(
nullptr)
34 , owned_shape_table_(
nullptr) {
◆ ~SampleIterator()
tesseract::SampleIterator::~SampleIterator |
( |
| ) |
|
◆ AtEnd()
bool tesseract::SampleIterator::AtEnd |
( |
| ) |
const |
◆ Begin()
void tesseract::SampleIterator::Begin |
( |
| ) |
|
Definition at line 86 of file sampleiterator.cpp.
88 shape_char_index_ = 0;
90 shape_font_index_ = 0;
◆ charset_map()
const IndexMapBiDi& tesseract::SampleIterator::charset_map |
( |
| ) |
const |
|
inline |
◆ Clear()
void tesseract::SampleIterator::Clear |
( |
| ) |
|
Definition at line 43 of file sampleiterator.cpp.
44 delete owned_shape_table_;
45 owned_shape_table_ =
nullptr;
◆ CompactCharsetSize()
int tesseract::SampleIterator::CompactCharsetSize |
( |
| ) |
const |
◆ GetCompactClassID()
int tesseract::SampleIterator::GetCompactClassID |
( |
| ) |
const |
Definition at line 141 of file sampleiterator.cpp.
int SparseToCompact(int sparse_index) const override
int GetSparseClassID() const
◆ GetSample()
Definition at line 102 of file sampleiterator.cpp.
103 if (shape_table_ !=
nullptr) {
104 const UnicharAndFonts *shape_entry = GetShapeEntry();
105 int char_id = shape_entry->unichar_id;
106 int font_id = shape_entry->font_ids[shape_font_index_];
107 return *sample_set_->
GetSample(font_id, char_id, sample_index_);
109 return *sample_set_->
GetSample(shape_index_);
const TrainingSample * GetSample(int index) const
◆ GetSparseClassID()
int tesseract::SampleIterator::GetSparseClassID |
( |
| ) |
const |
Definition at line 148 of file sampleiterator.cpp.
UNICHAR_ID class_id() const
const TrainingSample & GetSample() const
◆ GlobalSampleIndex()
int tesseract::SampleIterator::GlobalSampleIndex |
( |
| ) |
const |
Definition at line 126 of file sampleiterator.cpp.
127 if (shape_table_ !=
nullptr) {
128 const UnicharAndFonts *shape_entry = GetShapeEntry();
129 int char_id = shape_entry->unichar_id;
130 int font_id = shape_entry->font_ids[shape_font_index_];
int GlobalSampleIndex(int font_id, int class_id, int index) const
◆ Init()
Definition at line 49 of file sampleiterator.cpp.
55 randomize_ = randomize;
56 if (shape_table_ ==
nullptr && charset_map_ !=
nullptr) {
59 int num_fonts = sample_set_->
NumFonts();
60 owned_shape_table_ =
new ShapeTable(sample_set_->
unicharset());
62 for (
int c = 0; c < charsetsize; ++c) {
65 int shape_id = owned_shape_table_->
AddShape(c, 0);
66 for (
int f = 1; f < num_fonts; ++f) {
68 owned_shape_table_->
AddToShape(shape_id, c, f);
72 shape_table_ = owned_shape_table_;
74 if (shape_table_ !=
nullptr) {
void AddToShape(unsigned shape_id, int unichar_id, int font_id)
unsigned AddShape(int unichar_id, int font_id)
unsigned NumShapes() const
const TrainingSampleSet * sample_set() const
const IndexMapBiDi & charset_map() const
const ShapeTable * shape_table() const
int NumClassSamples(int font_id, int class_id, bool randomize) const
const UNICHARSET & unicharset() const
int num_raw_samples() const
◆ MapSampleFeatures()
void tesseract::SampleIterator::MapSampleFeatures |
( |
const IntFeatureMap & |
feature_map | ) |
|
Definition at line 219 of file sampleiterator.cpp.
222 MapFeatures(*sample, feature_map);
TrainingSample * MutableSample() const
◆ MutableSample()
Definition at line 113 of file sampleiterator.cpp.
114 if (shape_table_ !=
nullptr) {
115 const UnicharAndFonts *shape_entry = GetShapeEntry();
116 int char_id = shape_entry->unichar_id;
117 int font_id = shape_entry->font_ids[shape_font_index_];
118 return sample_set_->
MutableSample(font_id, char_id, sample_index_);
TrainingSample * mutable_sample(int index)
TrainingSample * MutableSample(int font_id, int class_id, int index)
◆ Next()
void tesseract::SampleIterator::Next |
( |
| ) |
|
Definition at line 154 of file sampleiterator.cpp.
155 if (shape_table_ !=
nullptr) {
158 if (sample_index_ < num_samples_) {
165 if (shape_font_index_ >= num_shape_fonts_) {
167 shape_font_index_ = 0;
169 if (shape_char_index_ >= num_shape_chars_) {
171 shape_char_index_ = 0;
174 }
while (shape_index_ < num_shapes_ && charset_map_ !=
nullptr &&
176 if (shape_index_ >= num_shapes_) {
179 num_shape_chars_ = shape_table_->
GetShape(shape_index_).
size();
182 const UnicharAndFonts *shape_entry = GetShapeEntry();
183 num_shape_fonts_ = shape_entry->font_ids.size();
184 int char_id = shape_entry->unichar_id;
185 int font_id = shape_entry->font_ids[shape_font_index_];
186 num_samples_ = sample_set_->
NumClassSamples(font_id, char_id, randomize_);
187 }
while (num_samples_ == 0);
const Shape & GetShape(unsigned shape_id) const
◆ NormalizeSamples()
double tesseract::SampleIterator::NormalizeSamples |
( |
| ) |
|
Definition at line 241 of file sampleiterator.cpp.
242 double total_weight = 0.0;
243 int sample_count = 0;
245 const TrainingSample &sample =
GetSample();
246 total_weight += sample.weight();
250 double min_assigned_sample_weight = 1.0;
251 if (total_weight > 0.0) {
254 double weight = sample->weight() / total_weight;
255 if (weight < min_assigned_sample_weight) {
256 min_assigned_sample_weight = weight;
258 sample->set_weight(weight);
261 return min_assigned_sample_weight;
◆ sample_set()
◆ shape_table()
const ShapeTable* tesseract::SampleIterator::shape_table |
( |
| ) |
const |
|
inline |
◆ SparseCharsetSize()
int tesseract::SampleIterator::SparseCharsetSize |
( |
| ) |
const |
Definition at line 200 of file sampleiterator.cpp.
201 return charset_map_ !=
nullptr
int SparseSize() const override
◆ UniformSamples()
int tesseract::SampleIterator::UniformSamples |
( |
| ) |
|
Definition at line 228 of file sampleiterator.cpp.
229 int num_good_samples = 0;
232 sample->set_weight(1.0);
236 return num_good_samples;
double NormalizeSamples()
The documentation for this class was generated from the following files: