23 # include "config_auto.h"
34 #ifndef DISABLED_LEGACY_ENGINE
54 if ((fp = fopen(path.
c_str(),
"rb")) !=
nullptr) {
58 path +=
"tessconfigs/";
60 if ((fp = fopen(path.
c_str(),
"rb")) !=
nullptr) {
80 const char* arg0,
const char* textbase,
const char* language,
84 TessdataManager* mgr) {
89 lang = language !=
nullptr ? language :
"eng";
96 if (!mgr->is_loaded() && !mgr->Init(tessdata_path.
c_str())) {
97 tprintf(
"Error opening data file %s\n", tessdata_path.
c_str());
99 "Please make sure the TESSDATA_PREFIX environment variable is set"
100 " to your \"tessdata\" directory.\n");
103 #ifndef DISABLED_LEGACY_ENGINE
107 if (!mgr->IsLSTMAvailable()) {
109 }
else if (!mgr->IsBaseAvailable()) {
115 #endif // ndef DISABLED_LEGACY_ENGINE
130 for (
int i = 0; i < configs_size; ++i) {
136 if (vars_vec !=
nullptr && vars_values !=
nullptr) {
137 for (
int i = 0; i < vars_vec->
size(); ++i) {
139 (*vars_values)[i].c_str(),
140 set_params_constraint, this->
params())) {
141 tprintf(
"Warning: The parameter '%s' was not found.\n", (*vars_vec)[i].c_str());
148 if (params_file !=
nullptr) {
152 tprintf(
"Failed to open %s for writing params.\n",
169 #ifndef ANDROID_BUILD
170 # ifdef DISABLED_LEGACY_ENGINE
175 # endif // ndef DISABLED_LEGACY_ENGINE
181 tprintf(
"Error: LSTM requested, but not present!! Loading tesseract.\n");
185 #endif // ndef ANDROID_BUILD
190 #ifndef ANDROID_BUILD
192 #endif // ndef ANDROID_BUILD
194 #ifndef DISABLED_LEGACY_ENGINE
197 tprintf(
"Error: Tesseract (legacy) engine requested, but components are "
198 "not present in %s!!\n", tessdata_path.
c_str());
201 #endif // ndef DISABLED_LEGACY_ENGINE
203 tprintf(
"Error: Size of unicharset is greater than MAX_NUM_CLASSES\n");
208 #ifndef DISABLED_LEGACY_ENGINE
228 static_cast<ParamsModel::PassEnum>(p));
235 #endif // ndef DISABLED_LEGACY_ENGINE
241 static bool IsStrInList(
const STRING& str,
243 for (
int i = 0; i < str_list.
size(); ++i) {
244 if (str_list[i] == str)
return true;
258 while (remains.length() > 0) {
260 const char* start = remains.c_str();
261 while (*start ==
'+') ++start;
264 target = not_to_load;
268 int end = strlen(start);
269 const char* plus = strchr(start,
'+');
270 if (plus !=
nullptr && plus - start < end) end = plus - start;
272 lang_code.truncate_at(end);
276 if (!IsStrInList(lang_code, *target)) {
288 char** configs,
int configs_size,
291 bool set_only_non_debug_params,
292 TessdataManager* mgr) {
297 sub_langs_.delete_data_pointers();
301 bool loaded_primary =
false;
303 for (
int lang_index = 0; lang_index < langs_to_load.
size(); ++lang_index) {
304 if (!IsStrInList(langs_to_load[lang_index], langs_not_to_load)) {
305 const char* lang_str = langs_to_load[lang_index].c_str();
307 if (!loaded_primary) {
314 arg0, textbase, lang_str, oem, configs, configs_size, vars_vec,
315 vars_values, set_only_non_debug_params, mgr);
319 if (!loaded_primary) {
321 tprintf(
"Failed loading language '%s'\n", lang_str);
324 &langs_to_load, &langs_not_to_load);
325 loaded_primary =
true;
329 tprintf(
"Failed loading language '%s'\n", lang_str);
332 sub_langs_.push_back(tess_to_init);
335 &langs_to_load, &langs_not_to_load);
340 if (!loaded_primary) {
341 tprintf(
"Tesseract couldn't load any languages!\n");
344 #ifndef DISABLED_LEGACY_ENGINE
345 if (!sub_langs_.empty()) {
352 for (
int s = 0; s < sub_langs_.size(); ++s) {
353 sub_langs_[s]->language_model_->getParamsModel().Copy(
356 tprintf(
"Using params model of the primary language\n");
359 for (
int s = 0; s < sub_langs_.size(); ++s) {
360 sub_langs_[s]->language_model_->getParamsModel().Clear();
366 #endif // ndef DISABLED_LEGACY_ENGINE
388 char** configs,
int configs_size,
391 bool set_only_non_debug_params,
392 TessdataManager* mgr) {
394 configs_size, vars_vec, vars_values,
395 set_only_non_debug_params, mgr)) {
409 #ifndef DISABLED_LEGACY_ENGINE
414 for (
int i = 0; i < new_fonts.
size(); ++i) {
423 for (
int i = 0; i < lang_fonts->
size(); ++i) {
424 int index = all_fonts.
get_id(lang_fonts->
get(i));
435 using namespace std::placeholders;
441 for (
int i = 0; i < sub_langs_.size(); ++i) {
446 for (
int i = 0; i < sub_langs_.size(); ++i) {
449 font_table_size_ = all_fonts.
size();
454 const char* language, TessdataManager* mgr) {
456 nullptr, 0,
nullptr,
nullptr,
false, mgr))
464 #endif // ndef DISABLED_LEGACY_ENGINE