Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #1073 (use default language only when necessary) #3610

Merged
merged 2 commits into from
Oct 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/api/baseapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,8 @@ int TessBaseAPI::Init(const char *data, int data_size, const char *language, Ocr
char **configs, int configs_size, const std::vector<std::string> *vars_vec,
const std::vector<std::string> *vars_values, bool set_only_non_debug_params,
FileReader reader) {
// Default language is "eng".
if (language == nullptr) {
language = "eng";
language = "";
}
if (data == nullptr) {
data = "";
Expand Down
8 changes: 5 additions & 3 deletions src/api/tesseractmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -654,12 +654,14 @@ int main(int argc, char **argv) {
return EXIT_FAILURE;
}

if (lang == nullptr) {
// Set default language if none was given.
bool in_recognition_mode = !list_langs && !print_parameters && !print_fonts_table;

if (lang == nullptr && in_recognition_mode) {
// Set default language model if none was given and a model file is needed.
lang = "eng";
}

if (image == nullptr && !list_langs && !print_parameters && !print_fonts_table) {
if (image == nullptr && in_recognition_mode) {
return EXIT_SUCCESS;
}

Expand Down
12 changes: 6 additions & 6 deletions src/ccmain/tessedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,12 @@ void Tesseract::read_config_file(const char *filename, SetParamConstraint constr
// from the language-specific config file (stored in [lang].traineddata), from
// the config files specified on the command line or left as the default
// OEM_TESSERACT_ONLY if none of the configs specify this variable.
bool Tesseract::init_tesseract_lang_data(const std::string &arg0, const std::string &textbase,
bool Tesseract::init_tesseract_lang_data(const std::string &arg0,
const std::string &language, OcrEngineMode oem,
char **configs, int configs_size,
const std::vector<std::string> *vars_vec,
const std::vector<std::string> *vars_values,
bool set_only_non_debug_params, TessdataManager *mgr) {
// Set the basename, compute the data directory.
main_setup(arg0, textbase);

// Set the language data path prefix
lang = !language.empty() ? language : "eng";
language_data_path_prefix = datadir;
Expand Down Expand Up @@ -300,6 +297,9 @@ int Tesseract::init_tesseract(const std::string &arg0, const std::string &textba
std::vector<std::string> langs_not_to_load;
ParseLanguageString(language, &langs_to_load, &langs_not_to_load);

// Set the basename, compute the data directory.
main_setup(arg0, textbase);

for (auto *lang : sub_langs_) {
delete lang;
}
Expand Down Expand Up @@ -348,7 +348,7 @@ int Tesseract::init_tesseract(const std::string &arg0, const std::string &textba
}
}
}
if (!loaded_primary) {
if (!loaded_primary && !langs_to_load.empty()) {
tprintf("Tesseract couldn't load any languages!\n");
return -1; // Couldn't load any language!
}
Expand Down Expand Up @@ -399,7 +399,7 @@ int Tesseract::init_tesseract_internal(const std::string &arg0, const std::strin
const std::vector<std::string> *vars_vec,
const std::vector<std::string> *vars_values,
bool set_only_non_debug_params, TessdataManager *mgr) {
if (!init_tesseract_lang_data(arg0, textbase, language, oem, configs, configs_size, vars_vec,
if (!init_tesseract_lang_data(arg0, language, oem, configs, configs_size, vars_vec,
vars_values, set_only_non_debug_params, mgr)) {
return -1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ccmain/tesseractclass.h
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ class TESS_API Tesseract : public Wordrec {
void recognize_page(std::string &image_name);
void end_tesseract();

bool init_tesseract_lang_data(const std::string &arg0, const std::string &textbase,
bool init_tesseract_lang_data(const std::string &arg0,
const std::string &language, OcrEngineMode oem, char **configs,
int configs_size, const std::vector<std::string> *vars_vec,
const std::vector<std::string> *vars_values,
Expand Down