24#define _USE_MATH_DEFINES
26#include "config_auto.h"
64#ifndef GRAPHICS_DISABLED
65static void DisplayProtoList(
const char* ch,
LIST protolist) {
67 520, 520, -130.0, 130.0, -130.0, 130.0);
68 LIST proto = protolist;
75 else if (prototype->
Merged)
82 float dx =
static_cast<float>(
LengthOf(prototype->
Mean) * cos(angle) / 2);
83 float dy =
static_cast<float>(
LengthOf(prototype->
Mean) * sin(angle) / 2);
84 c_move(window, (x - dx) * 256, (y - dy) * 256);
85 c_draw(window, (x + dx) * 256, (y + dy) * 256);
87 tprintf(
"Green proto at (%g,%g)+(%g,%g) %d samples\n",
90 tprintf(
"Red proto at (%g,%g)+(%g,%g) %d samples\n",
99static LIST ClusterOneConfig(
int shape_id,
const char* class_label,
115 #ifndef GRAPHICS_DISABLED
116 if (strcmp(FLAGS_test_ch.c_str(), class_label) == 0)
117 DisplayProtoList(FLAGS_test_ch.c_str(), proto_list);
125 if (merge_class ==
nullptr) {
127 mf_classes =
push(mf_classes, merge_class);
131 LIST proto_it = proto_list;
147 static_cast<float>(merge_class->
NumMerged[p_id]),
164 int num_configs = shape_table->
NumShapes();
165 config_map->
Init(num_configs,
true);
167 for (
int c1 = 0; c1 < num_configs; ++c1) {
172 for (
int c2 = c1 + 1; c2 < num_configs; ++c2) {
174 config_map->
Merge(c1, c2);
209int main (
int argc,
char **argv) {
210 tesseract::CheckSharedLibraryVersion();
221 if (trainer ==
nullptr)
return 1;
228 SetupConfigMap(shape_table, &config_map);
230 WriteShapeTable(file_prefix, *shape_table);
240 unicharset = &shape_set;
244 for (
int s = 0; s < num_shapes; ++s) {
252 int num_configs = shape_table->
NumShapes();
254 for (
int s = 0; s < num_configs; ++s) {
255 int unichar_id, font_id;
256 if (unicharset == &shape_set) {
263 const char* class_label = unicharset->
id_to_unichar(unichar_id);
264 mf_classes = ClusterOneConfig(s, class_label, mf_classes, *shape_table,
267 STRING inttemp_file = file_prefix;
268 inttemp_file +=
"inttemp";
269 STRING pffmtable_file = file_prefix;
270 pffmtable_file +=
"pffmtable";
274 *shape_table, float_classes,
277 for (
int c = 0; c < unicharset->
size(); ++c) {
280 delete [] float_classes;
285 if (!FLAGS_test_ch.empty()) {
287 printf(
"Hit return to exit...\n");
288 while (getchar() !=
'\n');
DLLSYM void tprintf(const char *format,...)
void FreeProtoList(LIST *ProtoList)
void FreeClusterer(CLUSTERER *Clusterer)
LIST ClusterSamples(CLUSTERER *Clusterer, CLUSTERCONFIG *Config)
int AddProtoToClass(CLASS_TYPE Class)
void FreeClassFields(CLASS_TYPE Class)
int AddConfigToClass(CLASS_TYPE Class)
#define AddProtoToConfig(Pid, Config)
#define ProtoIn(Class, Pid)
void c_draw(void *win, double x, double y)
void c_move(void *win, double x, double y)
void c_line_color_index(void *win, C_COL index)
void c_make_current(void *win)
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)
LIST push(LIST list, void *element)
void FreeLabeledClassList(LIST ClassList)
CLASS_STRUCT * SetUpForFloat2Int(const UNICHARSET &unicharset, LIST LabeledClassList)
void ParseArguments(int *argc, char ***argv)
void CleanUpUnusedData(LIST ProtoList)
FEATURE_DEFS_STRUCT feature_defs
LIST RemoveInsignificantProtos(LIST ProtoList, bool KeepSigProtos, bool KeepInsigProtos, int N)
void MergeInsignificantProtos(LIST ProtoList, const char *label, CLUSTERER *Clusterer, CLUSTERCONFIG *clusterconfig)
MERGE_CLASS FindClass(LIST List, const char *Label)
MERGE_CLASS NewLabeledClass(const char *Label)
void ComputeMergedProto(PROTO p1, PROTO p2, float w1, float w2, PROTO MergedProto)
void MakeNewFromOld(PROTO New, PROTOTYPE *Old)
int FindClosestExistingProto(CLASS_TYPE Class, int NumMerged[], PROTOTYPE *Prototype)
int main(int argc, char **argv)
const int kMaxShapeLabelLength
MasterTrainer * LoadTrainingData(int argc, const char *const *argv, bool replication, ShapeTable **shape_table, STRING *file_prefix)
int push_back(T object)
Add an element in the table.
void Init(int size, bool all_mapped)
bool Merge(int compact_index1, int compact_index2)
int SparseToCompact(int sparse_index) const override
const char * string() const
void unichar_insert(const char *const unichar_repr, OldUncleanUnichars old_style)
const char * id_to_unichar(UNICHAR_ID id) const
UnicityTableEqEq< int > font_set
bool IsEqualUnichars(Shape *other)
bool AnyMultipleUnichars() const
void GetFirstUnicharAndFont(int shape_id, int *unichar_id, int *font_id) const
Shape * MutableShape(int shape_id)
int NumMerged[MAX_NUM_PROTOS]
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)
const UNICHARSET & unicharset() const
CLUSTERER * SetupForClustering(const ShapeTable &shape_table, const FEATURE_DEFS_STRUCT &feature_defs, int shape_id, int *num_samples)