olena: olena-2.0-575-ga594568 Restrict workaround-related locale changes to LC_NUMERIC.

* scribo/text/recognition.hh: Here. --- scribo/ChangeLog | 6 ++++ scribo/scribo/text/recognition.hh | 60 +++++++++++++++++-------------------- 2 files changed, 34 insertions(+), 32 deletions(-) diff --git a/scribo/ChangeLog b/scribo/ChangeLog index 4b8d9be..412f271 100644 --- a/scribo/ChangeLog +++ b/scribo/ChangeLog @@ -1,5 +1,11 @@ 2013-06-25 Roland Levillain <roland@lrde.epita.fr> + Restrict workaround-related locale changes to LC_NUMERIC. + + * scribo/text/recognition.hh: Here. + +2013-06-25 Roland Levillain <roland@lrde.epita.fr> + More locale-related Tesseract workarounds. * scribo/text/recognition.hh: Here. diff --git a/scribo/scribo/text/recognition.hh b/scribo/scribo/text/recognition.hh index 614975b..d74ae5c 100644 --- a/scribo/scribo/text/recognition.hh +++ b/scribo/scribo/text/recognition.hh @@ -122,12 +122,20 @@ namespace scribo { mln_trace("scribo::text::recognition"); - // Tesseract is known to have issues while reading training data - // depending on the current locales in use. Training data files use - // float data and the decimal separator can be either '.' or ',' - // causing errors. - // Setting locale to "C" fix that issue. - setlocale(LC_ALL, "C"); + /* Tesseract is known to have issues while reading training + data, depending on the locale in use. Training data files + contain floating-point values and the decimal separator may + either be '.' or ',' which may trigger a fatal error with the + following message: + + Error: Illegal min or max specification! + + The recommended solution is to set the locale of LC_NUMERIC + to "C". For more information, see: + + http://code.google.com/p/tesseract-ocr/wiki/FAQ#Error:_Illegal_min_or_max_sp... + */ + setlocale(LC_NUMERIC, "C"); // Initialize Tesseract. TessBaseAPI::InitWithLanguage(NULL, NULL, language, NULL, false, 0, NULL); @@ -202,8 +210,8 @@ namespace scribo delete [] s; } - // Restore default locale. - setlocale(LC_ALL, ""); + // Restore the default locale from the environment. + setlocale(LC_NUMERIC, ""); } @@ -219,12 +227,8 @@ namespace scribo const I& line = exact(line_); mln_precondition(line.is_valid()); - // Tesseract is known to have issues while reading training data - // depending on the current locales in use. Training data files use - // float data and the decimal separator can be either '.' or ',' - // causing errors. - // Setting locale to "C" fix that issue. - setlocale(LC_ALL, "C"); + // See the above explanations about setlocale. + setlocale(LC_NUMERIC, "C"); // Initialize Tesseract. TessBaseAPI::InitWithLanguage(NULL, NULL, language, NULL, false, 0, NULL); @@ -279,8 +283,8 @@ namespace scribo if (!output_file.empty()) file.close(); - // Restore default locale. - setlocale(LC_ALL, ""); + // See the above explanations about setlocale. + setlocale(LC_NUMERIC, ""); } @@ -296,12 +300,8 @@ namespace scribo { mln_trace("scribo::text::recognition"); - // Tesseract is known to have issues while reading training data - // depending on the current locales in use. Training data files use - // float data and the decimal separator can be either '.' or ',' - // causing errors. - // Setting locale to "C" fix that issue. - setlocale(LC_ALL, "C"); + // See the above explanations about setlocale. + setlocale(LC_NUMERIC, "C"); // Initialize Tesseract. tesseract::TessBaseAPI tess; @@ -369,8 +369,8 @@ namespace scribo delete[] s; } - // Restore default locale. - setlocale(LC_ALL, ""); + // Restore the default locale from the environment. + setlocale(LC_NUMERIC, ""); } @@ -386,12 +386,8 @@ namespace scribo const I& line = exact(line_); mln_precondition(line.is_valid()); - // Tesseract is known to have issues while reading training data - // depending on the current locales in use. Training data files use - // float data and the decimal separator can be either '.' or ',' - // causing errors. - // Setting locale to "C" fix that issue. - setlocale(LC_ALL, "C"); + // Restore the default locale from the environment. + setlocale(LC_NUMERIC, "C"); // Initialize Tesseract. tesseract::TessBaseAPI tess; @@ -439,8 +435,8 @@ namespace scribo if (!output_file.empty()) file.close(); - // Restore default locale. - setlocale(LC_ALL, ""); + // Restore the default locale from the environment. + setlocale(LC_NUMERIC, ""); } -- 1.7.10.4
participants (1)
-
Roland Levillain