24 #include "config_auto.h" 36 #ifndef DISABLED_LEGACY_ENGINE 46 #ifdef DISABLED_LEGACY_ENGINE 51 #define API_CONFIG "configs/api_config" 66 if ((fp = fopen(path.
string(),
"rb")) !=
nullptr) {
70 path +=
"tessconfigs/";
72 if ((fp = fopen(path.
string(),
"rb")) !=
nullptr) {
92 const char *arg0,
const char *textbase,
const char *language,
101 lang = language !=
nullptr ? language :
"eng";
109 tprintf(
"Error opening data file %s\n", tessdata_path.
string());
110 tprintf(
"Please make sure the TESSDATA_PREFIX environment variable is set" 111 " to your \"tessdata\" directory.\n");
114 #ifndef DISABLED_LEGACY_ENGINE 126 #endif // ndef DISABLED_LEGACY_ENGINE 140 for (
int i = 0; i < configs_size; ++i) {
146 if (vars_vec !=
nullptr && vars_values !=
nullptr) {
147 for (
int i = 0; i < vars_vec->
size(); ++i) {
149 (*vars_values)[i].
string(),
150 set_params_constraint, this->
params())) {
151 tprintf(
"Error setting param %s\n", (*vars_vec)[i].
string());
159 if (params_file !=
nullptr) {
163 tprintf(
"Failed to open %s for writing params.\n",
180 #ifndef ANDROID_BUILD 181 #ifdef DISABLED_LEGACY_ENGINE 186 #endif // ndef DISABLED_LEGACY_ENGINE 192 tprintf(
"Error: LSTM requested, but not present!! Loading tesseract.\n");
196 #endif // ndef ANDROID_BUILD 201 #ifndef ANDROID_BUILD 203 #endif // ndef ANDROID_BUILD 205 #ifndef DISABLED_LEGACY_ENGINE 210 #endif // ndef DISABLED_LEGACY_ENGINE 212 tprintf(
"Error: Size of unicharset is greater than MAX_NUM_CLASSES\n");
228 #ifndef DISABLED_LEGACY_ENGINE 235 static_cast<ParamsModel::PassEnum>(p));
242 #endif // ndef DISABLED_LEGACY_ENGINE 248 static bool IsStrInList(
const STRING& str,
250 for (
int i = 0; i < str_list.
size(); ++i) {
251 if (str_list[i] == str)
266 while (remains.
length() > 0) {
268 const char* start = remains.
string();
269 while (*start ==
'+')
273 target = not_to_load;
277 int end = strlen(start);
278 const char* plus = strchr(start,
'+');
279 if (plus !=
nullptr && plus - start < end)
286 if (!IsStrInList(lang_code, *target)) {
298 char **configs,
int configs_size,
301 bool set_only_non_debug_params,
307 sub_langs_.delete_data_pointers();
311 bool loaded_primary =
false;
313 for (
int lang_index = 0; lang_index < langs_to_load.
size(); ++lang_index) {
314 if (!IsStrInList(langs_to_load[lang_index], langs_not_to_load)) {
315 const char *lang_str = langs_to_load[lang_index].string();
317 if (!loaded_primary) {
324 arg0, textbase, lang_str, oem, configs, configs_size, vars_vec,
325 vars_values, set_only_non_debug_params, mgr);
329 if (!loaded_primary) {
331 tprintf(
"Failed loading language '%s'\n", lang_str);
334 &langs_to_load, &langs_not_to_load);
335 loaded_primary =
true;
339 tprintf(
"Failed loading language '%s'\n", lang_str);
342 sub_langs_.push_back(tess_to_init);
345 &langs_to_load, &langs_not_to_load);
350 if (!loaded_primary) {
351 tprintf(
"Tesseract couldn't load any languages!\n");
354 #ifndef DISABLED_LEGACY_ENGINE 355 if (!sub_langs_.empty()) {
362 for (
int s = 0; s < sub_langs_.size(); ++s) {
363 sub_langs_[s]->language_model_->getParamsModel().Copy(
366 tprintf(
"Using params model of the primary language\n");
369 for (
int s = 0; s < sub_langs_.size(); ++s) {
370 sub_langs_[s]->language_model_->getParamsModel().Clear();
376 #endif // ndef DISABLED_LEGACY_ENGINE 398 char **configs,
int configs_size,
401 bool set_only_non_debug_params,
404 configs_size, vars_vec, vars_values,
405 set_only_non_debug_params, mgr)) {
419 #ifndef DISABLED_LEGACY_ENGINE 424 for (
int i = 0; i < new_fonts.
size(); ++i) {
433 for (
int i = 0; i < lang_fonts->
size(); ++i) {
434 int index = all_fonts.
get_id(lang_fonts->
get(i));
450 for (
int i = 0; i < sub_langs_.size(); ++i) {
455 for (
int i = 0; i < sub_langs_.size(); ++i) {
458 font_table_size_ = all_fonts.
size();
465 nullptr, 0,
nullptr,
nullptr,
false, mgr))
473 #endif // ndef DISABLED_LEGACY_ENGINE
const UNICHARSET & GetUnicharset() const
static DawgCache * GlobalDawgCache()
bool IsLSTMAvailable() const
char * tessedit_load_sublangs
char * tessedit_write_params_to_file
static void PrintParams(FILE *fp, const ParamsVectors *member_params)
bool GetComponent(TessdataType type, TFile *fp)
Dict & getDict() override
UnicityTable< FontInfo > & get_fontinfo_table()
void CopyFrom(const UNICHARSET &src)
int tessedit_ocr_engine_mode
const char * string() const
bool use_ambigs_for_adaption
static bool SetParam(const char *name, const char *value, SetParamConstraint constraint, ParamsVectors *member_params)
int init_tesseract_lm(const char *arg0, const char *textbase, const char *language, TessdataManager *mgr)
STRING language_data_path_prefix
_ConstTessMemberResultCallback_0_0< false, R, T1 >::base * NewPermanentTessCallback(const T1 *obj, R(T2::*member)() const)
void LoadUniversal(const UNICHARSET &encoder_set, UNICHARSET *unicharset)
ETEXT_DESC * global_monitor
bool init_tesseract_lang_data(const char *arg0, const char *textbase, const char *language, OcrEngineMode oem, char **configs, int configs_size, const GenericVector< STRING > *vars_vec, const GenericVector< STRING > *vars_values, bool set_only_init_params, TessdataManager *mgr)
bool tessedit_init_config_only
bool major_right_to_left() const
int init_tesseract(const char *arg0, const char *textbase, const char *language, OcrEngineMode oem, char **configs, int configs_size, const GenericVector< STRING > *vars_vec, const GenericVector< STRING > *vars_values, bool set_only_init_params, TessdataManager *mgr)
std::unique_ptr< LanguageModel > language_model_
void set_compare_callback(TessResultCallback2< bool, T const &, T const &> *cb)
bool CompareFontInfo(const FontInfo &fi1, const FontInfo &fi2)
bool tessedit_ambigs_training
void SetupUniversalFontIds()
int size() const
Return the size used.
bool Load(const char *lang, TessdataManager *mgr)
void ParseLanguageString(const char *lang_str, GenericVector< STRING > *to_load, GenericVector< STRING > *not_to_load)
bool Init(const char *data_file_name)
bool tessedit_use_primary_params_model
static bool ReadParamsFile(const char *file, SetParamConstraint constraint, ParamsVectors *member_params)
int get_id(T object) const
void Load(const STRING &lang, TessdataManager *data_file)
int init_tesseract_internal(const char *arg0, const char *textbase, const char *language, OcrEngineMode oem, char **configs, int configs_size, const GenericVector< STRING > *vars_vec, const GenericVector< STRING > *vars_values, bool set_only_init_params, TessdataManager *mgr)
DLLSYM void tprintf(const char *format,...)
static bool ReadParamsFromFp(SetParamConstraint constraint, TFile *fp, ParamsVectors *member_params)
void truncate_at(int32_t index)
void program_editup(const char *textbase, TessdataManager *init_classifier, TessdataManager *init_dict)
int push_back(T object)
Add an element in the table.
void SetupForLoad(DawgCache *dawg_cache)
const T & get(int id) const
Return the object from an id.
void InitUnicharAmbigs(const UNICHARSET &unicharset, bool use_ambigs_for_adaption)
void read_config_file(const char *filename, SetParamConstraint constraint)
void main_setup(const char *argv0, const char *basename)
CCUtil::main_setup - set location of tessdata and name of image.
void LoadUnicharAmbigs(const UNICHARSET &encoder_set, TFile *ambigs_file, int debug_level, bool use_ambigs_for_adaption, UNICHARSET *unicharset)
bool load_from_file(const char *const filename, bool skip_fragments)
bool IsBaseAvailable() const
UnicharAmbigs unichar_ambigs
bool IsComponentAvailable(TessdataType type) const