24#define _USE_MATH_DEFINES
26# include "config_auto.h"
56#ifndef GRAPHICS_DISABLED
57static void DisplayProtoList(
const char *
ch,
LIST protolist) {
58 auto window = std::make_unique<ScrollView>(
"Char samples", 50, 200, 520, 520, 260, 260,
true);
59 LIST proto = protolist;
62 if (prototype->Significant) {
63 window->Pen(ScrollView::GREEN);
64 }
else if (prototype->NumSamples == 0) {
65 window->Pen(ScrollView::BLUE);
66 }
else if (prototype->Merged) {
67 window->Pen(ScrollView::MAGENTA);
69 window->Pen(ScrollView::RED);
74 auto dx =
static_cast<float>(
LengthOf(prototype->Mean) * cos(angle) / 2);
75 auto dy =
static_cast<float>(
LengthOf(prototype->Mean) * sin(angle) / 2);
76 window->SetCursor((
x - dx) * 256, (
y - dy) * 256);
77 window->DrawTo((
x + dx) * 256, (
y + dy) * 256);
78 auto prototypeNumSamples = prototype->NumSamples;
79 if (prototype->Significant) {
80 tprintf(
"Green proto at (%g,%g)+(%g,%g) %d samples\n",
x,
y, dx, dy, prototypeNumSamples);
81 }
else if (prototype->NumSamples > 0 && !prototype->Merged) {
82 tprintf(
"Red proto at (%g,%g)+(%g,%g) %d samples\n",
x,
y, dx, dy, prototypeNumSamples);
91static LIST ClusterOneConfig(
int shape_id,
const char *class_label,
LIST mf_classes,
103#ifndef GRAPHICS_DISABLED
104 if (strcmp(FLAGS_test_ch.c_str(), class_label) == 0) {
105 DisplayProtoList(FLAGS_test_ch.c_str(), proto_list);
112 if (merge_class ==
nullptr) {
114 mf_classes =
push(mf_classes, merge_class);
118 LIST proto_it = proto_list;
133 static_cast<float>(merge_class->
NumMerged[p_id]), 1.0,
149 int num_configs = shape_table->
NumShapes();
150 config_map->
Init(num_configs,
true);
152 for (
int c1 = 0; c1 < num_configs; ++c1) {
157 for (
int c2 = c1 + 1; c2 < num_configs; ++c2) {
159 config_map->
Merge(c1, c2);
194int main(
int argc,
char **argv) {
195 tesseract::CheckSharedLibraryVersion();
200 std::string file_prefix;
203 if (trainer ==
nullptr) {
212 SetupConfigMap(shape_table, &config_map);
224 unicharset = &shape_set;
228 for (
int s = 0; s < num_shapes; ++s) {
229 char shape_label[14];
230 snprintf(shape_label,
sizeof(shape_label),
"sh%04d", s);
236 int num_configs = shape_table->
NumShapes();
238 for (
int s = 0; s < num_configs; ++s) {
239 int unichar_id, font_id;
240 if (unicharset == &shape_set) {
247 const char *class_label = unicharset->
id_to_unichar(unichar_id);
248 mf_classes = ClusterOneConfig(s, class_label, mf_classes, *shape_table, trainer.get());
250 std::string inttemp_file = file_prefix;
251 inttemp_file +=
"inttemp";
252 std::string pffmtable_file = file_prefix;
253 pffmtable_file +=
"pffmtable";
257 inttemp_file.c_str(), pffmtable_file.c_str());
258 for (
size_t c = 0; c < unicharset->
size(); ++c) {
261 delete[] float_classes;
265 if (!FLAGS_test_ch.empty()) {
267 printf(
"Hit return to exit...\n");
268 while (getchar() !=
'\n') {
void ComputeMergedProto(PROTO_STRUCT *p1, PROTO_STRUCT *p2, float w1, float w2, PROTO_STRUCT *MergedProto)
int FindClosestExistingProto(CLASS_TYPE Class, int NumMerged[], PROTOTYPE *Prototype)
void MakeNewFromOld(PROTO_STRUCT *New, PROTOTYPE *Old)
int main(int argc, char **argv)
#define AddProtoToConfig(Pid, Config)
#define ProtoIn(Class, Pid)
MERGE_CLASS FindClass(LIST List, const std::string &Label)
void WriteShapeTable(const std::string &file_prefix, const ShapeTable &shape_table)
void tprintf(const char *format,...)
void ParseArguments(int *argc, char ***argv)
int AddConfigToClass(CLASS_TYPE Class)
int AddProtoToClass(CLASS_TYPE Class)
void FreeClassFields(CLASS_TYPE Class)
FEATURE_DEFS_STRUCT feature_defs
void MergeInsignificantProtos(LIST ProtoList, const char *label, CLUSTERER *Clusterer, CLUSTERCONFIG *clusterconfig)
void FreeProtoList(LIST *ProtoList)
std::unique_ptr< MasterTrainer > LoadTrainingData(const char *const *filelist, bool replication, ShapeTable **shape_table, std::string &file_prefix)
void CleanUpUnusedData(LIST ProtoList)
void FreeClusterer(CLUSTERER *Clusterer)
LIST push(LIST list, void *element)
LIST RemoveInsignificantProtos(LIST ProtoList, bool KeepSigProtos, bool KeepInsigProtos, int N)
CLASS_STRUCT * SetUpForFloat2Int(const UNICHARSET &unicharset, LIST LabeledClassList)
LIST ClusterSamples(CLUSTERER *Clusterer, CLUSTERCONFIG *Config)
void FreeLabeledClassList(LIST ClassList)
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
void unichar_insert(const char *const unichar_repr, OldUncleanUnichars old_style)
const char * id_to_unichar(UNICHAR_ID id) const
std::vector< BIT_VECTOR > Configurations
UnicityTable< int > font_set
bool IsEqualUnichars(Shape *other)
bool AnyMultipleUnichars() const
Shape * MutableShape(unsigned shape_id)
unsigned NumShapes() const
void GetFirstUnicharAndFont(unsigned shape_id, int *unichar_id, int *font_id) const
tesseract::CLASS_TYPE Class
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)