Skip to content

Commit

Permalink
Merge pull request tesseract-ocr#2430 from stweil/fix
Browse files Browse the repository at this point in the history
Fix reading of parameter from traineddata normproto component and make function independent of locale
  • Loading branch information
zdenop authored May 12, 2019
2 parents c07bc4e + 5d92fbf commit 746674f
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/classify/clusttool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,24 @@ uint16_t ReadSampleSize(TFile *fp) {
*/
PARAM_DESC *ReadParamDesc(TFile *fp, uint16_t N) {
PARAM_DESC *ParamDesc;
char linear_token[TOKENSIZE], essential_token[TOKENSIZE];

ParamDesc = static_cast<PARAM_DESC *>(Emalloc (N * sizeof (PARAM_DESC)));
for (int i = 0; i < N; i++) {
const int kMaxLineSize = TOKENSIZE * 4;
char line[kMaxLineSize];
ASSERT_HOST(fp->FGets(line, kMaxLineSize) != nullptr);
ASSERT_HOST(sscanf(line,
"%" QUOTED_TOKENSIZE "s %" QUOTED_TOKENSIZE "s %f %f",
linear_token, essential_token, &ParamDesc[i].Min,
&ParamDesc[i].Max) == 4);
std::istringstream stream(line);
// Use "C" locale (needed for float values Min, Max).
stream.imbue(std::locale::classic());
std::string linear_token;
stream >> linear_token;
std::string essential_token;
stream >> essential_token;
stream >> ParamDesc[i].Min;
stream >> ParamDesc[i].Max;
ASSERT_HOST(!stream.fail());
ParamDesc[i].Circular = (linear_token[0] == 'c');
ParamDesc[i].NonEssential = (linear_token[0] != 'e');
ParamDesc[i].NonEssential = (essential_token[0] != 'e');
ParamDesc[i].Range = ParamDesc[i].Max - ParamDesc[i].Min;
ParamDesc[i].HalfRange = ParamDesc[i].Range / 2;
ParamDesc[i].MidRange = (ParamDesc[i].Max + ParamDesc[i].Min) / 2;
Expand Down

0 comments on commit 746674f

Please sign in to comment.