Skip to content

Commit eaefbea

Browse files
committed
Handle null raw_choice - fixes #235
1 parent 2597296 commit eaefbea

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

ccmain/control.cpp

+20-8
Original file line numberDiff line numberDiff line change
@@ -1255,14 +1255,26 @@ float Tesseract::ClassifyBlobAsWord(int pass_n, PAGE_RES_IT* pr_it,
12551255
SetupWordPassN(1, &wd);
12561256
classify_word_and_language(pass_n, &it, &wd);
12571257
if (debug_noise_removal) {
1258-
tprintf("word xheight=%g, row=%g, range=[%g,%g]\n", word_res->x_height,
1259-
wd.row->x_height(), wd.word->raw_choice->min_x_height(),
1260-
wd.word->raw_choice->max_x_height());
1261-
}
1262-
float cert = wd.word->raw_choice->certainty();
1263-
float rat = wd.word->raw_choice->rating();
1264-
*c2 = rat > 0.0f ? cert * cert / rat : 0.0f;
1265-
*best_str = wd.word->raw_choice->unichar_string();
1258+
if (wd.word->raw_choice != NULL) {
1259+
tprintf("word xheight=%g, row=%g, range=[%g,%g]\n", word_res->x_height,
1260+
wd.row->x_height(), wd.word->raw_choice->min_x_height(),
1261+
wd.word->raw_choice->max_x_height());
1262+
} else {
1263+
tprintf("Got word with null raw choice xheight=%g, row=%g\n", word_res->x_height,
1264+
wd.row->x_height());
1265+
}
1266+
}
1267+
float cert = 0.0f;
1268+
if (wd.word->raw_choice != NULL) { // This probably shouldn't happen, but...
1269+
cert = wd.word->raw_choice->certainty();
1270+
float rat = wd.word->raw_choice->rating();
1271+
*c2 = rat > 0.0f ? cert * cert / rat : 0.0f;
1272+
*best_str = wd.word->raw_choice->unichar_string();
1273+
} else {
1274+
*c2 = 0.0f;
1275+
*best_str = "";
1276+
}
1277+
12661278
it.DeleteCurrentWord();
12671279
pr_it->ResetWordIterator();
12681280
return cert;

0 commit comments

Comments
 (0)