#include <sampleiterator.h>
Definition at line 92 of file sampleiterator.h.
◆ SampleIterator()
tesseract::SampleIterator::SampleIterator |
( |
| ) |
|
Definition at line 27 of file sampleiterator.cpp.
28 : charset_map_(
nullptr),
29 shape_table_(
nullptr),
32 owned_shape_table_(
nullptr) {
◆ ~SampleIterator()
tesseract::SampleIterator::~SampleIterator |
( |
| ) |
|
◆ AtEnd()
bool tesseract::SampleIterator::AtEnd |
( |
| ) |
const |
◆ Begin()
void tesseract::SampleIterator::Begin |
( |
| ) |
|
Definition at line 87 of file sampleiterator.cpp.
89 shape_char_index_ = 0;
91 shape_font_index_ = 0;
◆ charset_map()
const IndexMapBiDi& tesseract::SampleIterator::charset_map |
( |
| ) |
const |
|
inline |
◆ Clear()
void tesseract::SampleIterator::Clear |
( |
| ) |
|
Definition at line 41 of file sampleiterator.cpp.
42 delete owned_shape_table_;
43 owned_shape_table_ =
nullptr;
◆ CompactCharsetSize()
int tesseract::SampleIterator::CompactCharsetSize |
( |
| ) |
const |
◆ GetCompactClassID()
int tesseract::SampleIterator::GetCompactClassID |
( |
| ) |
const |
Definition at line 142 of file sampleiterator.cpp.
143 return charset_map_ !=
nullptr ? charset_map_->
SparseToCompact(shape_index_)
int GetSparseClassID() const
virtual int SparseToCompact(int sparse_index) const
◆ GetSample()
Definition at line 103 of file sampleiterator.cpp.
104 if (shape_table_ !=
nullptr) {
105 const UnicharAndFonts* shape_entry = GetShapeEntry();
106 int char_id = shape_entry->unichar_id;
107 int font_id = shape_entry->font_ids[shape_font_index_];
108 return *sample_set_->
GetSample(font_id, char_id, sample_index_);
110 return *sample_set_->
GetSample(shape_index_);
const TrainingSample * GetSample(int index) const
◆ GetSparseClassID()
int tesseract::SampleIterator::GetSparseClassID |
( |
| ) |
const |
Definition at line 150 of file sampleiterator.cpp.
const TrainingSample & GetSample() const
UNICHAR_ID class_id() const
◆ GlobalSampleIndex()
int tesseract::SampleIterator::GlobalSampleIndex |
( |
| ) |
const |
Definition at line 127 of file sampleiterator.cpp.
128 if (shape_table_ !=
nullptr) {
129 const UnicharAndFonts* shape_entry = GetShapeEntry();
130 int char_id = shape_entry->unichar_id;
131 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 47 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) {
77 num_shapes_ = randomize ? sample_set_->
num_samples()
const TrainingSampleSet * sample_set() const
int num_raw_samples() const
int NumClassSamples(int font_id, int class_id, bool randomize) const
void AddToShape(int shape_id, int unichar_id, int font_id)
const UNICHARSET & unicharset() const
const ShapeTable * shape_table() const
int AddShape(int unichar_id, int font_id)
const IndexMapBiDi & charset_map() const
◆ MapSampleFeatures()
void tesseract::SampleIterator::MapSampleFeatures |
( |
const IntFeatureMap & |
feature_map | ) |
|
◆ MutableSample()
Definition at line 114 of file sampleiterator.cpp.
115 if (shape_table_ !=
nullptr) {
116 const UnicharAndFonts* shape_entry = GetShapeEntry();
117 int char_id = shape_entry->unichar_id;
118 int font_id = shape_entry->font_ids[shape_font_index_];
119 return sample_set_->
MutableSample(font_id, char_id, sample_index_);
TrainingSample * MutableSample(int font_id, int class_id, int index)
TrainingSample * mutable_sample(int index)
◆ Next()
void tesseract::SampleIterator::Next |
( |
| ) |
|
Definition at line 156 of file sampleiterator.cpp.
157 if (shape_table_ !=
nullptr) {
160 if (sample_index_ < num_samples_)
166 if (shape_font_index_ >= num_shape_fonts_) {
168 shape_font_index_ = 0;
170 if (shape_char_index_ >= num_shape_chars_) {
172 shape_char_index_ = 0;
175 }
while (shape_index_ < num_shapes_ &&
176 charset_map_ !=
nullptr &&
178 if (shape_index_ >= num_shapes_)
180 num_shape_chars_ = shape_table_->
GetShape(shape_index_).
size();
183 const UnicharAndFonts* shape_entry = GetShapeEntry();
184 num_shape_fonts_ = shape_entry->font_ids.size();
185 int char_id = shape_entry->unichar_id;
186 int font_id = shape_entry->font_ids[shape_font_index_];
187 num_samples_ = sample_set_->
NumClassSamples(font_id, char_id, randomize_);
188 }
while (num_samples_ == 0);
int NumClassSamples(int font_id, int class_id, bool randomize) const
const Shape & GetShape(int shape_id) const
virtual int SparseToCompact(int sparse_index) const
◆ NormalizeSamples()
double tesseract::SampleIterator::NormalizeSamples |
( |
| ) |
|
Definition at line 233 of file sampleiterator.cpp.
234 double total_weight = 0.0;
235 int sample_count = 0;
238 total_weight +=
sample.weight();
242 double min_assigned_sample_weight = 1.0;
243 if (total_weight > 0.0) {
246 double weight =
sample->weight() / total_weight;
247 if (weight < min_assigned_sample_weight)
248 min_assigned_sample_weight = weight;
249 sample->set_weight(weight);
252 return min_assigned_sample_weight;
TrainingSample * MutableSample() const
const TrainingSample & GetSample() const
◆ sample_set()
◆ shape_table()
const ShapeTable* tesseract::SampleIterator::shape_table |
( |
| ) |
const |
|
inline |
◆ SparseCharsetSize()
int tesseract::SampleIterator::SparseCharsetSize |
( |
| ) |
const |
Definition at line 202 of file sampleiterator.cpp.
203 return charset_map_ !=
nullptr 205 : (shape_table_ !=
nullptr ? shape_table_->
NumShapes()
virtual int SparseSize() const
◆ UniformSamples()
int tesseract::SampleIterator::UniformSamples |
( |
| ) |
|
Definition at line 220 of file sampleiterator.cpp.
221 int num_good_samples = 0;
228 return num_good_samples;
double NormalizeSamples()
TrainingSample * MutableSample() const
The documentation for this class was generated from the following files: