39 #define PROGRAM_FEATURE_TYPE "cn" 47 static void WriteNormProtos(
const char *Directory,
LIST LabeledProtoList,
50 static void WriteProtos(FILE* File, uint16_t N,
LIST ProtoList,
51 bool WriteSigProtos,
bool WriteInsigProtos);
113 int main(
int argc,
char *argv[]) {
114 tesseract::CheckSharedLibraryVersion();
119 const char *PageName;
132 printf(
"Reading %s ...\n", PageName);
133 FILE *TrainingPage = fopen(PageName,
"rb");
137 TrainingPage, &CharList);
138 fclose(TrainingPage);
142 printf(
"Clustering ...\n");
146 pCharList = CharList;
155 if (Clusterer ==
nullptr) {
156 fprintf(stderr,
"Error: nullptr clusterer!\n");
170 printf(
"0 significant protos for %s." 171 " Retrying clustering with MinSamples = %f%%\n",
182 WriteNormProtos(FLAGS_D.c_str(), NormProtoList,
185 for (
int i = 0; i < freeable_protos.
size(); ++i) {
206 static void WriteNormProtos(
const char *Directory,
LIST LabeledProtoList,
214 if (Directory !=
nullptr && Directory[0] !=
'\0') {
215 Filename += Directory;
218 Filename +=
"normproto";
219 printf (
"\nWriting %s ...", Filename.
string());
220 File = fopen(Filename.
string(),
"wb");
222 fprintf(File,
"%0d\n", feature_desc->
NumParams);
229 printf (
"\nError! Not enough protos for %s: %d protos" 230 " (%d significant protos" 231 ", %d insignificant protos)\n",
232 LabeledProto->
Label, N,
237 fprintf(File,
"\n%s %d\n", LabeledProto->
Label, N);
238 WriteProtos(File, feature_desc->
NumParams, LabeledProto->
List,
true,
false);
246 static void WriteProtos(FILE* File, uint16_t N,
LIST ProtoList,
247 bool WriteSigProtos,
bool WriteInsigProtos)
const char * string() const
#define PROGRAM_FEATURE_TYPE
void ReadTrainingSamples(const FEATURE_DEFS_STRUCT &feature_definitions, const char *feature_name, int max_samples, UNICHARSET *unicharset, FILE *file, LIST *training_samples)
void ParseArguments(int *argc, char ***argv)
struct LABELEDLISTNODE * LABELEDLIST
const PARAM_DESC * ParamDesc
void WritePrototype(FILE *File, uint16_t N, PROTOTYPE *Proto)
void FreeProtoList(LIST *ProtoList)
void FreeNormProtoList(LIST CharList)
void InitFeatureDefs(FEATURE_DEFS_STRUCT *featuredefs)
LIST ClusterSamples(CLUSTERER *Clusterer, CLUSTERCONFIG *Config)
void WriteParamDesc(FILE *File, uint16_t N, const PARAM_DESC ParamDesc[])
void AddToNormProtosList(LIST *NormProtoList, LIST ProtoList, char *CharName)
void FreeTrainingSamples(LIST CharList)
int NumberOfProtos(LIST ProtoList, bool CountSigProtos, bool CountInsigProtos)
void FreeClusterer(CLUSTERER *Clusterer)
const FEATURE_DESC_STRUCT * FeatureDesc[NUM_FEATURE_TYPES]
const char * GetNextFilename(int argc, const char *const *argv)
uint32_t ShortNameToFeatureType(const FEATURE_DEFS_STRUCT &FeatureDefs, const char *ShortName)
CLUSTERER * SetUpForClustering(const FEATURE_DEFS_STRUCT &FeatureDefs, LABELEDLIST char_sample, const char *program_feature_type)
int main(int argc, char *argv[])
DECLARE_STRING_PARAM_FLAG(D)