39 #include "config_auto.h" 44 #include "allheaders.h" 56 "Take segmentation and labeling from box file",
58 BOOL_MEMBER(tessedit_resegment_from_line_boxes, false,
59 "Conversion of word/line box file to char box file",
62 "Generate training data from boxed chars", this->params()),
64 "Generate more boxes from boxed chars", this->params()),
66 "Break input into lines and remap boxes if present",
69 "Dump intermediate images made during page segmentation",
75 "Page seg mode: 0=osd only, 1=auto+osd, 2=auto, 3=col, 4=block," 76 " 5=line, 6=word, 7=char" 77 " (Values from PageSegMode enum in publictypes.h)",
80 "Which OCR engine(s) to run (Tesseract, LSTM, both)." 81 " Defaults to loading and running the most accurate" 85 "Blacklist of chars not to recognize", this->params()),
87 "Whitelist of chars to recognize", this->params()),
89 "List of chars to override tessedit_char_blacklist",
92 "Perform training for ambiguities", this->params()),
95 "Whether to use the top-line splitting process for Devanagari " 96 "documents while performing page-segmentation.",
100 "Whether to use the top-line splitting process for Devanagari " 101 "documents while performing ocr.",
104 "Write all parameters to the given file.", this->params()),
106 "Generate and print debug" 107 " information for adaption",
109 INT_MEMBER(bidi_debug, 0,
"Debug level for BiDi", this->params()),
110 INT_MEMBER(applybox_debug, 1,
"Debug level", this->params()),
111 INT_MEMBER(applybox_page, 0,
"Page number to apply boxes from",
114 "Exposure value follows" 115 " this pattern in the image filename. The name of the image" 116 " files are expected to be in the form" 117 " [lang].[fontname].exp[num].tif",
119 BOOL_MEMBER(applybox_learn_chars_and_char_frags_mode, false,
120 "Learn both character fragments (as is done in the" 121 " special low exposure mode) as well as unfragmented" 126 " is assumed to contain ngrams. Only learn the ngrams" 127 " whose outlines overlap horizontally.",
129 BOOL_MEMBER(tessedit_display_outwords, false,
"Draw output words",
131 BOOL_MEMBER(tessedit_dump_choices, false,
"Dump char choices",
133 BOOL_MEMBER(tessedit_timing_debug, false,
"Print timing stats",
136 "Try to improve fuzzy spaces", this->params()),
138 "Don't bother with word plausibility", this->params()),
139 BOOL_MEMBER(tessedit_fix_hyphens, true,
"Crunch double hyphens?",
141 BOOL_MEMBER(tessedit_redo_xheight, true,
"Check/Correct x-height",
144 "Add words to the document dictionary", this->params()),
145 BOOL_MEMBER(tessedit_debug_fonts, false,
"Output font info per char",
147 BOOL_MEMBER(tessedit_debug_block_rejection, false,
"Block and Row stats",
149 BOOL_MEMBER(tessedit_enable_bigram_correction, true,
150 "Enable correction based on the word bigram dictionary.",
152 BOOL_MEMBER(tessedit_enable_dict_correction, false,
153 "Enable single word correction based on the dictionary.",
156 "Amount of debug output for bigram correction.",
159 "Remove and conditionally reassign small outlines when they" 160 " confuse layout analysis, determining diacritics vs noise",
162 INT_MEMBER(debug_noise_removal, 0,
"Debug reassignment of small outlines",
168 "Hingepoint for base char certainty", this->params()),
172 "Hingepoint for disjoint certainty", this->params()),
176 "Threshold for new punc char certainty", this->params()),
179 "Scaling on certainty diff from Hingepoint",
181 INT_MEMBER(noise_maxperblob, 8,
"Max diacritics to apply to a blob",
183 INT_MEMBER(noise_maxperword, 16,
"Max diacritics to apply to a word",
185 INT_MEMBER(debug_x_ht_level, 0,
"Reestimate debug", this->params()),
186 BOOL_MEMBER(debug_acceptable_wds, false,
"Dump word pass/fail chk",
188 STRING_MEMBER(chs_leading_punct,
"('`\"",
"Leading punctuation",
190 STRING_MEMBER(chs_trailing_punct1,
").,;:?!",
"1st Trailing punctuation",
192 STRING_MEMBER(chs_trailing_punct2,
")'`\"",
"2nd Trailing punctuation",
195 "good_quality_doc lte rejection limit", this->params()),
197 "good_quality_doc gte good blobs limit", this->params()),
199 "good_quality_doc lte outline error limit", this->params()),
201 "good_quality_doc gte good char limit", this->params()),
202 INT_MEMBER(quality_min_initial_alphas_reqd, 2,
"alphas in a good word",
205 "Adaptation decision algorithm for tess", this->params()),
207 "Do minimal rejection on pass 1 output", this->params()),
208 BOOL_MEMBER(tessedit_test_adaption, false,
"Test adaption criteria",
210 BOOL_MEMBER(tessedit_matcher_log, false,
"Log matcher activity",
213 "Adaptation decision algorithm for tess", this->params()),
214 BOOL_MEMBER(test_pt, false,
"Test for point", this->params()),
215 double_MEMBER(test_pt_x, 99999.99,
"xcoord", this->params()),
216 double_MEMBER(test_pt_y, 99999.99,
"ycoord", this->params()),
217 INT_MEMBER(multilang_debug_level, 0,
"Print multilang debug info.",
219 INT_MEMBER(paragraph_debug_level, 0,
"Print paragraph debug info.",
222 "Run paragraph detection on the post-text-recognition " 226 "Use ratings matrix/beam search with lstm", this->params()),
227 STRING_MEMBER(outlines_odd,
"%| ",
"Non standard number of outlines",
229 STRING_MEMBER(outlines_2,
"ij!?%\":;",
"Non standard number of outlines",
232 "Allow outline errs in unrejection?", this->params()),
234 "Reduce rejection on good docs", this->params()),
235 BOOL_MEMBER(tessedit_use_reject_spaces, true,
"Reject spaces?",
238 "%rej allowed before rej whole doc", this->params()),
240 "%rej allowed before rej whole block", this->params()),
242 "%rej allowed before rej whole row", this->params()),
244 "Number of row rejects in whole word rejects" 245 " which prevents whole row rejection",
247 BOOL_MEMBER(tessedit_preserve_blk_rej_perfect_wds, true,
248 "Only rej partially rejected words in block rejection",
250 BOOL_MEMBER(tessedit_preserve_row_rej_perfect_wds, true,
251 "Only rej partially rejected words in row rejection",
254 "Use word segmentation quality metric", this->params()),
256 "Use word segmentation quality metric", this->params()),
258 "Only preserve wds longer than this", this->params()),
260 "Apply row rejection to good docs", this->params()),
262 "rej good doc wd if more than this fraction rejected",
265 "Reject all bad quality wds", this->params()),
266 BOOL_MEMBER(tessedit_debug_doc_rejection, false,
"Page stats",
269 "Output data to debug file", this->params()),
270 BOOL_MEMBER(bland_unrej, false,
"unrej potential with no checks",
273 "good_quality_doc gte good char limit", this->params()),
275 "Mark v.bad words for tilde crunch", this->params()),
276 BOOL_MEMBER(hocr_font_info, false,
"Add font info to hocr output",
278 BOOL_MEMBER(crunch_early_merge_tess_fails, true,
"Before word crunch?",
280 BOOL_MEMBER(crunch_early_convert_bad_unlv_chs, false,
281 "Take out ~^ early?", this->params()),
282 double_MEMBER(crunch_terrible_rating, 80.0,
"crunch rating lt this",
284 BOOL_MEMBER(crunch_terrible_garbage, true,
"As it says", this->params()),
286 "crunch garbage cert lt this", this->params()),
288 "crunch garbage rating lt this", this->params()),
289 double_MEMBER(crunch_pot_poor_rate, 40,
"POTENTIAL crunch rating lt this",
291 double_MEMBER(crunch_pot_poor_cert, -8.0,
"POTENTIAL crunch cert lt this",
293 BOOL_MEMBER(crunch_pot_garbage, true,
"POTENTIAL crunch garbage",
295 double_MEMBER(crunch_del_rating, 60,
"POTENTIAL crunch rating lt this",
297 double_MEMBER(crunch_del_cert, -10.0,
"POTENTIAL crunch cert lt this",
299 double_MEMBER(crunch_del_min_ht, 0.7,
"Del if word ht lt xht x this",
301 double_MEMBER(crunch_del_max_ht, 3.0,
"Del if word ht gt xht x this",
304 "Del if word width lt xht x this", this->params()),
306 "Del if word gt xht x this above bl", this->params()),
308 "Del if word gt xht x this below bl", this->params()),
309 double_MEMBER(crunch_small_outlines_size, 0.6,
"Small if lt xht x this",
311 INT_MEMBER(crunch_rating_max, 10,
"For adj length in rating per ch",
314 "How many potential indicators needed", this->params()),
315 BOOL_MEMBER(crunch_leave_ok_strings, true,
"Don't touch sensible strings",
317 BOOL_MEMBER(crunch_accept_ok, true,
"Use acceptability in okstring",
320 "Don't pot crunch sensible strings", this->params()),
321 BOOL_MEMBER(crunch_include_numerals, false,
"Fiddle alpha figures",
324 "Don't crunch words with long lower case strings",
327 "Don't crunch words with long lower case strings",
330 "Crunch words with long repetitions", this->params()),
331 INT_MEMBER(crunch_debug, 0,
"As it says", this->params()),
333 "How many non-noise blbs either side?", this->params()),
334 double_MEMBER(fixsp_small_outlines_size, 0.28,
"Small if lt xht x this",
337 "Reward punctuation joins", this->params()),
338 INT_MEMBER(fixsp_done_mode, 1,
"What constitues done for spacing",
340 INT_MEMBER(debug_fix_space_level, 0,
"Contextual fixspace debug",
343 "Punct. chs expected WITHIN numbers", this->params()),
345 "Max allowed deviation of blob top outside of font data",
348 "Min change in xht before actually trying it", this->params()),
350 "Debug level for sub & superscript fixer", this->params()),
352 superscript_worse_certainty, 2.0,
353 "How many times worse " 354 "certainty does a superscript position glyph need to be for " 355 "us to try classifying it as a char with a different " 359 superscript_bettered_certainty, 0.97,
361 "badness do we think sufficient to choose a superscript " 362 "over what we'd thought. For example, a value of 0.6 means " 363 "we want to reduce badness of certainty by at least 40%",
366 "A superscript scaled down more than this is unbelievably " 367 "small. For example, 0.3 means we expect the font size to " 368 "be no smaller than 30% of the text line font size.",
371 "Maximum top of a character measured as a multiple of " 372 "x-height above the baseline for us to reconsider whether " 376 "Minimum bottom of a character measured as a multiple of " 377 "x-height above the baseline for us to reconsider whether " 378 "it's a superscript.",
380 BOOL_MEMBER(tessedit_write_block_separators, false,
381 "Write block separators in output", this->params()),
382 BOOL_MEMBER(tessedit_write_rep_codes, false,
"Write repetition char code",
384 BOOL_MEMBER(tessedit_write_unlv, false,
"Write .unlv output file",
386 BOOL_MEMBER(tessedit_create_txt, false,
"Write .txt output file",
388 BOOL_MEMBER(tessedit_create_hocr, false,
"Write .html hOCR output file",
390 BOOL_MEMBER(tessedit_create_tsv, false,
"Write .tsv output file",
392 BOOL_MEMBER(tessedit_create_pdf, false,
"Write .pdf output file",
395 "Create PDF with only one invisible text layer",
397 INT_MEMBER(jpg_quality, 85,
"Set JPEG quality level", this->params()),
398 INT_MEMBER(user_defined_dpi, 0,
"Specify DPI for input image",
401 "Specify minimum characters to try during OSD",
404 "Output char for unidentified blobs", this->params()),
405 INT_MEMBER(suspect_level, 99,
"Suspect marker level", this->params()),
407 "Min suspect level for rejecting spaces", this->params()),
409 "Don't suspect dict wds longer than this", this->params()),
410 BOOL_MEMBER(suspect_constrain_1Il, false,
"UNLV keep 1Il chars rejected",
413 "Don't touch bad rating limit", this->params()),
414 double_MEMBER(suspect_accept_rating, -999.9,
"Accept good rating limit",
417 "Only reject tess failures", this->params()),
418 BOOL_MEMBER(tessedit_zero_rejection, false,
"Don't reject ANYTHING",
421 "Make output have exactly one word per WERD", this->params()),
423 "Don't reject ANYTHING AT ALL", this->params()),
425 "Force all rep chars the same", this->params()),
426 INT_MEMBER(tessedit_reject_mode, 0,
"Rejection algorithm",
428 BOOL_MEMBER(tessedit_rejection_debug, false,
"Adaption debug",
430 BOOL_MEMBER(tessedit_flip_0O, true,
"Contextual 0O O0 flips",
433 "Aspect ratio dot/hyphen test", this->params()),
435 "Aspect ratio dot/hyphen test", this->params()),
437 "Use DOC dawg in 11l conf. detector", this->params()),
438 BOOL_MEMBER(rej_1Il_use_dict_word, false,
"Use dictword test",
440 BOOL_MEMBER(rej_1Il_trust_permuter_type, true,
"Don't double check",
442 BOOL_MEMBER(rej_use_tess_accepted, true,
"Individual rejection control",
444 BOOL_MEMBER(rej_use_tess_blanks, true,
"Individual rejection control",
446 BOOL_MEMBER(rej_use_good_perm, true,
"Individual rejection control",
448 BOOL_MEMBER(rej_use_sensible_wd, false,
"Extend permuter check",
450 BOOL_MEMBER(rej_alphas_in_number_perm, false,
"Extend permuter check",
453 "if >this fract", this->params()),
454 INT_MEMBER(tessedit_image_border, 2,
"Rej blbs near image edge limit",
457 "Allow NN to unrej", this->params()),
458 STRING_MEMBER(conflict_set_I_l_1,
"Il1[]",
"Il1 conflict set",
460 INT_MEMBER(min_sane_x_ht_pixels, 8,
"Reject any x-ht lt or eq than this",
462 BOOL_MEMBER(tessedit_create_boxfile, false,
"Output text with boxes",
466 " , else specific page to process",
469 "Capture the image from the IPE", this->params()),
470 BOOL_MEMBER(interactive_display_mode, false,
"Run interactively?",
472 STRING_MEMBER(file_type,
".tif",
"Filename extension", this->params()),
473 BOOL_MEMBER(tessedit_override_permuter, true,
"According to dict_word",
476 "List of languages to load with this one", this->params()),
477 BOOL_MEMBER(tessedit_use_primary_params_model, false,
478 "In multilingual mode use params model of the" 482 "Min acceptable orientation margin", this->params()),
483 BOOL_MEMBER(textord_tabfind_show_vlines, false,
"Debug line finding",
488 "Allow feature extractors to see the original outline",
491 "Only initialize with the config file. Useful if the " 492 "instance is not going to be used for OCR but say only " 493 "for layout analysis.",
495 BOOL_MEMBER(textord_equation_detect, false,
"Turn on equation detector",
498 "Enable vertical detection", this->params()),
499 BOOL_MEMBER(textord_tabfind_force_vertical_text, false,
500 "Force using vertical text page mode", this->params()),
502 textord_tabfind_vertical_text_ratio, 0.5,
503 "Fraction of textlines deemed vertical to use vertical page " 507 textord_tabfind_aligned_gap_fraction, 0.75,
508 "Fraction of height used as a minimum gap for aligned blobs.",
510 INT_MEMBER(tessedit_parallelize, 0,
"Run in parallel where possible",
513 "Preserve multiple interword spaces", this->params()),
515 "Page separator (default is form feed control character)",
518 "Allows to include alternative symbols choices in the hOCR output. " 519 "Valid input values are 0, 1 and 2. 0 is the default value. " 520 "With 1 the alternative symbol choices per timestep are included. " 521 "With 2 the alternative symbol choices are accumulated per character.",
524 backup_config_file_(nullptr),
525 pix_binary_(nullptr),
527 pix_original_(nullptr),
528 pix_thresholds_(nullptr),
529 source_resolution_(0),
531 right_to_left_(false),
532 scaled_color_(nullptr),
536 most_recently_used_(this),
538 equ_detect_(nullptr),
539 #ifndef ANDROID_BUILD
540 lstm_recognizer_(nullptr),
542 train_line_page_num_(0) {
547 pixDestroy(&pix_original_);
549 sub_langs_.delete_data_pointers();
550 #ifndef ANDROID_BUILD 551 delete lstm_recognizer_;
552 lstm_recognizer_ =
nullptr;
560 if (lstm_recognizer_ && lstm_recognizer_->
GetDict())
562 return *
const_cast<Dict*
>(lstm_recognizer_->
GetDict());
572 pixDestroy(&pix_binary_);
573 pixDestroy(&pix_grey_);
574 pixDestroy(&pix_thresholds_);
575 pixDestroy(&scaled_color_);
576 deskew_ =
FCOORD(1.0f, 0.0f);
577 reskew_ =
FCOORD(1.0f, 0.0f);
580 for (
int i = 0; i < sub_langs_.size(); ++i)
581 sub_langs_[i]->
Clear();
584 #ifndef DISABLED_LEGACY_ENGINE 587 equ_detect_ = detector;
594 for (
int i = 0; i < sub_langs_.size(); ++i) {
595 sub_langs_[i]->ResetAdaptiveClassifierInternal();
599 #endif //ndef DISABLED_LEGACY_ENGINE 604 for (
int i = 0; i < sub_langs_.size(); ++i) {
605 sub_langs_[i]->getDict().ResetDocumentDictionary();
615 for (
int i = 0; i < sub_langs_.size(); ++i) {
616 sub_langs_[i]->unicharset.set_black_and_whitelist(
630 for (
int i = 0; i < sub_langs_.size(); ++i) {
633 static_cast<int32_t
>(sub_langs_[i]->pageseg_devanagari_split_strategy));
634 if (pageseg_strategy > max_pageseg_strategy)
635 max_pageseg_strategy = pageseg_strategy;
636 pixDestroy(&sub_langs_[i]->pix_binary_);
637 sub_langs_[i]->pix_binary_ = pixClone(
pix_binary());
643 if (splitter_.
Split(
true, &pixa_debug_)) {
645 pixDestroy(&pix_binary_);
661 for (
int i = 0; i < sub_langs_.size(); ++i) {
664 static_cast<int32_t
>(sub_langs_[i]->ocr_devanagari_split_strategy));
665 if (ocr_strategy > max_ocr_strategy)
666 max_ocr_strategy = ocr_strategy;
672 bool split_for_ocr = splitter_.
Split(
false, &pixa_debug_);
675 pixDestroy(&pix_binary_);
676 pix_binary_ = pixClone(splitter_.
orig_pix());
681 BLOCK block(
"",
TRUE, 0, 0, 0, 0, pixGetWidth(pix_binary_),
682 pixGetHeight(pix_binary_));
char * tessedit_char_whitelist
#define STRING_MEMBER(name, val, comment, vec)
void PrepareForTessOCR(BLOCK_LIST *block_list, Tesseract *osd_tess, OSResults *osr)
void ResetDocumentDictionary()
Assume a single uniform block of text. (Default.)
Dict & getDict() override
const char * string() const
char * tessedit_char_unblacklist
void RefreshSegmentationWithNewBlobs(C_BLOB_LIST *new_blobs)
void SetLangTesseract(Tesseract *lang_tesseract)
#define BOOL_INIT_MEMBER(name, val, comment, vec)
void set_black_and_whitelist(const char *blacklist, const char *whitelist, const char *unblacklist)
#define INT_MEMBER(name, val, comment, vec)
C_BLOB_LIST * blob_list()
get blobs
const Dict * GetDict() const
#define INT_INIT_MEMBER(name, val, comment, vec)
int pageseg_devanagari_split_strategy
#define BOOL_MEMBER(name, val, comment, vec)
#define double_MEMBER(name, val, comment, vec)
void SetEquationDetect(EquationDetect *detector)
bool HasDifferentSplitStrategies() const
char * tessedit_char_blacklist
void WritePDF(const char *filename)
void ResetAdaptiveClassifier()
bool textord_use_cjk_fp_model
void set_orig_pix(Pix *pix)
void ResetDocumentDictionary()
void ResetAdaptiveClassifierInternal()
void set_pageseg_split_strategy(SplitStrategy strategy)
bool Split(bool split_for_pageseg, DebugPixa *pixa_debug)
int ocr_devanagari_split_strategy
void SetBlackAndWhitelist()
void set_use_cjk_fp_model(bool flag)
void set_ocr_split_strategy(SplitStrategy strategy)
void extract_edges(Pix *pix, BLOCK *block)
void set_segmentation_block_list(BLOCK_LIST *block_list)