Skip to content

Commit

Permalink
Fix FP division by zero in LanguageModel::ExtractFeaturesFromPath (is…
Browse files Browse the repository at this point in the history
…sue tesseract-ocr#3995)

Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil committed Jan 19, 2023
1 parent 85cab7f commit 3df0c78
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/wordrec/language_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1375,7 +1375,12 @@ void LanguageModel::ExtractFeaturesFromPath(const ViterbiStateEntry &vse, float
// features[PTRAIN_NUM_BAD_FONT] = vse.consistency_info.inconsistent_font;

// Classifier-related features.
features[PTRAIN_RATING_PER_CHAR] = vse.ratings_sum / vse.outline_length;
if (vse.outline_length > 0.0f) {
features[PTRAIN_RATING_PER_CHAR] = vse.ratings_sum / vse.outline_length;
} else {
// Avoid FP division by 0.
features[PTRAIN_RATING_PER_CHAR] = 0.0f;
}
}

WERD_CHOICE *LanguageModel::ConstructWord(ViterbiStateEntry *vse, WERD_RES *word_res,
Expand Down

0 comments on commit 3df0c78

Please sign in to comment.