#include <trainingsample.h>
Definition at line 53 of file trainingsample.h.
◆ TrainingSample()
tesseract::TrainingSample::TrainingSample |
( |
| ) |
|
|
inline |
Definition at line 55 of file trainingsample.h.
56 : class_id_(INVALID_UNICHAR_ID), font_id_(0), page_num_(0),
57 num_features_(0), num_micro_features_(0), outline_length_(0),
58 features_(
nullptr), micro_features_(
nullptr), weight_(1.0),
59 max_dist_(0.0), sample_index_(0),
60 features_are_indexed_(
false), features_are_mapped_(
false),
◆ ~TrainingSample()
tesseract::TrainingSample::~TrainingSample |
( |
| ) |
|
◆ bounding_box()
const TBOX& tesseract::TrainingSample::bounding_box |
( |
| ) |
const |
|
inline |
◆ class_id()
UNICHAR_ID tesseract::TrainingSample::class_id |
( |
| ) |
const |
|
inline |
◆ cn_feature()
float tesseract::TrainingSample::cn_feature |
( |
int |
index | ) |
const |
|
inline |
◆ Copy()
Definition at line 182 of file trainingsample.cpp.
184 sample->class_id_ = class_id_;
185 sample->font_id_ = font_id_;
186 sample->weight_ = weight_;
187 sample->sample_index_ = sample_index_;
188 sample->num_features_ = num_features_;
189 if (num_features_ > 0) {
191 memcpy(
sample->features_, features_, num_features_ *
sizeof(features_[0]));
193 sample->num_micro_features_ = num_micro_features_;
194 if (num_micro_features_ > 0) {
196 memcpy(
sample->micro_features_, micro_features_,
197 num_micro_features_ *
sizeof(micro_features_[0]));
199 memcpy(
sample->cn_feature_, cn_feature_,
sizeof(*cn_feature_) * kNumCNParams);
200 memcpy(
sample->geo_feature_, geo_feature_,
sizeof(*geo_feature_) *
GeoCount);
◆ CopyFromFeatures()
◆ DeSerialize()
bool tesseract::TrainingSample::DeSerialize |
( |
bool |
swap, |
|
|
FILE * |
fp |
|
) |
| |
Definition at line 88 of file trainingsample.cpp.
89 if (fread(&class_id_,
sizeof(class_id_), 1, fp) != 1)
return false;
90 if (fread(&font_id_,
sizeof(font_id_), 1, fp) != 1)
return false;
91 if (fread(&page_num_,
sizeof(page_num_), 1, fp) != 1)
return false;
92 if (!bounding_box_.
DeSerialize(swap, fp))
return false;
93 if (fread(&num_features_,
sizeof(num_features_), 1, fp) != 1)
return false;
94 if (fread(&num_micro_features_,
sizeof(num_micro_features_), 1, fp) != 1)
96 if (fread(&outline_length_,
sizeof(outline_length_), 1, fp) != 1)
99 ReverseN(&class_id_,
sizeof(class_id_));
100 ReverseN(&num_features_,
sizeof(num_features_));
101 ReverseN(&num_micro_features_,
sizeof(num_micro_features_));
102 ReverseN(&outline_length_,
sizeof(outline_length_));
105 if (num_features_ > UINT16_MAX)
return false;
106 if (num_micro_features_ > UINT16_MAX)
return false;
109 if (fread(features_,
sizeof(*features_), num_features_, fp)
112 delete [] micro_features_;
113 micro_features_ =
new MicroFeature[num_micro_features_];
114 if (fread(micro_features_,
sizeof(*micro_features_), num_micro_features_,
115 fp) != num_micro_features_)
117 if (fread(cn_feature_,
sizeof(*cn_feature_), kNumCNParams, fp) !=
118 kNumCNParams)
return false;
◆ DeSerializeCreate()
TrainingSample * tesseract::TrainingSample::DeSerializeCreate |
( |
bool |
swap, |
|
|
FILE * |
fp |
|
) |
| |
|
static |
◆ DisplayFeatures()
Definition at line 316 of file trainingsample.cpp.
318 #ifndef GRAPHICS_DISABLED
319 for (uint32_t f = 0; f < num_features_; ++f) {
322 #endif // GRAPHICS_DISABLED
◆ ExtractCharDesc()
void tesseract::TrainingSample::ExtractCharDesc |
( |
int |
feature_type, |
|
|
int |
micro_type, |
|
|
int |
cn_type, |
|
|
int |
geo_type, |
|
|
CHAR_DESC_STRUCT * |
char_desc |
|
) |
| |
Definition at line 205 of file trainingsample.cpp.
213 if (char_features ==
nullptr) {
214 tprintf(
"Error: no features to train on of type %s\n",
221 for (uint32_t f = 0; f < num_features_; ++f) {
232 delete[] micro_features_;
233 char_features = char_desc->
FeatureSets[micro_type];
234 if (char_features ==
nullptr) {
235 tprintf(
"Error: no features to train on of type %s\n",
237 num_micro_features_ = 0;
238 micro_features_ =
nullptr;
241 micro_features_ =
new MicroFeature[num_micro_features_];
242 for (uint32_t f = 0; f < num_micro_features_; ++f) {
243 for (
int d = 0; d <
MFCount; ++d) {
250 if (char_features ==
nullptr) {
251 tprintf(
"Error: no CN feature to train on.\n");
262 if (char_features ==
nullptr) {
263 tprintf(
"Error: no Geo feature to train on.\n");
270 features_are_indexed_ =
false;
271 features_are_mapped_ =
false;
◆ features()
◆ features_are_mapped()
bool tesseract::TrainingSample::features_are_mapped |
( |
| ) |
const |
|
inline |
◆ font_id()
int tesseract::TrainingSample::font_id |
( |
| ) |
const |
|
inline |
◆ geo_feature()
int tesseract::TrainingSample::geo_feature |
( |
int |
index | ) |
const |
|
inline |
◆ GetCNFeature()
◆ GetSamplePix()
Pix * tesseract::TrainingSample::GetSamplePix |
( |
int |
padding, |
|
|
Pix * |
page_pix |
|
) |
| const |
Definition at line 329 of file trainingsample.cpp.
330 if (page_pix ==
nullptr)
332 int page_width = pixGetWidth(page_pix);
333 int page_height = pixGetHeight(page_pix);
335 padded_box.
pad(padding, padding);
337 TBOX page_box(0, 0, page_width, page_height);
338 padded_box &= page_box;
339 Box* box = boxCreate(page_box.left(), page_height - page_box.top(),
340 page_box.width(), page_box.height());
341 Pix* sample_pix = pixClipRectangle(page_pix, box,
nullptr);
◆ indexed_features()
const GenericVector<int>& tesseract::TrainingSample::indexed_features |
( |
| ) |
const |
|
inline |
◆ IndexFeatures()
void tesseract::TrainingSample::IndexFeatures |
( |
const IntFeatureSpace & |
feature_space | ) |
|
Definition at line 276 of file trainingsample.cpp.
278 feature_space.IndexAndSortFeatures(features_, num_features_,
280 features_are_indexed_ =
true;
281 features_are_mapped_ =
false;
◆ is_error()
bool tesseract::TrainingSample::is_error |
( |
| ) |
const |
|
inline |
◆ MapFeatures()
void tesseract::TrainingSample::MapFeatures |
( |
const IntFeatureMap & |
feature_map | ) |
|
Definition at line 286 of file trainingsample.cpp.
288 feature_map.feature_space().IndexAndSortFeatures(features_, num_features_,
291 features_are_indexed_ =
false;
292 features_are_mapped_ =
true;
◆ mapped_features()
const GenericVector<int>& tesseract::TrainingSample::mapped_features |
( |
| ) |
const |
|
inline |
◆ max_dist()
double tesseract::TrainingSample::max_dist |
( |
| ) |
const |
|
inline |
◆ micro_features()
const MicroFeature* tesseract::TrainingSample::micro_features |
( |
| ) |
const |
|
inline |
◆ num_features()
uint32_t tesseract::TrainingSample::num_features |
( |
| ) |
const |
|
inline |
◆ num_micro_features()
uint32_t tesseract::TrainingSample::num_micro_features |
( |
| ) |
const |
|
inline |
◆ outline_length()
int tesseract::TrainingSample::outline_length |
( |
| ) |
const |
|
inline |
◆ page_num()
int tesseract::TrainingSample::page_num |
( |
| ) |
const |
|
inline |
◆ RandomizedCopy()
TrainingSample * tesseract::TrainingSample::RandomizedCopy |
( |
int |
index | ) |
const |
Definition at line 163 of file trainingsample.cpp.
165 if (index >= 0 && index < kSampleRandomSize) {
167 const int yshift = kYShiftValues[index / kSampleScaleSize];
168 double scaling = kScaleValues[index % kSampleScaleSize];
169 for (uint32_t i = 0; i < num_features_; ++i) {
172 sample->features_[i].X = ClipToRange<int>(result + 0.5, 0, UINT8_MAX);
175 sample->features_[i].Y = ClipToRange<int>(result + 0.5, 0, UINT8_MAX);
◆ RenderToPix()
Pix * tesseract::TrainingSample::RenderToPix |
( |
const UNICHARSET * |
unicharset | ) |
const |
Definition at line 296 of file trainingsample.cpp.
298 for (uint32_t f = 0; f < num_features_; ++f) {
299 int start_x = features_[f].
X;
301 double dx = cos((features_[f].Theta / 256.0) * 2.0 * M_PI - M_PI);
302 double dy = -sin((features_[f].Theta / 256.0) * 2.0 * M_PI - M_PI);
303 for (
int i = 0; i <= 5; ++i) {
304 int x = static_cast<int>(start_x + dx * i);
305 int y = static_cast<int>(start_y + dy * i);
306 if (x >= 0 && x < 256 && y >= 0 && y < 256)
307 pixSetPixel(pix, x, y, 1);
310 if (unicharset !=
nullptr)
◆ sample_index()
int tesseract::TrainingSample::sample_index |
( |
| ) |
const |
|
inline |
◆ Serialize()
bool tesseract::TrainingSample::Serialize |
( |
FILE * |
fp | ) |
const |
Definition at line 55 of file trainingsample.cpp.
56 if (fwrite(&class_id_,
sizeof(class_id_), 1, fp) != 1)
return false;
57 if (fwrite(&font_id_,
sizeof(font_id_), 1, fp) != 1)
return false;
58 if (fwrite(&page_num_,
sizeof(page_num_), 1, fp) != 1)
return false;
59 if (!bounding_box_.
Serialize(fp))
return false;
60 if (fwrite(&num_features_,
sizeof(num_features_), 1, fp) != 1)
return false;
61 if (fwrite(&num_micro_features_,
sizeof(num_micro_features_), 1, fp) != 1)
63 if (fwrite(&outline_length_,
sizeof(outline_length_), 1, fp) != 1)
65 if (fwrite(features_,
sizeof(*features_), num_features_, fp) != num_features_)
67 if (fwrite(micro_features_,
sizeof(*micro_features_), num_micro_features_,
68 fp) != num_micro_features_)
70 if (fwrite(cn_feature_,
sizeof(*cn_feature_), kNumCNParams, fp) !=
71 kNumCNParams)
return false;
◆ set_bounding_box()
void tesseract::TrainingSample::set_bounding_box |
( |
const TBOX & |
box | ) |
|
|
inline |
◆ set_class_id()
void tesseract::TrainingSample::set_class_id |
( |
int |
id | ) |
|
|
inline |
◆ set_font_id()
void tesseract::TrainingSample::set_font_id |
( |
int |
id | ) |
|
|
inline |
◆ set_is_error()
void tesseract::TrainingSample::set_is_error |
( |
bool |
value | ) |
|
|
inline |
◆ set_max_dist()
void tesseract::TrainingSample::set_max_dist |
( |
double |
value | ) |
|
|
inline |
◆ set_page_num()
void tesseract::TrainingSample::set_page_num |
( |
int |
page | ) |
|
|
inline |
◆ set_sample_index()
void tesseract::TrainingSample::set_sample_index |
( |
int |
value | ) |
|
|
inline |
◆ set_weight()
void tesseract::TrainingSample::set_weight |
( |
double |
value | ) |
|
|
inline |
◆ weight()
double tesseract::TrainingSample::weight |
( |
| ) |
const |
|
inline |
The documentation for this class was generated from the following files: