Skip to content

Commit

Permalink
Handle null raw_choice - fixes #235, fixes #246
Browse files Browse the repository at this point in the history
  • Loading branch information
tfmorris authored and zdenop committed Oct 13, 2018
1 parent 90403ef commit f6fd9b3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
27 changes: 19 additions & 8 deletions src/ccmain/control.cpp
Expand Up @@ -1300,14 +1300,25 @@ float Tesseract::ClassifyBlobAsWord(int pass_n, PAGE_RES_IT* pr_it,
SetupWordPassN(1, &wd);
classify_word_and_language(pass_n, &it, &wd);
if (debug_noise_removal) {
tprintf("word xheight=%g, row=%g, range=[%g,%g]\n", word_res->x_height,
wd.row->x_height(), wd.word->raw_choice->min_x_height(),
wd.word->raw_choice->max_x_height());
}
const float cert = wd.word->raw_choice->certainty();
const float rat = wd.word->raw_choice->rating();
*c2 = rat > 0.0f ? cert * cert / rat : 0.0f;
*best_str = wd.word->raw_choice->unichar_string();
if (wd.word->raw_choice != NULL) {
tprintf("word xheight=%g, row=%g, range=[%g,%g]\n", word_res->x_height,
wd.row->x_height(), wd.word->raw_choice->min_x_height(),
wd.word->raw_choice->max_x_height());
} else {
tprintf("Got word with null raw choice xheight=%g, row=%g\n", word_res->x_height,
wd.row->x_height());
}
}
float cert = 0.0f;
if (wd.word->raw_choice != NULL) { // This probably shouldn't happen, but...
cert = wd.word->raw_choice->certainty();
float rat = wd.word->raw_choice->rating();
*c2 = rat > 0.0f ? cert * cert / rat : 0.0f;
*best_str = wd.word->raw_choice->unichar_string();
} else {
*c2 = 0.0f;
*best_str = "";
}
it.DeleteCurrentWord();
pr_it->ResetWordIterator();
return cert;
Expand Down
6 changes: 5 additions & 1 deletion src/training/stringrenderer.cpp
Expand Up @@ -543,7 +543,11 @@ void StringRenderer::ComputeClusterBoxes() {
// pango.
std::vector<std::string> cluster_text;
if (GetClusterStrings(&cluster_text)) {
ASSERT_HOST(cluster_text.size() == start_byte_to_box.size());
tprintf("* %d, cluster_text.size(): %d\t", page_, cluster_text.size());
tprintf("start_byte_to_box.size(): %d\n", start_byte_to_box.size());
if (cluster_text.size() != start_byte_to_box.size())
tprintf(">%s<\n", cluster_text[0].c_str());
ASSERT_HOST(cluster_text.size() == start_byte_to_box.size());
int ind = 0;
for (std::map<int, BoxChar*>::iterator it = start_byte_to_box.begin();
it != start_byte_to_box.end(); ++it, ++ind) {
Expand Down

0 comments on commit f6fd9b3

Please sign in to comment.