Skip to content

Commit 3df0c78

Browse files
committed
Fix FP division by zero in LanguageModel::ExtractFeaturesFromPath (issue tesseract-ocr#3995)
Signed-off-by: Stefan Weil <[email protected]>
1 parent 85cab7f commit 3df0c78

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/wordrec/language_model.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -1375,7 +1375,12 @@ void LanguageModel::ExtractFeaturesFromPath(const ViterbiStateEntry &vse, float
13751375
// features[PTRAIN_NUM_BAD_FONT] = vse.consistency_info.inconsistent_font;
13761376

13771377
// Classifier-related features.
1378-
features[PTRAIN_RATING_PER_CHAR] = vse.ratings_sum / vse.outline_length;
1378+
if (vse.outline_length > 0.0f) {
1379+
features[PTRAIN_RATING_PER_CHAR] = vse.ratings_sum / vse.outline_length;
1380+
} else {
1381+
// Avoid FP division by 0.
1382+
features[PTRAIN_RATING_PER_CHAR] = 0.0f;
1383+
}
13791384
}
13801385

13811386
WERD_CHOICE *LanguageModel::ConstructWord(ViterbiStateEntry *vse, WERD_RES *word_res,

0 commit comments

Comments
 (0)