tesseract
5.0.0-alpha-619-ge9db
|
Go to the documentation of this file.
24 #define _USE_MATH_DEFINES // for M_PI
26 #include "config_auto.h"
61 #ifndef GRAPHICS_DISABLED
62 static void DisplayProtoList(
const char* ch,
LIST protolist) {
64 520, 520, -130.0, 130.0, -130.0, 130.0);
65 LIST proto = protolist;
72 else if (prototype->
Merged)
79 float dx = static_cast<float>(
LengthOf(prototype->
Mean) * cos(angle) / 2);
80 float dy = static_cast<float>(
LengthOf(prototype->
Mean) * sin(angle) / 2);
81 c_move(window, (x - dx) * 256, (y - dy) * 256);
82 c_draw(window, (x + dx) * 256, (y + dy) * 256);
84 tprintf(
"Green proto at (%g,%g)+(%g,%g) %d samples\n",
87 tprintf(
"Red proto at (%g,%g)+(%g,%g) %d samples\n",
92 #endif // GRAPHICS_DISABLED
96 static LIST ClusterOneConfig(
int shape_id,
const char* class_label,
112 #ifndef GRAPHICS_DISABLED
113 if (strcmp(FLAGS_test_ch.c_str(), class_label) == 0)
114 DisplayProtoList(FLAGS_test_ch.c_str(), proto_list);
115 #endif // GRAPHICS_DISABLED
122 if (merge_class ==
nullptr) {
124 mf_classes =
push(mf_classes, merge_class);
128 LIST proto_it = proto_list;
144 static_cast<float>(merge_class->
NumMerged[p_id]),
161 int num_configs = shape_table->
NumShapes();
162 config_map->
Init(num_configs,
true);
164 for (
int c1 = 0; c1 < num_configs; ++c1) {
169 for (
int c2 = c1 + 1; c2 < num_configs; ++c2) {
171 config_map->
Merge(c1, c2);
206 int main (
int argc,
char **argv) {
207 tesseract::CheckSharedLibraryVersion();
218 if (trainer ==
nullptr)
return 1;
225 SetupConfigMap(shape_table, &config_map);
237 unicharset = &shape_set;
241 for (
int s = 0; s < num_shapes; ++s) {
242 char shape_label[14];
243 snprintf(shape_label,
sizeof(shape_label),
"sh%04d", s);
249 int num_configs = shape_table->
NumShapes();
251 for (
int s = 0; s < num_configs; ++s) {
252 int unichar_id, font_id;
253 if (unicharset == &shape_set) {
260 const char* class_label = unicharset->
id_to_unichar(unichar_id);
261 mf_classes = ClusterOneConfig(s, class_label, mf_classes, *shape_table,
264 STRING inttemp_file = file_prefix;
265 inttemp_file +=
"inttemp";
266 STRING pffmtable_file = file_prefix;
267 pffmtable_file +=
"pffmtable";
271 *shape_table, float_classes,
272 inttemp_file.
c_str(),
273 pffmtable_file.
c_str());
274 for (
int c = 0; c < unicharset->
size(); ++c) {
277 delete [] float_classes;
282 if (!FLAGS_test_ch.empty()) {
284 printf(
"Hit return to exit...\n");
285 while (getchar() !=
'\n');
int AddProtoToClass(CLASS_TYPE Class)
int FindClosestExistingProto(CLASS_TYPE Class, int NumMerged[], PROTOTYPE *Prototype)
CLUSTERER * SetupForClustering(const ShapeTable &shape_table, const FEATURE_DEFS_STRUCT &feature_defs, int shape_id, int *num_samples)
void FreeClusterer(CLUSTERER *Clusterer)
int AddConfigToClass(CLASS_TYPE Class)
void ComputeMergedProto(PROTO p1, PROTO p2, float w1, float w2, PROTO MergedProto)
void FreeLabeledClassList(LIST ClassList)
void FreeProtoList(LIST *ProtoList)
int SparseToCompact(int sparse_index) const override
MERGE_CLASS FindClass(LIST List, const char *Label)
CLASS_STRUCT * SetUpForFloat2Int(const UNICHARSET &unicharset, LIST LabeledClassList)
int push_back(T object)
Add an element in the table.
#define ProtoIn(Class, Pid)
LIST ClusterSamples(CLUSTERER *Clusterer, CLUSTERCONFIG *Config)
void c_move(void *win, double x, double y)
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)
void FreeClassFields(CLASS_TYPE Class)
Shape * MutableShape(int shape_id)
void GetFirstUnicharAndFont(int shape_id, int *unichar_id, int *font_id) const
#define AddProtoToConfig(Pid, Config)
bool Merge(int compact_index1, int compact_index2)
const char * c_str() const
const UNICHARSET & unicharset() const
void CleanUpUnusedData(LIST ProtoList)
void MakeNewFromOld(PROTO New, PROTOTYPE *Old)
UnicityTableEqEq< int > font_set
FEATURE_DEFS_STRUCT feature_defs
void WriteShapeTable(const STRING &file_prefix, const ShapeTable &shape_table)
LIST RemoveInsignificantProtos(LIST ProtoList, bool KeepSigProtos, bool KeepInsigProtos, int N)
LIST push(LIST list, void *element)
int NumMerged[MAX_NUM_PROTOS]
bool IsEqualUnichars(Shape *other)
MasterTrainer * LoadTrainingData(int argc, const char *const *argv, bool replication, ShapeTable **shape_table, STRING *file_prefix)
void ParseArguments(int *argc, char ***argv)
void MergeInsignificantProtos(LIST ProtoList, const char *label, CLUSTERER *Clusterer, CLUSTERCONFIG *clusterconfig)
void Init(int size, bool all_mapped)
MERGE_CLASS NewLabeledClass(const char *Label)
bool AnyMultipleUnichars() const
ScrollView * c_create_window(const char *name, int16_t xpos, int16_t ypos, int16_t xsize, int16_t ysize, double xmin, double xmax, double ymin, double ymax)
void c_line_color_index(void *win, C_COL index)
DLLSYM void tprintf(const char *format,...)
void c_draw(void *win, double x, double y)
const char * id_to_unichar(UNICHAR_ID id) const
void unichar_insert(const char *const unichar_repr, OldUncleanUnichars old_style)
void c_make_current(void *win)
int main(int argc, char **argv)