Merge pull request #1818 from stweil/psm

Fix potential crash with --psm 0 and use osd.traineddata automatically
This commit is contained in:
zdenop 2018-08-01 16:56:56 +02:00 committed by GitHub
commit c044b8c916
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -359,6 +359,14 @@ static void ParseArgs(const int argc, char** argv, const char** lang,
*arg_i = i; *arg_i = i;
if (*pagesegmode == tesseract::PSM_OSD_ONLY) {
// That mode requires osd.traineddata, no other language or script files.
if (*lang != nullptr && strcmp(*lang, "osd")) {
fprintf(stderr, "Warning, ignoring -l %s for --psm 0\n", *lang);
}
*lang = "osd";
}
if (*outputbase == nullptr && noocr == false) { if (*outputbase == nullptr && noocr == false) {
PrintHelpMessage(argv[0]); PrintHelpMessage(argv[0]);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -432,7 +440,7 @@ static void PreloadRenderers(
**********************************************************************/ **********************************************************************/
int main(int argc, char** argv) { int main(int argc, char** argv) {
const char* lang = "eng"; const char* lang = nullptr;
const char* image = nullptr; const char* image = nullptr;
const char* outputbase = nullptr; const char* outputbase = nullptr;
const char* datapath = nullptr; const char* datapath = nullptr;
@ -465,6 +473,11 @@ int main(int argc, char** argv) {
&print_parameters, &vars_vec, &vars_values, &arg_i, &pagesegmode, &print_parameters, &vars_vec, &vars_values, &arg_i, &pagesegmode,
&enginemode); &enginemode);
if (lang == nullptr) {
// Set default language if none was given.
lang = "eng";
}
if (image == nullptr && !list_langs && !print_parameters) if (image == nullptr && !list_langs && !print_parameters)
return EXIT_SUCCESS; return EXIT_SUCCESS;