41 #define VARDIR "configs/"
43 #define API_CONFIG "configs/api_config"
58 if ((fp = fopen(path.
string(),
"rb")) !=
NULL) {
62 path +=
"tessconfigs/";
64 if ((fp = fopen(path.
string(),
"rb")) !=
NULL) {
84 const char *arg0,
const char *textbase,
const char *language,
88 bool set_only_non_debug_params) {
93 lang = language !=
NULL ? language :
"eng";
112 tprintf(
"Loaded language config file\n");
121 for (
int i = 0; i < configs_size; ++i) {
127 if (vars_vec !=
NULL && vars_values !=
NULL) {
128 for (
int i = 0; i < vars_vec->
size(); ++i) {
130 (*vars_values)[i].
string(),
131 set_params_constraint, this->
params())) {
132 tprintf(
"Error setting param %s\n", (*vars_vec)[i].
string());
139 FILE *params_file = fopen(tessedit_write_params_to_file.
string(),
"wb");
140 if (params_file !=
NULL) {
144 tprintf(
"Wrote parameters to %s\n",
145 tessedit_write_params_to_file.
string());
148 tprintf(
"Failed to open %s for writing params.\n",
149 tessedit_write_params_to_file.
string());
156 tprintf(
"Loading Tesseract/Cube with tessedit_ocr_engine_mode %d\n",
164 tprintf(
"Returning after loading config file\n");
175 tprintf(
"Error: Size of unicharset is greater than MAX_NUM_CLASSES\n");
203 #ifndef ANDROID_BUILD
207 tprintf(
"Loaded Cube w/out combiner\n");
211 tprintf(
"Loaded Cube with combiner\n");
220 static_cast<ParamsModel::PassEnum>(p));
235 static bool IsStrInList(
const STRING& str,
237 for (
int i = 0; i < str_list.
size(); ++i) {
238 if (str_list[i] == str)
253 while (remains.
length() > 0) {
255 const char* start = remains.
string();
256 while (*start ==
'+')
260 target = not_to_load;
264 int end = strlen(start);
265 const char* plus = strchr(start,
'+');
266 if (plus !=
NULL && plus - start < end)
273 if (!IsStrInList(lang_code, *target)) {
275 tprintf(
"Adding language '%s' to list\n", lang_code.
string());
286 const char *arg0,
const char *textbase,
const char *language,
290 bool set_only_non_debug_params) {
295 sub_langs_.delete_data_pointers();
299 bool loaded_primary =
false;
301 for (
int lang_index = 0; lang_index < langs_to_load.
size(); ++lang_index) {
302 if (!IsStrInList(langs_to_load[lang_index], langs_not_to_load)) {
303 const char *lang_str = langs_to_load[lang_index].string();
305 if (!loaded_primary) {
312 arg0, textbase, lang_str, oem, configs, configs_size,
313 vars_vec, vars_values, set_only_non_debug_params);
315 if (!loaded_primary) {
317 tprintf(
"Failed loading language '%s'\n", lang_str);
320 tprintf(
"Loaded language '%s' as main language\n", lang_str);
322 &langs_to_load, &langs_not_to_load);
323 loaded_primary =
true;
327 tprintf(
"Failed loading language '%s'\n", lang_str);
331 tprintf(
"Loaded language '%s' as secondary language\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 if (!sub_langs_.empty()) {
351 for (
int s = 0; s < sub_langs_.size(); ++s) {
352 sub_langs_[s]->language_model_->getParamsModel().Copy(
355 tprintf(
"Using params model of the primary language\n");
361 for (
int s = 0; s < sub_langs_.size(); ++s) {
362 sub_langs_[s]->language_model_->getParamsModel().Clear();
365 tprintf(
"Using default language params\n");
390 const char *arg0,
const char *textbase,
const char *language,
394 bool set_only_non_debug_params) {
396 configs_size, vars_vec, vars_values,
397 set_only_non_debug_params)) {
406 bool init_tesseract_classifier =
422 for (
int i = 0; i < new_fonts.
size(); ++i) {
431 for (
int i = 0; i < lang_fonts->
size(); ++i) {
432 int index = all_fonts.
get_id(lang_fonts->
get(i));
448 for (
int i = 0; i < sub_langs_.size(); ++i) {
453 for (
int i = 0; i < sub_langs_.size(); ++i) {
456 font_table_size_ = all_fonts.
size();
461 const char *textbase,
462 const char *language) {
FILE * GetDataFilePtr() const
void set_compare_callback(TessResultCallback2< bool, T const &, T const & > *cb)
bool major_right_to_left() const
static bool ReadParamsFromFp(FILE *fp, inT64 end_offset, SetParamConstraint constraint, ParamsVectors *member_params)
ETEXT_DESC * global_monitor
bool LoadFromFp(const char *lang, FILE *fp, inT64 end_offset)
char * tessedit_write_params_to_file
static void PrintParams(FILE *fp, const ParamsVectors *member_params)
inT64 GetEndOffset(TessdataType tessdata_type) const
bool load_from_file(const char *const filename, bool skip_fragments)
TessdataManager tessdata_manager
UnicharAmbigs unichar_ambigs
bool CompareFontInfo(const FontInfo &fi1, const FontInfo &fi2)
void LoadUniversal(const UNICHARSET &encoder_set, UNICHARSET *unicharset)
void ParseLanguageString(const char *lang_str, GenericVector< STRING > *to_load, GenericVector< STRING > *not_to_load)
static DawgCache * GlobalDawgCache()
void InitUnicharAmbigs(const UNICHARSET &unicharset, bool use_ambigs_for_adaption)
LanguageModel * language_model_
void LoadUnicharAmbigs(const UNICHARSET &encoder_set, TFile *ambigs_file, int debug_level, bool use_ambigs_for_adaption, UNICHARSET *unicharset)
void truncate_at(inT32 index)
void read_config_file(const char *filename, SetParamConstraint constraint)
int tessedit_ocr_engine_mode
bool Open(const STRING &filename, FileReader reader)
int push_back(T object)
Add an element in the table.
bool init_cube_objects(bool load_combiner, TessdataManager *tessdata_manager)
static bool SetParam(const char *name, const char *value, SetParamConstraint constraint, ParamsVectors *member_params)
_ConstTessMemberResultCallback_0_0< false, R, T1 >::base * NewPermanentTessCallback(const T1 *obj, R(T2::*member)() const)
bool tessedit_ambigs_training
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)
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)
int tessdata_manager_debug_level
STRING language_data_path_prefix
UnicityTable< FontInfo > & get_fontinfo_table()
char * tessedit_load_sublangs
bool tessedit_use_primary_params_model
const T & get(int id) const
Return the object from an id.
void Load(DawgCache *dawg_cache)
void program_editup(const char *textbase, bool init_classifier, bool init_permute)
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)
bool SeekToStart(TessdataType tessdata_type)
void main_setup(const char *argv0, const char *basename)
CCUtil::main_setup - set location of tessdata and name of image.
int size() const
Return the size used.
ParamsModel & getParamsModel()
bool tessedit_init_config_only
bool Init(const char *data_file_name, int debug_level)
void SetupUniversalFontIds()
static bool ReadParamsFile(const char *file, SetParamConstraint constraint, ParamsVectors *member_params)
void SetPass(PassEnum pass)
bool use_ambigs_for_adaption
const char * string() const
void CopyFrom(const UNICHARSET &src)
int get_id(T object) const
int init_tesseract_lm(const char *arg0, const char *textbase, const char *language)