24 #include "config_auto.h" 29 #define _USE_MATH_DEFINES 58 #define PROGRAM_FEATURE_TYPE "mf" 68 #ifndef GRAPHICS_DISABLED 69 static void DisplayProtoList(
const char* ch,
LIST protolist) {
71 520, 520, -130.0, 130.0, -130.0, 130.0);
72 LIST proto = protolist;
79 else if (prototype->
Merged)
86 float dx =
static_cast<float>(
LengthOf(prototype->
Mean) * cos(angle) / 2);
87 float dy =
static_cast<float>(
LengthOf(prototype->
Mean) * sin(angle) / 2);
88 c_move(window, (x - dx) * 256, (y - dy) * 256);
89 c_draw(window, (x + dx) * 256, (y + dy) * 256);
91 tprintf(
"Green proto at (%g,%g)+(%g,%g) %d samples\n",
94 tprintf(
"Red proto at (%g,%g)+(%g,%g) %d samples\n",
99 #endif // GRAPHICS_DISABLED 103 static LIST ClusterOneConfig(
int shape_id,
const char* class_label,
119 #ifndef GRAPHICS_DISABLED 120 if (strcmp(FLAGS_test_ch.c_str(), class_label) == 0)
121 DisplayProtoList(FLAGS_test_ch.c_str(), proto_list);
122 #endif // GRAPHICS_DISABLED 129 if (merge_class ==
nullptr) {
131 mf_classes =
push(mf_classes, merge_class);
135 LIST proto_it = proto_list;
151 static_cast<float>(merge_class->
NumMerged[p_id]),
168 int num_configs = shape_table->
NumShapes();
169 config_map->
Init(num_configs,
true);
171 for (
int c1 = 0; c1 < num_configs; ++c1) {
176 for (
int c2 = c1 + 1; c2 < num_configs; ++c2) {
178 config_map->
Merge(c1, c2);
213 int main (
int argc,
char **argv) {
214 tesseract::CheckSharedLibraryVersion();
225 if (trainer ==
nullptr)
return 1;
232 SetupConfigMap(shape_table, &config_map);
244 unicharset = &shape_set;
248 for (
int s = 0; s < num_shapes; ++s) {
256 int num_configs = shape_table->
NumShapes();
258 for (
int s = 0; s < num_configs; ++s) {
259 int unichar_id, font_id;
260 if (unicharset == &shape_set) {
267 const char* class_label = unicharset->
id_to_unichar(unichar_id);
268 mf_classes = ClusterOneConfig(s, class_label, mf_classes, *shape_table,
271 STRING inttemp_file = file_prefix;
272 inttemp_file +=
"inttemp";
273 STRING pffmtable_file = file_prefix;
274 pffmtable_file +=
"pffmtable";
278 *shape_table, float_classes,
281 for (
int c = 0; c < unicharset->
size(); ++c) {
284 delete [] float_classes;
289 if (!FLAGS_test_ch.empty()) {
291 printf(
"Hit return to exit...\n");
292 while (getchar() !=
'\n');
LIST RemoveInsignificantProtos(LIST ProtoList, bool KeepSigProtos, bool KeepInsigProtos, int N)
DECLARE_STRING_PARAM_FLAG(test_ch)
#define AddProtoToConfig(Pid, Config)
void FreeClassFields(CLASS_TYPE Class)
void ComputeMergedProto(PROTO p1, PROTO p2, float w1, float w2, PROTO MergedProto)
const UNICHARSET & unicharset() const
const char * string() const
void c_draw(void *win, double x, double y)
void ParseArguments(int *argc, char ***argv)
int NumMerged[MAX_NUM_PROTOS]
LIST push(LIST list, void *element)
void MergeInsignificantProtos(LIST ProtoList, const char *label, CLUSTERER *Clusterer, CLUSTERCONFIG *clusterconfig)
UnicityTableEqEq< int > font_set
#define ProtoIn(Class, Pid)
CLUSTERER * SetupForClustering(const ShapeTable &shape_table, const FEATURE_DEFS_STRUCT &feature_defs, int shape_id, int *num_samples)
FEATURE_DEFS_STRUCT feature_defs
bool AnyMultipleUnichars() const
void unichar_insert(const char *const unichar_repr, OldUncleanUnichars old_style)
MERGE_CLASS FindClass(LIST List, const char *Label)
Shape * MutableShape(int shape_id)
void FreeProtoList(LIST *ProtoList)
void MakeNewFromOld(PROTO New, PROTOTYPE *Old)
bool Merge(int compact_index1, int compact_index2)
void WriteShapeTable(const STRING &file_prefix, const ShapeTable &shape_table)
MERGE_CLASS NewLabeledClass(const char *Label)
int AddProtoToClass(CLASS_TYPE Class)
LIST ClusterSamples(CLUSTERER *Clusterer, CLUSTERCONFIG *Config)
void c_move(void *win, double x, double y)
bool IsEqualUnichars(Shape *other)
int AddConfigToClass(CLASS_TYPE Class)
DLLSYM void tprintf(const char *format,...)
int push_back(T object)
Add an element in the table.
void FreeLabeledClassList(LIST ClassList)
void FreeClusterer(CLUSTERER *Clusterer)
const char * id_to_unichar(UNICHAR_ID id) const
int main(int argc, char **argv)
void CleanUpUnusedData(LIST ProtoList)
void GetFirstUnicharAndFont(int shape_id, int *unichar_id, int *font_id) const
virtual int SparseToCompact(int sparse_index) const
CLASS_STRUCT * SetUpForFloat2Int(const UNICHARSET &unicharset, LIST LabeledClassList)
MasterTrainer * LoadTrainingData(int argc, const char *const *argv, bool replication, ShapeTable **shape_table, STRING *file_prefix)
const int kMaxShapeLabelLength
void c_make_current(void *win)
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)
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)
void Init(int size, bool all_mapped)
int FindClosestExistingProto(CLASS_TYPE Class, int NumMerged[], PROTOTYPE *Prototype)