46 #define VARDIR "configs/" 48 #define API_CONFIG "configs/api_config" 63 if ((fp = fopen(path.
string(),
"rb")) != NULL) {
67 path +=
"tessconfigs/";
69 if ((fp = fopen(path.
string(),
"rb")) != NULL) {
89 const char *arg0,
const char *textbase,
const char *language,
93 bool set_only_non_debug_params) {
98 lang = language != NULL ? language :
"eng";
117 tprintf(
"Loaded language config file\n");
126 for (
int i = 0; i < configs_size; ++i) {
132 if (vars_vec != NULL && vars_values != NULL) {
133 for (
int i = 0; i < vars_vec->
size(); ++i) {
135 (*vars_values)[i].
string(),
136 set_params_constraint, this->
params())) {
137 tprintf(
"Error setting param %s\n", (*vars_vec)[i].
string());
145 if (params_file != NULL) {
149 tprintf(
"Wrote parameters to %s\n",
153 tprintf(
"Failed to open %s for writing params.\n",
161 tprintf(
"Loading Tesseract/Cube with tessedit_ocr_engine_mode %d\n",
169 tprintf(
"Returning after loading config file\n");
180 tprintf(
"Error: Size of unicharset is greater than MAX_NUM_CLASSES\n");
208 #ifndef NO_CUBE_BUILD 212 tprintf(
"Loaded Cube w/out combiner\n");
216 tprintf(
"Loaded Cube with combiner\n");
225 static_cast<ParamsModel::PassEnum>(p));
240 static bool IsStrInList(
const STRING& str,
242 for (
int i = 0; i < str_list.
size(); ++i) {
243 if (str_list[i] == str)
258 while (remains.
length() > 0) {
260 const char* start = remains.
string();
261 while (*start ==
'+')
265 target = not_to_load;
269 int end = strlen(start);
270 const char* plus = strchr(start,
'+');
271 if (plus != NULL && plus - start < end)
278 if (!IsStrInList(lang_code, *target)) {
280 tprintf(
"Adding language '%s' to list\n", lang_code.
string());
291 const char *arg0,
const char *textbase,
const char *language,
295 bool set_only_non_debug_params) {
300 sub_langs_.delete_data_pointers();
304 bool loaded_primary =
false;
306 for (
int lang_index = 0; lang_index < langs_to_load.
size(); ++lang_index) {
307 if (!IsStrInList(langs_to_load[lang_index], langs_not_to_load)) {
308 const char *lang_str = langs_to_load[lang_index].string();
310 if (!loaded_primary) {
317 arg0, textbase, lang_str, oem, configs, configs_size,
318 vars_vec, vars_values, set_only_non_debug_params);
320 if (!loaded_primary) {
322 tprintf(
"Failed loading language '%s'\n", lang_str);
325 tprintf(
"Loaded language '%s' as main language\n", lang_str);
327 &langs_to_load, &langs_not_to_load);
328 loaded_primary =
true;
332 tprintf(
"Failed loading language '%s'\n", lang_str);
336 tprintf(
"Loaded language '%s' as secondary language\n", lang_str);
337 sub_langs_.push_back(tess_to_init);
340 &langs_to_load, &langs_not_to_load);
345 if (!loaded_primary) {
346 tprintf(
"Tesseract couldn't load any languages!\n");
349 if (!sub_langs_.empty()) {
356 for (
int s = 0; s < sub_langs_.size(); ++s) {
357 sub_langs_[s]->language_model_->getParamsModel().Copy(
360 tprintf(
"Using params model of the primary language\n");
366 for (
int s = 0; s < sub_langs_.size(); ++s) {
367 sub_langs_[s]->language_model_->getParamsModel().Clear();
370 tprintf(
"Using default language params\n");
395 const char *arg0,
const char *textbase,
const char *language,
399 bool set_only_non_debug_params) {
401 configs_size, vars_vec, vars_values,
402 set_only_non_debug_params)) {
411 bool init_tesseract_classifier =
427 for (
int i = 0; i < new_fonts.
size(); ++i) {
436 for (
int i = 0; i < lang_fonts->
size(); ++i) {
437 int index = all_fonts.
get_id(lang_fonts->
get(i));
453 for (
int i = 0; i < sub_langs_.size(); ++i) {
458 for (
int i = 0; i < sub_langs_.size(); ++i) {
461 font_table_size_ = all_fonts.
size();
466 const char *textbase,
467 const char *language) {
469 NULL, 0, NULL, NULL,
false))
bool init_cube_objects(bool load_combiner, TessdataManager *tessdata_manager)
void InitUnicharAmbigs(const UNICHARSET &unicharset, bool use_ambigs_for_adaption)
inT64 GetEndOffset(TessdataType tessdata_type) const
FILE * GetDataFilePtr() const
int tessedit_ocr_engine_mode
char * tessedit_write_params_to_file
int init_tesseract_lm(const char *arg0, const char *textbase, const char *language)
_ConstTessMemberResultCallback_0_0< false, R, T1 >::base * NewPermanentTessCallback(const T1 *obj, R(T2::*member)() const)
ParamsModel & getParamsModel()
const STRING & GetDataFileName() const
bool use_ambigs_for_adaption
char * tessedit_load_sublangs
void LoadUniversal(const UNICHARSET &encoder_set, UNICHARSET *unicharset)
bool Open(const STRING &filename, FileReader reader)
void Load(const char *data_file_name, const STRING &lang)
void SetPass(PassEnum pass)
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)
ETEXT_DESC * global_monitor
void read_config_file(const char *filename, SetParamConstraint constraint)
bool tessedit_init_config_only
void SetupForLoad(DawgCache *dawg_cache)
UnicharAmbigs unichar_ambigs
void set_compare_callback(TessResultCallback2< bool, T const &, T const &> *cb)
TessdataManager tessdata_manager
void SetupUniversalFontIds()
int size() const
Return the size used.
void truncate_at(inT32 index)
const char * string() const
bool Init(const char *data_file_name, int debug_level)
bool tessedit_ambigs_training
bool LoadFromFp(const char *lang, FILE *fp, inT64 end_offset)
bool major_right_to_left() const
bool tessedit_use_primary_params_model
bool load_from_file(const char *const filename, bool skip_fragments)
void program_editup(const char *textbase, bool init_classifier, bool init_permute)
static bool SetParam(const char *name, const char *value, SetParamConstraint constraint, ParamsVectors *member_params)
LanguageModel * language_model_
void ParseLanguageString(const char *lang_str, GenericVector< STRING > *to_load, GenericVector< STRING > *not_to_load)
static bool ReadParamsFromFp(FILE *fp, inT64 end_offset, SetParamConstraint constraint, ParamsVectors *member_params)
void CopyFrom(const UNICHARSET &src)
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)
static bool TESS_API ReadParamsFile(const char *file, SetParamConstraint constraint, ParamsVectors *member_params)
STRING language_data_path_prefix
bool CompareFontInfo(const FontInfo &fi1, const FontInfo &fi2)
bool SeekToStart(TessdataType tessdata_type)
int tessdata_manager_debug_level
static DawgCache * GlobalDawgCache()
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)
const T & get(int id) const
Return the object from an id.
UnicityTable< FontInfo > & get_fontinfo_table()
static void PrintParams(FILE *fp, const ParamsVectors *member_params)
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)
int get_id(T object) const
int push_back(T object)
Add an element in the table.