25 #ifndef DISABLED_LEGACY_ENGINE
44 STRING output_fname = fname;
45 const char* lastdot = strrchr(output_fname.
c_str(),
'.');
46 if (lastdot !=
nullptr)
47 output_fname[lastdot - output_fname.
c_str()] =
'\0';
48 output_fname +=
".txt";
49 FILE* output_file = fopen(output_fname.
c_str(),
"a+");
50 if (output_file ==
nullptr) {
51 tprintf(
"Error: Could not open file %s\n", output_fname.
c_str());
59 while (page_res_it->
block() !=
nullptr && page_res_it->
word() ==
nullptr)
62 if (page_res_it->
word() !=
nullptr) {
69 if (tbox->
left() < 0) {
89 const char* lastdot = strrchr(box_fname.
c_str(),
'.');
90 if (lastdot !=
nullptr)
91 box_fname[lastdot - box_fname.
c_str()] =
'\0';
94 FILE* box_file = fopen(box_fname.
c_str(),
"r");
95 if (box_file ==
nullptr) {
96 tprintf(
"Error: Could not open file %s\n", box_fname.
c_str());
110 int examined_words = 0;
112 keep_going = read_t(&page_res_it, &tbox);
120 keep_going = read_t(&page_res_it, &tbox);
130 keep_going = read_t(&page_res_it, &tbox);
144 }
while (keep_going);
153 if (page_res_it.
word()) {
159 if (examined_words < 0.85 * total_words) {
161 "TODO(antonova): clean up recog_training_segmented; "
162 " It examined only a small fraction of the ambigs image.\n");
164 tprintf(
"recog_training_segmented: examined %d / %d words.\n", examined_words,
169 static void PrintPath(
int length,
const BLOB_CHOICE** blob_choices,
170 const UNICHARSET& unicharset,
const char* label,
173 float certainty = 0.0f;
174 for (
int i = 0; i < length; ++i) {
176 fprintf(output_file,
"%s",
178 rating += blob_choice->
rating();
179 if (certainty > blob_choice->
certainty())
182 fprintf(output_file,
"\t%s\t%.4f\t%.4f\n", label, rating, certainty);
187 static void PrintMatrixPaths(
int col,
int dim,
const MATRIX& ratings,
189 const UNICHARSET& unicharset,
const char* label,
191 for (
int row = col; row < dim && row - col < ratings.
bandwidth(); ++row) {
193 BLOB_CHOICE_IT bc_it(ratings.
get(col, row));
194 for (bc_it.mark_cycle_pt(); !bc_it.cycled_list(); bc_it.forward()) {
195 blob_choices[length] = bc_it.data();
197 PrintMatrixPaths(row + 1, dim, ratings, length + 1, blob_choices,
198 unicharset, label, output_file);
200 PrintPath(length + 1, blob_choices, unicharset, label, output_file);
226 tprintf(
"Not outputting illegal unichar %s\n", label);
232 const auto** blob_choices =
new const BLOB_CHOICE*[dim];
235 delete[] blob_choices;