tesseract
3.03
|
00001 00002 // File: tesseractclass.cpp 00003 // Description: An instance of Tesseract. For thread safety, *every* 00004 // global variable goes in here, directly, or indirectly. 00005 // Author: Ray Smith 00006 // Created: Fri Mar 07 08:17:01 PST 2008 00007 // 00008 // (C) Copyright 2008, Google Inc. 00009 // Licensed under the Apache License, Version 2.0 (the "License"); 00010 // you may not use this file except in compliance with the License. 00011 // You may obtain a copy of the License at 00012 // http://www.apache.org/licenses/LICENSE-2.0 00013 // Unless required by applicable law or agreed to in writing, software 00014 // distributed under the License is distributed on an "AS IS" BASIS, 00015 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00016 // See the License for the specific language governing permissions and 00017 // limitations under the License. 00018 // 00020 00021 #include "tesseractclass.h" 00022 00023 #include "allheaders.h" 00024 #include "cube_reco_context.h" 00025 #include "edgblob.h" 00026 #include "equationdetect.h" 00027 #include "globals.h" 00028 #include "tesseract_cube_combiner.h" 00029 00030 // Include automatically generated configuration file if running autoconf. 00031 #ifdef HAVE_CONFIG_H 00032 #include "config_auto.h" 00033 #endif 00034 00035 namespace tesseract { 00036 00037 Tesseract::Tesseract() 00038 : BOOL_MEMBER(tessedit_resegment_from_boxes, false, 00039 "Take segmentation and labeling from box file", 00040 this->params()), 00041 BOOL_MEMBER(tessedit_resegment_from_line_boxes, false, 00042 "Conversion of word/line box file to char box file", 00043 this->params()), 00044 BOOL_MEMBER(tessedit_train_from_boxes, false, 00045 "Generate training data from boxed chars", this->params()), 00046 BOOL_MEMBER(tessedit_make_boxes_from_boxes, false, 00047 "Generate more boxes from boxed chars", this->params()), 00048 BOOL_MEMBER(tessedit_dump_pageseg_images, false, 00049 "Dump intermediate images made during page segmentation", 00050 this->params()), 00051 // The default for pageseg_mode is the old behaviour, so as not to 00052 // upset anything that relies on that. 00053 INT_MEMBER(tessedit_pageseg_mode, PSM_SINGLE_BLOCK, 00054 "Page seg mode: 0=osd only, 1=auto+osd, 2=auto, 3=col, 4=block," 00055 " 5=line, 6=word, 7=char" 00056 " (Values from PageSegMode enum in publictypes.h)", 00057 this->params()), 00058 INT_INIT_MEMBER(tessedit_ocr_engine_mode, tesseract::OEM_TESSERACT_ONLY, 00059 "Which OCR engine(s) to run (Tesseract, Cube, both)." 00060 " Defaults to loading and running only Tesseract" 00061 " (no Cube,no combiner)." 00062 " Values from OcrEngineMode enum in tesseractclass.h)", 00063 this->params()), 00064 STRING_MEMBER(tessedit_char_blacklist, "", 00065 "Blacklist of chars not to recognize", this->params()), 00066 STRING_MEMBER(tessedit_char_whitelist, "", 00067 "Whitelist of chars to recognize", this->params()), 00068 BOOL_MEMBER(tessedit_ambigs_training, false, 00069 "Perform training for ambiguities", this->params()), 00070 INT_MEMBER(pageseg_devanagari_split_strategy, 00071 tesseract::ShiroRekhaSplitter::NO_SPLIT, 00072 "Whether to use the top-line splitting process for Devanagari " 00073 "documents while performing page-segmentation.", this->params()), 00074 INT_MEMBER(ocr_devanagari_split_strategy, 00075 tesseract::ShiroRekhaSplitter::NO_SPLIT, 00076 "Whether to use the top-line splitting process for Devanagari " 00077 "documents while performing ocr.", this->params()), 00078 STRING_MEMBER(tessedit_write_params_to_file, "", 00079 "Write all parameters to the given file.", this->params()), 00080 BOOL_MEMBER(tessedit_adaption_debug, false, "Generate and print debug" 00081 " information for adaption", this->params()), 00082 INT_MEMBER(bidi_debug, 0, "Debug level for BiDi", this->params()), 00083 INT_MEMBER(applybox_debug, 1, "Debug level", this->params()), 00084 INT_MEMBER(applybox_page, 0, 00085 "Page number to apply boxes from", this->params()), 00086 STRING_MEMBER(applybox_exposure_pattern, ".exp", "Exposure value follows" 00087 " this pattern in the image filename. The name of the image" 00088 " files are expected to be in the form" 00089 " [lang].[fontname].exp[num].tif", this->params()), 00090 BOOL_MEMBER(applybox_learn_chars_and_char_frags_mode, false, 00091 "Learn both character fragments (as is done in the" 00092 " special low exposure mode) as well as unfragmented" 00093 " characters.", this->params()), 00094 BOOL_MEMBER(applybox_learn_ngrams_mode, false, "Each bounding box" 00095 " is assumed to contain ngrams. Only learn the ngrams" 00096 " whose outlines overlap horizontally.", this->params()), 00097 BOOL_MEMBER(tessedit_display_outwords, false, 00098 "Draw output words", this->params()), 00099 BOOL_MEMBER(tessedit_training_tess, false, 00100 "Call Tess to learn blobs", this->params()), 00101 BOOL_MEMBER(tessedit_dump_choices, false, 00102 "Dump char choices", this->params()), 00103 BOOL_MEMBER(tessedit_timing_debug, false, "Print timing stats", 00104 this->params()), 00105 BOOL_MEMBER(tessedit_fix_fuzzy_spaces, true, 00106 "Try to improve fuzzy spaces", this->params()), 00107 BOOL_MEMBER(tessedit_unrej_any_wd, false, 00108 "Dont bother with word plausibility", this->params()), 00109 BOOL_MEMBER(tessedit_fix_hyphens, true, 00110 "Crunch double hyphens?", this->params()), 00111 BOOL_MEMBER(tessedit_redo_xheight, true, 00112 "Check/Correct x-height", this->params()), 00113 BOOL_MEMBER(tessedit_enable_doc_dict, true, 00114 "Add words to the document dictionary", this->params()), 00115 BOOL_MEMBER(tessedit_debug_fonts, false, 00116 "Output font info per char", this->params()), 00117 BOOL_MEMBER(tessedit_debug_block_rejection, false, 00118 "Block and Row stats", this->params()), 00119 BOOL_MEMBER(tessedit_enable_bigram_correction, true, 00120 "Enable correction based on the word bigram dictionary.", 00121 this->params()), 00122 INT_MEMBER(tessedit_bigram_debug, 0, 00123 "Amount of debug output for bigram correction.", 00124 this->params()), 00125 INT_MEMBER(debug_x_ht_level, 0, "Reestimate debug", this->params()), 00126 BOOL_MEMBER(debug_acceptable_wds, false, 00127 "Dump word pass/fail chk", this->params()), 00128 STRING_MEMBER(chs_leading_punct, "('`\"", 00129 "Leading punctuation", this->params()), 00130 STRING_MEMBER(chs_trailing_punct1, ").,;:?!", 00131 "1st Trailing punctuation", this->params()), 00132 STRING_MEMBER(chs_trailing_punct2, ")'`\"", 00133 "2nd Trailing punctuation", this->params()), 00134 double_MEMBER(quality_rej_pc, 0.08, 00135 "good_quality_doc lte rejection limit", this->params()), 00136 double_MEMBER(quality_blob_pc, 0.0, 00137 "good_quality_doc gte good blobs limit", this->params()), 00138 double_MEMBER(quality_outline_pc, 1.0, 00139 "good_quality_doc lte outline error limit", this->params()), 00140 double_MEMBER(quality_char_pc, 0.95, 00141 "good_quality_doc gte good char limit", this->params()), 00142 INT_MEMBER(quality_min_initial_alphas_reqd, 2, 00143 "alphas in a good word", this->params()), 00144 INT_MEMBER(tessedit_tess_adaption_mode, 0x27, 00145 "Adaptation decision algorithm for tess", this->params()), 00146 BOOL_MEMBER(tessedit_minimal_rej_pass1, false, 00147 "Do minimal rejection on pass 1 output", this->params()), 00148 BOOL_MEMBER(tessedit_test_adaption, false, 00149 "Test adaption criteria", this->params()), 00150 BOOL_MEMBER(tessedit_matcher_log, false, 00151 "Log matcher activity", this->params()), 00152 INT_MEMBER(tessedit_test_adaption_mode, 3, 00153 "Adaptation decision algorithm for tess", this->params()), 00154 BOOL_MEMBER(test_pt, false, "Test for point", this->params()), 00155 double_MEMBER(test_pt_x, 99999.99, "xcoord", this->params()), 00156 double_MEMBER(test_pt_y, 99999.99, "ycoord", this->params()), 00157 INT_MEMBER(paragraph_debug_level, 0, "Print paragraph debug info.", 00158 this->params()), 00159 BOOL_MEMBER(paragraph_text_based, true, 00160 "Run paragraph detection on the post-text-recognition " 00161 "(more accurate)", this->params()), 00162 INT_MEMBER(cube_debug_level, 0, "Print cube debug info.", this->params()), 00163 STRING_MEMBER(outlines_odd, "%| ", "Non standard number of outlines", 00164 this->params()), 00165 STRING_MEMBER(outlines_2, "ij!?%\":;", 00166 "Non standard number of outlines", this->params()), 00167 BOOL_MEMBER(docqual_excuse_outline_errs, false, 00168 "Allow outline errs in unrejection?", this->params()), 00169 BOOL_MEMBER(tessedit_good_quality_unrej, true, 00170 "Reduce rejection on good docs", this->params()), 00171 BOOL_MEMBER(tessedit_use_reject_spaces, true, 00172 "Reject spaces?", this->params()), 00173 double_MEMBER(tessedit_reject_doc_percent, 65.00, 00174 "%rej allowed before rej whole doc", this->params()), 00175 double_MEMBER(tessedit_reject_block_percent, 45.00, 00176 "%rej allowed before rej whole block", this->params()), 00177 double_MEMBER(tessedit_reject_row_percent, 40.00, 00178 "%rej allowed before rej whole row", this->params()), 00179 double_MEMBER(tessedit_whole_wd_rej_row_percent, 70.00, 00180 "Number of row rejects in whole word rejects" 00181 "which prevents whole row rejection", this->params()), 00182 BOOL_MEMBER(tessedit_preserve_blk_rej_perfect_wds, true, 00183 "Only rej partially rejected words in block rejection", 00184 this->params()), 00185 BOOL_MEMBER(tessedit_preserve_row_rej_perfect_wds, true, 00186 "Only rej partially rejected words in row rejection", 00187 this->params()), 00188 BOOL_MEMBER(tessedit_dont_blkrej_good_wds, false, 00189 "Use word segmentation quality metric", this->params()), 00190 BOOL_MEMBER(tessedit_dont_rowrej_good_wds, false, 00191 "Use word segmentation quality metric", this->params()), 00192 INT_MEMBER(tessedit_preserve_min_wd_len, 2, 00193 "Only preserve wds longer than this", this->params()), 00194 BOOL_MEMBER(tessedit_row_rej_good_docs, true, 00195 "Apply row rejection to good docs", this->params()), 00196 double_MEMBER(tessedit_good_doc_still_rowrej_wd, 1.1, 00197 "rej good doc wd if more than this fraction rejected", 00198 this->params()), 00199 BOOL_MEMBER(tessedit_reject_bad_qual_wds, true, 00200 "Reject all bad quality wds", this->params()), 00201 BOOL_MEMBER(tessedit_debug_doc_rejection, false, 00202 "Page stats", this->params()), 00203 BOOL_MEMBER(tessedit_debug_quality_metrics, false, 00204 "Output data to debug file", this->params()), 00205 BOOL_MEMBER(bland_unrej, false, 00206 "unrej potential with no chekcs", this->params()), 00207 double_MEMBER(quality_rowrej_pc, 1.1, 00208 "good_quality_doc gte good char limit", this->params()), 00209 BOOL_MEMBER(unlv_tilde_crunching, true, 00210 "Mark v.bad words for tilde crunch", this->params()), 00211 BOOL_MEMBER(crunch_early_merge_tess_fails, true, 00212 "Before word crunch?", this->params()), 00213 BOOL_MEMBER(crunch_early_convert_bad_unlv_chs, false, 00214 "Take out ~^ early?", this->params()), 00215 double_MEMBER(crunch_terrible_rating, 80.0, 00216 "crunch rating lt this", this->params()), 00217 BOOL_MEMBER(crunch_terrible_garbage, true, "As it says", this->params()), 00218 double_MEMBER(crunch_poor_garbage_cert, -9.0, 00219 "crunch garbage cert lt this", this->params()), 00220 double_MEMBER(crunch_poor_garbage_rate, 60, 00221 "crunch garbage rating lt this", this->params()), 00222 double_MEMBER(crunch_pot_poor_rate, 40, 00223 "POTENTIAL crunch rating lt this", this->params()), 00224 double_MEMBER(crunch_pot_poor_cert, -8.0, 00225 "POTENTIAL crunch cert lt this", this->params()), 00226 BOOL_MEMBER(crunch_pot_garbage, true, 00227 "POTENTIAL crunch garbage", this->params()), 00228 double_MEMBER(crunch_del_rating, 60, 00229 "POTENTIAL crunch rating lt this", this->params()), 00230 double_MEMBER(crunch_del_cert, -10.0, 00231 "POTENTIAL crunch cert lt this", this->params()), 00232 double_MEMBER(crunch_del_min_ht, 0.7, 00233 "Del if word ht lt xht x this", this->params()), 00234 double_MEMBER(crunch_del_max_ht, 3.0, 00235 "Del if word ht gt xht x this", this->params()), 00236 double_MEMBER(crunch_del_min_width, 3.0, 00237 "Del if word width lt xht x this", this->params()), 00238 double_MEMBER(crunch_del_high_word, 1.5, 00239 "Del if word gt xht x this above bl", this->params()), 00240 double_MEMBER(crunch_del_low_word, 0.5, 00241 "Del if word gt xht x this below bl", this->params()), 00242 double_MEMBER(crunch_small_outlines_size, 0.6, 00243 "Small if lt xht x this", this->params()), 00244 INT_MEMBER(crunch_rating_max, 10, 00245 "For adj length in rating per ch", this->params()), 00246 INT_MEMBER(crunch_pot_indicators, 1, 00247 "How many potential indicators needed", this->params()), 00248 BOOL_MEMBER(crunch_leave_ok_strings, true, 00249 "Dont touch sensible strings", this->params()), 00250 BOOL_MEMBER(crunch_accept_ok, true, 00251 "Use acceptability in okstring", this->params()), 00252 BOOL_MEMBER(crunch_leave_accept_strings, false, 00253 "Dont pot crunch sensible strings", this->params()), 00254 BOOL_MEMBER(crunch_include_numerals, false, 00255 "Fiddle alpha figures", this->params()), 00256 INT_MEMBER(crunch_leave_lc_strings, 4, 00257 "Dont crunch words with long lower case strings", 00258 this->params()), 00259 INT_MEMBER(crunch_leave_uc_strings, 4, 00260 "Dont crunch words with long lower case strings", 00261 this->params()), 00262 INT_MEMBER(crunch_long_repetitions, 3, 00263 "Crunch words with long repetitions", this->params()), 00264 INT_MEMBER(crunch_debug, 0, "As it says", this->params()), 00265 INT_MEMBER(fixsp_non_noise_limit, 1, 00266 "How many non-noise blbs either side?", this->params()), 00267 double_MEMBER(fixsp_small_outlines_size, 0.28, 00268 "Small if lt xht x this", this->params()), 00269 BOOL_MEMBER(tessedit_prefer_joined_punct, false, 00270 "Reward punctation joins", this->params()), 00271 INT_MEMBER(fixsp_done_mode, 1, 00272 "What constitues done for spacing", this->params()), 00273 INT_MEMBER(debug_fix_space_level, 0, 00274 "Contextual fixspace debug", this->params()), 00275 STRING_MEMBER(numeric_punctuation, ".,", 00276 "Punct. chs expected WITHIN numbers", this->params()), 00277 INT_MEMBER(x_ht_acceptance_tolerance, 8, 00278 "Max allowed deviation of blob top outside of font data", 00279 this->params()), 00280 INT_MEMBER(x_ht_min_change, 8, 00281 "Min change in xht before actually trying it", this->params()), 00282 INT_MEMBER(superscript_debug, 0, "Debug level for sub & superscript fixer", 00283 this->params()), 00284 double_MEMBER(superscript_worse_certainty, 2.0, "How many times worse " 00285 "certainty does a superscript position glyph need to be for " 00286 "us to try classifying it as a char with a different " 00287 "baseline?", this->params()), 00288 double_MEMBER(superscript_bettered_certainty, 0.97, "What reduction in " 00289 "badness do we think sufficient to choose a superscript " 00290 "over what we'd thought. For example, a value of 0.6 means " 00291 "we want to reduce badness of certainty by at least 40%", 00292 this->params()), 00293 double_MEMBER(superscript_scaledown_ratio, 0.4, 00294 "A superscript scaled down more than this is unbelievably " 00295 "small. For example, 0.3 means we expect the font size to " 00296 "be no smaller than 30% of the text line font size.", 00297 this->params()), 00298 double_MEMBER(subscript_max_y_top, 0.5, 00299 "Maximum top of a character measured as a multiple of " 00300 "x-height above the baseline for us to reconsider whether " 00301 "it's a subscript.", this->params()), 00302 double_MEMBER(superscript_min_y_bottom, 0.3, 00303 "Minimum bottom of a character measured as a multiple of " 00304 "x-height above the baseline for us to reconsider whether " 00305 "it's a superscript.", this->params()), 00306 BOOL_MEMBER(tessedit_write_block_separators, false, 00307 "Write block separators in output", this->params()), 00308 BOOL_MEMBER(tessedit_write_rep_codes, false, 00309 "Write repetition char code", this->params()), 00310 BOOL_MEMBER(tessedit_write_unlv, false, 00311 "Write .unlv output file", this->params()), 00312 BOOL_MEMBER(tessedit_create_hocr, false, 00313 "Write .html hOCR output file", this->params()), 00314 BOOL_MEMBER(tessedit_create_pdf, false, 00315 "Write .pdf output file", this->params()), 00316 STRING_MEMBER(unrecognised_char, "|", 00317 "Output char for unidentified blobs", this->params()), 00318 INT_MEMBER(suspect_level, 99, "Suspect marker level", this->params()), 00319 INT_MEMBER(suspect_space_level, 100, 00320 "Min suspect level for rejecting spaces", this->params()), 00321 INT_MEMBER(suspect_short_words, 2, 00322 "Dont Suspect dict wds longer than this", this->params()), 00323 BOOL_MEMBER(suspect_constrain_1Il, false, 00324 "UNLV keep 1Il chars rejected", this->params()), 00325 double_MEMBER(suspect_rating_per_ch, 999.9, 00326 "Dont touch bad rating limit", this->params()), 00327 double_MEMBER(suspect_accept_rating, -999.9, 00328 "Accept good rating limit", this->params()), 00329 BOOL_MEMBER(tessedit_minimal_rejection, false, 00330 "Only reject tess failures", this->params()), 00331 BOOL_MEMBER(tessedit_zero_rejection, false, 00332 "Dont reject ANYTHING", this->params()), 00333 BOOL_MEMBER(tessedit_word_for_word, false, 00334 "Make output have exactly one word per WERD", this->params()), 00335 BOOL_MEMBER(tessedit_zero_kelvin_rejection, false, 00336 "Dont reject ANYTHING AT ALL", this->params()), 00337 BOOL_MEMBER(tessedit_consistent_reps, true, 00338 "Force all rep chars the same", this->params()), 00339 INT_MEMBER(tessedit_reject_mode, 0, "Rejection algorithm", this->params()), 00340 BOOL_MEMBER(tessedit_rejection_debug, false, 00341 "Adaption debug", this->params()), 00342 BOOL_MEMBER(tessedit_flip_0O, true, 00343 "Contextual 0O O0 flips", this->params()), 00344 double_MEMBER(tessedit_lower_flip_hyphen, 1.5, 00345 "Aspect ratio dot/hyphen test", this->params()), 00346 double_MEMBER(tessedit_upper_flip_hyphen, 1.8, 00347 "Aspect ratio dot/hyphen test", this->params()), 00348 BOOL_MEMBER(rej_trust_doc_dawg, false, 00349 "Use DOC dawg in 11l conf. detector", this->params()), 00350 BOOL_MEMBER(rej_1Il_use_dict_word, false, 00351 "Use dictword test", this->params()), 00352 BOOL_MEMBER(rej_1Il_trust_permuter_type, true, 00353 "Dont double check", this->params()), 00354 BOOL_MEMBER(rej_use_tess_accepted, true, 00355 "Individual rejection control", this->params()), 00356 BOOL_MEMBER(rej_use_tess_blanks, true, 00357 "Individual rejection control", this->params()), 00358 BOOL_MEMBER(rej_use_good_perm, true, 00359 "Individual rejection control", this->params()), 00360 BOOL_MEMBER(rej_use_sensible_wd, false, 00361 "Extend permuter check", this->params()), 00362 BOOL_MEMBER(rej_alphas_in_number_perm, false, 00363 "Extend permuter check", this->params()), 00364 double_MEMBER(rej_whole_of_mostly_reject_word_fract, 0.85, 00365 "if >this fract", this->params()), 00366 INT_MEMBER(tessedit_image_border, 2, 00367 "Rej blbs near image edge limit", this->params()), 00368 STRING_MEMBER(ok_repeated_ch_non_alphanum_wds, "-?*\075", 00369 "Allow NN to unrej", this->params()), 00370 STRING_MEMBER(conflict_set_I_l_1, "Il1[]", 00371 "Il1 conflict set", this->params()), 00372 INT_MEMBER(min_sane_x_ht_pixels, 8, 00373 "Reject any x-ht lt or eq than this", this->params()), 00374 BOOL_MEMBER(tessedit_create_boxfile, false, 00375 "Output text with boxes", this->params()), 00376 INT_MEMBER(tessedit_page_number, -1, "-1 -> All pages" 00377 " , else specifc page to process", this->params()), 00378 BOOL_MEMBER(tessedit_write_images, false, 00379 "Capture the image from the IPE", this->params()), 00380 BOOL_MEMBER(interactive_display_mode, false, "Run interactively?", 00381 this->params()), 00382 STRING_MEMBER(file_type, ".tif", "Filename extension", this->params()), 00383 BOOL_MEMBER(tessedit_override_permuter, true, 00384 "According to dict_word", this->params()), 00385 INT_MEMBER(tessdata_manager_debug_level, 0, "Debug level for" 00386 " TessdataManager functions.", this->params()), 00387 STRING_MEMBER(tessedit_load_sublangs, "", 00388 "List of languages to load with this one", this->params()), 00389 BOOL_MEMBER(tessedit_use_primary_params_model, false, 00390 "In multilingual mode use params model of the" 00391 " primary language", this->params()), 00392 double_MEMBER(min_orientation_margin, 7.0, 00393 "Min acceptable orientation margin", this->params()), 00394 BOOL_MEMBER(textord_tabfind_show_vlines, false, "Debug line finding", 00395 this->params()), 00396 BOOL_MEMBER(textord_use_cjk_fp_model, FALSE, "Use CJK fixed pitch model", 00397 this->params()), 00398 BOOL_MEMBER(poly_allow_detailed_fx, false, 00399 "Allow feature extractors to see the original outline", 00400 this->params()), 00401 BOOL_INIT_MEMBER(tessedit_init_config_only, false, 00402 "Only initialize with the config file. Useful if the " 00403 "instance is not going to be used for OCR but say only " 00404 "for layout analysis.", this->params()), 00405 BOOL_MEMBER(textord_equation_detect, false, "Turn on equation detector", 00406 this->params()), 00407 INT_MEMBER(tessedit_parallelize, 0, "Run in parallel where possible", 00408 this->params()), 00409 00410 // The following parameters were deprecated and removed from their original 00411 // locations. The parameters are temporarily kept here to give Tesseract 00412 // users a chance to updated their [lang].traineddata and config files 00413 // without introducing failures during Tesseract initialization. 00414 // TODO(ocr-team): remove these parameters from the code once we are 00415 // reasonably sure that Tesseract users have updated their data files. 00416 // 00417 // BEGIN DEPRECATED PARAMETERS 00418 INT_MEMBER(tessedit_ok_mode, 5, 00419 "Acceptance decision algorithm", this->params()), 00420 BOOL_INIT_MEMBER(load_fixed_length_dawgs, true, "Load fixed length dawgs" 00421 " (e.g. for non-space delimited languages)", 00422 this->params()), 00423 INT_MEMBER(segment_debug, 0, "Debug the whole segmentation process", 00424 this->params()), 00425 BOOL_MEMBER(permute_debug, 0, "Debug char permutation process", 00426 this->params()), 00427 double_MEMBER(bestrate_pruning_factor, 2.0, "Multiplying factor of" 00428 " current best rate to prune other hypotheses", 00429 this->params()), 00430 BOOL_MEMBER(permute_script_word, 0, 00431 "Turn on word script consistency permuter", 00432 this->params()), 00433 BOOL_MEMBER(segment_segcost_rating, 0, 00434 "incorporate segmentation cost in word rating?", 00435 this->params()), 00436 double_MEMBER(segment_reward_script, 0.95, 00437 "Score multipler for script consistency within a word. " 00438 "Being a 'reward' factor, it should be <= 1. " 00439 "Smaller value implies bigger reward.", 00440 this->params()), 00441 BOOL_MEMBER(permute_fixed_length_dawg, 0, 00442 "Turn on fixed-length phrasebook search permuter", 00443 this->params()), 00444 BOOL_MEMBER(permute_chartype_word, 0, 00445 "Turn on character type (property) consistency permuter", 00446 this->params()), 00447 double_MEMBER(segment_reward_chartype, 0.97, 00448 "Score multipler for char type consistency within a word. ", 00449 this->params()), 00450 double_MEMBER(segment_reward_ngram_best_choice, 0.99, 00451 "Score multipler for ngram permuter's best choice" 00452 " (only used in the Han script path).", 00453 this->params()), 00454 BOOL_MEMBER(ngram_permuter_activated, false, 00455 "Activate character-level n-gram-based permuter", 00456 this->params()), 00457 BOOL_MEMBER(permute_only_top, false, "Run only the top choice permuter", 00458 this->params()), 00459 INT_MEMBER(language_model_fixed_length_choices_depth, 3, 00460 "Depth of blob choice lists to explore" 00461 " when fixed length dawgs are on", 00462 this->params()), 00463 BOOL_MEMBER(use_new_state_cost, FALSE, 00464 "use new state cost heuristics for segmentation state" 00465 " evaluation", this->params()), 00466 double_MEMBER(heuristic_segcost_rating_base, 1.25, 00467 "base factor for adding segmentation cost into word rating." 00468 "It's a multiplying factor, the larger the value above 1, " 00469 "the bigger the effect of segmentation cost.", 00470 this->params()), 00471 double_MEMBER(heuristic_weight_rating, 1.0, 00472 "weight associated with char rating in combined cost of" 00473 "state", this->params()), 00474 double_MEMBER(heuristic_weight_width, 1000.0, 00475 "weight associated with width evidence in combined cost of" 00476 " state", this->params()), 00477 double_MEMBER(heuristic_weight_seamcut, 0.0, 00478 "weight associated with seam cut in combined cost of state", 00479 this->params()), 00480 double_MEMBER(heuristic_max_char_wh_ratio, 2.0, 00481 "max char width-to-height ratio allowed in segmentation", 00482 this->params()), 00483 BOOL_MEMBER(enable_new_segsearch, true, 00484 "Enable new segmentation search path.", this->params()), 00485 double_MEMBER(segsearch_max_fixed_pitch_char_wh_ratio, 2.0, 00486 "Maximum character width-to-height ratio for" 00487 " fixed-pitch fonts", 00488 this->params()), 00489 // END DEPRECATED PARAMETERS 00490 00491 backup_config_file_(NULL), 00492 pix_binary_(NULL), 00493 cube_binary_(NULL), 00494 pix_grey_(NULL), 00495 pix_thresholds_(NULL), 00496 source_resolution_(0), 00497 textord_(this), 00498 right_to_left_(false), 00499 scaled_color_(NULL), 00500 scaled_factor_(-1), 00501 deskew_(1.0f, 0.0f), 00502 reskew_(1.0f, 0.0f), 00503 most_recently_used_(this), 00504 font_table_size_(0), 00505 cube_cntxt_(NULL), 00506 tess_cube_combiner_(NULL), 00507 equ_detect_(NULL) { 00508 } 00509 00510 Tesseract::~Tesseract() { 00511 Clear(); 00512 end_tesseract(); 00513 sub_langs_.delete_data_pointers(); 00514 // Delete cube objects. 00515 if (cube_cntxt_ != NULL) { 00516 delete cube_cntxt_; 00517 cube_cntxt_ = NULL; 00518 } 00519 if (tess_cube_combiner_ != NULL) { 00520 delete tess_cube_combiner_; 00521 tess_cube_combiner_ = NULL; 00522 } 00523 } 00524 00525 void Tesseract::Clear() { 00526 pixDestroy(&pix_binary_); 00527 pixDestroy(&cube_binary_); 00528 pixDestroy(&pix_grey_); 00529 pixDestroy(&pix_thresholds_); 00530 pixDestroy(&scaled_color_); 00531 deskew_ = FCOORD(1.0f, 0.0f); 00532 reskew_ = FCOORD(1.0f, 0.0f); 00533 splitter_.Clear(); 00534 scaled_factor_ = -1; 00535 for (int i = 0; i < sub_langs_.size(); ++i) 00536 sub_langs_[i]->Clear(); 00537 } 00538 00539 void Tesseract::SetEquationDetect(EquationDetect* detector) { 00540 equ_detect_ = detector; 00541 equ_detect_->SetLangTesseract(this); 00542 } 00543 00544 // Clear all memory of adaption for this and all subclassifiers. 00545 void Tesseract::ResetAdaptiveClassifier() { 00546 ResetAdaptiveClassifierInternal(); 00547 for (int i = 0; i < sub_langs_.size(); ++i) { 00548 sub_langs_[i]->ResetAdaptiveClassifierInternal(); 00549 } 00550 } 00551 00552 // Clear the document dictionary for this and all subclassifiers. 00553 void Tesseract::ResetDocumentDictionary() { 00554 getDict().ResetDocumentDictionary(); 00555 for (int i = 0; i < sub_langs_.size(); ++i) { 00556 sub_langs_[i]->getDict().ResetDocumentDictionary(); 00557 } 00558 } 00559 00560 void Tesseract::SetBlackAndWhitelist() { 00561 // Set the white and blacklists (if any) 00562 unicharset.set_black_and_whitelist(tessedit_char_blacklist.string(), 00563 tessedit_char_whitelist.string()); 00564 // Black and white lists should apply to all loaded classifiers. 00565 for (int i = 0; i < sub_langs_.size(); ++i) { 00566 sub_langs_[i]->unicharset.set_black_and_whitelist( 00567 tessedit_char_blacklist.string(), tessedit_char_whitelist.string()); 00568 } 00569 } 00570 00571 // Perform steps to prepare underlying binary image/other data structures for 00572 // page segmentation. 00573 void Tesseract::PrepareForPageseg() { 00574 textord_.set_use_cjk_fp_model(textord_use_cjk_fp_model); 00575 pixDestroy(&cube_binary_); 00576 cube_binary_ = pixClone(pix_binary()); 00577 // Find the max splitter strategy over all langs. 00578 ShiroRekhaSplitter::SplitStrategy max_pageseg_strategy = 00579 static_cast<ShiroRekhaSplitter::SplitStrategy>( 00580 static_cast<inT32>(pageseg_devanagari_split_strategy)); 00581 for (int i = 0; i < sub_langs_.size(); ++i) { 00582 ShiroRekhaSplitter::SplitStrategy pageseg_strategy = 00583 static_cast<ShiroRekhaSplitter::SplitStrategy>( 00584 static_cast<inT32>(sub_langs_[i]->pageseg_devanagari_split_strategy)); 00585 if (pageseg_strategy > max_pageseg_strategy) 00586 max_pageseg_strategy = pageseg_strategy; 00587 // Clone the cube image to all the sub langs too. 00588 pixDestroy(&sub_langs_[i]->cube_binary_); 00589 sub_langs_[i]->cube_binary_ = pixClone(pix_binary()); 00590 pixDestroy(&sub_langs_[i]->pix_binary_); 00591 sub_langs_[i]->pix_binary_ = pixClone(pix_binary()); 00592 } 00593 // Perform shiro-rekha (top-line) splitting and replace the current image by 00594 // the newly splitted image. 00595 splitter_.set_orig_pix(pix_binary()); 00596 splitter_.set_pageseg_split_strategy(max_pageseg_strategy); 00597 if (splitter_.Split(true)) { 00598 ASSERT_HOST(splitter_.splitted_image()); 00599 pixDestroy(&pix_binary_); 00600 pix_binary_ = pixClone(splitter_.splitted_image()); 00601 } 00602 } 00603 00604 // Perform steps to prepare underlying binary image/other data structures for 00605 // OCR. The current segmentation is required by this method. 00606 // Note that this method resets pix_binary_ to the original binarized image, 00607 // which may be different from the image actually used for OCR depending on the 00608 // value of devanagari_ocr_split_strategy. 00609 void Tesseract::PrepareForTessOCR(BLOCK_LIST* block_list, 00610 Tesseract* osd_tess, OSResults* osr) { 00611 // Find the max splitter strategy over all langs. 00612 ShiroRekhaSplitter::SplitStrategy max_ocr_strategy = 00613 static_cast<ShiroRekhaSplitter::SplitStrategy>( 00614 static_cast<inT32>(ocr_devanagari_split_strategy)); 00615 for (int i = 0; i < sub_langs_.size(); ++i) { 00616 ShiroRekhaSplitter::SplitStrategy ocr_strategy = 00617 static_cast<ShiroRekhaSplitter::SplitStrategy>( 00618 static_cast<inT32>(sub_langs_[i]->ocr_devanagari_split_strategy)); 00619 if (ocr_strategy > max_ocr_strategy) 00620 max_ocr_strategy = ocr_strategy; 00621 } 00622 // Utilize the segmentation information available. 00623 splitter_.set_segmentation_block_list(block_list); 00624 splitter_.set_ocr_split_strategy(max_ocr_strategy); 00625 // Run the splitter for OCR 00626 bool split_for_ocr = splitter_.Split(false); 00627 // Restore pix_binary to the binarized original pix for future reference. 00628 ASSERT_HOST(splitter_.orig_pix()); 00629 pixDestroy(&pix_binary_); 00630 pix_binary_ = pixClone(splitter_.orig_pix()); 00631 // If the pageseg and ocr strategies are different, refresh the block list 00632 // (from the last SegmentImage call) with blobs from the real image to be used 00633 // for OCR. 00634 if (splitter_.HasDifferentSplitStrategies()) { 00635 BLOCK block("", TRUE, 0, 0, 0, 0, pixGetWidth(pix_binary_), 00636 pixGetHeight(pix_binary_)); 00637 Pix* pix_for_ocr = split_for_ocr ? splitter_.splitted_image() : 00638 splitter_.orig_pix(); 00639 extract_edges(pix_for_ocr, &block); 00640 splitter_.RefreshSegmentationWithNewBlobs(block.blob_list()); 00641 } 00642 // The splitter isn't needed any more after this, so save memory by clearing. 00643 splitter_.Clear(); 00644 } 00645 00646 } // namespace tesseract