All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
tesseractclass.cpp
Go to the documentation of this file.
1 // File: tesseractclass.cpp
3 // Description: The Tesseract class. It holds/owns everything needed
4 // to run Tesseract on a single language, and also a set of
5 // sub-Tesseracts to run sub-languages. For thread safety, *every*
6 // variable that was previously global or static (except for
7 // constant data, and some visual debugging flags) has been moved
8 // in here, directly, or indirectly.
9 // This makes it safe to run multiple Tesseracts in different
10 // threads in parallel, and keeps the different language
11 // instances separate.
12 // Some global functions remain, but they are isolated re-entrant
13 // functions that operate on their arguments. Functions that work
14 // on variable data have been moved to an appropriate class based
15 // mostly on the directory hierarchy. For more information see
16 // slide 6 of "2ArchitectureAndDataStructures" in
17 // https://drive.google.com/file/d/0B7l10Bj_LprhbUlIUFlCdGtDYkE/edit?usp=sharing
18 // Some global data and related functions still exist in the
19 // training-related code, but they don't interfere with normal
20 // recognition operation.
21 // Author: Ray Smith
22 // Created: Fri Mar 07 08:17:01 PST 2008
23 //
24 // (C) Copyright 2008, Google Inc.
25 // Licensed under the Apache License, Version 2.0 (the "License");
26 // you may not use this file except in compliance with the License.
27 // You may obtain a copy of the License at
28 // http://www.apache.org/licenses/LICENSE-2.0
29 // Unless required by applicable law or agreed to in writing, software
30 // distributed under the License is distributed on an "AS IS" BASIS,
31 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
32 // See the License for the specific language governing permissions and
33 // limitations under the License.
34 //
36 
37 #include "tesseractclass.h"
38 
39 #include "allheaders.h"
40 #ifndef ANDROID_BUILD
41 #include "cube_reco_context.h"
42 #endif
43 #include "edgblob.h"
44 #include "equationdetect.h"
45 #include "globals.h"
46 #ifndef ANDROID_BUILD
48 #endif
49 
50 // Include automatically generated configuration file if running autoconf.
51 #ifdef HAVE_CONFIG_H
52 #include "config_auto.h"
53 #endif
54 
55 namespace tesseract {
56 
58  : BOOL_MEMBER(tessedit_resegment_from_boxes, false,
59  "Take segmentation and labeling from box file",
60  this->params()),
61  BOOL_MEMBER(tessedit_resegment_from_line_boxes, false,
62  "Conversion of word/line box file to char box file",
63  this->params()),
64  BOOL_MEMBER(tessedit_train_from_boxes, false,
65  "Generate training data from boxed chars", this->params()),
66  BOOL_MEMBER(tessedit_make_boxes_from_boxes, false,
67  "Generate more boxes from boxed chars", this->params()),
68  BOOL_MEMBER(tessedit_dump_pageseg_images, false,
69  "Dump intermediate images made during page segmentation",
70  this->params()),
71  // The default for pageseg_mode is the old behaviour, so as not to
72  // upset anything that relies on that.
73  INT_MEMBER(
74  tessedit_pageseg_mode, PSM_SINGLE_BLOCK,
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)",
78  this->params()),
79  INT_INIT_MEMBER(tessedit_ocr_engine_mode, tesseract::OEM_TESSERACT_ONLY,
80  "Which OCR engine(s) to run (Tesseract, Cube, both)."
81  " Defaults to loading and running only Tesseract"
82  " (no Cube,no combiner)."
83  " Values from OcrEngineMode enum in tesseractclass.h)",
84  this->params()),
85  STRING_MEMBER(tessedit_char_blacklist, "",
86  "Blacklist of chars not to recognize", this->params()),
87  STRING_MEMBER(tessedit_char_whitelist, "",
88  "Whitelist of chars to recognize", this->params()),
89  STRING_MEMBER(tessedit_char_unblacklist, "",
90  "List of chars to override tessedit_char_blacklist",
91  this->params()),
92  BOOL_MEMBER(tessedit_ambigs_training, false,
93  "Perform training for ambiguities", this->params()),
94  INT_MEMBER(pageseg_devanagari_split_strategy,
95  tesseract::ShiroRekhaSplitter::NO_SPLIT,
96  "Whether to use the top-line splitting process for Devanagari "
97  "documents while performing page-segmentation.",
98  this->params()),
99  INT_MEMBER(ocr_devanagari_split_strategy,
100  tesseract::ShiroRekhaSplitter::NO_SPLIT,
101  "Whether to use the top-line splitting process for Devanagari "
102  "documents while performing ocr.",
103  this->params()),
104  STRING_MEMBER(tessedit_write_params_to_file, "",
105  "Write all parameters to the given file.", this->params()),
106  BOOL_MEMBER(tessedit_adaption_debug, false,
107  "Generate and print debug"
108  " information for adaption",
109  this->params()),
110  INT_MEMBER(bidi_debug, 0, "Debug level for BiDi", this->params()),
111  INT_MEMBER(applybox_debug, 1, "Debug level", this->params()),
112  INT_MEMBER(applybox_page, 0, "Page number to apply boxes from",
113  this->params()),
114  STRING_MEMBER(applybox_exposure_pattern, ".exp",
115  "Exposure value follows"
116  " this pattern in the image filename. The name of the image"
117  " files are expected to be in the form"
118  " [lang].[fontname].exp[num].tif",
119  this->params()),
120  BOOL_MEMBER(applybox_learn_chars_and_char_frags_mode, false,
121  "Learn both character fragments (as is done in the"
122  " special low exposure mode) as well as unfragmented"
123  " characters.",
124  this->params()),
125  BOOL_MEMBER(applybox_learn_ngrams_mode, false,
126  "Each bounding box"
127  " is assumed to contain ngrams. Only learn the ngrams"
128  " whose outlines overlap horizontally.",
129  this->params()),
130  BOOL_MEMBER(tessedit_display_outwords, false, "Draw output words",
131  this->params()),
132  BOOL_MEMBER(tessedit_dump_choices, false, "Dump char choices",
133  this->params()),
134  BOOL_MEMBER(tessedit_timing_debug, false, "Print timing stats",
135  this->params()),
136  BOOL_MEMBER(tessedit_fix_fuzzy_spaces, true,
137  "Try to improve fuzzy spaces", this->params()),
138  BOOL_MEMBER(tessedit_unrej_any_wd, false,
139  "Dont bother with word plausibility", this->params()),
140  BOOL_MEMBER(tessedit_fix_hyphens, true, "Crunch double hyphens?",
141  this->params()),
142  BOOL_MEMBER(tessedit_redo_xheight, true, "Check/Correct x-height",
143  this->params()),
144  BOOL_MEMBER(tessedit_enable_doc_dict, true,
145  "Add words to the document dictionary", this->params()),
146  BOOL_MEMBER(tessedit_debug_fonts, false, "Output font info per char",
147  this->params()),
148  BOOL_MEMBER(tessedit_debug_block_rejection, false, "Block and Row stats",
149  this->params()),
150  BOOL_MEMBER(tessedit_enable_bigram_correction, true,
151  "Enable correction based on the word bigram dictionary.",
152  this->params()),
153  BOOL_MEMBER(tessedit_enable_dict_correction, false,
154  "Enable single word correction based on the dictionary.",
155  this->params()),
156  INT_MEMBER(tessedit_bigram_debug, 0,
157  "Amount of debug output for bigram correction.",
158  this->params()),
159  BOOL_MEMBER(enable_noise_removal, true,
160  "Remove and conditionally reassign small outlines when they"
161  " confuse layout analysis, determining diacritics vs noise",
162  this->params()),
163  INT_MEMBER(debug_noise_removal, 0, "Debug reassignment of small outlines",
164  this->params()),
165  // Worst (min) certainty, for which a diacritic is allowed to make the
166  // base
167  // character worse and still be included.
168  double_MEMBER(noise_cert_basechar, -8.0,
169  "Hingepoint for base char certainty", this->params()),
170  // Worst (min) certainty, for which a non-overlapping diacritic is allowed
171  // to make the base character worse and still be included.
172  double_MEMBER(noise_cert_disjoint, -1.0,
173  "Hingepoint for disjoint certainty", this->params()),
174  // Worst (min) certainty, for which a diacritic is allowed to make a new
175  // stand-alone blob.
176  double_MEMBER(noise_cert_punc, -3.0,
177  "Threshold for new punc char certainty", this->params()),
178  // Factor of certainty margin for adding diacritics to not count as worse.
179  double_MEMBER(noise_cert_factor, 0.375,
180  "Scaling on certainty diff from Hingepoint",
181  this->params()),
182  INT_MEMBER(noise_maxperblob, 8, "Max diacritics to apply to a blob",
183  this->params()),
184  INT_MEMBER(noise_maxperword, 16, "Max diacritics to apply to a word",
185  this->params()),
186  INT_MEMBER(debug_x_ht_level, 0, "Reestimate debug", this->params()),
187  BOOL_MEMBER(debug_acceptable_wds, false, "Dump word pass/fail chk",
188  this->params()),
189  STRING_MEMBER(chs_leading_punct, "('`\"", "Leading punctuation",
190  this->params()),
191  STRING_MEMBER(chs_trailing_punct1, ").,;:?!", "1st Trailing punctuation",
192  this->params()),
193  STRING_MEMBER(chs_trailing_punct2, ")'`\"", "2nd Trailing punctuation",
194  this->params()),
195  double_MEMBER(quality_rej_pc, 0.08,
196  "good_quality_doc lte rejection limit", this->params()),
197  double_MEMBER(quality_blob_pc, 0.0,
198  "good_quality_doc gte good blobs limit", this->params()),
199  double_MEMBER(quality_outline_pc, 1.0,
200  "good_quality_doc lte outline error limit", this->params()),
201  double_MEMBER(quality_char_pc, 0.95,
202  "good_quality_doc gte good char limit", this->params()),
203  INT_MEMBER(quality_min_initial_alphas_reqd, 2, "alphas in a good word",
204  this->params()),
205  INT_MEMBER(tessedit_tess_adaption_mode, 0x27,
206  "Adaptation decision algorithm for tess", this->params()),
207  BOOL_MEMBER(tessedit_minimal_rej_pass1, false,
208  "Do minimal rejection on pass 1 output", this->params()),
209  BOOL_MEMBER(tessedit_test_adaption, false, "Test adaption criteria",
210  this->params()),
211  BOOL_MEMBER(tessedit_matcher_log, false, "Log matcher activity",
212  this->params()),
213  INT_MEMBER(tessedit_test_adaption_mode, 3,
214  "Adaptation decision algorithm for tess", this->params()),
215  BOOL_MEMBER(test_pt, false, "Test for point", this->params()),
216  double_MEMBER(test_pt_x, 99999.99, "xcoord", this->params()),
217  double_MEMBER(test_pt_y, 99999.99, "ycoord", this->params()),
218  INT_MEMBER(paragraph_debug_level, 0, "Print paragraph debug info.",
219  this->params()),
220  BOOL_MEMBER(paragraph_text_based, true,
221  "Run paragraph detection on the post-text-recognition "
222  "(more accurate)",
223  this->params()),
224  INT_MEMBER(cube_debug_level, 0, "Print cube debug info.", this->params()),
225  STRING_MEMBER(outlines_odd, "%| ", "Non standard number of outlines",
226  this->params()),
227  STRING_MEMBER(outlines_2, "ij!?%\":;", "Non standard number of outlines",
228  this->params()),
229  BOOL_MEMBER(docqual_excuse_outline_errs, false,
230  "Allow outline errs in unrejection?", this->params()),
231  BOOL_MEMBER(tessedit_good_quality_unrej, true,
232  "Reduce rejection on good docs", this->params()),
233  BOOL_MEMBER(tessedit_use_reject_spaces, true, "Reject spaces?",
234  this->params()),
235  double_MEMBER(tessedit_reject_doc_percent, 65.00,
236  "%rej allowed before rej whole doc", this->params()),
237  double_MEMBER(tessedit_reject_block_percent, 45.00,
238  "%rej allowed before rej whole block", this->params()),
239  double_MEMBER(tessedit_reject_row_percent, 40.00,
240  "%rej allowed before rej whole row", this->params()),
241  double_MEMBER(tessedit_whole_wd_rej_row_percent, 70.00,
242  "Number of row rejects in whole word rejects"
243  "which prevents whole row rejection",
244  this->params()),
245  BOOL_MEMBER(tessedit_preserve_blk_rej_perfect_wds, true,
246  "Only rej partially rejected words in block rejection",
247  this->params()),
248  BOOL_MEMBER(tessedit_preserve_row_rej_perfect_wds, true,
249  "Only rej partially rejected words in row rejection",
250  this->params()),
251  BOOL_MEMBER(tessedit_dont_blkrej_good_wds, false,
252  "Use word segmentation quality metric", this->params()),
253  BOOL_MEMBER(tessedit_dont_rowrej_good_wds, false,
254  "Use word segmentation quality metric", this->params()),
255  INT_MEMBER(tessedit_preserve_min_wd_len, 2,
256  "Only preserve wds longer than this", this->params()),
257  BOOL_MEMBER(tessedit_row_rej_good_docs, true,
258  "Apply row rejection to good docs", this->params()),
259  double_MEMBER(tessedit_good_doc_still_rowrej_wd, 1.1,
260  "rej good doc wd if more than this fraction rejected",
261  this->params()),
262  BOOL_MEMBER(tessedit_reject_bad_qual_wds, true,
263  "Reject all bad quality wds", this->params()),
264  BOOL_MEMBER(tessedit_debug_doc_rejection, false, "Page stats",
265  this->params()),
266  BOOL_MEMBER(tessedit_debug_quality_metrics, false,
267  "Output data to debug file", this->params()),
268  BOOL_MEMBER(bland_unrej, false, "unrej potential with no chekcs",
269  this->params()),
270  double_MEMBER(quality_rowrej_pc, 1.1,
271  "good_quality_doc gte good char limit", this->params()),
272  BOOL_MEMBER(unlv_tilde_crunching, true,
273  "Mark v.bad words for tilde crunch", this->params()),
274  BOOL_MEMBER(hocr_font_info, false, "Add font info to hocr output",
275  this->params()),
276  BOOL_MEMBER(crunch_early_merge_tess_fails, true, "Before word crunch?",
277  this->params()),
278  BOOL_MEMBER(crunch_early_convert_bad_unlv_chs, false,
279  "Take out ~^ early?", this->params()),
280  double_MEMBER(crunch_terrible_rating, 80.0, "crunch rating lt this",
281  this->params()),
282  BOOL_MEMBER(crunch_terrible_garbage, true, "As it says", this->params()),
283  double_MEMBER(crunch_poor_garbage_cert, -9.0,
284  "crunch garbage cert lt this", this->params()),
285  double_MEMBER(crunch_poor_garbage_rate, 60,
286  "crunch garbage rating lt this", this->params()),
287  double_MEMBER(crunch_pot_poor_rate, 40, "POTENTIAL crunch rating lt this",
288  this->params()),
289  double_MEMBER(crunch_pot_poor_cert, -8.0, "POTENTIAL crunch cert lt this",
290  this->params()),
291  BOOL_MEMBER(crunch_pot_garbage, true, "POTENTIAL crunch garbage",
292  this->params()),
293  double_MEMBER(crunch_del_rating, 60, "POTENTIAL crunch rating lt this",
294  this->params()),
295  double_MEMBER(crunch_del_cert, -10.0, "POTENTIAL crunch cert lt this",
296  this->params()),
297  double_MEMBER(crunch_del_min_ht, 0.7, "Del if word ht lt xht x this",
298  this->params()),
299  double_MEMBER(crunch_del_max_ht, 3.0, "Del if word ht gt xht x this",
300  this->params()),
301  double_MEMBER(crunch_del_min_width, 3.0,
302  "Del if word width lt xht x this", this->params()),
303  double_MEMBER(crunch_del_high_word, 1.5,
304  "Del if word gt xht x this above bl", this->params()),
305  double_MEMBER(crunch_del_low_word, 0.5,
306  "Del if word gt xht x this below bl", this->params()),
307  double_MEMBER(crunch_small_outlines_size, 0.6, "Small if lt xht x this",
308  this->params()),
309  INT_MEMBER(crunch_rating_max, 10, "For adj length in rating per ch",
310  this->params()),
311  INT_MEMBER(crunch_pot_indicators, 1,
312  "How many potential indicators needed", this->params()),
313  BOOL_MEMBER(crunch_leave_ok_strings, true, "Dont touch sensible strings",
314  this->params()),
315  BOOL_MEMBER(crunch_accept_ok, true, "Use acceptability in okstring",
316  this->params()),
317  BOOL_MEMBER(crunch_leave_accept_strings, false,
318  "Dont pot crunch sensible strings", this->params()),
319  BOOL_MEMBER(crunch_include_numerals, false, "Fiddle alpha figures",
320  this->params()),
321  INT_MEMBER(crunch_leave_lc_strings, 4,
322  "Dont crunch words with long lower case strings",
323  this->params()),
324  INT_MEMBER(crunch_leave_uc_strings, 4,
325  "Dont crunch words with long lower case strings",
326  this->params()),
327  INT_MEMBER(crunch_long_repetitions, 3,
328  "Crunch words with long repetitions", this->params()),
329  INT_MEMBER(crunch_debug, 0, "As it says", this->params()),
330  INT_MEMBER(fixsp_non_noise_limit, 1,
331  "How many non-noise blbs either side?", this->params()),
332  double_MEMBER(fixsp_small_outlines_size, 0.28, "Small if lt xht x this",
333  this->params()),
334  BOOL_MEMBER(tessedit_prefer_joined_punct, false,
335  "Reward punctation joins", this->params()),
336  INT_MEMBER(fixsp_done_mode, 1, "What constitues done for spacing",
337  this->params()),
338  INT_MEMBER(debug_fix_space_level, 0, "Contextual fixspace debug",
339  this->params()),
340  STRING_MEMBER(numeric_punctuation, ".,",
341  "Punct. chs expected WITHIN numbers", this->params()),
342  INT_MEMBER(x_ht_acceptance_tolerance, 8,
343  "Max allowed deviation of blob top outside of font data",
344  this->params()),
345  INT_MEMBER(x_ht_min_change, 8,
346  "Min change in xht before actually trying it", this->params()),
347  INT_MEMBER(superscript_debug, 0,
348  "Debug level for sub & superscript fixer", this->params()),
350  superscript_worse_certainty, 2.0,
351  "How many times worse "
352  "certainty does a superscript position glyph need to be for "
353  "us to try classifying it as a char with a different "
354  "baseline?",
355  this->params()),
357  superscript_bettered_certainty, 0.97,
358  "What reduction in "
359  "badness do we think sufficient to choose a superscript "
360  "over what we'd thought. For example, a value of 0.6 means "
361  "we want to reduce badness of certainty by at least 40%",
362  this->params()),
363  double_MEMBER(superscript_scaledown_ratio, 0.4,
364  "A superscript scaled down more than this is unbelievably "
365  "small. For example, 0.3 means we expect the font size to "
366  "be no smaller than 30% of the text line font size.",
367  this->params()),
368  double_MEMBER(subscript_max_y_top, 0.5,
369  "Maximum top of a character measured as a multiple of "
370  "x-height above the baseline for us to reconsider whether "
371  "it's a subscript.",
372  this->params()),
373  double_MEMBER(superscript_min_y_bottom, 0.3,
374  "Minimum bottom of a character measured as a multiple of "
375  "x-height above the baseline for us to reconsider whether "
376  "it's a superscript.",
377  this->params()),
378  BOOL_MEMBER(tessedit_write_block_separators, false,
379  "Write block separators in output", this->params()),
380  BOOL_MEMBER(tessedit_write_rep_codes, false, "Write repetition char code",
381  this->params()),
382  BOOL_MEMBER(tessedit_write_unlv, false, "Write .unlv output file",
383  this->params()),
384  BOOL_MEMBER(tessedit_create_txt, true, "Write .txt output file",
385  this->params()),
386  BOOL_MEMBER(tessedit_create_hocr, false, "Write .html hOCR output file",
387  this->params()),
388  BOOL_MEMBER(tessedit_create_pdf, false, "Write .pdf output file",
389  this->params()),
390  STRING_MEMBER(unrecognised_char, "|",
391  "Output char for unidentified blobs", this->params()),
392  INT_MEMBER(suspect_level, 99, "Suspect marker level", this->params()),
393  INT_MEMBER(suspect_space_level, 100,
394  "Min suspect level for rejecting spaces", this->params()),
395  INT_MEMBER(suspect_short_words, 2,
396  "Dont Suspect dict wds longer than this", this->params()),
397  BOOL_MEMBER(suspect_constrain_1Il, false, "UNLV keep 1Il chars rejected",
398  this->params()),
399  double_MEMBER(suspect_rating_per_ch, 999.9, "Dont touch bad rating limit",
400  this->params()),
401  double_MEMBER(suspect_accept_rating, -999.9, "Accept good rating limit",
402  this->params()),
403  BOOL_MEMBER(tessedit_minimal_rejection, false,
404  "Only reject tess failures", this->params()),
405  BOOL_MEMBER(tessedit_zero_rejection, false, "Dont reject ANYTHING",
406  this->params()),
407  BOOL_MEMBER(tessedit_word_for_word, false,
408  "Make output have exactly one word per WERD", this->params()),
409  BOOL_MEMBER(tessedit_zero_kelvin_rejection, false,
410  "Dont reject ANYTHING AT ALL", this->params()),
411  BOOL_MEMBER(tessedit_consistent_reps, true,
412  "Force all rep chars the same", this->params()),
413  INT_MEMBER(tessedit_reject_mode, 0, "Rejection algorithm",
414  this->params()),
415  BOOL_MEMBER(tessedit_rejection_debug, false, "Adaption debug",
416  this->params()),
417  BOOL_MEMBER(tessedit_flip_0O, true, "Contextual 0O O0 flips",
418  this->params()),
419  double_MEMBER(tessedit_lower_flip_hyphen, 1.5,
420  "Aspect ratio dot/hyphen test", this->params()),
421  double_MEMBER(tessedit_upper_flip_hyphen, 1.8,
422  "Aspect ratio dot/hyphen test", this->params()),
423  BOOL_MEMBER(rej_trust_doc_dawg, false,
424  "Use DOC dawg in 11l conf. detector", this->params()),
425  BOOL_MEMBER(rej_1Il_use_dict_word, false, "Use dictword test",
426  this->params()),
427  BOOL_MEMBER(rej_1Il_trust_permuter_type, true, "Dont double check",
428  this->params()),
429  BOOL_MEMBER(rej_use_tess_accepted, true, "Individual rejection control",
430  this->params()),
431  BOOL_MEMBER(rej_use_tess_blanks, true, "Individual rejection control",
432  this->params()),
433  BOOL_MEMBER(rej_use_good_perm, true, "Individual rejection control",
434  this->params()),
435  BOOL_MEMBER(rej_use_sensible_wd, false, "Extend permuter check",
436  this->params()),
437  BOOL_MEMBER(rej_alphas_in_number_perm, false, "Extend permuter check",
438  this->params()),
439  double_MEMBER(rej_whole_of_mostly_reject_word_fract, 0.85,
440  "if >this fract", this->params()),
441  INT_MEMBER(tessedit_image_border, 2, "Rej blbs near image edge limit",
442  this->params()),
443  STRING_MEMBER(ok_repeated_ch_non_alphanum_wds, "-?*\075",
444  "Allow NN to unrej", this->params()),
445  STRING_MEMBER(conflict_set_I_l_1, "Il1[]", "Il1 conflict set",
446  this->params()),
447  INT_MEMBER(min_sane_x_ht_pixels, 8, "Reject any x-ht lt or eq than this",
448  this->params()),
449  BOOL_MEMBER(tessedit_create_boxfile, false, "Output text with boxes",
450  this->params()),
451  INT_MEMBER(tessedit_page_number, -1,
452  "-1 -> All pages"
453  " , else specifc page to process",
454  this->params()),
455  BOOL_MEMBER(tessedit_write_images, false,
456  "Capture the image from the IPE", this->params()),
457  BOOL_MEMBER(interactive_display_mode, false, "Run interactively?",
458  this->params()),
459  STRING_MEMBER(file_type, ".tif", "Filename extension", this->params()),
460  BOOL_MEMBER(tessedit_override_permuter, true, "According to dict_word",
461  this->params()),
462  INT_MEMBER(tessdata_manager_debug_level, 0,
463  "Debug level for"
464  " TessdataManager functions.",
465  this->params()),
466  STRING_MEMBER(tessedit_load_sublangs, "",
467  "List of languages to load with this one", this->params()),
468  BOOL_MEMBER(tessedit_use_primary_params_model, false,
469  "In multilingual mode use params model of the"
470  " primary language",
471  this->params()),
472  double_MEMBER(min_orientation_margin, 7.0,
473  "Min acceptable orientation margin", this->params()),
474  BOOL_MEMBER(textord_tabfind_show_vlines, false, "Debug line finding",
475  this->params()),
476  BOOL_MEMBER(textord_use_cjk_fp_model, FALSE, "Use CJK fixed pitch model",
477  this->params()),
478  BOOL_MEMBER(poly_allow_detailed_fx, false,
479  "Allow feature extractors to see the original outline",
480  this->params()),
481  BOOL_INIT_MEMBER(tessedit_init_config_only, false,
482  "Only initialize with the config file. Useful if the "
483  "instance is not going to be used for OCR but say only "
484  "for layout analysis.",
485  this->params()),
486  BOOL_MEMBER(textord_equation_detect, false, "Turn on equation detector",
487  this->params()),
488  BOOL_MEMBER(textord_tabfind_vertical_text, true,
489  "Enable vertical detection", this->params()),
490  BOOL_MEMBER(textord_tabfind_force_vertical_text, false,
491  "Force using vertical text page mode", this->params()),
493  textord_tabfind_vertical_text_ratio, 0.5,
494  "Fraction of textlines deemed vertical to use vertical page "
495  "mode",
496  this->params()),
498  textord_tabfind_aligned_gap_fraction, 0.75,
499  "Fraction of height used as a minimum gap for aligned blobs.",
500  this->params()),
501  INT_MEMBER(tessedit_parallelize, 0, "Run in parallel where possible",
502  this->params()),
503  BOOL_MEMBER(preserve_interword_spaces, false,
504  "Preserve multiple interword spaces", this->params()),
505  BOOL_MEMBER(include_page_breaks, FALSE,
506  "Include page separator string in output text after each "
507  "image/page.",
508  this->params()),
509  STRING_MEMBER(page_separator, "\f",
510  "Page separator (default is form feed control character)",
511  this->params()),
512 
513  // The following parameters were deprecated and removed from their
514  // original
515  // locations. The parameters are temporarily kept here to give Tesseract
516  // users a chance to updated their [lang].traineddata and config files
517  // without introducing failures during Tesseract initialization.
518  // TODO(ocr-team): remove these parameters from the code once we are
519  // reasonably sure that Tesseract users have updated their data files.
520  //
521  // BEGIN DEPRECATED PARAMETERS
522  BOOL_MEMBER(textord_tabfind_vertical_horizontal_mix, true,
523  "find horizontal lines such as headers in vertical page mode",
524  this->params()),
525  INT_MEMBER(tessedit_ok_mode, 5, "Acceptance decision algorithm",
526  this->params()),
527  BOOL_INIT_MEMBER(load_fixed_length_dawgs, true,
528  "Load fixed length dawgs"
529  " (e.g. for non-space delimited languages)",
530  this->params()),
531  INT_MEMBER(segment_debug, 0, "Debug the whole segmentation process",
532  this->params()),
533  BOOL_MEMBER(permute_debug, 0, "Debug char permutation process",
534  this->params()),
535  double_MEMBER(bestrate_pruning_factor, 2.0,
536  "Multiplying factor of"
537  " current best rate to prune other hypotheses",
538  this->params()),
539  BOOL_MEMBER(permute_script_word, 0,
540  "Turn on word script consistency permuter", this->params()),
541  BOOL_MEMBER(segment_segcost_rating, 0,
542  "incorporate segmentation cost in word rating?",
543  this->params()),
544  double_MEMBER(segment_reward_script, 0.95,
545  "Score multipler for script consistency within a word. "
546  "Being a 'reward' factor, it should be <= 1. "
547  "Smaller value implies bigger reward.",
548  this->params()),
549  BOOL_MEMBER(permute_fixed_length_dawg, 0,
550  "Turn on fixed-length phrasebook search permuter",
551  this->params()),
552  BOOL_MEMBER(permute_chartype_word, 0,
553  "Turn on character type (property) consistency permuter",
554  this->params()),
555  double_MEMBER(segment_reward_chartype, 0.97,
556  "Score multipler for char type consistency within a word. ",
557  this->params()),
558  double_MEMBER(segment_reward_ngram_best_choice, 0.99,
559  "Score multipler for ngram permuter's best choice"
560  " (only used in the Han script path).",
561  this->params()),
562  BOOL_MEMBER(ngram_permuter_activated, false,
563  "Activate character-level n-gram-based permuter",
564  this->params()),
565  BOOL_MEMBER(permute_only_top, false, "Run only the top choice permuter",
566  this->params()),
567  INT_MEMBER(language_model_fixed_length_choices_depth, 3,
568  "Depth of blob choice lists to explore"
569  " when fixed length dawgs are on",
570  this->params()),
571  BOOL_MEMBER(use_new_state_cost, FALSE,
572  "use new state cost heuristics for segmentation state"
573  " evaluation",
574  this->params()),
575  double_MEMBER(heuristic_segcost_rating_base, 1.25,
576  "base factor for adding segmentation cost into word rating."
577  "It's a multiplying factor, the larger the value above 1, "
578  "the bigger the effect of segmentation cost.",
579  this->params()),
580  double_MEMBER(heuristic_weight_rating, 1.0,
581  "weight associated with char rating in combined cost of"
582  "state",
583  this->params()),
584  double_MEMBER(heuristic_weight_width, 1000.0,
585  "weight associated with width evidence in combined cost of"
586  " state",
587  this->params()),
588  double_MEMBER(heuristic_weight_seamcut, 0.0,
589  "weight associated with seam cut in combined cost of state",
590  this->params()),
591  double_MEMBER(heuristic_max_char_wh_ratio, 2.0,
592  "max char width-to-height ratio allowed in segmentation",
593  this->params()),
594  BOOL_MEMBER(enable_new_segsearch, true,
595  "Enable new segmentation search path.", this->params()),
596  double_MEMBER(segsearch_max_fixed_pitch_char_wh_ratio, 2.0,
597  "Maximum character width-to-height ratio for"
598  " fixed-pitch fonts",
599  this->params()),
600  // END DEPRECATED PARAMETERS
601 
602  backup_config_file_(NULL),
603  pix_binary_(NULL),
604  cube_binary_(NULL),
605  pix_grey_(NULL),
606  pix_thresholds_(NULL),
607  source_resolution_(0),
608  textord_(this),
609  right_to_left_(false),
610  scaled_color_(NULL),
611  scaled_factor_(-1),
612  deskew_(1.0f, 0.0f),
613  reskew_(1.0f, 0.0f),
614  most_recently_used_(this),
615  font_table_size_(0),
616 #ifndef ANDROID_BUILD
617  cube_cntxt_(NULL),
618  tess_cube_combiner_(NULL),
619 #endif
620  equ_detect_(NULL) {
621 }
622 
624  Clear();
625  end_tesseract();
626  sub_langs_.delete_data_pointers();
627 #ifndef ANDROID_BUILD
628  // Delete cube objects.
629  if (cube_cntxt_ != NULL) {
630  delete cube_cntxt_;
631  cube_cntxt_ = NULL;
632  }
633  if (tess_cube_combiner_ != NULL) {
634  delete tess_cube_combiner_;
635  tess_cube_combiner_ = NULL;
636  }
637 #endif
638 }
639 
641  pixDestroy(&pix_binary_);
642  pixDestroy(&cube_binary_);
643  pixDestroy(&pix_grey_);
644  pixDestroy(&pix_thresholds_);
645  pixDestroy(&scaled_color_);
646  deskew_ = FCOORD(1.0f, 0.0f);
647  reskew_ = FCOORD(1.0f, 0.0f);
648  splitter_.Clear();
649  scaled_factor_ = -1;
650  for (int i = 0; i < sub_langs_.size(); ++i)
651  sub_langs_[i]->Clear();
652 }
653 
655  equ_detect_ = detector;
656  equ_detect_->SetLangTesseract(this);
657 }
658 
659 // Clear all memory of adaption for this and all subclassifiers.
662  for (int i = 0; i < sub_langs_.size(); ++i) {
663  sub_langs_[i]->ResetAdaptiveClassifierInternal();
664  }
665 }
666 
667 // Clear the document dictionary for this and all subclassifiers.
670  for (int i = 0; i < sub_langs_.size(); ++i) {
671  sub_langs_[i]->getDict().ResetDocumentDictionary();
672  }
673 }
674 
676  // Set the white and blacklists (if any)
678  tessedit_char_whitelist.string(),
679  tessedit_char_unblacklist.string());
680  // Black and white lists should apply to all loaded classifiers.
681  for (int i = 0; i < sub_langs_.size(); ++i) {
682  sub_langs_[i]->unicharset.set_black_and_whitelist(
684  tessedit_char_unblacklist.string());
685  }
686 }
687 
688 // Perform steps to prepare underlying binary image/other data structures for
689 // page segmentation.
692  pixDestroy(&cube_binary_);
693  cube_binary_ = pixClone(pix_binary());
694  // Find the max splitter strategy over all langs.
695  ShiroRekhaSplitter::SplitStrategy max_pageseg_strategy =
698  for (int i = 0; i < sub_langs_.size(); ++i) {
699  ShiroRekhaSplitter::SplitStrategy pageseg_strategy =
701  static_cast<inT32>(sub_langs_[i]->pageseg_devanagari_split_strategy));
702  if (pageseg_strategy > max_pageseg_strategy)
703  max_pageseg_strategy = pageseg_strategy;
704  // Clone the cube image to all the sub langs too.
705  pixDestroy(&sub_langs_[i]->cube_binary_);
706  sub_langs_[i]->cube_binary_ = pixClone(pix_binary());
707  pixDestroy(&sub_langs_[i]->pix_binary_);
708  sub_langs_[i]->pix_binary_ = pixClone(pix_binary());
709  }
710  // Perform shiro-rekha (top-line) splitting and replace the current image by
711  // the newly splitted image.
712  splitter_.set_orig_pix(pix_binary());
713  splitter_.set_pageseg_split_strategy(max_pageseg_strategy);
714  if (splitter_.Split(true)) {
715  ASSERT_HOST(splitter_.splitted_image());
716  pixDestroy(&pix_binary_);
717  pix_binary_ = pixClone(splitter_.splitted_image());
718  }
719 }
720 
721 // Perform steps to prepare underlying binary image/other data structures for
722 // OCR. The current segmentation is required by this method.
723 // Note that this method resets pix_binary_ to the original binarized image,
724 // which may be different from the image actually used for OCR depending on the
725 // value of devanagari_ocr_split_strategy.
726 void Tesseract::PrepareForTessOCR(BLOCK_LIST* block_list,
727  Tesseract* osd_tess, OSResults* osr) {
728  // Find the max splitter strategy over all langs.
729  ShiroRekhaSplitter::SplitStrategy max_ocr_strategy =
731  static_cast<inT32>(ocr_devanagari_split_strategy));
732  for (int i = 0; i < sub_langs_.size(); ++i) {
733  ShiroRekhaSplitter::SplitStrategy ocr_strategy =
735  static_cast<inT32>(sub_langs_[i]->ocr_devanagari_split_strategy));
736  if (ocr_strategy > max_ocr_strategy)
737  max_ocr_strategy = ocr_strategy;
738  }
739  // Utilize the segmentation information available.
740  splitter_.set_segmentation_block_list(block_list);
741  splitter_.set_ocr_split_strategy(max_ocr_strategy);
742  // Run the splitter for OCR
743  bool split_for_ocr = splitter_.Split(false);
744  // Restore pix_binary to the binarized original pix for future reference.
745  ASSERT_HOST(splitter_.orig_pix());
746  pixDestroy(&pix_binary_);
747  pix_binary_ = pixClone(splitter_.orig_pix());
748  // If the pageseg and ocr strategies are different, refresh the block list
749  // (from the last SegmentImage call) with blobs from the real image to be used
750  // for OCR.
751  if (splitter_.HasDifferentSplitStrategies()) {
752  BLOCK block("", TRUE, 0, 0, 0, 0, pixGetWidth(pix_binary_),
753  pixGetHeight(pix_binary_));
754  Pix* pix_for_ocr = split_for_ocr ? splitter_.splitted_image() :
755  splitter_.orig_pix();
756  extract_edges(pix_for_ocr, &block);
757  splitter_.RefreshSegmentationWithNewBlobs(block.blob_list());
758  }
759  // The splitter isn't needed any more after this, so save memory by clearing.
760  splitter_.Clear();
761 }
762 
763 } // namespace tesseract
C_BLOB_LIST * blob_list()
get blobs
Definition: ocrblock.h:132
void extract_edges(Pix *pix, BLOCK *block)
Definition: edgblob.cpp:334
#define STRING_MEMBER(name, val, comment, vec)
Definition: params.h:307
void set_use_cjk_fp_model(bool flag)
Definition: textord.h:95
void RefreshSegmentationWithNewBlobs(C_BLOB_LIST *new_blobs)
UNICHARSET unicharset
Definition: ccutil.h:72
#define BOOL_MEMBER(name, val, comment, vec)
Definition: params.h:304
#define ASSERT_HOST(x)
Definition: errcode.h:84
#define BOOL_INIT_MEMBER(name, val, comment, vec)
Definition: params.h:316
void PrepareForTessOCR(BLOCK_LIST *block_list, Tesseract *osd_tess, OSResults *osr)
Definition: ocrblock.h:30
void set_pageseg_split_strategy(SplitStrategy strategy)
void SetLangTesseract(Tesseract *lang_tesseract)
#define INT_MEMBER(name, val, comment, vec)
Definition: params.h:301
Dict & getDict()
Definition: classify.h:65
void set_segmentation_block_list(BLOCK_LIST *block_list)
Assume a single uniform block of text. (Default.)
Definition: publictypes.h:160
bool Split(bool split_for_pageseg)
#define FALSE
Definition: capi.h:29
void SetEquationDetect(EquationDetect *detector)
#define TRUE
Definition: capi.h:28
void set_ocr_split_strategy(SplitStrategy strategy)
#define double_MEMBER(name, val, comment, vec)
Definition: params.h:310
void ResetAdaptiveClassifierInternal()
Definition: adaptmatch.cpp:613
#define NULL
Definition: host.h:144
Pix * pix_binary() const
void set_black_and_whitelist(const char *blacklist, const char *whitelist, const char *unblacklist)
Definition: unicharset.cpp:948
Definition: points.h:189
void ResetDocumentDictionary()
Definition: dict.h:301
#define INT_INIT_MEMBER(name, val, comment, vec)
Definition: params.h:313
int inT32
Definition: host.h:102