12 #include "config_auto.h"
15 #include "allheaders.h"
30 static float convert_prob_to_tess_certainty(
float prob) {
31 return (prob - 1.0) * 20.0;
50 boxGetGeometry(char_box, &left, &top, &width, &height);
51 left += word_box.
left() - x_offset;
54 bottom = top - height;
55 return TBOX(left, bottom, right, top);
71 tprintf(
"Cube WARNING (extract_cube_state): Invalid cube object "
72 "passed to extract_cube_state\n");
81 if (!cube_search_obj) {
83 tprintf(
"Cube WARNING (Extract_cube_state): Could not retrieve "
84 "cube's search object in extract_cube_state.\n");
89 if (!beam_search_obj) {
91 tprintf(
"Cube WARNING (Extract_cube_state): Could not retrieve "
92 "cube's beam search object in extract_cube_state.\n");
100 *char_samples = beam_search_obj->
BackTrack(
101 cube_search_obj, best_node_index, num_chars,
NULL, char_boxes);
122 tprintf(
"Cube WARNING (create_cube_box_word): Invalid box_word.\n");
130 for (
int i = 0; i < num_chars; ++i) {
131 Box* char_box = boxaGetBox(char_boxes, i, L_CLONE);
132 if (x_offset < 0 || char_box->x < x_offset) {
133 x_offset = char_box->x;
135 boxDestroy(&char_box);
138 for (
int i = 0; i < num_chars; ++i) {
139 Box* char_box = boxaGetBox(char_boxes, i, L_CLONE);
141 boxDestroy(&char_box);
165 for (
int i = 0; i < num_chars; ++i) {
166 uch_id = cube_char_set->
UnicharID(char_samples[i]->StrLabel());
167 if (uch_id != INVALID_UNICHAR_ID)
169 uch_id, 1, 0.0, certainty);
173 BLOB_CHOICE_LIST *choices_list;
174 BLOB_CHOICE_IT choices_list_it;
175 BLOB_CHOICE_LIST_CLIST *blob_choices =
new BLOB_CHOICE_LIST_CLIST();
176 BLOB_CHOICE_LIST_C_IT blob_choices_it;
177 blob_choices_it.set_to_list(blob_choices);
179 for (
int i = 0; i < werd_choice->
length(); ++i) {
181 choices_list =
new BLOB_CHOICE_LIST();
182 choices_list_it.set_to_list(choices_list);
185 0.0, certainty, -1, -1, 0, 0, 0,
false);
186 choices_list_it.add_after_then_move(blob_choice);
188 blob_choices_it.add_to_end(choices_list);
209 if (cube_cntxt_ ==
NULL) {
211 tprintf(
"Cube WARNING (Tesseract::init_cube_objects()): Failed to "
212 "instantiate CubeRecoContext\n");
223 if (tess_cube_combiner_ !=
NULL) {
224 delete tess_cube_combiner_;
225 tess_cube_combiner_ =
NULL;
228 tprintf(
"Cube ERROR (Failed to instantiate TesseractCubeCombiner\n");
242 if (page_res ==
NULL || tess_cube_combiner_ ==
NULL)
250 int combiner_run_thresh = convert_prob_to_tess_certainty(
263 if (cube_obj !=
NULL)
287 if (!cube_binary_ || !cube_cntxt_) {
289 tprintf(
"Tesseract::run_cube(): NULL binary image.\n");
300 tprintf(
"Cube can't process rotated word at:");
307 cube_cntxt_, cube_binary_, word_box.
left(),
308 pixGetHeight(cube_binary_) - word_box.
top(),
325 float combiner_prob = tess_cube_combiner_->
CombineResults(tess_word,
335 tprintf(
"Combiner prob = %g vs threshold %g\n",
353 tprintf(
"Cube INFO: tesseract result replaced by cube: %s -> %s\n",
374 if (!cube_alt_list || cube_alt_list->
AltCount() <= 0) {
376 tprintf(
"Cube returned nothing for word at:");
385 char_32 *cube_best_32 = cube_alt_list->
Alt(0);
387 float cube_certainty = convert_prob_to_tess_certainty(cube_prob);
388 string cube_best_str;
393 Boxa *char_boxes =
NULL;
398 tprintf(
"Cube WARNING (Tesseract::cube_recognize): Cannot extract "
412 boxaDestroy(&char_boxes);
413 if (!box_word_success) {
415 tprintf(
"Cube WARNING (Tesseract::cube_recognize): Could not "
416 "create cube BoxWord\n");
423 WERD_CHOICE* cube_werd_choice = create_werd_choice(
424 char_samples, num_chars, cube_best_str.c_str(), cube_certainty,
426 delete []char_samples;
428 if (!cube_werd_choice) {
430 tprintf(
"Cube WARNING (Tesseract::cube_recognize): Could not "
431 "create cube WERD_CHOICE\n");
437 tprintf(
"Cube result: %s r=%g, c=%g\n",
439 cube_werd_choice->
rating(),
444 fill_werd_res(cube_box_word, cube_werd_choice, cube_best_str.c_str(), word);
456 const char* cube_best_str,
465 tess_werd_res->
word);