tesseract  3.05.00
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tesseract::Tesseract Class Reference

#include <tesseractclass.h>

Inheritance diagram for tesseract::Tesseract:
tesseract::Wordrec tesseract::Classify tesseract::CCStruct tesseract::CUtil tesseract::CCUtil

Public Member Functions

 Tesseract ()
 
 ~Tesseract ()
 
void Clear ()
 
void ResetAdaptiveClassifier ()
 
void ResetDocumentDictionary ()
 
void SetEquationDetect (EquationDetect *detector)
 
const FCOORDreskew () const
 
Pix ** mutable_pix_binary ()
 
Pix * pix_binary () const
 
Pix * pix_grey () const
 
void set_pix_grey (Pix *grey_pix)
 
Pix * pix_original () const
 
void set_pix_original (Pix *original_pix)
 
Pix * BestPix () const
 
void set_pix_thresholds (Pix *thresholds)
 
int source_resolution () const
 
void set_source_resolution (int ppi)
 
int ImageWidth () const
 
int ImageHeight () const
 
Pix * scaled_color () const
 
int scaled_factor () const
 
void SetScaledColor (int factor, Pix *color)
 
const Textordtextord () const
 
Textordmutable_textord ()
 
bool right_to_left () const
 
int num_sub_langs () const
 
Tesseractget_sub_lang (int index) const
 
bool AnyTessLang () const
 
void SetBlackAndWhitelist ()
 
void PrepareForPageseg ()
 
void PrepareForTessOCR (BLOCK_LIST *block_list, Tesseract *osd_tess, OSResults *osr)
 
int SegmentPage (const STRING *input_file, BLOCK_LIST *blocks, Tesseract *osd_tess, OSResults *osr)
 
void SetupWordScripts (BLOCK_LIST *blocks)
 
int AutoPageSeg (PageSegMode pageseg_mode, BLOCK_LIST *blocks, TO_BLOCK_LIST *to_blocks, BLOBNBOX_LIST *diacritic_blobs, Tesseract *osd_tess, OSResults *osr)
 
ColumnFinderSetupPageSegAndDetectOrientation (PageSegMode pageseg_mode, BLOCK_LIST *blocks, Tesseract *osd_tess, OSResults *osr, TO_BLOCK_LIST *to_blocks, Pix **photo_mask_pix, Pix **music_mask_pix)
 
void PrerecAllWordsPar (const GenericVector< WordData > &words)
 
bool ProcessTargetWord (const TBOX &word_box, const TBOX &target_word_box, const char *word_config, int pass)
 
void SetupAllWordsPassN (int pass_n, const TBOX *target_word_box, const char *word_config, PAGE_RES *page_res, GenericVector< WordData > *words)
 
void SetupWordPassN (int pass_n, WordData *word)
 
bool RecogAllWordsPassN (int pass_n, ETEXT_DESC *monitor, PAGE_RES_IT *pr_it, GenericVector< WordData > *words)
 
bool recog_all_words (PAGE_RES *page_res, ETEXT_DESC *monitor, const TBOX *target_word_box, const char *word_config, int dopasses)
 
void rejection_passes (PAGE_RES *page_res, ETEXT_DESC *monitor, const TBOX *target_word_box, const char *word_config)
 
void bigram_correction_pass (PAGE_RES *page_res)
 
void blamer_pass (PAGE_RES *page_res)
 
void script_pos_pass (PAGE_RES *page_res)
 
int RetryWithLanguage (const WordData &word_data, WordRecognizer recognizer, WERD_RES **in_word, PointerVector< WERD_RES > *best_words)
 
bool ReassignDiacritics (int pass, PAGE_RES_IT *pr_it, bool *make_next_word_fuzzy)
 
void AssignDiacriticsToOverlappingBlobs (const GenericVector< C_OUTLINE * > &outlines, int pass, WERD *real_word, PAGE_RES_IT *pr_it, GenericVector< bool > *word_wanted, GenericVector< bool > *overlapped_any_blob, GenericVector< C_BLOB * > *target_blobs)
 
void AssignDiacriticsToNewBlobs (const GenericVector< C_OUTLINE * > &outlines, int pass, WERD *real_word, PAGE_RES_IT *pr_it, GenericVector< bool > *word_wanted, GenericVector< C_BLOB * > *target_blobs)
 
bool SelectGoodDiacriticOutlines (int pass, float certainty_threshold, PAGE_RES_IT *pr_it, C_BLOB *blob, const GenericVector< C_OUTLINE * > &outlines, int num_outlines, GenericVector< bool > *ok_outlines)
 
float ClassifyBlobPlusOutlines (const GenericVector< bool > &ok_outlines, const GenericVector< C_OUTLINE * > &outlines, int pass_n, PAGE_RES_IT *pr_it, C_BLOB *blob, STRING *best_str)
 
float ClassifyBlobAsWord (int pass_n, PAGE_RES_IT *pr_it, C_BLOB *blob, STRING *best_str, float *c2)
 
void classify_word_and_language (int pass_n, PAGE_RES_IT *pr_it, WordData *word_data)
 
void classify_word_pass1 (const WordData &word_data, WERD_RES **in_word, PointerVector< WERD_RES > *out_words)
 
void recog_pseudo_word (PAGE_RES *page_res, TBOX &selection_box)
 
void fix_rep_char (PAGE_RES_IT *page_res_it)
 
ACCEPTABLE_WERD_TYPE acceptable_word_string (const UNICHARSET &char_set, const char *s, const char *lengths)
 
void match_word_pass_n (int pass_n, WERD_RES *word, ROW *row, BLOCK *block)
 
void classify_word_pass2 (const WordData &word_data, WERD_RES **in_word, PointerVector< WERD_RES > *out_words)
 
void ReportXhtFixResult (bool accept_new_word, float new_x_ht, WERD_RES *word, WERD_RES *new_word)
 
bool RunOldFixXht (WERD_RES *word, BLOCK *block, ROW *row)
 
bool TrainedXheightFix (WERD_RES *word, BLOCK *block, ROW *row)
 
bool TestNewNormalization (int original_misfits, float baseline_shift, float new_x_ht, WERD_RES *word, BLOCK *block, ROW *row)
 
BOOL8 recog_interactive (PAGE_RES_IT *pr_it)
 
void set_word_fonts (WERD_RES *word)
 
void font_recognition_pass (PAGE_RES *page_res)
 
void dictionary_correction_pass (PAGE_RES *page_res)
 
BOOL8 check_debug_pt (WERD_RES *word, int location)
 
bool SubAndSuperscriptFix (WERD_RES *word_res)
 
void GetSubAndSuperscriptCandidates (const WERD_RES *word, int *num_rebuilt_leading, ScriptPos *leading_pos, float *leading_certainty, int *num_rebuilt_trailing, ScriptPos *trailing_pos, float *trailing_certainty, float *avg_certainty, float *unlikely_threshold)
 
WERD_RESTrySuperscriptSplits (int num_chopped_leading, float leading_certainty, ScriptPos leading_pos, int num_chopped_trailing, float trailing_certainty, ScriptPos trailing_pos, WERD_RES *word, bool *is_good, int *retry_leading, int *retry_trailing)
 
bool BelievableSuperscript (bool debug, const WERD_RES &word, float certainty_threshold, int *left_ok, int *right_ok) const
 
void output_pass (PAGE_RES_IT &page_res_it, const TBOX *target_word_box)
 
void write_results (PAGE_RES_IT &page_res_it, char newline_type, BOOL8 force_eol)
 
void set_unlv_suspects (WERD_RES *word)
 
UNICHAR_ID get_rep_char (WERD_RES *word)
 
BOOL8 acceptable_number_string (const char *s, const char *lengths)
 
inT16 count_alphanums (const WERD_CHOICE &word)
 
inT16 count_alphas (const WERD_CHOICE &word)
 
void read_config_file (const char *filename, SetParamConstraint constraint)
 
int init_tesseract (const char *arg0, const char *textbase, const char *language, OcrEngineMode oem, char **configs, int configs_size, const GenericVector< STRING > *vars_vec, const GenericVector< STRING > *vars_values, bool set_only_init_params)
 
int init_tesseract (const char *datapath, const char *language, OcrEngineMode oem)
 
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)
 
void SetupUniversalFontIds ()
 
int init_tesseract_lm (const char *arg0, const char *textbase, const char *language)
 
void recognize_page (STRING &image_name)
 
void end_tesseract ()
 
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)
 
void ParseLanguageString (const char *lang_str, GenericVector< STRING > *to_load, GenericVector< STRING > *not_to_load)
 
SVMenuNodebuild_menu_new ()
 
void pgeditor_main (int width, int height, PAGE_RES *page_res)
 
void process_image_event (const SVEvent &event)
 
BOOL8 process_cmd_win_event (inT32 cmd_event, char *new_value)
 
void debug_word (PAGE_RES *page_res, const TBOX &selection_box)
 
void do_re_display (BOOL8(tesseract::Tesseract::*word_painter)(PAGE_RES_IT *pr_it))
 
BOOL8 word_display (PAGE_RES_IT *pr_it)
 
BOOL8 word_bln_display (PAGE_RES_IT *pr_it)
 
BOOL8 word_blank_and_set_display (PAGE_RES_IT *pr_its)
 
BOOL8 word_set_display (PAGE_RES_IT *pr_it)
 
BOOL8 word_dumper (PAGE_RES_IT *pr_it)
 
void blob_feature_display (PAGE_RES *page_res, const TBOX &selection_box)
 
void make_reject_map (WERD_RES *word, ROW *row, inT16 pass)
 
BOOL8 one_ell_conflict (WERD_RES *word_res, BOOL8 update_map)
 
inT16 first_alphanum_index (const char *word, const char *word_lengths)
 
inT16 first_alphanum_offset (const char *word, const char *word_lengths)
 
inT16 alpha_count (const char *word, const char *word_lengths)
 
BOOL8 word_contains_non_1_digit (const char *word, const char *word_lengths)
 
void dont_allow_1Il (WERD_RES *word)
 
inT16 count_alphanums (WERD_RES *word)
 
void flip_0O (WERD_RES *word)
 
BOOL8 non_0_digit (const UNICHARSET &ch_set, UNICHAR_ID unichar_id)
 
BOOL8 non_O_upper (const UNICHARSET &ch_set, UNICHAR_ID unichar_id)
 
BOOL8 repeated_nonalphanum_wd (WERD_RES *word, ROW *row)
 
void nn_match_word (WERD_RES *word, ROW *row)
 
void nn_recover_rejects (WERD_RES *word, ROW *row)
 
void set_done (WERD_RES *word, inT16 pass)
 
inT16 safe_dict_word (const WERD_RES *werd_res)
 
void flip_hyphens (WERD_RES *word)
 
void reject_I_1_L (WERD_RES *word)
 
void reject_edge_blobs (WERD_RES *word)
 
void reject_mostly_rejects (WERD_RES *word)
 
BOOL8 word_adaptable (WERD_RES *word, uinT16 mode)
 
void recog_word_recursive (WERD_RES *word)
 
void recog_word (WERD_RES *word)
 
void split_and_recog_word (WERD_RES *word)
 
void split_word (WERD_RES *word, int split_pt, WERD_RES **right_piece, BlamerBundle **orig_blamer_bundle) const
 
void join_words (WERD_RES *word, WERD_RES *word2, BlamerBundle *orig_bb) const
 
void match_current_words (WERD_RES_LIST &words, ROW *row, BLOCK *block)
 
inT16 fp_eval_word_spacing (WERD_RES_LIST &word_res_list)
 
void dump_words (WERD_RES_LIST &perm, inT16 score, inT16 mode, BOOL8 improved)
 
BOOL8 fixspace_thinks_word_done (WERD_RES *word)
 
GARBAGE_LEVEL garbage_word (WERD_RES *word, BOOL8 ok_dict_word)
 
BOOL8 potential_word_crunch (WERD_RES *word, GARBAGE_LEVEL garbage_level, BOOL8 ok_dict_word)
 
void tilde_crunch (PAGE_RES_IT &page_res_it)
 
void unrej_good_quality_words (PAGE_RES_IT &page_res_it)
 
void doc_and_block_rejection (PAGE_RES_IT &page_res_it, BOOL8 good_quality_doc)
 
void quality_based_rejection (PAGE_RES_IT &page_res_it, BOOL8 good_quality_doc)
 
void convert_bad_unlv_chs (WERD_RES *word_res)
 
void tilde_delete (PAGE_RES_IT &page_res_it)
 
inT16 word_blob_quality (WERD_RES *word, ROW *row)
 
void word_char_quality (WERD_RES *word, ROW *row, inT16 *match_count, inT16 *accepted_match_count)
 
void unrej_good_chs (WERD_RES *word, ROW *row)
 
inT16 count_outline_errs (char c, inT16 outline_count)
 
inT16 word_outline_errs (WERD_RES *word)
 
BOOL8 terrible_word_crunch (WERD_RES *word, GARBAGE_LEVEL garbage_level)
 
CRUNCH_MODE word_deletable (WERD_RES *word, inT16 &delete_mode)
 
inT16 failure_count (WERD_RES *word)
 
BOOL8 noise_outlines (TWERD *word)
 
void tess_segment_pass_n (int pass_n, WERD_RES *word)
 
PAGE_RESApplyBoxes (const STRING &fname, bool find_segmentation, BLOCK_LIST *block_list)
 
void PreenXHeights (BLOCK_LIST *block_list)
 
PAGE_RESSetupApplyBoxes (const GenericVector< TBOX > &boxes, BLOCK_LIST *block_list)
 
void MaximallyChopWord (const GenericVector< TBOX > &boxes, BLOCK *block, ROW *row, WERD_RES *word_res)
 
bool ResegmentCharBox (PAGE_RES *page_res, const TBOX *prev_box, const TBOX &box, const TBOX &next_box, const char *correct_text)
 
bool ResegmentWordBox (BLOCK_LIST *block_list, const TBOX &box, const TBOX &next_box, const char *correct_text)
 
void ReSegmentByClassification (PAGE_RES *page_res)
 
bool ConvertStringToUnichars (const char *utf8, GenericVector< UNICHAR_ID > *class_ids)
 
bool FindSegmentation (const GenericVector< UNICHAR_ID > &target_text, WERD_RES *word_res)
 
void SearchForText (const GenericVector< BLOB_CHOICE_LIST * > *choices, int choices_pos, int choices_length, const GenericVector< UNICHAR_ID > &target_text, int text_index, float rating, GenericVector< int > *segmentation, float *best_rating, GenericVector< int > *best_segmentation)
 
void TidyUp (PAGE_RES *page_res)
 
void ReportFailedBox (int boxfile_lineno, TBOX box, const char *box_ch, const char *err_msg)
 
void CorrectClassifyWords (PAGE_RES *page_res)
 
void ApplyBoxTraining (const STRING &fontname, PAGE_RES *page_res)
 
int CountMisfitTops (WERD_RES *word_res)
 
float ComputeCompatibleXheight (WERD_RES *word_res, float *baseline_shift)
 
FILE * init_recog_training (const STRING &fname)
 
void recog_training_segmented (const STRING &fname, PAGE_RES *page_res, volatile ETEXT_DESC *monitor, FILE *output_file)
 
void ambigs_classify_and_output (const char *label, PAGE_RES_IT *pr_it, FILE *output_file)
 
CubeRecoContextGetCubeRecoContext ()
 
init_cube_objects

Instantiates Tesseract object's CubeRecoContext and TesseractCubeCombiner. Returns false if cube context could not be created or if load_combiner is true, but the combiner could not be loaded.

bool init_cube_objects (bool load_combiner, TessdataManager *tessdata_manager)
 
run_cube_combiner

Iterates through tesseract's results and calls cube on each word, combining the results with the existing tesseract result.

void run_cube_combiner (PAGE_RES *page_res)
 
cube_word_pass1

Recognizes a single word using (only) cube. Compatible with Tesseract's classify_word_pass1/classify_word_pass2.

void cube_word_pass1 (BLOCK *block, ROW *row, WERD_RES *word)
 
cube_recognize_word

Cube recognizer to recognize a single word as with classify_word_pass1 but also returns the cube object in case the combiner is needed.

CubeObjectcube_recognize_word (BLOCK *block, WERD_RES *word)
 
cube_combine_word

Combines the cube and tesseract results for a single word, leaving the result in tess_word.

void cube_combine_word (CubeObject *cube_obj, WERD_RES *cube_word, WERD_RES *tess_word)
 
cube_recognize

Call cube on the current word, and write the result to word. Sets up a fake result and returns false if something goes wrong.

bool cube_recognize (CubeObject *cube_obj, BLOCK *block, WERD_RES *word)
 
fill_werd_res

Fill Tesseract's word result fields with cube's.

void fill_werd_res (const BoxWord &cube_box_word, const char *cube_best_str, WERD_RES *tess_werd_res)
 
extract_cube_state

Extract CharSamp objects and character bounding boxes from the CubeObject's state. The caller should free both structres.

bool extract_cube_state (CubeObject *cube_obj, int *num_chars, Boxa **char_boxes, CharSamp ***char_samples)
 
create_cube_box_word

Fill the given BoxWord with boxes from character bounding boxes. The char_boxes have local coordinates w.r.t. the word bounding box, i.e., the left-most character bbox of each word has (0,0) left-top coord, but the BoxWord must be defined in page coordinates.

bool create_cube_box_word (Boxa *char_boxes, int num_chars, TBOX word_box, BoxWord *box_word)
 
eval_word_spacing()

The basic measure is the number of characters in contextually confirmed words. (I.e the word is done) If all words are contextually confirmed the evaluation is deemed perfect.

Some fiddles are done to handle "1"s as these are VERY frequent causes of fuzzy spaces. The problem with the basic measure is that "561 63" would score the same as "56163", though given our knowledge that the space is fuzzy, and that there is a "1" next to the fuzzy space, we need to ensure that "56163" is preferred.

The solution is to NOT COUNT the score of any word which has a digit at one end and a "1Il" as the character the other side of the space.

Conversly, any character next to a "1" within a word is counted as a positive score. Thus "561 63" would score 4 (3 chars in a numeric word plus 1 side of the "1" joined). "56163" would score 7 - all chars in a numeric word + 2 sides of a "1" joined.

The joined 1 rule is applied to any word REGARDLESS of contextual confirmation. Thus "PS7a71 3/7a" scores 1 (neither word is contexutally confirmed. The only score is from the joined 1. "PS7a713/7a" scores 2.

BOOL8 digit_or_numeric_punct (WERD_RES *word, int char_position)
 
inT16 eval_word_spacing (WERD_RES_LIST &word_res_list)
 
fix_sp_fp_word()

Test the current word to see if it can be split by deleting noise blobs. If so, do the business. Return with the iterator pointing to the same place if the word is unchanged, or the last of the replacement words.

void fix_noisy_space_list (WERD_RES_LIST &best_perm, ROW *row, BLOCK *block)
 
void fix_sp_fp_word (WERD_RES_IT &word_res_it, ROW *row, BLOCK *block)
 
inT16 worst_noise_blob (WERD_RES *word_res, float *worst_noise_score)
 
float blob_noise_score (TBLOB *blob)
 
void break_noisiest_blob_word (WERD_RES_LIST &words)
 
fix_fuzzy_spaces()

Walk over the page finding sequences of words joined by fuzzy spaces. Extract them as a sublist, process the sublist to find the optimal arrangement of spaces then replace the sublist in the ROW_RES.

Parameters
monitorprogress monitor
word_countcount of words in doc
[out]page_res
void fix_fuzzy_space_list (WERD_RES_LIST &best_perm, ROW *row, BLOCK *block)
 
void fix_fuzzy_spaces (ETEXT_DESC *monitor, inT32 word_count, PAGE_RES *page_res)
 
process_selected_words()

Walk the current block list applying the specified word processor function to each word that overlaps the selection_box.

void process_selected_words (PAGE_RES *page_res, TBOX &selection_box, BOOL8(tesseract::Tesseract::*word_processor)(PAGE_RES_IT *pr_it))
 
tess_add_doc_word

Add the given word to the document dictionary

void tess_add_doc_word (WERD_CHOICE *word_choice)
 
tess_acceptable_word
Returns
true if the word is regarded as "good enough".
Parameters
word_choiceafter context
raw_choicebefore context
bool tess_acceptable_word (WERD_RES *word)
 
- Public Member Functions inherited from tesseract::Wordrec
 Wordrec ()
 
virtual ~Wordrec ()
 
void SaveAltChoices (const LIST &best_choices, WERD_RES *word)
 
void FillLattice (const MATRIX &ratings, const WERD_CHOICE_LIST &best_choices, const UNICHARSET &unicharset, BlamerBundle *blamer_bundle)
 
void CallFillLattice (const MATRIX &ratings, const WERD_CHOICE_LIST &best_choices, const UNICHARSET &unicharset, BlamerBundle *blamer_bundle)
 
void SegSearch (WERD_RES *word_res, BestChoiceBundle *best_choice_bundle, BlamerBundle *blamer_bundle)
 
void WordSearch (WERD_RES *word_res)
 
void InitialSegSearch (WERD_RES *word_res, LMPainPoints *pain_points, GenericVector< SegSearchPending > *pending, BestChoiceBundle *best_choice_bundle, BlamerBundle *blamer_bundle)
 
void DoSegSearch (WERD_RES *word_res)
 
SEAMattempt_blob_chop (TWERD *word, TBLOB *blob, inT32 blob_number, bool italic_blob, const GenericVector< SEAM * > &seams)
 
SEAMchop_numbered_blob (TWERD *word, inT32 blob_number, bool italic_blob, const GenericVector< SEAM * > &seams)
 
SEAMchop_overlapping_blob (const GenericVector< TBOX > &boxes, bool italic_blob, WERD_RES *word_res, int *blob_number)
 
void add_seam_to_queue (float new_priority, SEAM *new_seam, SeamQueue *seams)
 
void choose_best_seam (SeamQueue *seam_queue, const SPLIT *split, PRIORITY priority, SEAM **seam_result, TBLOB *blob, SeamPile *seam_pile)
 
void combine_seam (const SeamPile &seam_pile, const SEAM *seam, SeamQueue *seam_queue)
 
SEAMpick_good_seam (TBLOB *blob)
 
void try_point_pairs (EDGEPT *points[MAX_NUM_POINTS], inT16 num_points, SeamQueue *seam_queue, SeamPile *seam_pile, SEAM **seam, TBLOB *blob)
 
void try_vertical_splits (EDGEPT *points[MAX_NUM_POINTS], inT16 num_points, EDGEPT_CLIST *new_points, SeamQueue *seam_queue, SeamPile *seam_pile, SEAM **seam, TBLOB *blob)
 
PRIORITY grade_split_length (register SPLIT *split)
 
PRIORITY grade_sharpness (register SPLIT *split)
 
bool near_point (EDGEPT *point, EDGEPT *line_pt_0, EDGEPT *line_pt_1, EDGEPT **near_pt)
 
virtual BLOB_CHOICE_LIST * classify_piece (const GenericVector< SEAM * > &seams, inT16 start, inT16 end, const char *description, TWERD *word, BlamerBundle *blamer_bundle)
 
void merge_fragments (MATRIX *ratings, inT16 num_blobs)
 
void get_fragment_lists (inT16 current_frag, inT16 current_row, inT16 start, inT16 num_frag_parts, inT16 num_blobs, MATRIX *ratings, BLOB_CHOICE_LIST *choice_lists)
 
void merge_and_put_fragment_lists (inT16 row, inT16 column, inT16 num_frag_parts, BLOB_CHOICE_LIST *choice_lists, MATRIX *ratings)
 
void fill_filtered_fragment_list (BLOB_CHOICE_LIST *choices, int fragment_pos, int num_frag_parts, BLOB_CHOICE_LIST *filtered_choices)
 
void program_editup (const char *textbase, bool init_classifier, bool init_permute)
 
void cc_recog (WERD_RES *word)
 
void program_editdown (inT32 elasped_time)
 
void set_pass1 ()
 
void set_pass2 ()
 
int end_recog ()
 
BLOB_CHOICE_LIST * call_matcher (TBLOB *blob)
 
int dict_word (const WERD_CHOICE &word)
 
BLOB_CHOICE_LIST * classify_blob (TBLOB *blob, const char *string, C_COL color, BlamerBundle *blamer_bundle)
 
PRIORITY point_priority (EDGEPT *point)
 
void add_point_to_list (PointHeap *point_heap, EDGEPT *point)
 
bool is_inside_angle (EDGEPT *pt)
 
int angle_change (EDGEPT *point1, EDGEPT *point2, EDGEPT *point3)
 
EDGEPTpick_close_point (EDGEPT *critical_point, EDGEPT *vertical_point, int *best_dist)
 
void prioritize_points (TESSLINE *outline, PointHeap *points)
 
void new_min_point (EDGEPT *local_min, PointHeap *points)
 
void new_max_point (EDGEPT *local_max, PointHeap *points)
 
void vertical_projection_point (EDGEPT *split_point, EDGEPT *target_point, EDGEPT **best_point, EDGEPT_CLIST *new_points)
 
SEAMimprove_one_blob (const GenericVector< BLOB_CHOICE * > &blob_choices, DANGERR *fixpt, bool split_next_to_fragment, bool italic_blob, WERD_RES *word, int *blob_number)
 
SEAMchop_one_blob (const GenericVector< TBOX > &boxes, const GenericVector< BLOB_CHOICE * > &blob_choices, WERD_RES *word_res, int *blob_number)
 
void chop_word_main (WERD_RES *word)
 
void improve_by_chopping (float rating_cert_scale, WERD_RES *word, BestChoiceBundle *best_choice_bundle, BlamerBundle *blamer_bundle, LMPainPoints *pain_points, GenericVector< SegSearchPending > *pending)
 
int select_blob_to_split (const GenericVector< BLOB_CHOICE * > &blob_choices, float rating_ceiling, bool split_next_to_fragment)
 
int select_blob_to_split_from_fixpt (DANGERR *fixpt)
 
- Public Member Functions inherited from tesseract::Classify
 Classify ()
 
virtual ~Classify ()
 
DictgetDict ()
 
const ShapeTableshape_table () const
 
void SetStaticClassifier (ShapeClassifier *static_classifier)
 
void AddLargeSpeckleTo (int blob_length, BLOB_CHOICE_LIST *choices)
 
bool LargeSpeckle (const TBLOB &blob)
 
ADAPT_TEMPLATES NewAdaptedTemplates (bool InitFromUnicharset)
 
int GetFontinfoId (ADAPT_CLASS Class, uinT8 ConfigId)
 
int PruneClasses (const INT_TEMPLATES_STRUCT *int_templates, int num_features, int keep_this, const INT_FEATURE_STRUCT *features, const uinT8 *normalization_factors, const uinT16 *expected_num_features, GenericVector< CP_RESULT_STRUCT > *results)
 
void ReadNewCutoffs (FILE *CutoffFile, bool swap, inT64 end_offset, CLASS_CUTOFF_ARRAY Cutoffs)
 
void PrintAdaptedTemplates (FILE *File, ADAPT_TEMPLATES Templates)
 
void WriteAdaptedTemplates (FILE *File, ADAPT_TEMPLATES Templates)
 
ADAPT_TEMPLATES ReadAdaptedTemplates (FILE *File)
 
FLOAT32 ComputeNormMatch (CLASS_ID ClassId, const FEATURE_STRUCT &feature, BOOL8 DebugMatch)
 
void FreeNormProtos ()
 
NORM_PROTOSReadNormProtos (FILE *File, inT64 end_offset)
 
void ConvertProto (PROTO Proto, int ProtoId, INT_CLASS Class)
 
INT_TEMPLATES CreateIntTemplates (CLASSES FloatProtos, const UNICHARSET &target_unicharset)
 
void LearnWord (const char *fontname, WERD_RES *word)
 
void LearnPieces (const char *fontname, int start, int length, float threshold, CharSegmentationType segmentation, const char *correct_text, WERD_RES *word)
 
void InitAdaptiveClassifier (bool load_pre_trained_templates)
 
void InitAdaptedClass (TBLOB *Blob, CLASS_ID ClassId, int FontinfoId, ADAPT_CLASS Class, ADAPT_TEMPLATES Templates)
 
void AmbigClassifier (const GenericVector< INT_FEATURE_STRUCT > &int_features, const INT_FX_RESULT_STRUCT &fx_info, const TBLOB *blob, INT_TEMPLATES templates, ADAPT_CLASS *classes, UNICHAR_ID *ambiguities, ADAPT_RESULTS *results)
 
void MasterMatcher (INT_TEMPLATES templates, inT16 num_features, const INT_FEATURE_STRUCT *features, const uinT8 *norm_factors, ADAPT_CLASS *classes, int debug, int matcher_multiplier, const TBOX &blob_box, const GenericVector< CP_RESULT_STRUCT > &results, ADAPT_RESULTS *final_results)
 
void ExpandShapesAndApplyCorrections (ADAPT_CLASS *classes, bool debug, int class_id, int bottom, int top, float cp_rating, int blob_length, int matcher_multiplier, const uinT8 *cn_factors, UnicharRating *int_result, ADAPT_RESULTS *final_results)
 
double ComputeCorrectedRating (bool debug, int unichar_id, double cp_rating, double im_rating, int feature_misses, int bottom, int top, int blob_length, int matcher_multiplier, const uinT8 *cn_factors)
 
void ConvertMatchesToChoices (const DENORM &denorm, const TBOX &box, ADAPT_RESULTS *Results, BLOB_CHOICE_LIST *Choices)
 
void AddNewResult (const UnicharRating &new_result, ADAPT_RESULTS *results)
 
int GetAdaptiveFeatures (TBLOB *Blob, INT_FEATURE_ARRAY IntFeatures, FEATURE_SET *FloatFeatures)
 
void DebugAdaptiveClassifier (TBLOB *Blob, ADAPT_RESULTS *Results)
 
PROTO_ID MakeNewTempProtos (FEATURE_SET Features, int NumBadFeat, FEATURE_ID BadFeat[], INT_CLASS IClass, ADAPT_CLASS Class, BIT_VECTOR TempProtoMask)
 
int MakeNewTemporaryConfig (ADAPT_TEMPLATES Templates, CLASS_ID ClassId, int FontinfoId, int NumFeatures, INT_FEATURE_ARRAY Features, FEATURE_SET FloatFeatures)
 
void MakePermanent (ADAPT_TEMPLATES Templates, CLASS_ID ClassId, int ConfigId, TBLOB *Blob)
 
void PrintAdaptiveMatchResults (const ADAPT_RESULTS &results)
 
void RemoveExtraPuncs (ADAPT_RESULTS *Results)
 
void RemoveBadMatches (ADAPT_RESULTS *Results)
 
void SetAdaptiveThreshold (FLOAT32 Threshold)
 
void ShowBestMatchFor (int shape_id, const INT_FEATURE_STRUCT *features, int num_features)
 
STRING ClassIDToDebugStr (const INT_TEMPLATES_STRUCT *templates, int class_id, int config_id) const
 
int ClassAndConfigIDToFontOrShapeID (int class_id, int int_result_config) const
 
int ShapeIDToClassID (int shape_id) const
 
UNICHAR_IDBaselineClassifier (TBLOB *Blob, const GenericVector< INT_FEATURE_STRUCT > &int_features, const INT_FX_RESULT_STRUCT &fx_info, ADAPT_TEMPLATES Templates, ADAPT_RESULTS *Results)
 
int CharNormClassifier (TBLOB *blob, const TrainingSample &sample, ADAPT_RESULTS *adapt_results)
 
int CharNormTrainingSample (bool pruner_only, int keep_this, const TrainingSample &sample, GenericVector< UnicharRating > *results)
 
UNICHAR_IDGetAmbiguities (TBLOB *Blob, CLASS_ID CorrectClass)
 
void DoAdaptiveMatch (TBLOB *Blob, ADAPT_RESULTS *Results)
 
void AdaptToChar (TBLOB *Blob, CLASS_ID ClassId, int FontinfoId, FLOAT32 Threshold, ADAPT_TEMPLATES adaptive_templates)
 
void DisplayAdaptedChar (TBLOB *blob, INT_CLASS_STRUCT *int_class)
 
bool AdaptableWord (WERD_RES *word)
 
void EndAdaptiveClassifier ()
 
void SettupPass1 ()
 
void SettupPass2 ()
 
void AdaptiveClassifier (TBLOB *Blob, BLOB_CHOICE_LIST *Choices)
 
void ClassifyAsNoise (ADAPT_RESULTS *Results)
 
void ResetAdaptiveClassifierInternal ()
 
void SwitchAdaptiveClassifier ()
 
void StartBackupAdaptiveClassifier ()
 
int GetCharNormFeature (const INT_FX_RESULT_STRUCT &fx_info, INT_TEMPLATES templates, uinT8 *pruner_norm_array, uinT8 *char_norm_array)
 
void ComputeCharNormArrays (FEATURE_STRUCT *norm_feature, INT_TEMPLATES_STRUCT *templates, uinT8 *char_norm_array, uinT8 *pruner_array)
 
bool TempConfigReliable (CLASS_ID class_id, const TEMP_CONFIG &config)
 
void UpdateAmbigsGroup (CLASS_ID class_id, TBLOB *Blob)
 
bool AdaptiveClassifierIsFull () const
 
bool AdaptiveClassifierIsEmpty () const
 
bool LooksLikeGarbage (TBLOB *blob)
 
void RefreshDebugWindow (ScrollView **win, const char *msg, int y_offset, const TBOX &wbox)
 
void ClearCharNormArray (uinT8 *char_norm_array)
 
void ComputeIntCharNormArray (const FEATURE_STRUCT &norm_feature, uinT8 *char_norm_array)
 
void ComputeIntFeatures (FEATURE_SET Features, INT_FEATURE_ARRAY IntFeatures)
 
INT_TEMPLATES ReadIntTemplates (FILE *File)
 
void WriteIntTemplates (FILE *File, INT_TEMPLATES Templates, const UNICHARSET &target_unicharset)
 
CLASS_ID GetClassToDebug (const char *Prompt, bool *adaptive_on, bool *pretrained_on, int *shape_id)
 
void ShowMatchDisplay ()
 
UnicityTable< FontInfo > & get_fontinfo_table ()
 
const UnicityTable< FontInfo > & get_fontinfo_table () const
 
UnicityTable< FontSet > & get_fontset_table ()
 
void NormalizeOutlines (LIST Outlines, FLOAT32 *XScale, FLOAT32 *YScale)
 
FEATURE_SET ExtractOutlineFeatures (TBLOB *Blob)
 
FEATURE_SET ExtractPicoFeatures (TBLOB *Blob)
 
FEATURE_SET ExtractIntCNFeatures (const TBLOB &blob, const INT_FX_RESULT_STRUCT &fx_info)
 
FEATURE_SET ExtractIntGeoFeatures (const TBLOB &blob, const INT_FX_RESULT_STRUCT &fx_info)
 
void LearnBlob (const STRING &fontname, TBLOB *Blob, const DENORM &cn_denorm, const INT_FX_RESULT_STRUCT &fx_info, const char *blob_text)
 
bool WriteTRFile (const STRING &filename)
 
- Public Member Functions inherited from tesseract::CCStruct
 CCStruct ()
 
 ~CCStruct ()
 
- Public Member Functions inherited from tesseract::CUtil
 CUtil ()
 
 ~CUtil ()
 
void read_variables (const char *filename, bool global_only)
 
- Public Member Functions inherited from tesseract::CCUtil
 CCUtil ()
 
virtual ~CCUtil ()
 
void main_setup (const char *argv0, const char *basename)
 CCUtil::main_setup - set location of tessdata and name of image. More...
 
ParamsVectorsparams ()
 

Public Attributes

bool tessedit_resegment_from_boxes = false
 
bool tessedit_resegment_from_line_boxes = false
 
bool tessedit_train_from_boxes = false
 
bool tessedit_make_boxes_from_boxes = false
 
bool tessedit_dump_pageseg_images = false
 
int tessedit_pageseg_mode = PSM_SINGLE_BLOCK
 
int tessedit_ocr_engine_mode = tesseract::OEM_TESSERACT_ONLY
 
char * tessedit_char_blacklist = ""
 
char * tessedit_char_whitelist = ""
 
char * tessedit_char_unblacklist = ""
 
bool tessedit_ambigs_training = false
 
int pageseg_devanagari_split_strategy = tesseract::ShiroRekhaSplitter::NO_SPLIT
 
int ocr_devanagari_split_strategy = tesseract::ShiroRekhaSplitter::NO_SPLIT
 
char * tessedit_write_params_to_file = ""
 
bool tessedit_adaption_debug = false
 
int bidi_debug = 0
 
int applybox_debug = 1
 
int applybox_page = 0
 
char * applybox_exposure_pattern = ".exp"
 
bool applybox_learn_chars_and_char_frags_mode = false
 
bool applybox_learn_ngrams_mode = false
 
bool tessedit_display_outwords = false
 
bool tessedit_dump_choices = false
 
bool tessedit_timing_debug = false
 
bool tessedit_fix_fuzzy_spaces = true
 
bool tessedit_unrej_any_wd = false
 
bool tessedit_fix_hyphens = true
 
bool tessedit_redo_xheight = true
 
bool tessedit_enable_doc_dict = true
 
bool tessedit_debug_fonts = false
 
bool tessedit_debug_block_rejection = false
 
bool tessedit_enable_bigram_correction = true
 
bool tessedit_enable_dict_correction = false
 
int tessedit_bigram_debug = 0
 
bool enable_noise_removal = true
 
int debug_noise_removal = 0
 
double noise_cert_basechar = -8.0
 
double noise_cert_disjoint = -2.5
 
double noise_cert_punc = -2.5
 
double noise_cert_factor = 0.375
 
int noise_maxperblob = 8
 
int noise_maxperword = 16
 
int debug_x_ht_level = 0
 
bool debug_acceptable_wds = false
 
char * chs_leading_punct = "('`\""
 
char * chs_trailing_punct1 = ").,;:?!"
 
char * chs_trailing_punct2 = ")'`\""
 
double quality_rej_pc = 0.08
 
double quality_blob_pc = 0.0
 
double quality_outline_pc = 1.0
 
double quality_char_pc = 0.95
 
int quality_min_initial_alphas_reqd = 2
 
int tessedit_tess_adaption_mode = 0x27
 
bool tessedit_minimal_rej_pass1 = false
 
bool tessedit_test_adaption = false
 
bool tessedit_matcher_log = false
 
int tessedit_test_adaption_mode = 3
 
bool test_pt = false
 
double test_pt_x = 99999.99
 
double test_pt_y = 99999.99
 
int paragraph_debug_level = 0
 
bool paragraph_text_based = true
 
int cube_debug_level = 1
 
char * outlines_odd = "%| "
 
char * outlines_2 = "ij!?%\":;"
 
bool docqual_excuse_outline_errs = false
 
bool tessedit_good_quality_unrej = true
 
bool tessedit_use_reject_spaces = true
 
double tessedit_reject_doc_percent = 65.00
 
double tessedit_reject_block_percent = 45.00
 
double tessedit_reject_row_percent = 40.00
 
double tessedit_whole_wd_rej_row_percent = 70.00
 
bool tessedit_preserve_blk_rej_perfect_wds = true
 
bool tessedit_preserve_row_rej_perfect_wds = true
 
bool tessedit_dont_blkrej_good_wds = false
 
bool tessedit_dont_rowrej_good_wds = false
 
int tessedit_preserve_min_wd_len = 2
 
bool tessedit_row_rej_good_docs = true
 
double tessedit_good_doc_still_rowrej_wd = 1.1
 
bool tessedit_reject_bad_qual_wds = true
 
bool tessedit_debug_doc_rejection = false
 
bool tessedit_debug_quality_metrics = false
 
bool bland_unrej = false
 
double quality_rowrej_pc = 1.1
 
bool unlv_tilde_crunching = true
 
bool hocr_font_info = false
 
bool crunch_early_merge_tess_fails = true
 
bool crunch_early_convert_bad_unlv_chs = false
 
double crunch_terrible_rating = 80.0
 
bool crunch_terrible_garbage = true
 
double crunch_poor_garbage_cert = -9.0
 
double crunch_poor_garbage_rate = 60
 
double crunch_pot_poor_rate = 40
 
double crunch_pot_poor_cert = -8.0
 
bool crunch_pot_garbage = true
 
double crunch_del_rating = 60
 
double crunch_del_cert = -10.0
 
double crunch_del_min_ht = 0.7
 
double crunch_del_max_ht = 3.0
 
double crunch_del_min_width = 3.0
 
double crunch_del_high_word = 1.5
 
double crunch_del_low_word = 0.5
 
double crunch_small_outlines_size = 0.6
 
int crunch_rating_max = 10
 
int crunch_pot_indicators = 1
 
bool crunch_leave_ok_strings = true
 
bool crunch_accept_ok = true
 
bool crunch_leave_accept_strings = false
 
bool crunch_include_numerals = false
 
int crunch_leave_lc_strings = 4
 
int crunch_leave_uc_strings = 4
 
int crunch_long_repetitions = 3
 
int crunch_debug = 0
 
int fixsp_non_noise_limit = 1
 
double fixsp_small_outlines_size = 0.28
 
bool tessedit_prefer_joined_punct = false
 
int fixsp_done_mode = 1
 
int debug_fix_space_level = 0
 
char * numeric_punctuation = ".,"
 
int x_ht_acceptance_tolerance = 8
 
int x_ht_min_change = 8
 
int superscript_debug = 0
 
double superscript_worse_certainty = 2.0
 
double superscript_bettered_certainty = 0.97
 
double superscript_scaledown_ratio = 0.4
 
double subscript_max_y_top = 0.5
 
double superscript_min_y_bottom = 0.3
 
bool tessedit_write_block_separators = false
 
bool tessedit_write_rep_codes = false
 
bool tessedit_write_unlv = false
 
bool tessedit_create_txt = false
 
bool tessedit_create_hocr = false
 
bool tessedit_create_tsv = false
 
bool tessedit_create_pdf = false
 
char * unrecognised_char = "|"
 
int suspect_level = 99
 
int suspect_space_level = 100
 
int suspect_short_words = 2
 
bool suspect_constrain_1Il = false
 
double suspect_rating_per_ch = 999.9
 
double suspect_accept_rating = -999.9
 
bool tessedit_minimal_rejection = false
 
bool tessedit_zero_rejection = false
 
bool tessedit_word_for_word = false
 
bool tessedit_zero_kelvin_rejection = false
 
bool tessedit_consistent_reps = true
 
int tessedit_reject_mode = 0
 
bool tessedit_rejection_debug = false
 
bool tessedit_flip_0O = true
 
double tessedit_lower_flip_hyphen = 1.5
 
double tessedit_upper_flip_hyphen = 1.8
 
bool rej_trust_doc_dawg = false
 
bool rej_1Il_use_dict_word = false
 
bool rej_1Il_trust_permuter_type = true
 
bool rej_use_tess_accepted = true
 
bool rej_use_tess_blanks = true
 
bool rej_use_good_perm = true
 
bool rej_use_sensible_wd = false
 
bool rej_alphas_in_number_perm = false
 
double rej_whole_of_mostly_reject_word_fract = 0.85
 
int tessedit_image_border = 2
 
char * ok_repeated_ch_non_alphanum_wds = "-?*\075"
 
char * conflict_set_I_l_1 = "Il1[]"
 
int min_sane_x_ht_pixels = 8
 
bool tessedit_create_boxfile = false
 
int tessedit_page_number = -1
 
bool tessedit_write_images = false
 
bool interactive_display_mode = false
 
char * file_type = ".tif"
 
bool tessedit_override_permuter = true
 
int tessdata_manager_debug_level = 0
 
char * tessedit_load_sublangs = ""
 
bool tessedit_use_primary_params_model = false
 
double min_orientation_margin = 7.0
 
bool textord_tabfind_show_vlines = false
 
bool textord_use_cjk_fp_model = FALSE
 
bool poly_allow_detailed_fx = false
 
bool tessedit_init_config_only = false
 
bool textord_equation_detect = false
 
bool textord_tabfind_vertical_text = true
 
bool textord_tabfind_force_vertical_text = false
 
double textord_tabfind_vertical_text_ratio = 0.5
 
double textord_tabfind_aligned_gap_fraction = 0.75
 
int tessedit_parallelize = 0
 
bool preserve_interword_spaces = false
 
bool include_page_breaks = false
 
char * page_separator = "\f"
 
bool textord_tabfind_vertical_horizontal_mix = true
 
int tessedit_ok_mode = 5
 
bool load_fixed_length_dawgs = true
 
int segment_debug = 0
 
bool permute_debug = 0
 
double bestrate_pruning_factor = 2.0
 
bool permute_script_word = 0
 
bool segment_segcost_rating = 0
 
double segment_reward_script = 0.95
 
bool permute_fixed_length_dawg = 0
 
bool permute_chartype_word = 0
 
double segment_reward_chartype = 0.97
 
double segment_reward_ngram_best_choice = 0.99
 
bool ngram_permuter_activated = false
 
bool permute_only_top = false
 
int language_model_fixed_length_choices_depth = 3
 
bool use_new_state_cost = FALSE
 
double heuristic_segcost_rating_base = 1.25
 
double heuristic_weight_rating = 1
 
double heuristic_weight_width = 1000.0
 
double heuristic_weight_seamcut = 0
 
double heuristic_max_char_wh_ratio = 2.0
 
bool enable_new_segsearch = false
 
double segsearch_max_fixed_pitch_char_wh_ratio = 2.0
 
- Public Attributes inherited from tesseract::Wordrec
bool merge_fragments_in_matrix = TRUE
 
bool wordrec_no_block = FALSE
 
bool wordrec_enable_assoc = TRUE
 
bool force_word_assoc = FALSE
 
double wordrec_worst_state = 1
 
bool fragments_guide_chopper = FALSE
 
int repair_unchopped_blobs = 1
 
double tessedit_certainty_threshold = -2.25
 
int chop_debug = 0
 
bool chop_enable = 1
 
bool chop_vertical_creep = 0
 
int chop_split_length = 10000
 
int chop_same_distance = 2
 
int chop_min_outline_points = 6
 
int chop_seam_pile_size = 150
 
bool chop_new_seam_pile = 1
 
int chop_inside_angle = -50
 
int chop_min_outline_area = 2000
 
double chop_split_dist_knob = 0.5
 
double chop_overlap_knob = 0.9
 
double chop_center_knob = 0.15
 
int chop_centered_maxwidth = 90
 
double chop_sharpness_knob = 0.06
 
double chop_width_change_knob = 5.0
 
double chop_ok_split = 100.0
 
double chop_good_split = 50.0
 
int chop_x_y_weight = 3
 
int segment_adjust_debug = 0
 
bool assume_fixed_pitch_char_segment = FALSE
 
int wordrec_debug_level = 0
 
int wordrec_max_join_chunks = 4
 
bool wordrec_skip_no_truth_words = false
 
bool wordrec_debug_blamer = false
 
bool wordrec_run_blamer = false
 
int segsearch_debug_level = 0
 
int segsearch_max_pain_points = 2000
 
int segsearch_max_futile_classifications = 10
 
double segsearch_max_char_wh_ratio = 2.0
 
bool save_alt_choices = true
 
LanguageModellanguage_model_
 
PRIORITY pass2_ok_split
 
WERD_CHOICEprev_word_best_choice_
 
GenericVector< int > blame_reasons_
 
void(Wordrec::* fill_lattice_ )(const MATRIX &ratings, const WERD_CHOICE_LIST &best_choices, const UNICHARSET &unicharset, BlamerBundle *blamer_bundle)
 
- Public Attributes inherited from tesseract::Classify
bool allow_blob_division = true
 
bool prioritize_division = FALSE
 
int tessedit_single_match = FALSE
 
bool classify_enable_learning = true
 
int classify_debug_level = 0
 
int classify_norm_method = character
 
double classify_char_norm_range = 0.2
 
double classify_min_norm_scale_x = 0.0
 
double classify_max_norm_scale_x = 0.325
 
double classify_min_norm_scale_y = 0.0
 
double classify_max_norm_scale_y = 0.325
 
double classify_max_rating_ratio = 1.5
 
double classify_max_certainty_margin = 5.5
 
bool tess_cn_matching = 0
 
bool tess_bn_matching = 0
 
bool classify_enable_adaptive_matcher = 1
 
bool classify_use_pre_adapted_templates = 0
 
bool classify_save_adapted_templates = 0
 
bool classify_enable_adaptive_debugger = 0
 
bool classify_nonlinear_norm = 0
 
int matcher_debug_level = 0
 
int matcher_debug_flags = 0
 
int classify_learning_debug_level = 0
 
double matcher_good_threshold = 0.125
 
double matcher_reliable_adaptive_result = 0.0
 
double matcher_perfect_threshold = 0.02
 
double matcher_bad_match_pad = 0.15
 
double matcher_rating_margin = 0.1
 
double matcher_avg_noise_size = 12.0
 
int matcher_permanent_classes_min = 1
 
int matcher_min_examples_for_prototyping = 3
 
int matcher_sufficient_examples_for_prototyping = 5
 
double matcher_clustering_max_angle_delta = 0.015
 
double classify_misfit_junk_penalty = 0.0
 
double rating_scale = 1.5
 
double certainty_scale = 20.0
 
double tessedit_class_miss_scale = 0.00390625
 
double classify_adapted_pruning_factor = 2.5
 
double classify_adapted_pruning_threshold = -1.0
 
int classify_adapt_proto_threshold = 230
 
int classify_adapt_feature_threshold = 230
 
bool disable_character_fragments = TRUE
 
double classify_character_fragments_garbage_certainty_threshold = -3.0
 
bool classify_debug_character_fragments = FALSE
 
bool matcher_debug_separate_windows = FALSE
 
char * classify_learn_debug_str = ""
 
int classify_class_pruner_threshold = 229
 
int classify_class_pruner_multiplier = 15
 
int classify_cp_cutoff_strength = 7
 
int classify_integer_matcher_multiplier = 10
 
INT_TEMPLATES PreTrainedTemplates
 
ADAPT_TEMPLATES AdaptedTemplates
 
ADAPT_TEMPLATES BackupAdaptedTemplates
 
BIT_VECTOR AllProtosOn
 
BIT_VECTOR AllConfigsOn
 
BIT_VECTOR AllConfigsOff
 
BIT_VECTOR TempProtoMask
 
bool EnableLearning
 
NORM_PROTOSNormProtos
 
UnicityTable< FontInfofontinfo_table_
 
UnicityTable< FontSetfontset_table_
 
int il1_adaption_test = 0
 
bool classify_bln_numeric_mode = 0
 
double speckle_large_max_size = 0.30
 
double speckle_rating_penalty = 10.0
 
- Public Attributes inherited from tesseract::CCUtil
STRING datadir
 
STRING imagebasename
 
STRING lang
 
STRING language_data_path_prefix
 
TessdataManager tessdata_manager
 
UNICHARSET unicharset
 
UnicharAmbigs unichar_ambigs
 
STRING imagefile
 
STRING directory
 
char * m_data_sub_dir = "tessdata/"
 
int ambigs_debug_level = 0
 
bool use_definite_ambigs_for_classifier = 0
 
bool use_ambigs_for_adaption = 0
 

Additional Inherited Members

- Static Public Member Functions inherited from tesseract::Classify
static void SetupBLCNDenorms (const TBLOB &blob, bool nonlinear_norm, DENORM *bl_denorm, DENORM *cn_denorm, INT_FX_RESULT_STRUCT *fx_info)
 
static void ExtractFeatures (const TBLOB &blob, bool nonlinear_norm, GenericVector< INT_FEATURE_STRUCT > *bl_features, GenericVector< INT_FEATURE_STRUCT > *cn_features, INT_FX_RESULT_STRUCT *results, GenericVector< int > *outline_cn_counts)
 
- Static Public Attributes inherited from tesseract::CCStruct
static const double kDescenderFraction = 0.25
 
static const double kXHeightFraction = 0.5
 
static const double kAscenderFraction = 0.25
 
static const double kXHeightCapRatio
 
- Protected Member Functions inherited from tesseract::Wordrec
bool SegSearchDone (int num_futile_classifications)
 
void UpdateSegSearchNodes (float rating_cert_scale, int starting_col, GenericVector< SegSearchPending > *pending, WERD_RES *word_res, LMPainPoints *pain_points, BestChoiceBundle *best_choice_bundle, BlamerBundle *blamer_bundle)
 
void ProcessSegSearchPainPoint (float pain_point_priority, const MATRIX_COORD &pain_point, const char *pain_point_type, GenericVector< SegSearchPending > *pending, WERD_RES *word_res, LMPainPoints *pain_points, BlamerBundle *blamer_bundle)
 
void ResetNGramSearch (WERD_RES *word_res, BestChoiceBundle *best_choice_bundle, GenericVector< SegSearchPending > *pending)
 
void InitBlamerForSegSearch (WERD_RES *word_res, LMPainPoints *pain_points, BlamerBundle *blamer_bundle, STRING *blamer_debug)
 
- Protected Attributes inherited from tesseract::Classify
IntegerMatcher im_
 
FEATURE_DEFS_STRUCT feature_defs_
 
ShapeTableshape_table_
 

Detailed Description

Definition at line 170 of file tesseractclass.h.

Constructor & Destructor Documentation

tesseract::Tesseract::Tesseract ( )

Definition at line 57 of file tesseractclass.cpp.

59  "Take segmentation and labeling from box file",
60  this->params()),
62  "Conversion of word/line box file to char box file",
63  this->params()),
65  "Generate training data from boxed chars", this->params()),
67  "Generate more boxes from boxed chars", this->params()),
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(
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()),
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()),
86  "Blacklist of chars not to recognize", this->params()),
88  "Whitelist of chars to recognize", this->params()),
90  "List of chars to override tessedit_char_blacklist",
91  this->params()),
93  "Perform training for ambiguities", this->params()),
96  "Whether to use the top-line splitting process for Devanagari "
97  "documents while performing page-segmentation.",
98  this->params()),
101  "Whether to use the top-line splitting process for Devanagari "
102  "documents while performing ocr.",
103  this->params()),
105  "Write all parameters to the given file.", this->params()),
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()),
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()),
121  "Learn both character fragments (as is done in the"
122  " special low exposure mode) as well as unfragmented"
123  " characters.",
124  this->params()),
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()),
137  "Try to improve fuzzy spaces", this->params()),
139  "Don't 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()),
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()),
151  "Enable correction based on the word bigram dictionary.",
152  this->params()),
154  "Enable single word correction based on the dictionary.",
155  this->params()),
157  "Amount of debug output for bigram correction.",
158  this->params()),
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.
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.
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.
177  "Threshold for new punc char certainty", this->params()),
178  // Factor of certainty margin for adding diacritics to not count as worse.
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()),
196  "good_quality_doc lte rejection limit", this->params()),
198  "good_quality_doc gte good blobs limit", this->params()),
200  "good_quality_doc lte outline error limit", this->params()),
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()),
206  "Adaptation decision algorithm for tess", this->params()),
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()),
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()),
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()),
230  "Allow outline errs in unrejection?", this->params()),
232  "Reduce rejection on good docs", this->params()),
233  BOOL_MEMBER(tessedit_use_reject_spaces, true, "Reject spaces?",
234  this->params()),
236  "%rej allowed before rej whole doc", this->params()),
238  "%rej allowed before rej whole block", this->params()),
240  "%rej allowed before rej whole row", this->params()),
242  "Number of row rejects in whole word rejects"
243  "which prevents whole row rejection",
244  this->params()),
246  "Only rej partially rejected words in block rejection",
247  this->params()),
249  "Only rej partially rejected words in row rejection",
250  this->params()),
252  "Use word segmentation quality metric", this->params()),
254  "Use word segmentation quality metric", this->params()),
256  "Only preserve wds longer than this", this->params()),
258  "Apply row rejection to good docs", this->params()),
260  "rej good doc wd if more than this fraction rejected",
261  this->params()),
263  "Reject all bad quality wds", this->params()),
264  BOOL_MEMBER(tessedit_debug_doc_rejection, false, "Page stats",
265  this->params()),
267  "Output data to debug file", this->params()),
268  BOOL_MEMBER(bland_unrej, false, "unrej potential with no chekcs",
269  this->params()),
271  "good_quality_doc gte good char limit", this->params()),
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()),
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()),
284  "crunch garbage cert lt this", this->params()),
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()),
302  "Del if word width lt xht x this", this->params()),
304  "Del if word gt xht x this above bl", this->params()),
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()),
312  "How many potential indicators needed", this->params()),
313  BOOL_MEMBER(crunch_leave_ok_strings, true, "Don't touch sensible strings",
314  this->params()),
315  BOOL_MEMBER(crunch_accept_ok, true, "Use acceptability in okstring",
316  this->params()),
318  "Don't pot crunch sensible strings", this->params()),
319  BOOL_MEMBER(crunch_include_numerals, false, "Fiddle alpha figures",
320  this->params()),
322  "Don't crunch words with long lower case strings",
323  this->params()),
325  "Don't crunch words with long lower case strings",
326  this->params()),
328  "Crunch words with long repetitions", this->params()),
329  INT_MEMBER(crunch_debug, 0, "As it says", this->params()),
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()),
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()),
341  "Punct. chs expected WITHIN numbers", this->params()),
343  "Max allowed deviation of blob top outside of font data",
344  this->params()),
346  "Min change in xht before actually trying it", this->params()),
348  "Debug level for sub & superscript fixer", this->params()),
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()),
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()),
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()),
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()),
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()),
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, false, "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_tsv, false, "Write .tsv output file",
389  this->params()),
390  BOOL_MEMBER(tessedit_create_pdf, false, "Write .pdf output file",
391  this->params()),
393  "Output char for unidentified blobs", this->params()),
394  INT_MEMBER(suspect_level, 99, "Suspect marker level", this->params()),
396  "Min suspect level for rejecting spaces", this->params()),
398  "Don't suspect dict wds longer than this", this->params()),
399  BOOL_MEMBER(suspect_constrain_1Il, false, "UNLV keep 1Il chars rejected",
400  this->params()),
402  "Don't touch bad rating limit", this->params()),
403  double_MEMBER(suspect_accept_rating, -999.9, "Accept good rating limit",
404  this->params()),
406  "Only reject tess failures", this->params()),
407  BOOL_MEMBER(tessedit_zero_rejection, false, "Don't reject ANYTHING",
408  this->params()),
410  "Make output have exactly one word per WERD", this->params()),
412  "Don't reject ANYTHING AT ALL", this->params()),
414  "Force all rep chars the same", this->params()),
415  INT_MEMBER(tessedit_reject_mode, 0, "Rejection algorithm",
416  this->params()),
417  BOOL_MEMBER(tessedit_rejection_debug, false, "Adaption debug",
418  this->params()),
419  BOOL_MEMBER(tessedit_flip_0O, true, "Contextual 0O O0 flips",
420  this->params()),
422  "Aspect ratio dot/hyphen test", this->params()),
424  "Aspect ratio dot/hyphen test", this->params()),
426  "Use DOC dawg in 11l conf. detector", this->params()),
427  BOOL_MEMBER(rej_1Il_use_dict_word, false, "Use dictword test",
428  this->params()),
429  BOOL_MEMBER(rej_1Il_trust_permuter_type, true, "Don't double check",
430  this->params()),
431  BOOL_MEMBER(rej_use_tess_accepted, true, "Individual rejection control",
432  this->params()),
433  BOOL_MEMBER(rej_use_tess_blanks, true, "Individual rejection control",
434  this->params()),
435  BOOL_MEMBER(rej_use_good_perm, true, "Individual rejection control",
436  this->params()),
437  BOOL_MEMBER(rej_use_sensible_wd, false, "Extend permuter check",
438  this->params()),
439  BOOL_MEMBER(rej_alphas_in_number_perm, false, "Extend permuter check",
440  this->params()),
442  "if >this fract", this->params()),
443  INT_MEMBER(tessedit_image_border, 2, "Rej blbs near image edge limit",
444  this->params()),
446  "Allow NN to unrej", this->params()),
447  STRING_MEMBER(conflict_set_I_l_1, "Il1[]", "Il1 conflict set",
448  this->params()),
449  INT_MEMBER(min_sane_x_ht_pixels, 8, "Reject any x-ht lt or eq than this",
450  this->params()),
451  BOOL_MEMBER(tessedit_create_boxfile, false, "Output text with boxes",
452  this->params()),
454  "-1 -> All pages"
455  " , else specifc page to process",
456  this->params()),
458  "Capture the image from the IPE", this->params()),
459  BOOL_MEMBER(interactive_display_mode, false, "Run interactively?",
460  this->params()),
461  STRING_MEMBER(file_type, ".tif", "Filename extension", this->params()),
462  BOOL_MEMBER(tessedit_override_permuter, true, "According to dict_word",
463  this->params()),
465  "Debug level for"
466  " TessdataManager functions.",
467  this->params()),
469  "List of languages to load with this one", this->params()),
471  "In multilingual mode use params model of the"
472  " primary language",
473  this->params()),
475  "Min acceptable orientation margin", this->params()),
476  BOOL_MEMBER(textord_tabfind_show_vlines, false, "Debug line finding",
477  this->params()),
478  BOOL_MEMBER(textord_use_cjk_fp_model, FALSE, "Use CJK fixed pitch model",
479  this->params()),
481  "Allow feature extractors to see the original outline",
482  this->params()),
484  "Only initialize with the config file. Useful if the "
485  "instance is not going to be used for OCR but say only "
486  "for layout analysis.",
487  this->params()),
488  BOOL_MEMBER(textord_equation_detect, false, "Turn on equation detector",
489  this->params()),
491  "Enable vertical detection", this->params()),
493  "Force using vertical text page mode", this->params()),
496  "Fraction of textlines deemed vertical to use vertical page "
497  "mode",
498  this->params()),
501  "Fraction of height used as a minimum gap for aligned blobs.",
502  this->params()),
503  INT_MEMBER(tessedit_parallelize, 0, "Run in parallel where possible",
504  this->params()),
506  "Preserve multiple interword spaces", this->params()),
508  "Include page separator string in output text after each "
509  "image/page.",
510  this->params()),
512  "Page separator (default is form feed control character)",
513  this->params()),
514 
515  // The following parameters were deprecated and removed from their
516  // original
517  // locations. The parameters are temporarily kept here to give Tesseract
518  // users a chance to updated their [lang].traineddata and config files
519  // without introducing failures during Tesseract initialization.
520  // TODO(ocr-team): remove these parameters from the code once we are
521  // reasonably sure that Tesseract users have updated their data files.
522  //
523  // BEGIN DEPRECATED PARAMETERS
525  "find horizontal lines such as headers in vertical page mode",
526  this->params()),
527  INT_MEMBER(tessedit_ok_mode, 5, "Acceptance decision algorithm",
528  this->params()),
530  "Load fixed length dawgs"
531  " (e.g. for non-space delimited languages)",
532  this->params()),
533  INT_MEMBER(segment_debug, 0, "Debug the whole segmentation process",
534  this->params()),
535  BOOL_MEMBER(permute_debug, 0, "Debug char permutation process",
536  this->params()),
538  "Multiplying factor of"
539  " current best rate to prune other hypotheses",
540  this->params()),
542  "Turn on word script consistency permuter", this->params()),
544  "incorporate segmentation cost in word rating?",
545  this->params()),
547  "Score multipler for script consistency within a word. "
548  "Being a 'reward' factor, it should be <= 1. "
549  "Smaller value implies bigger reward.",
550  this->params()),
552  "Turn on fixed-length phrasebook search permuter",
553  this->params()),
555  "Turn on character type (property) consistency permuter",
556  this->params()),
558  "Score multipler for char type consistency within a word. ",
559  this->params()),
561  "Score multipler for ngram permuter's best choice"
562  " (only used in the Han script path).",
563  this->params()),
565  "Activate character-level n-gram-based permuter",
566  this->params()),
567  BOOL_MEMBER(permute_only_top, false, "Run only the top choice permuter",
568  this->params()),
570  "Depth of blob choice lists to explore"
571  " when fixed length dawgs are on",
572  this->params()),
574  "use new state cost heuristics for segmentation state"
575  " evaluation",
576  this->params()),
578  "base factor for adding segmentation cost into word rating."
579  "It's a multiplying factor, the larger the value above 1, "
580  "the bigger the effect of segmentation cost.",
581  this->params()),
583  "weight associated with char rating in combined cost of"
584  "state",
585  this->params()),
587  "weight associated with width evidence in combined cost of"
588  " state",
589  this->params()),
591  "weight associated with seam cut in combined cost of state",
592  this->params()),
594  "max char width-to-height ratio allowed in segmentation",
595  this->params()),
597  "Enable new segmentation search path.", this->params()),
599  "Maximum character width-to-height ratio for"
600  " fixed-pitch fonts",
601  this->params()),
602  // END DEPRECATED PARAMETERS
603 
604  backup_config_file_(NULL),
605  pix_binary_(NULL),
606  cube_binary_(NULL),
607  pix_grey_(NULL),
608  pix_original_(NULL),
609  pix_thresholds_(NULL),
610  source_resolution_(0),
611  textord_(this),
612  right_to_left_(false),
613  scaled_color_(NULL),
614  scaled_factor_(-1),
615  deskew_(1.0f, 0.0f),
616  reskew_(1.0f, 0.0f),
617  most_recently_used_(this),
618  font_table_size_(0),
619 #ifndef NO_CUBE_BUILD
620  cube_cntxt_(NULL),
621  tess_cube_combiner_(NULL),
622 #endif
623  equ_detect_(NULL) {
624 }
bool tessedit_preserve_blk_rej_perfect_wds
#define STRING_MEMBER(name, val, comment, vec)
Definition: params.h:307
double superscript_bettered_certainty
double heuristic_segcost_rating_base
double tessedit_reject_block_percent
Assume a single uniform block of text. (Default.)
Definition: publictypes.h:160
double segsearch_max_fixed_pitch_char_wh_ratio
double tessedit_reject_doc_percent
char * ok_repeated_ch_non_alphanum_wds
#define BOOL_MEMBER(name, val, comment, vec)
Definition: params.h:304
#define BOOL_INIT_MEMBER(name, val, comment, vec)
Definition: params.h:316
double textord_tabfind_aligned_gap_fraction
double rej_whole_of_mostly_reject_word_fract
bool applybox_learn_chars_and_char_frags_mode
bool textord_tabfind_vertical_horizontal_mix
double superscript_scaledown_ratio
#define FALSE
Definition: capi.h:46
double textord_tabfind_vertical_text_ratio
double tessedit_good_doc_still_rowrej_wd
double tessedit_whole_wd_rej_row_percent
bool crunch_early_convert_bad_unlv_chs
#define INT_INIT_MEMBER(name, val, comment, vec)
Definition: params.h:313
int language_model_fixed_length_choices_depth
double superscript_worse_certainty
bool tessedit_preserve_row_rej_perfect_wds
double tessedit_reject_row_percent
ParamsVectors * params()
Definition: ccutil.h:63
char * tessedit_write_params_to_file
bool tessedit_enable_bigram_correction
bool textord_tabfind_force_vertical_text
#define double_MEMBER(name, val, comment, vec)
Definition: params.h:310
#define INT_MEMBER(name, val, comment, vec)
Definition: params.h:301
bool tessedit_resegment_from_line_boxes
double segment_reward_ngram_best_choice
tesseract::Tesseract::~Tesseract ( )

Definition at line 626 of file tesseractclass.cpp.

626  {
627  Clear();
628  pixDestroy(&pix_original_);
629  end_tesseract();
630  sub_langs_.delete_data_pointers();
631 #ifndef NO_CUBE_BUILD
632  // Delete cube objects.
633  if (cube_cntxt_ != NULL) {
634  delete cube_cntxt_;
635  cube_cntxt_ = NULL;
636  }
637  if (tess_cube_combiner_ != NULL) {
638  delete tess_cube_combiner_;
639  tess_cube_combiner_ = NULL;
640  }
641 #endif
642 }

Member Function Documentation

BOOL8 tesseract::Tesseract::acceptable_number_string ( const char *  s,
const char *  lengths 
)

Definition at line 419 of file output.cpp.

420  {
421  BOOL8 prev_digit = FALSE;
422 
423  if (*lengths == 1 && *s == '(')
424  s++;
425 
426  if (*lengths == 1 &&
427  ((*s == '$') || (*s == '.') || (*s == '+') || (*s == '-')))
428  s++;
429 
430  for (; *s != '\0'; s += *(lengths++)) {
431  if (unicharset.get_isdigit(s, *lengths))
432  prev_digit = TRUE;
433  else if (prev_digit &&
434  (*lengths == 1 && ((*s == '.') || (*s == ',') || (*s == '-'))))
435  prev_digit = FALSE;
436  else if (prev_digit && *lengths == 1 &&
437  (*(s + *lengths) == '\0') && ((*s == '%') || (*s == ')')))
438  return TRUE;
439  else if (prev_digit &&
440  *lengths == 1 && (*s == '%') &&
441  (*(lengths + 1) == 1 && *(s + *lengths) == ')') &&
442  (*(s + *lengths + *(lengths + 1)) == '\0'))
443  return TRUE;
444  else
445  return FALSE;
446  }
447  return TRUE;
448 }
#define TRUE
Definition: capi.h:45
bool get_isdigit(UNICHAR_ID unichar_id) const
Definition: unicharset.h:469
#define FALSE
Definition: capi.h:46
UNICHARSET unicharset
Definition: ccutil.h:70
unsigned char BOOL8
Definition: host.h:113
ACCEPTABLE_WERD_TYPE tesseract::Tesseract::acceptable_word_string ( const UNICHARSET char_set,
const char *  s,
const char *  lengths 
)

Definition at line 1668 of file control.cpp.

1669  {
1670  int i = 0;
1671  int offset = 0;
1672  int leading_punct_count;
1673  int upper_count = 0;
1674  int hyphen_pos = -1;
1676 
1677  if (strlen (lengths) > 20)
1678  return word_type;
1679 
1680  /* Single Leading punctuation char*/
1681 
1682  if (s[offset] != '\0' && STRING(chs_leading_punct).contains(s[offset]))
1683  offset += lengths[i++];
1684  leading_punct_count = i;
1685 
1686  /* Initial cap */
1687  while (s[offset] != '\0' && char_set.get_isupper(s + offset, lengths[i])) {
1688  offset += lengths[i++];
1689  upper_count++;
1690  }
1691  if (upper_count > 1) {
1692  word_type = AC_UPPER_CASE;
1693  } else {
1694  /* Lower case word, possibly with an initial cap */
1695  while (s[offset] != '\0' && char_set.get_islower(s + offset, lengths[i])) {
1696  offset += lengths[i++];
1697  }
1698  if (i - leading_punct_count < quality_min_initial_alphas_reqd)
1699  goto not_a_word;
1700  /*
1701  Allow a single hyphen in a lower case word
1702  - don't trust upper case - I've seen several cases of "H" -> "I-I"
1703  */
1704  if (lengths[i] == 1 && s[offset] == '-') {
1705  hyphen_pos = i;
1706  offset += lengths[i++];
1707  if (s[offset] != '\0') {
1708  while ((s[offset] != '\0') &&
1709  char_set.get_islower(s + offset, lengths[i])) {
1710  offset += lengths[i++];
1711  }
1712  if (i < hyphen_pos + 3)
1713  goto not_a_word;
1714  }
1715  } else {
1716  /* Allow "'s" in NON hyphenated lower case words */
1717  if (lengths[i] == 1 && (s[offset] == '\'') &&
1718  lengths[i + 1] == 1 && (s[offset + lengths[i]] == 's')) {
1719  offset += lengths[i++];
1720  offset += lengths[i++];
1721  }
1722  }
1723  if (upper_count > 0)
1724  word_type = AC_INITIAL_CAP;
1725  else
1726  word_type = AC_LOWER_CASE;
1727  }
1728 
1729  /* Up to two different, constrained trailing punctuation chars */
1730  if (lengths[i] == 1 && s[offset] != '\0' &&
1731  STRING(chs_trailing_punct1).contains(s[offset]))
1732  offset += lengths[i++];
1733  if (lengths[i] == 1 && s[offset] != '\0' && i > 0 &&
1734  s[offset - lengths[i - 1]] != s[offset] &&
1735  STRING(chs_trailing_punct2).contains (s[offset]))
1736  offset += lengths[i++];
1737 
1738  if (s[offset] != '\0')
1739  word_type = AC_UNACCEPTABLE;
1740 
1741  not_a_word:
1742 
1743  if (word_type == AC_UNACCEPTABLE) {
1744  /* Look for abbreviation string */
1745  i = 0;
1746  offset = 0;
1747  if (s[0] != '\0' && char_set.get_isupper(s, lengths[0])) {
1748  word_type = AC_UC_ABBREV;
1749  while (s[offset] != '\0' &&
1750  char_set.get_isupper(s + offset, lengths[i]) &&
1751  lengths[i + 1] == 1 && s[offset + lengths[i]] == '.') {
1752  offset += lengths[i++];
1753  offset += lengths[i++];
1754  }
1755  }
1756  else if (s[0] != '\0' && char_set.get_islower(s, lengths[0])) {
1757  word_type = AC_LC_ABBREV;
1758  while (s[offset] != '\0' &&
1759  char_set.get_islower(s + offset, lengths[i]) &&
1760  lengths[i + 1] == 1 && s[offset + lengths[i]] == '.') {
1761  offset += lengths[i++];
1762  offset += lengths[i++];
1763  }
1764  }
1765  if (s[offset] != '\0')
1766  word_type = AC_UNACCEPTABLE;
1767  }
1768 
1769  return word_type;
1770 }
BOOL8 contains(const char c) const
Definition: strngs.cpp:192
bool get_isupper(UNICHAR_ID unichar_id) const
Definition: unicharset.h:462
Definition: strngs.h:44
ALL upper case.
Definition: control.h:38
a.b.c.
Definition: control.h:40
ALL but initial lc.
Definition: control.h:39
ALL lower case.
Definition: control.h:37
Unacceptable word.
Definition: control.h:36
ACCEPTABLE_WERD_TYPE
Definition: control.h:34
bool get_islower(UNICHAR_ID unichar_id) const
Definition: unicharset.h:455
A.B.C.
Definition: control.h:41
inT16 tesseract::Tesseract::alpha_count ( const char *  word,
const char *  word_lengths 
)

Definition at line 495 of file reject.cpp.

496  {
497  inT16 i;
498  inT16 offset;
499  inT16 count = 0;
500 
501  for (i = 0, offset = 0; word[offset] != '\0'; offset += word_lengths[i++]) {
502  if (unicharset.get_isalpha (word + offset, word_lengths[i]))
503  count++;
504  }
505  return count;
506 }
int count(LIST var_list)
Definition: oldlist.cpp:108
bool get_isalpha(UNICHAR_ID unichar_id) const
Definition: unicharset.h:448
short inT16
Definition: host.h:100
UNICHARSET unicharset
Definition: ccutil.h:70
void tesseract::Tesseract::ambigs_classify_and_output ( const char *  label,
PAGE_RES_IT pr_it,
FILE *  output_file 
)

Definition at line 202 of file recogtraining.cpp.

204  {
205  // Classify word.
206  fflush(stdout);
207  WordData word_data(*pr_it);
208  SetupWordPassN(1, &word_data);
209  classify_word_and_language(1, pr_it, &word_data);
210  WERD_RES* werd_res = word_data.word;
211  WERD_CHOICE *best_choice = werd_res->best_choice;
212  ASSERT_HOST(best_choice != NULL);
213 
214  // Compute the number of unichars in the label.
215  GenericVector<UNICHAR_ID> encoding;
216  if (!unicharset.encode_string(label, true, &encoding, NULL, NULL)) {
217  tprintf("Not outputting illegal unichar %s\n", label);
218  return;
219  }
220 
221  // Dump all paths through the ratings matrix (which is normally small).
222  int dim = werd_res->ratings->dimension();
223  const BLOB_CHOICE** blob_choices = new const BLOB_CHOICE*[dim];
224  PrintMatrixPaths(0, dim, *werd_res->ratings, 0, blob_choices,
225  unicharset, label, output_file);
226  delete [] blob_choices;
227 }
int dimension() const
Definition: matrix.h:530
void classify_word_and_language(int pass_n, PAGE_RES_IT *pr_it, WordData *word_data)
Definition: control.cpp:1274
MATRIX * ratings
Definition: pageres.h:215
WERD * word
Definition: pageres.h:175
#define tprintf(...)
Definition: tprintf.h:31
UNICHARSET unicharset
Definition: ccutil.h:70
WERD_CHOICE * best_choice
Definition: pageres.h:219
#define ASSERT_HOST(x)
Definition: errcode.h:84
bool encode_string(const char *str, bool give_up_on_failure, GenericVector< UNICHAR_ID > *encoding, GenericVector< char > *lengths, int *encoded_length) const
Definition: unicharset.cpp:234
void SetupWordPassN(int pass_n, WordData *word)
Definition: control.cpp:168
bool tesseract::Tesseract::AnyTessLang ( ) const
inline

Definition at line 262 of file tesseractclass.h.

262  {
263  if (tessedit_ocr_engine_mode != OEM_CUBE_ONLY) return true;
264  for (int i = 0; i < sub_langs_.size(); ++i) {
265  if (sub_langs_[i]->tessedit_ocr_engine_mode != OEM_CUBE_ONLY)
266  return true;
267  }
268  return false;
269  }
PAGE_RES * tesseract::Tesseract::ApplyBoxes ( const STRING fname,
bool  find_segmentation,
BLOCK_LIST *  block_list 
)

Definition at line 117 of file applybox.cpp.

119  {
120  GenericVector<TBOX> boxes;
121  GenericVector<STRING> texts, full_texts;
122  if (!ReadAllBoxes(applybox_page, true, fname, &boxes, &texts, &full_texts,
123  NULL)) {
124  return NULL; // Can't do it.
125  }
126 
127  int box_count = boxes.size();
128  int box_failures = 0;
129  // Add an empty everything to the end.
130  boxes.push_back(TBOX());
131  texts.push_back(STRING());
132  full_texts.push_back(STRING());
133 
134  // In word mode, we use the boxes to make a word for each box, but
135  // in blob mode we use the existing words and maximally chop them first.
136  PAGE_RES* page_res = find_segmentation ?
137  NULL : SetupApplyBoxes(boxes, block_list);
138  clear_any_old_text(block_list);
139 
140  for (int i = 0; i < boxes.size() - 1; i++) {
141  bool foundit = false;
142  if (page_res != NULL) {
143  if (i == 0) {
144  foundit = ResegmentCharBox(page_res, NULL, boxes[i], boxes[i + 1],
145  full_texts[i].string());
146  } else {
147  foundit = ResegmentCharBox(page_res, &boxes[i-1], boxes[i],
148  boxes[i + 1], full_texts[i].string());
149  }
150  } else {
151  foundit = ResegmentWordBox(block_list, boxes[i], boxes[i + 1],
152  texts[i].string());
153  }
154  if (!foundit) {
155  box_failures++;
156  ReportFailedBox(i, boxes[i], texts[i].string(),
157  "FAILURE! Couldn't find a matching blob");
158  }
159  }
160 
161  if (page_res == NULL) {
162  // In word/line mode, we now maximally chop all the words and resegment
163  // them with the classifier.
164  page_res = SetupApplyBoxes(boxes, block_list);
165  ReSegmentByClassification(page_res);
166  }
167  if (applybox_debug > 0) {
168  tprintf("APPLY_BOXES:\n");
169  tprintf(" Boxes read from boxfile: %6d\n", box_count);
170  if (box_failures > 0)
171  tprintf(" Boxes failed resegmentation: %6d\n", box_failures);
172  }
173  TidyUp(page_res);
174  return page_res;
175 }
Definition: strngs.h:44
void ReportFailedBox(int boxfile_lineno, TBOX box, const char *box_ch, const char *err_msg)
Definition: applybox.cpp:764
bool ResegmentCharBox(PAGE_RES *page_res, const TBOX *prev_box, const TBOX &box, const TBOX &next_box, const char *correct_text)
Definition: applybox.cpp:340
#define tprintf(...)
Definition: tprintf.h:31
int size() const
Definition: genericvector.h:72
Definition: rect.h:30
void TidyUp(PAGE_RES *page_res)
Definition: applybox.cpp:706
bool ReadAllBoxes(int target_page, bool skip_blanks, const STRING &filename, GenericVector< TBOX > *boxes, GenericVector< STRING > *texts, GenericVector< STRING > *box_texts, GenericVector< int > *pages)
Definition: boxread.cpp:50
PAGE_RES * SetupApplyBoxes(const GenericVector< TBOX > &boxes, BLOCK_LIST *block_list)
Definition: applybox.cpp:217
int push_back(T object)
void ReSegmentByClassification(PAGE_RES *page_res)
Definition: applybox.cpp:509
bool ResegmentWordBox(BLOCK_LIST *block_list, const TBOX &box, const TBOX &next_box, const char *correct_text)
Definition: applybox.cpp:438
void tesseract::Tesseract::ApplyBoxTraining ( const STRING fontname,
PAGE_RES page_res 
)

Calls LearnWord to extract features for labelled blobs within each word. Features are stored in an internal buffer.

Definition at line 796 of file applybox.cpp.

796  {
797  PAGE_RES_IT pr_it(page_res);
798  int word_count = 0;
799  for (WERD_RES *word_res = pr_it.word(); word_res != NULL;
800  word_res = pr_it.forward()) {
801  LearnWord(fontname.string(), word_res);
802  ++word_count;
803  }
804  tprintf("Generated training data for %d words\n", word_count);
805 }
WERD * word
Definition: pageres.h:175
#define tprintf(...)
Definition: tprintf.h:31
void LearnWord(const char *fontname, WERD_RES *word)
Definition: adaptmatch.cpp:244
const char * string() const
Definition: strngs.cpp:201
void tesseract::Tesseract::AssignDiacriticsToNewBlobs ( const GenericVector< C_OUTLINE * > &  outlines,
int  pass,
WERD real_word,
PAGE_RES_IT pr_it,
GenericVector< bool > *  word_wanted,
GenericVector< C_BLOB * > *  target_blobs 
)

Definition at line 1035 of file control.cpp.

1038  {
1039  GenericVector<bool> blob_wanted;
1040  word_wanted->init_to_size(outlines.size(), false);
1041  target_blobs->init_to_size(outlines.size(), NULL);
1042  // Check for outlines that need to be turned into stand-alone blobs.
1043  for (int i = 0; i < outlines.size(); ++i) {
1044  if (outlines[i] == NULL) continue;
1045  // Get a set of adjacent outlines that don't overlap any existing blob.
1046  blob_wanted.init_to_size(outlines.size(), false);
1047  int num_blob_outlines = 0;
1048  TBOX total_ol_box(outlines[i]->bounding_box());
1049  while (i < outlines.size() && outlines[i] != NULL) {
1050  blob_wanted[i] = true;
1051  total_ol_box += outlines[i]->bounding_box();
1052  ++i;
1053  ++num_blob_outlines;
1054  }
1055  // Find the insertion point.
1056  C_BLOB_IT blob_it(real_word->cblob_list());
1057  while (!blob_it.at_last() &&
1058  blob_it.data_relative(1)->bounding_box().left() <=
1059  total_ol_box.left()) {
1060  blob_it.forward();
1061  }
1062  // Choose which combination of them we actually want and where to put
1063  // them.
1064  if (debug_noise_removal)
1065  tprintf("Num blobless outlines = %d\n", num_blob_outlines);
1066  C_BLOB* left_blob = blob_it.data();
1067  TBOX left_box = left_blob->bounding_box();
1068  C_BLOB* right_blob = blob_it.at_last() ? NULL : blob_it.data_relative(1);
1069  if ((left_box.x_overlap(total_ol_box) || right_blob == NULL ||
1070  !right_blob->bounding_box().x_overlap(total_ol_box)) &&
1071  SelectGoodDiacriticOutlines(pass, noise_cert_disjoint, pr_it, left_blob,
1072  outlines, num_blob_outlines,
1073  &blob_wanted)) {
1074  if (debug_noise_removal) tprintf("Added to left blob\n");
1075  for (int j = 0; j < blob_wanted.size(); ++j) {
1076  if (blob_wanted[j]) {
1077  (*word_wanted)[j] = true;
1078  (*target_blobs)[j] = left_blob;
1079  }
1080  }
1081  } else if (right_blob != NULL &&
1082  (!left_box.x_overlap(total_ol_box) ||
1083  right_blob->bounding_box().x_overlap(total_ol_box)) &&
1085  right_blob, outlines,
1086  num_blob_outlines, &blob_wanted)) {
1087  if (debug_noise_removal) tprintf("Added to right blob\n");
1088  for (int j = 0; j < blob_wanted.size(); ++j) {
1089  if (blob_wanted[j]) {
1090  (*word_wanted)[j] = true;
1091  (*target_blobs)[j] = right_blob;
1092  }
1093  }
1094  } else if (SelectGoodDiacriticOutlines(pass, noise_cert_punc, pr_it, NULL,
1095  outlines, num_blob_outlines,
1096  &blob_wanted)) {
1097  if (debug_noise_removal) tprintf("Fitted between blobs\n");
1098  for (int j = 0; j < blob_wanted.size(); ++j) {
1099  if (blob_wanted[j]) {
1100  (*word_wanted)[j] = true;
1101  (*target_blobs)[j] = NULL;
1102  }
1103  }
1104  }
1105  }
1106 }
TBOX bounding_box() const
Definition: stepblob.cpp:250
bool SelectGoodDiacriticOutlines(int pass, float certainty_threshold, PAGE_RES_IT *pr_it, C_BLOB *blob, const GenericVector< C_OUTLINE * > &outlines, int num_outlines, GenericVector< bool > *ok_outlines)
Definition: control.cpp:1111
void init_to_size(int size, T t)
#define tprintf(...)
Definition: tprintf.h:31
int size() const
Definition: genericvector.h:72
Definition: rect.h:30
bool x_overlap(const TBOX &box) const
Definition: rect.h:391
C_BLOB_LIST * cblob_list()
Definition: werd.h:100
void tesseract::Tesseract::AssignDiacriticsToOverlappingBlobs ( const GenericVector< C_OUTLINE * > &  outlines,
int  pass,
WERD real_word,
PAGE_RES_IT pr_it,
GenericVector< bool > *  word_wanted,
GenericVector< bool > *  overlapped_any_blob,
GenericVector< C_BLOB * > *  target_blobs 
)

Definition at line 982 of file control.cpp.

986  {
987  GenericVector<bool> blob_wanted;
988  word_wanted->init_to_size(outlines.size(), false);
989  overlapped_any_blob->init_to_size(outlines.size(), false);
990  target_blobs->init_to_size(outlines.size(), NULL);
991  // For each real blob, find the outlines that seriously overlap it.
992  // A single blob could be several merged characters, so there can be quite
993  // a few outlines overlapping, and the full engine needs to be used to chop
994  // and join to get a sensible result.
995  C_BLOB_IT blob_it(real_word->cblob_list());
996  for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
997  C_BLOB* blob = blob_it.data();
998  TBOX blob_box = blob->bounding_box();
999  blob_wanted.init_to_size(outlines.size(), false);
1000  int num_blob_outlines = 0;
1001  for (int i = 0; i < outlines.size(); ++i) {
1002  if (blob_box.major_x_overlap(outlines[i]->bounding_box()) &&
1003  !(*word_wanted)[i]) {
1004  blob_wanted[i] = true;
1005  (*overlapped_any_blob)[i] = true;
1006  ++num_blob_outlines;
1007  }
1008  }
1009  if (debug_noise_removal) {
1010  tprintf("%d noise outlines overlap blob at:", num_blob_outlines);
1011  blob_box.print();
1012  }
1013  // If any outlines overlap the blob, and not too many, classify the blob
1014  // (using the full engine, languages and all), and choose the maximal
1015  // combination of outlines that doesn't hurt the end-result classification
1016  // by too much. Mark them as wanted.
1017  if (0 < num_blob_outlines && num_blob_outlines < noise_maxperblob) {
1018  if (SelectGoodDiacriticOutlines(pass, noise_cert_basechar, pr_it, blob,
1019  outlines, num_blob_outlines,
1020  &blob_wanted)) {
1021  for (int i = 0; i < blob_wanted.size(); ++i) {
1022  if (blob_wanted[i]) {
1023  // Claim the outline and record where it is going.
1024  (*word_wanted)[i] = true;
1025  (*target_blobs)[i] = blob;
1026  }
1027  }
1028  }
1029  }
1030  }
1031 }
TBOX bounding_box() const
Definition: stepblob.cpp:250
bool SelectGoodDiacriticOutlines(int pass, float certainty_threshold, PAGE_RES_IT *pr_it, C_BLOB *blob, const GenericVector< C_OUTLINE * > &outlines, int num_outlines, GenericVector< bool > *ok_outlines)
Definition: control.cpp:1111
void init_to_size(int size, T t)
#define tprintf(...)
Definition: tprintf.h:31
int size() const
Definition: genericvector.h:72
Definition: rect.h:30
void print() const
Definition: rect.h:270
bool major_x_overlap(const TBOX &box) const
Definition: rect.h:402
C_BLOB_LIST * cblob_list()
Definition: werd.h:100
int tesseract::Tesseract::AutoPageSeg ( PageSegMode  pageseg_mode,
BLOCK_LIST *  blocks,
TO_BLOCK_LIST *  to_blocks,
BLOBNBOX_LIST *  diacritic_blobs,
Tesseract osd_tess,
OSResults osr 
)

Auto page segmentation. Divide the page image into blocks of uniform text linespacing and images.

Resolution (in ppi) is derived from the input image.

The output goes in the blocks list with corresponding TO_BLOCKs in the to_blocks list.

If !PSM_COL_FIND_ENABLED(pageseg_mode), then no attempt is made to divide the image into columns, but multiple blocks are still made if the text is of non-uniform linespacing.

If diacritic_blobs is non-null, then diacritics/noise blobs, that would confuse layout anaylsis by causing textline overlap, are placed there, with the expectation that they will be reassigned to words later and noise/diacriticness determined via classification.

If osd (orientation and script detection) is true then that is performed as well. If only_osd is true, then only orientation and script detection is performed. If osd is desired, (osd or only_osd) then osr_tess must be another Tesseract that was initialized especially for osd, and the results will be output into osr (orientation and script result).

Definition at line 225 of file pagesegmain.cpp.

228  {
229  if (textord_debug_images) {
230  WriteDebugBackgroundImage(textord_debug_printable, pix_binary_);
231  }
232  Pix* photomask_pix = NULL;
233  Pix* musicmask_pix = NULL;
234  // The blocks made by the ColumnFinder. Moved to blocks before return.
235  BLOCK_LIST found_blocks;
236  TO_BLOCK_LIST temp_blocks;
237 
238  ColumnFinder* finder = SetupPageSegAndDetectOrientation(
239  pageseg_mode, blocks, osd_tess, osr, &temp_blocks, &photomask_pix,
240  &musicmask_pix);
241  int result = 0;
242  if (finder != NULL) {
243  TO_BLOCK_IT to_block_it(&temp_blocks);
244  TO_BLOCK* to_block = to_block_it.data();
245  if (musicmask_pix != NULL) {
246  // TODO(rays) pass the musicmask_pix into FindBlocks and mark music
247  // blocks separately. For now combine with photomask_pix.
248  pixOr(photomask_pix, photomask_pix, musicmask_pix);
249  }
250  if (equ_detect_) {
251  finder->SetEquationDetect(equ_detect_);
252  }
253  result = finder->FindBlocks(
254  pageseg_mode, scaled_color_, scaled_factor_, to_block, photomask_pix,
255  pix_thresholds_, pix_grey_, &found_blocks, diacritic_blobs, to_blocks);
256  if (result >= 0)
257  finder->GetDeskewVectors(&deskew_, &reskew_);
258  delete finder;
259  }
260  pixDestroy(&photomask_pix);
261  pixDestroy(&musicmask_pix);
262  if (result < 0) return result;
263 
264  blocks->clear();
265  BLOCK_IT block_it(blocks);
266  // Move the found blocks to the input/output blocks.
267  block_it.add_list_after(&found_blocks);
268 
269  if (textord_debug_images) {
270  // The debug image is no longer needed so delete it.
271  unlink(AlignedBlob::textord_debug_pix().string());
272  }
273  return result;
274 }
bool textord_debug_images
Definition: alignedblob.cpp:33
static const STRING & textord_debug_pix()
Definition: alignedblob.h:112
bool textord_debug_printable
Definition: alignedblob.cpp:34
ColumnFinder * SetupPageSegAndDetectOrientation(PageSegMode pageseg_mode, BLOCK_LIST *blocks, Tesseract *osd_tess, OSResults *osr, TO_BLOCK_LIST *to_blocks, Pix **photo_mask_pix, Pix **music_mask_pix)
bool tesseract::Tesseract::BelievableSuperscript ( bool  debug,
const WERD_RES word,
float  certainty_threshold,
int *  left_ok,
int *  right_ok 
) const

Return whether this is believable superscript or subscript text.

We insist that:

  • there are no punctuation marks.
  • there are no italics.
  • no normal-sized character is smaller than superscript_scaledown_ratio of what it ought to be, and
  • each character is at least as certain as certainty_threshold.
Parameters
[in]debugIf true, spew debug output
[in]wordThe word whose best_choice we're evaluating
[in]certainty_thresholdIf any of the characters have less certainty than this, reject.
[out]left_okHow many left-side characters were ok?
[out]right_okHow many right-side characters were ok?
Returns
Whether the complete best choice is believable as a superscript.

Definition at line 520 of file superscript.cpp.

524  {
525  int initial_ok_run_count = 0;
526  int ok_run_count = 0;
527  float worst_certainty = 0.0f;
528  const WERD_CHOICE &wc = *word.best_choice;
529 
530  const UnicityTable<FontInfo>& fontinfo_table = get_fontinfo_table();
531  for (int i = 0; i < wc.length(); i++) {
532  TBLOB *blob = word.rebuild_word->blobs[i];
533  UNICHAR_ID unichar_id = wc.unichar_id(i);
534  float char_certainty = wc.certainty(i);
535  bool bad_certainty = char_certainty < certainty_threshold;
536  bool is_punc = wc.unicharset()->get_ispunctuation(unichar_id);
537  bool is_italic = word.fontinfo && word.fontinfo->is_italic();
538  BLOB_CHOICE *choice = word.GetBlobChoice(i);
539  if (choice && fontinfo_table.size() > 0) {
540  // Get better information from the specific choice, if available.
541  int font_id1 = choice->fontinfo_id();
542  bool font1_is_italic = font_id1 >= 0
543  ? fontinfo_table.get(font_id1).is_italic() : false;
544  int font_id2 = choice->fontinfo_id2();
545  is_italic = font1_is_italic &&
546  (font_id2 < 0 || fontinfo_table.get(font_id2).is_italic());
547  }
548 
549  float height_fraction = 1.0f;
550  float char_height = blob->bounding_box().height();
551  float normal_height = char_height;
552  if (wc.unicharset()->top_bottom_useful()) {
553  int min_bot, max_bot, min_top, max_top;
554  wc.unicharset()->get_top_bottom(unichar_id,
555  &min_bot, &max_bot,
556  &min_top, &max_top);
557  float hi_height = max_top - max_bot;
558  float lo_height = min_top - min_bot;
559  normal_height = (hi_height + lo_height) / 2;
560  if (normal_height >= kBlnXHeight) {
561  // Only ding characters that we have decent information for because
562  // they're supposed to be normal sized, not tiny specks or dashes.
563  height_fraction = char_height / normal_height;
564  }
565  }
566  bool bad_height = height_fraction < superscript_scaledown_ratio;
567 
568  if (debug) {
569  if (is_italic) {
570  tprintf(" Rejecting: superscript is italic.\n");
571  }
572  if (is_punc) {
573  tprintf(" Rejecting: punctuation present.\n");
574  }
575  const char *char_str = wc.unicharset()->id_to_unichar(unichar_id);
576  if (bad_certainty) {
577  tprintf(" Rejecting: don't believe character %s with certainty %.2f "
578  "which is less than threshold %.2f\n", char_str,
579  char_certainty, certainty_threshold);
580  }
581  if (bad_height) {
582  tprintf(" Rejecting: character %s seems too small @ %.2f versus "
583  "expected %.2f\n", char_str, char_height, normal_height);
584  }
585  }
586  if (bad_certainty || bad_height || is_punc || is_italic) {
587  if (ok_run_count == i) {
588  initial_ok_run_count = ok_run_count;
589  }
590  ok_run_count = 0;
591  } else {
592  ok_run_count++;
593  }
594  if (char_certainty < worst_certainty) {
595  worst_certainty = char_certainty;
596  }
597  }
598  bool all_ok = ok_run_count == wc.length();
599  if (all_ok && debug) {
600  tprintf(" Accept: worst revised certainty is %.2f\n", worst_certainty);
601  }
602  if (!all_ok) {
603  if (left_ok) *left_ok = initial_ok_run_count;
604  if (right_ok) *right_ok = ok_run_count;
605  }
606  return all_ok;
607 }
bool is_italic() const
Definition: fontinfo.h:111
int UNICHAR_ID
Definition: unichar.h:33
const FontInfo * fontinfo
Definition: pageres.h:288
GenericVector< TBLOB * > blobs
Definition: blobs.h:436
BLOB_CHOICE * GetBlobChoice(int index) const
Definition: pageres.cpp:742
const UNICHARSET * unicharset() const
Definition: ratngs.h:298
UNICHAR_ID unichar_id(int index) const
Definition: ratngs.h:313
TBOX bounding_box() const
Definition: blobs.cpp:482
int length() const
Definition: ratngs.h:301
inT16 height() const
Definition: rect.h:104
#define tprintf(...)
Definition: tprintf.h:31
inT16 fontinfo_id2() const
Definition: ratngs.h:88
int size() const
Return the size used.
double superscript_scaledown_ratio
inT16 fontinfo_id() const
Definition: ratngs.h:85
const char * id_to_unichar(UNICHAR_ID id) const
Definition: unicharset.cpp:266
UnicityTable< FontInfo > & get_fontinfo_table()
Definition: classify.h:345
bool get_ispunctuation(UNICHAR_ID unichar_id) const
Definition: unicharset.h:476
const T & get(int id) const
Return the object from an id.
WERD_CHOICE * best_choice
Definition: pageres.h:219
const int kBlnXHeight
Definition: normalis.h:28
void get_top_bottom(UNICHAR_ID unichar_id, int *min_bottom, int *max_bottom, int *min_top, int *max_top) const
Definition: unicharset.h:525
Definition: blobs.h:261
bool top_bottom_useful() const
Definition: unicharset.h:494
float certainty() const
Definition: ratngs.h:328
TWERD * rebuild_word
Definition: pageres.h:244
Pix* tesseract::Tesseract::BestPix ( ) const
inline

Definition at line 218 of file tesseractclass.h.

218 { return pix_original_; }
void tesseract::Tesseract::bigram_correction_pass ( PAGE_RES page_res)

Definition at line 448 of file control.cpp.

448  {
449  PAGE_RES_IT word_it(page_res);
450 
451  WERD_RES *w_prev = NULL;
452  WERD_RES *w = word_it.word();
453  while (1) {
454  w_prev = w;
455  while (word_it.forward() != NULL &&
456  (!word_it.word() || word_it.word()->part_of_combo)) {
457  // advance word_it, skipping over parts of combos
458  }
459  if (!word_it.word()) break;
460  w = word_it.word();
461  if (!w || !w_prev || w->uch_set != w_prev->uch_set) {
462  continue;
463  }
464  if (w_prev->word->flag(W_REP_CHAR) || w->word->flag(W_REP_CHAR)) {
465  if (tessedit_bigram_debug) {
466  tprintf("Skipping because one of the words is W_REP_CHAR\n");
467  }
468  continue;
469  }
470  // Two words sharing the same language model, excellent!
471  GenericVector<WERD_CHOICE *> overrides_word1;
472  GenericVector<WERD_CHOICE *> overrides_word2;
473 
474  STRING orig_w1_str = w_prev->best_choice->unichar_string();
475  STRING orig_w2_str = w->best_choice->unichar_string();
476  WERD_CHOICE prev_best(w->uch_set);
477  {
478  int w1start, w1end;
479  w_prev->best_choice->GetNonSuperscriptSpan(&w1start, &w1end);
480  prev_best = w_prev->best_choice->shallow_copy(w1start, w1end);
481  }
482  WERD_CHOICE this_best(w->uch_set);
483  {
484  int w2start, w2end;
485  w->best_choice->GetNonSuperscriptSpan(&w2start, &w2end);
486  this_best = w->best_choice->shallow_copy(w2start, w2end);
487  }
488 
489  if (w->tesseract->getDict().valid_bigram(prev_best, this_best)) {
490  if (tessedit_bigram_debug) {
491  tprintf("Top choice \"%s %s\" verified by bigram model.\n",
492  orig_w1_str.string(), orig_w2_str.string());
493  }
494  continue;
495  }
496  if (tessedit_bigram_debug > 2) {
497  tprintf("Examining alt choices for \"%s %s\".\n",
498  orig_w1_str.string(), orig_w2_str.string());
499  }
500  if (tessedit_bigram_debug > 1) {
501  if (!w_prev->best_choices.singleton()) {
502  w_prev->PrintBestChoices();
503  }
504  if (!w->best_choices.singleton()) {
505  w->PrintBestChoices();
506  }
507  }
508  float best_rating = 0.0;
509  int best_idx = 0;
510  WERD_CHOICE_IT prev_it(&w_prev->best_choices);
511  for (prev_it.mark_cycle_pt(); !prev_it.cycled_list(); prev_it.forward()) {
512  WERD_CHOICE *p1 = prev_it.data();
513  WERD_CHOICE strip1(w->uch_set);
514  {
515  int p1start, p1end;
516  p1->GetNonSuperscriptSpan(&p1start, &p1end);
517  strip1 = p1->shallow_copy(p1start, p1end);
518  }
519  WERD_CHOICE_IT w_it(&w->best_choices);
520  for (w_it.mark_cycle_pt(); !w_it.cycled_list(); w_it.forward()) {
521  WERD_CHOICE *p2 = w_it.data();
522  WERD_CHOICE strip2(w->uch_set);
523  {
524  int p2start, p2end;
525  p2->GetNonSuperscriptSpan(&p2start, &p2end);
526  strip2 = p2->shallow_copy(p2start, p2end);
527  }
528  if (w->tesseract->getDict().valid_bigram(strip1, strip2)) {
529  overrides_word1.push_back(p1);
530  overrides_word2.push_back(p2);
531  if (overrides_word1.size() == 1 ||
532  p1->rating() + p2->rating() < best_rating) {
533  best_rating = p1->rating() + p2->rating();
534  best_idx = overrides_word1.size() - 1;
535  }
536  }
537  }
538  }
539  if (!overrides_word1.empty()) {
540  // Excellent, we have some bigram matches.
542  *overrides_word1[best_idx]) &&
544  *overrides_word2[best_idx])) {
545  if (tessedit_bigram_debug > 1) {
546  tprintf("Top choice \"%s %s\" verified (sans case) by bigram "
547  "model.\n", orig_w1_str.string(), orig_w2_str.string());
548  }
549  continue;
550  }
551  STRING new_w1_str = overrides_word1[best_idx]->unichar_string();
552  STRING new_w2_str = overrides_word2[best_idx]->unichar_string();
553  if (new_w1_str != orig_w1_str) {
554  w_prev->ReplaceBestChoice(overrides_word1[best_idx]);
555  }
556  if (new_w2_str != orig_w2_str) {
557  w->ReplaceBestChoice(overrides_word2[best_idx]);
558  }
559  if (tessedit_bigram_debug > 0) {
560  STRING choices_description;
561  int num_bigram_choices
562  = overrides_word1.size() * overrides_word2.size();
563  if (num_bigram_choices == 1) {
564  choices_description = "This was the unique bigram choice.";
565  } else {
566  if (tessedit_bigram_debug > 1) {
567  STRING bigrams_list;
568  const int kMaxChoicesToPrint = 20;
569  for (int i = 0; i < overrides_word1.size() &&
570  i < kMaxChoicesToPrint; i++) {
571  if (i > 0) { bigrams_list += ", "; }
572  WERD_CHOICE *p1 = overrides_word1[i];
573  WERD_CHOICE *p2 = overrides_word2[i];
574  bigrams_list += p1->unichar_string() + " " + p2->unichar_string();
575  if (i == kMaxChoicesToPrint) {
576  bigrams_list += " ...";
577  }
578  }
579  choices_description = "There were many choices: {";
580  choices_description += bigrams_list;
581  choices_description += "}";
582  } else {
583  choices_description.add_str_int("There were ", num_bigram_choices);
584  choices_description += " compatible bigrams.";
585  }
586  }
587  tprintf("Replaced \"%s %s\" with \"%s %s\" with bigram model. %s\n",
588  orig_w1_str.string(), orig_w2_str.string(),
589  new_w1_str.string(), new_w2_str.string(),
590  choices_description.string());
591  }
592  }
593  }
594 }
BOOL8 flag(WERD_FLAGS mask) const
Definition: werd.h:128
Definition: strngs.h:44
tesseract::Tesseract * tesseract
Definition: pageres.h:266
bool empty() const
Definition: genericvector.h:84
WERD * word
Definition: pageres.h:175
void PrintBestChoices() const
Definition: pageres.cpp:709
#define tprintf(...)
Definition: tprintf.h:31
int size() const
Definition: genericvector.h:72
Dict & getDict()
Definition: classify.h:65
const STRING & unichar_string() const
Definition: ratngs.h:525
void add_str_int(const char *str, int number)
Definition: strngs.cpp:384
float rating() const
Definition: ratngs.h:325
WERD_CHOICE_LIST best_choices
Definition: pageres.h:227
WERD_CHOICE * best_choice
Definition: pageres.h:219
const UNICHARSET * uch_set
Definition: pageres.h:192
int push_back(T object)
bool valid_bigram(const WERD_CHOICE &word1, const WERD_CHOICE &word2) const
Definition: dict.cpp:763
void ReplaceBestChoice(WERD_CHOICE *choice)
Definition: pageres.cpp:787
const char * string() const
Definition: strngs.cpp:201
bool EqualIgnoringCaseAndTerminalPunct(const WERD_CHOICE &word1, const WERD_CHOICE &word2)
Definition: ratngs.cpp:791
WERD_CHOICE shallow_copy(int start, int end) const
Definition: ratngs.cpp:392
void GetNonSuperscriptSpan(int *start, int *end) const
Definition: ratngs.cpp:375
void tesseract::Tesseract::blamer_pass ( PAGE_RES page_res)

Definition at line 692 of file control.cpp.

692  {
693  if (!wordrec_run_blamer) return;
694  PAGE_RES_IT page_res_it(page_res);
695  for (page_res_it.restart_page(); page_res_it.word() != NULL;
696  page_res_it.forward()) {
697  WERD_RES *word = page_res_it.word();
700  }
701  tprintf("Blame reasons:\n");
702  for (int bl = 0; bl < IRR_NUM_REASONS; ++bl) {
704  static_cast<IncorrectResultReason>(bl)),
705  page_res->blame_reasons[bl]);
706  }
707  if (page_res->misadaption_log.length() > 0) {
708  tprintf("Misadaption log:\n");
709  for (int i = 0; i < page_res->misadaption_log.length(); ++i) {
710  tprintf("%s\n", page_res->misadaption_log[i].string());
711  }
712  }
713 }
static void LastChanceBlame(bool debug, WERD_RES *word)
Definition: blamer.cpp:547
GenericVector< STRING > misadaption_log
Definition: pageres.h:73
BlamerBundle * blamer_bundle
Definition: pageres.h:230
GenericVector< int > blame_reasons
Definition: pageres.h:68
WERD * word
Definition: pageres.h:175
bool wordrec_run_blamer
Definition: wordrec.h:168
#define tprintf(...)
Definition: tprintf.h:31
bool wordrec_debug_blamer
Definition: wordrec.h:167
static const char * IncorrectReasonName(IncorrectResultReason irr)
Definition: blamer.cpp:56
int length() const
Definition: genericvector.h:79
IncorrectResultReason incorrect_result_reason() const
Definition: blamer.h:106
void tesseract::Tesseract::blob_feature_display ( PAGE_RES page_res,
const TBOX selection_box 
)

Definition at line 960 of file pgedit.cpp.

961  {
962  PAGE_RES_IT* it = make_pseudo_word(page_res, selection_box);
963  if (it != NULL) {
964  WERD_RES* word_res = it->word();
965  word_res->x_height = it->row()->row->x_height();
966  word_res->SetupForRecognition(unicharset, this, BestPix(),
971  it->row()->row, it->block()->block);
972  TWERD* bln_word = word_res->chopped_word;
973  TBLOB* bln_blob = bln_word->blobs[0];
974  INT_FX_RESULT_STRUCT fx_info;
977  Classify::ExtractFeatures(*bln_blob, classify_nonlinear_norm, &bl_features,
978  &cn_features, &fx_info, NULL);
979  // Display baseline features.
980  ScrollView* bl_win = CreateFeatureSpaceWindow("BL Features", 512, 0);
982  for (int f = 0; f < bl_features.size(); ++f)
983  RenderIntFeature(bl_win, &bl_features[f], ScrollView::GREEN);
984  bl_win->Update();
985  // Display cn features.
986  ScrollView* cn_win = CreateFeatureSpaceWindow("CN Features", 512, 0);
988  for (int f = 0; f < cn_features.size(); ++f)
989  RenderIntFeature(cn_win, &cn_features[f], ScrollView::GREEN);
990  cn_win->Update();
991 
992  it->DeleteCurrentWord();
993  delete it;
994  }
995 }
void RenderIntFeature(ScrollView *window, const INT_FEATURE_STRUCT *Feature, ScrollView::Color color)
Definition: intproto.cpp:1755
void ClearFeatureSpaceWindow(NORM_METHOD norm_method, ScrollView *window)
Definition: intproto.cpp:1095
GenericVector< TBLOB * > blobs
Definition: blobs.h:436
PAGE_RES_IT * make_pseudo_word(PAGE_RES *page_res, const TBOX &selection_box)
Definition: werdit.cpp:31
Pix * BestPix() const
float x_height() const
Definition: ocrrow.h:61
WERD_RES * word() const
Definition: pageres.h:736
TWERD * chopped_word
Definition: pageres.h:201
int size() const
Definition: genericvector.h:72
ROW_RES * row() const
Definition: pageres.h:739
bool classify_nonlinear_norm
Definition: classify.h:416
bool classify_bln_numeric_mode
Definition: classify.h:500
bool SetupForRecognition(const UNICHARSET &unicharset_in, tesseract::Tesseract *tesseract, Pix *pix, int norm_mode, const TBOX *norm_box, bool numeric_mode, bool use_body_size, bool allow_detailed_fx, ROW *row, const BLOCK *block)
Definition: pageres.cpp:294
ROW * row
Definition: pageres.h:127
UNICHARSET unicharset
Definition: ccutil.h:70
static void Update()
Definition: scrollview.cpp:715
static void ExtractFeatures(const TBLOB &blob, bool nonlinear_norm, GenericVector< INT_FEATURE_STRUCT > *bl_features, GenericVector< INT_FEATURE_STRUCT > *cn_features, INT_FX_RESULT_STRUCT *results, GenericVector< int > *outline_cn_counts)
Definition: intfx.cpp:445
Definition: blobs.h:395
BLOCK_RES * block() const
Definition: pageres.h:742
float x_height
Definition: pageres.h:295
ScrollView * CreateFeatureSpaceWindow(const char *name, int xpos, int ypos)
Definition: intproto.cpp:1920
Definition: blobs.h:261
void DeleteCurrentWord()
Definition: pageres.cpp:1450
BLOCK * block
Definition: pageres.h:99
float tesseract::Tesseract::blob_noise_score ( TBLOB blob)

Definition at line 760 of file fixspace.cpp.

760  {
761  TBOX box; // BB of outline
762  inT16 outline_count = 0;
763  inT16 max_dimension;
764  inT16 largest_outline_dimension = 0;
765 
766  for (TESSLINE* ol = blob->outlines; ol != NULL; ol= ol->next) {
767  outline_count++;
768  box = ol->bounding_box();
769  if (box.height() > box.width()) {
770  max_dimension = box.height();
771  } else {
772  max_dimension = box.width();
773  }
774 
775  if (largest_outline_dimension < max_dimension)
776  largest_outline_dimension = max_dimension;
777  }
778 
779  if (outline_count > 5) {
780  // penalise LOTS of blobs
781  largest_outline_dimension *= 2;
782  }
783 
784  box = blob->bounding_box();
785  if (box.bottom() > kBlnBaselineOffset * 4 ||
786  box.top() < kBlnBaselineOffset / 2) {
787  // Lax blob is if high or low
788  largest_outline_dimension /= 2;
789  }
790 
791  return largest_outline_dimension;
792 }
inT16 bottom() const
Definition: rect.h:61
TESSLINE * outlines
Definition: blobs.h:377
TBOX bounding_box() const
Definition: blobs.cpp:482
inT16 height() const
Definition: rect.h:104
Definition: rect.h:30
short inT16
Definition: host.h:100
inT16 top() const
Definition: rect.h:54
TESSLINE * next
Definition: blobs.h:258
const int kBlnBaselineOffset
Definition: normalis.h:29
inT16 width() const
Definition: rect.h:111
void tesseract::Tesseract::break_noisiest_blob_word ( WERD_RES_LIST &  words)

break_noisiest_blob_word() Find the word with the blob which looks like the worst noise. Break the word into two, deleting the noise blob.

Definition at line 615 of file fixspace.cpp.

615  {
616  WERD_RES_IT word_it(&words);
617  WERD_RES_IT worst_word_it;
618  float worst_noise_score = 9999;
619  int worst_blob_index = -1; // Noisiest blob of noisiest wd
620  int blob_index; // of wds noisiest blob
621  float noise_score; // of wds noisiest blob
622  WERD_RES *word_res;
623  C_BLOB_IT blob_it;
624  C_BLOB_IT rej_cblob_it;
625  C_BLOB_LIST new_blob_list;
626  C_BLOB_IT new_blob_it;
627  C_BLOB_IT new_rej_cblob_it;
628  WERD *new_word;
629  inT16 start_of_noise_blob;
630  inT16 i;
631 
632  for (word_it.mark_cycle_pt(); !word_it.cycled_list(); word_it.forward()) {
633  blob_index = worst_noise_blob(word_it.data(), &noise_score);
634  if (blob_index > -1 && worst_noise_score > noise_score) {
635  worst_noise_score = noise_score;
636  worst_blob_index = blob_index;
637  worst_word_it = word_it;
638  }
639  }
640  if (worst_blob_index < 0) {
641  words.clear(); // signal termination
642  return;
643  }
644 
645  /* Now split the worst_word_it */
646 
647  word_res = worst_word_it.data();
648 
649  /* Move blobs before noise blob to a new bloblist */
650 
651  new_blob_it.set_to_list(&new_blob_list);
652  blob_it.set_to_list(word_res->word->cblob_list());
653  for (i = 0; i < worst_blob_index; i++, blob_it.forward()) {
654  new_blob_it.add_after_then_move(blob_it.extract());
655  }
656  start_of_noise_blob = blob_it.data()->bounding_box().left();
657  delete blob_it.extract(); // throw out noise blob
658 
659  new_word = new WERD(&new_blob_list, word_res->word);
660  new_word->set_flag(W_EOL, FALSE);
661  word_res->word->set_flag(W_BOL, FALSE);
662  word_res->word->set_blanks(1); // After break
663 
664  new_rej_cblob_it.set_to_list(new_word->rej_cblob_list());
665  rej_cblob_it.set_to_list(word_res->word->rej_cblob_list());
666  for (;
667  (!rej_cblob_it.empty() &&
668  (rej_cblob_it.data()->bounding_box().left() < start_of_noise_blob));
669  rej_cblob_it.forward()) {
670  new_rej_cblob_it.add_after_then_move(rej_cblob_it.extract());
671  }
672 
673  WERD_RES* new_word_res = new WERD_RES(new_word);
674  new_word_res->combination = TRUE;
675  worst_word_it.add_before_then_move(new_word_res);
676 
677  word_res->ClearResults();
678 }
Definition: werd.h:36
#define TRUE
Definition: capi.h:45
void set_blanks(uinT8 new_blanks)
Definition: werd.h:107
void ClearResults()
Definition: pageres.cpp:1141
void set_flag(WERD_FLAGS mask, BOOL8 value)
Definition: werd.h:129
Definition: werd.h:60
WERD * word
Definition: pageres.h:175
#define FALSE
Definition: capi.h:46
BOOL8 combination
Definition: pageres.h:318
short inT16
Definition: host.h:100
Definition: werd.h:35
inT16 worst_noise_blob(WERD_RES *word_res, float *worst_noise_score)
Definition: fixspace.cpp:680
C_BLOB_LIST * cblob_list()
Definition: werd.h:100
C_BLOB_LIST * rej_cblob_list()
Definition: werd.h:95
SVMenuNode * tesseract::Tesseract::build_menu_new ( )

Definition at line 257 of file pgedit.cpp.

257  {
258  SVMenuNode* parent_menu;
259  SVMenuNode* root_menu_item = new SVMenuNode();
260 
261  SVMenuNode* modes_menu_item = root_menu_item->AddChild("MODES");
262 
263  modes_menu_item->AddChild("Change Display", CHANGE_DISP_CMD_EVENT);
264  modes_menu_item->AddChild("Dump Word", DUMP_WERD_CMD_EVENT);
265  modes_menu_item->AddChild("Show Point", SHOW_POINT_CMD_EVENT);
266  modes_menu_item->AddChild("Show BL Norm Word", SHOW_BLN_WERD_CMD_EVENT);
267  modes_menu_item->AddChild("Config Words", DEBUG_WERD_CMD_EVENT);
268  modes_menu_item->AddChild("Recog Words", RECOG_WERDS);
269  modes_menu_item->AddChild("Recog Blobs", RECOG_PSEUDO);
270  modes_menu_item->AddChild("Show Blob Features", SHOW_BLOB_FEATURES);
271 
272  parent_menu = root_menu_item->AddChild("DISPLAY");
273 
274  parent_menu->AddChild("Blamer", BLAMER_CMD_EVENT, FALSE);
275  parent_menu->AddChild("Bounding Boxes", BOUNDING_BOX_CMD_EVENT, FALSE);
276  parent_menu->AddChild("Correct Text", CORRECT_TEXT_CMD_EVENT, FALSE);
277  parent_menu->AddChild("Polygonal Approx", POLYGONAL_CMD_EVENT, FALSE);
278  parent_menu->AddChild("Baseline Normalized", BL_NORM_CMD_EVENT, FALSE);
279  parent_menu->AddChild("Edge Steps", BITMAP_CMD_EVENT, TRUE);
280  parent_menu->AddChild("Subscripts", SHOW_SUBSCRIPT_CMD_EVENT);
281  parent_menu->AddChild("Superscripts", SHOW_SUPERSCRIPT_CMD_EVENT);
282  parent_menu->AddChild("Italics", SHOW_ITALIC_CMD_EVENT);
283  parent_menu->AddChild("Bold", SHOW_BOLD_CMD_EVENT);
284  parent_menu->AddChild("Underline", SHOW_UNDERLINE_CMD_EVENT);
285  parent_menu->AddChild("FixedPitch", SHOW_FIXEDPITCH_CMD_EVENT);
286  parent_menu->AddChild("Serifs", SHOW_SERIF_CMD_EVENT);
287  parent_menu->AddChild("SmallCaps", SHOW_SMALLCAPS_CMD_EVENT);
288  parent_menu->AddChild("DropCaps", SHOW_DROPCAPS_CMD_EVENT);
289 
290 
291  parent_menu = root_menu_item->AddChild("OTHER");
292 
293  parent_menu->AddChild("Quit", QUIT_CMD_EVENT);
294  parent_menu->AddChild("Show Image", IMAGE_CMD_EVENT, FALSE);
295  parent_menu->AddChild("ShowBlock Outlines", BLOCKS_CMD_EVENT, FALSE);
296  parent_menu->AddChild("Show Baselines", BASELINES_CMD_EVENT, FALSE);
297  parent_menu->AddChild("Uniform Display", UNIFORM_DISP_CMD_EVENT);
298  parent_menu->AddChild("Refresh Display", REFRESH_CMD_EVENT);
299 
300  return root_menu_item;
301 }
#define TRUE
Definition: capi.h:45
#define FALSE
Definition: capi.h:46
SVMenuNode * AddChild(const char *txt)
Definition: svmnode.cpp:59
BOOL8 tesseract::Tesseract::check_debug_pt ( WERD_RES word,
int  location 
)

Definition at line 1772 of file control.cpp.

1772  {
1773  BOOL8 show_map_detail = FALSE;
1774  inT16 i;
1775 
1776  if (!test_pt)
1777  return FALSE;
1778 
1779  tessedit_rejection_debug.set_value (FALSE);
1780  debug_x_ht_level.set_value(0);
1781 
1782  if (word->word->bounding_box ().contains (FCOORD (test_pt_x, test_pt_y))) {
1783  if (location < 0)
1784  return TRUE; // For breakpoint use
1785  tessedit_rejection_debug.set_value (TRUE);
1786  debug_x_ht_level.set_value(2);
1787  tprintf ("\n\nTESTWD::");
1788  switch (location) {
1789  case 0:
1790  tprintf ("classify_word_pass1 start\n");
1791  word->word->print();
1792  break;
1793  case 10:
1794  tprintf ("make_reject_map: initial map");
1795  break;
1796  case 20:
1797  tprintf ("make_reject_map: after NN");
1798  break;
1799  case 30:
1800  tprintf ("classify_word_pass2 - START");
1801  break;
1802  case 40:
1803  tprintf ("classify_word_pass2 - Pre Xht");
1804  break;
1805  case 50:
1806  tprintf ("classify_word_pass2 - END");
1807  show_map_detail = TRUE;
1808  break;
1809  case 60:
1810  tprintf ("fixspace");
1811  break;
1812  case 70:
1813  tprintf ("MM pass START");
1814  break;
1815  case 80:
1816  tprintf ("MM pass END");
1817  break;
1818  case 90:
1819  tprintf ("After Poor quality rejection");
1820  break;
1821  case 100:
1822  tprintf ("unrej_good_quality_words - START");
1823  break;
1824  case 110:
1825  tprintf ("unrej_good_quality_words - END");
1826  break;
1827  case 120:
1828  tprintf ("Write results pass");
1829  show_map_detail = TRUE;
1830  break;
1831  }
1832  if (word->best_choice != NULL) {
1833  tprintf(" \"%s\" ", word->best_choice->unichar_string().string());
1834  word->reject_map.print(debug_fp);
1835  tprintf("\n");
1836  if (show_map_detail) {
1837  tprintf("\"%s\"\n", word->best_choice->unichar_string().string());
1838  for (i = 0; word->best_choice->unichar_string()[i] != '\0'; i++) {
1839  tprintf("**** \"%c\" ****\n", word->best_choice->unichar_string()[i]);
1840  word->reject_map[i].full_print(debug_fp);
1841  }
1842  }
1843  } else {
1844  tprintf("null best choice\n");
1845  }
1846  tprintf ("Tess Accepted: %s\n", word->tess_accepted ? "TRUE" : "FALSE");
1847  tprintf ("Done flag: %s\n\n", word->done ? "TRUE" : "FALSE");
1848  return TRUE;
1849  } else {
1850  return FALSE;
1851  }
1852 }
#define TRUE
Definition: capi.h:45
void full_print(FILE *fp)
Definition: rejctmap.cpp:406
BOOL8 tess_accepted
Definition: pageres.h:280
Definition: points.h:189
WERD * word
Definition: pageres.h:175
FILE * debug_fp
Definition: tessvars.cpp:24
#define tprintf(...)
Definition: tprintf.h:31
REJMAP reject_map
Definition: pageres.h:271
TBOX bounding_box() const
Definition: werd.cpp:160
#define FALSE
Definition: capi.h:46
const STRING & unichar_string() const
Definition: ratngs.h:525
short inT16
Definition: host.h:100
void print(FILE *fp)
Definition: rejctmap.cpp:394
WERD_CHOICE * best_choice
Definition: pageres.h:219
void print()
Definition: werd.cpp:266
BOOL8 done
Definition: pageres.h:282
unsigned char BOOL8
Definition: host.h:113
bool contains(const FCOORD pt) const
Definition: rect.h:323
const char * string() const
Definition: strngs.cpp:201
void tesseract::Tesseract::classify_word_and_language ( int  pass_n,
PAGE_RES_IT pr_it,
WordData word_data 
)

Definition at line 1274 of file control.cpp.

1275  {
1276  WordRecognizer recognizer = pass_n == 1 ? &Tesseract::classify_word_pass1
1278  // Best result so far.
1279  PointerVector<WERD_RES> best_words;
1280  // Points to the best result. May be word or in lang_words.
1281  WERD_RES* word = word_data->word;
1282  clock_t start_t = clock();
1284  tprintf("%s word with lang %s at:",
1285  word->done ? "Already done" : "Processing",
1286  most_recently_used_->lang.string());
1287  word->word->bounding_box().print();
1288  }
1289  if (word->done) {
1290  // If done on pass1, leave it as-is.
1291  if (!word->tess_failed)
1292  most_recently_used_ = word->tesseract;
1293  return;
1294  }
1295  int sub = sub_langs_.size();
1296  if (most_recently_used_ != this) {
1297  // Get the index of the most_recently_used_.
1298  for (sub = 0; sub < sub_langs_.size() &&
1299  most_recently_used_ != sub_langs_[sub]; ++sub) {}
1300  }
1301  most_recently_used_->RetryWithLanguage(
1302  *word_data, recognizer, &word_data->lang_words[sub], &best_words);
1303  Tesseract* best_lang_tess = most_recently_used_;
1304  if (!WordsAcceptable(best_words)) {
1305  // Try all the other languages to see if they are any better.
1306  if (most_recently_used_ != this &&
1307  this->RetryWithLanguage(*word_data, recognizer,
1308  &word_data->lang_words[sub_langs_.size()],
1309  &best_words) > 0) {
1310  best_lang_tess = this;
1311  }
1312  for (int i = 0; !WordsAcceptable(best_words) && i < sub_langs_.size();
1313  ++i) {
1314  if (most_recently_used_ != sub_langs_[i] &&
1315  sub_langs_[i]->RetryWithLanguage(*word_data, recognizer,
1316  &word_data->lang_words[i],
1317  &best_words) > 0) {
1318  best_lang_tess = sub_langs_[i];
1319  }
1320  }
1321  }
1322  most_recently_used_ = best_lang_tess;
1323  if (!best_words.empty()) {
1324  if (best_words.size() == 1 && !best_words[0]->combination) {
1325  // Move the best single result to the main word.
1326  word_data->word->ConsumeWordResults(best_words[0]);
1327  } else {
1328  // Words came from LSTM, and must be moved to the PAGE_RES properly.
1329  word_data->word = best_words.back();
1330  pr_it->ReplaceCurrentWord(&best_words);
1331  }
1332  ASSERT_HOST(word_data->word->box_word != NULL);
1333  } else {
1334  tprintf("no best words!!\n");
1335  }
1336  clock_t ocr_t = clock();
1337  if (tessedit_timing_debug) {
1338  tprintf("%s (ocr took %.2f sec)\n",
1339  word->best_choice->unichar_string().string(),
1340  static_cast<double>(ocr_t-start_t)/CLOCKS_PER_SEC);
1341  }
1342 }
void classify_word_pass2(const WordData &word_data, WERD_RES **in_word, PointerVector< WERD_RES > *out_words)
Definition: control.cpp:1493
int RetryWithLanguage(const WordData &word_data, WordRecognizer recognizer, WERD_RES **in_word, PointerVector< WERD_RES > *best_words)
Definition: control.cpp:875
STRING lang
Definition: ccutil.h:67
tesseract::Tesseract * tesseract
Definition: pageres.h:266
WERD * word
Definition: pageres.h:175
#define tprintf(...)
Definition: tprintf.h:31
TBOX bounding_box() const
Definition: werd.cpp:160
BOOL8 tess_failed
Definition: pageres.h:272
const STRING & unichar_string() const
Definition: ratngs.h:525
void print() const
Definition: rect.h:270
void ReplaceCurrentWord(tesseract::PointerVector< WERD_RES > *words)
Definition: pageres.cpp:1322
WERD_CHOICE * best_choice
Definition: pageres.h:219
BOOL8 done
Definition: pageres.h:282
void(Tesseract::* WordRecognizer)(const WordData &word_data, WERD_RES **in_word, PointerVector< WERD_RES > *out_words)
#define ASSERT_HOST(x)
Definition: errcode.h:84
const char * string() const
Definition: strngs.cpp:201
void classify_word_pass1(const WordData &word_data, WERD_RES **in_word, PointerVector< WERD_RES > *out_words)
Definition: control.cpp:1350
void tesseract::Tesseract::classify_word_pass1 ( const WordData word_data,
WERD_RES **  in_word,
PointerVector< WERD_RES > *  out_words 
)

classify_word_pass1

Baseline normalize the word and pass it to Tess.

Definition at line 1350 of file control.cpp.

1352  {
1353  ROW* row = word_data.row;
1354  BLOCK* block = word_data.block;
1355  prev_word_best_choice_ = word_data.prev_word != NULL
1356  ? word_data.prev_word->word->best_choice : NULL;
1357 #ifndef NO_CUBE_BUILD
1358  // If we only intend to run cube - run it and return.
1360  cube_word_pass1(block, row, *in_word);
1361  return;
1362  }
1363 #endif
1364  WERD_RES* word = *in_word;
1365  match_word_pass_n(1, word, row, block);
1366  if (!word->tess_failed && !word->word->flag(W_REP_CHAR)) {
1367  word->tess_would_adapt = AdaptableWord(word);
1368  bool adapt_ok = word_adaptable(word, tessedit_tess_adaption_mode);
1369 
1370  if (adapt_ok) {
1371  // Send word to adaptive classifier for training.
1372  word->BestChoiceToCorrectText();
1373  LearnWord(NULL, word);
1374  // Mark misadaptions if running blamer.
1375  if (word->blamer_bundle != NULL) {
1378  }
1379  }
1380 
1381  if (tessedit_enable_doc_dict && !word->IsAmbiguous())
1383  }
1384 }
BOOL8 flag(WERD_FLAGS mask) const
Definition: werd.h:128
void BestChoiceToCorrectText()
Definition: pageres.cpp:917
Definition: ocrrow.h:32
BlamerBundle * blamer_bundle
Definition: pageres.h:230
WERD * word
Definition: pageres.h:175
bool AdaptableWord(WERD_RES *word)
Definition: adaptmatch.cpp:850
void tess_add_doc_word(WERD_CHOICE *word_choice)
Definition: tessbox.cpp:79
void LearnWord(const char *fontname, WERD_RES *word)
Definition: adaptmatch.cpp:244
BOOL8 tess_failed
Definition: pageres.h:272
bool wordrec_debug_blamer
Definition: wordrec.h:167
void cube_word_pass1(BLOCK *block, ROW *row, WERD_RES *word)
BOOL8 word_adaptable(WERD_RES *word, uinT16 mode)
Definition: adaptions.cpp:45
WERD_CHOICE * prev_word_best_choice_
Definition: wordrec.h:416
bool IsAmbiguous()
Definition: pageres.cpp:443
WERD_CHOICE * best_choice
Definition: pageres.h:219
void SetMisAdaptionDebug(const WERD_CHOICE *best_choice, bool debug)
Definition: blamer.cpp:574
BOOL8 tess_would_adapt
Definition: pageres.h:281
Definition: ocrblock.h:30
void match_word_pass_n(int pass_n, WERD_RES *word, ROW *row, BLOCK *block)
Definition: control.cpp:1554
void tesseract::Tesseract::classify_word_pass2 ( const WordData word_data,
WERD_RES **  in_word,
PointerVector< WERD_RES > *  out_words 
)

classify_word_pass2

Control what to do with the word in pass 2

Definition at line 1493 of file control.cpp.

1495  {
1496  // Return if we do not want to run Tesseract.
1499  word_data.word->best_choice != NULL)
1500  return;
1502  return;
1503  }
1504  ROW* row = word_data.row;
1505  BLOCK* block = word_data.block;
1506  WERD_RES* word = *in_word;
1507  prev_word_best_choice_ = word_data.prev_word != NULL
1508  ? word_data.prev_word->word->best_choice : NULL;
1509 
1511  check_debug_pt(word, 30);
1512  if (!word->done) {
1513  word->caps_height = 0.0;
1514  if (word->x_height == 0.0f)
1515  word->x_height = row->x_height();
1516  match_word_pass_n(2, word, row, block);
1517  check_debug_pt(word, 40);
1518  }
1519 
1520  SubAndSuperscriptFix(word);
1521 
1522  if (!word->tess_failed && !word->word->flag(W_REP_CHAR)) {
1524  block->classify_rotation().y() == 0.0f) {
1525  // Use the tops and bottoms since they are available.
1526  TrainedXheightFix(word, block, row);
1527  }
1528 
1530  }
1531 #ifndef GRAPHICS_DISABLED
1533  if (fx_win == NULL)
1534  create_fx_win();
1535  clear_fx_win();
1536  word->rebuild_word->plot(fx_win);
1537  TBOX wbox = word->rebuild_word->bounding_box();
1538  fx_win->ZoomToRectangle(wbox.left(), wbox.top(),
1539  wbox.right(), wbox.bottom());
1541  }
1542 #endif
1544  check_debug_pt(word, 50);
1545 }
BOOL8 flag(WERD_FLAGS mask) const
Definition: werd.h:128
inT16 bottom() const
Definition: rect.h:61
void create_fx_win()
Definition: drawfx.cpp:60
TBOX bounding_box() const
Definition: blobs.cpp:881
Definition: ocrrow.h:32
float x_height() const
Definition: ocrrow.h:61
void clear_fx_win()
Definition: drawfx.cpp:73
WERD * word
Definition: pageres.h:175
void ZoomToRectangle(int x1, int y1, int x2, int y2)
Definition: scrollview.cpp:765
#define SUBLOC_NORM
Definition: errcode.h:59
BOOL8 check_debug_pt(WERD_RES *word, int location)
Definition: control.cpp:1772
Definition: rect.h:30
BOOL8 tess_failed
Definition: pageres.h:272
inT16 right() const
Definition: rect.h:75
WERD_CHOICE * prev_word_best_choice_
Definition: wordrec.h:416
void set_global_subloc_code(int loc_code)
Definition: globaloc.cpp:85
inT16 left() const
Definition: rect.h:68
float y() const
Definition: points.h:212
UNICHARSET unicharset
Definition: ccutil.h:70
static void Update()
Definition: scrollview.cpp:715
float x_height
Definition: pageres.h:295
bool SubAndSuperscriptFix(WERD_RES *word_res)
inT16 top() const
Definition: rect.h:54
float caps_height
Definition: pageres.h:296
FCOORD classify_rotation() const
Definition: ocrblock.h:144
BOOL8 done
Definition: pageres.h:282
EXTERN ScrollView * fx_win
Definition: drawfx.cpp:51
bool script_has_xheight() const
Definition: unicharset.h:848
bool top_bottom_useful() const
Definition: unicharset.h:494
void plot(ScrollView *window)
Definition: blobs.cpp:918
Definition: ocrblock.h:30
void match_word_pass_n(int pass_n, WERD_RES *word, ROW *row, BLOCK *block)
Definition: control.cpp:1554
bool TrainedXheightFix(WERD_RES *word, BLOCK *block, ROW *row)
Definition: control.cpp:1408
TWERD * rebuild_word
Definition: pageres.h:244
float tesseract::Tesseract::ClassifyBlobAsWord ( int  pass_n,
PAGE_RES_IT pr_it,
C_BLOB blob,
STRING best_str,
float *  c2 
)

Definition at line 1238 of file control.cpp.

1239  {
1240  WERD* real_word = pr_it->word()->word;
1241  WERD* word = real_word->ConstructFromSingleBlob(
1242  real_word->flag(W_BOL), real_word->flag(W_EOL), C_BLOB::deep_copy(blob));
1243  WERD_RES* word_res = pr_it->InsertSimpleCloneWord(*pr_it->word(), word);
1244  // Get a new iterator that points to the new word.
1245  PAGE_RES_IT it(pr_it->page_res);
1246  while (it.word() != word_res && it.word() != NULL) it.forward();
1247  ASSERT_HOST(it.word() == word_res);
1248  WordData wd(it);
1249  // Force full initialization.
1250  SetupWordPassN(1, &wd);
1251  classify_word_and_language(pass_n, &it, &wd);
1252  if (debug_noise_removal) {
1253  tprintf("word xheight=%g, row=%g, range=[%g,%g]\n", word_res->x_height,
1254  wd.row->x_height(), wd.word->raw_choice->min_x_height(),
1255  wd.word->raw_choice->max_x_height());
1256  }
1257  float cert = wd.word->raw_choice->certainty();
1258  float rat = wd.word->raw_choice->rating();
1259  *c2 = rat > 0.0f ? cert * cert / rat : 0.0f;
1260  *best_str = wd.word->raw_choice->unichar_string();
1261  it.DeleteCurrentWord();
1262  pr_it->ResetWordIterator();
1263  return cert;
1264 }
Definition: werd.h:36
BOOL8 flag(WERD_FLAGS mask) const
Definition: werd.h:128
void ResetWordIterator()
Definition: pageres.cpp:1533
void classify_word_and_language(int pass_n, PAGE_RES_IT *pr_it, WordData *word_data)
Definition: control.cpp:1274
Definition: werd.h:60
static C_BLOB * deep_copy(const C_BLOB *src)
Definition: stepblob.h:113
WERD * word
Definition: pageres.h:175
WERD_RES * word() const
Definition: pageres.h:736
#define tprintf(...)
Definition: tprintf.h:31
WERD * ConstructFromSingleBlob(bool bol, bool eol, C_BLOB *blob)
Definition: werd.cpp:137
Definition: werd.h:35
float x_height
Definition: pageres.h:295
WERD_RES * InsertSimpleCloneWord(const WERD_RES &clone_res, WERD *new_word)
Definition: pageres.cpp:1269
#define ASSERT_HOST(x)
Definition: errcode.h:84
PAGE_RES * page_res
Definition: pageres.h:661
void SetupWordPassN(int pass_n, WordData *word)
Definition: control.cpp:168
float tesseract::Tesseract::ClassifyBlobPlusOutlines ( const GenericVector< bool > &  ok_outlines,
const GenericVector< C_OUTLINE * > &  outlines,
int  pass_n,
PAGE_RES_IT pr_it,
C_BLOB blob,
STRING best_str 
)

Definition at line 1196 of file control.cpp.

1199  {
1200  C_OUTLINE_IT ol_it;
1201  C_OUTLINE* first_to_keep = NULL;
1202  if (blob != NULL) {
1203  // Add the required outlines to the blob.
1204  ol_it.set_to_list(blob->out_list());
1205  first_to_keep = ol_it.data();
1206  }
1207  for (int i = 0; i < ok_outlines.size(); ++i) {
1208  if (ok_outlines[i]) {
1209  // This outline is to be added.
1210  if (blob == NULL) {
1211  blob = new C_BLOB(outlines[i]);
1212  ol_it.set_to_list(blob->out_list());
1213  } else {
1214  ol_it.add_before_stay_put(outlines[i]);
1215  }
1216  }
1217  }
1218  float c2;
1219  float cert = ClassifyBlobAsWord(pass_n, pr_it, blob, best_str, &c2);
1220  ol_it.move_to_first();
1221  if (first_to_keep == NULL) {
1222  // We created blob. Empty its outlines and delete it.
1223  for (; !ol_it.empty(); ol_it.forward()) ol_it.extract();
1224  delete blob;
1225  cert = -c2;
1226  } else {
1227  // Remove the outlines that we put in.
1228  for (; ol_it.data() != first_to_keep; ol_it.forward()) {
1229  ol_it.extract();
1230  }
1231  }
1232  return cert;
1233 }
float ClassifyBlobAsWord(int pass_n, PAGE_RES_IT *pr_it, C_BLOB *blob, STRING *best_str, float *c2)
Definition: control.cpp:1238
int size() const
Definition: genericvector.h:72
C_OUTLINE_LIST * out_list()
Definition: stepblob.h:64
void tesseract::Tesseract::Clear ( )

Definition at line 644 of file tesseractclass.cpp.

644  {
645  pixDestroy(&pix_binary_);
646  pixDestroy(&cube_binary_);
647  pixDestroy(&pix_grey_);
648  pixDestroy(&pix_thresholds_);
649  pixDestroy(&scaled_color_);
650  deskew_ = FCOORD(1.0f, 0.0f);
651  reskew_ = FCOORD(1.0f, 0.0f);
652  splitter_.Clear();
653  scaled_factor_ = -1;
654  for (int i = 0; i < sub_langs_.size(); ++i)
655  sub_langs_[i]->Clear();
656 }
Definition: points.h:189
float tesseract::Tesseract::ComputeCompatibleXheight ( WERD_RES word_res,
float *  baseline_shift 
)

Definition at line 101 of file fixxht.cpp.

102  {
103  STATS top_stats(0, MAX_UINT8);
104  STATS shift_stats(-MAX_UINT8, MAX_UINT8);
105  int bottom_shift = 0;
106  int num_blobs = word_res->rebuild_word->NumBlobs();
107  do {
108  top_stats.clear();
109  shift_stats.clear();
110  for (int blob_id = 0; blob_id < num_blobs; ++blob_id) {
111  TBLOB* blob = word_res->rebuild_word->blobs[blob_id];
112  UNICHAR_ID class_id = word_res->best_choice->unichar_id(blob_id);
113  if (unicharset.get_isalpha(class_id) ||
114  unicharset.get_isdigit(class_id)) {
115  int top = blob->bounding_box().top() + bottom_shift;
116  // Clip the top to the limit of normalized feature space.
117  if (top >= INT_FEAT_RANGE)
118  top = INT_FEAT_RANGE - 1;
119  int bottom = blob->bounding_box().bottom() + bottom_shift;
120  int min_bottom, max_bottom, min_top, max_top;
121  unicharset.get_top_bottom(class_id, &min_bottom, &max_bottom,
122  &min_top, &max_top);
123  // Chars with a wild top range would mess up the result so ignore them.
124  if (max_top - min_top > kMaxCharTopRange)
125  continue;
126  int misfit_dist = MAX((min_top - x_ht_acceptance_tolerance) - top,
127  top - (max_top + x_ht_acceptance_tolerance));
128  int height = top - kBlnBaselineOffset;
129  if (debug_x_ht_level >= 2) {
130  tprintf("Class %s: height=%d, bottom=%d,%d top=%d,%d, actual=%d,%d: ",
131  unicharset.id_to_unichar(class_id),
132  height, min_bottom, max_bottom, min_top, max_top,
133  bottom, top);
134  }
135  // Use only chars that fit in the expected bottom range, and where
136  // the range of tops is sensibly near the xheight.
137  if (min_bottom <= bottom + x_ht_acceptance_tolerance &&
138  bottom - x_ht_acceptance_tolerance <= max_bottom &&
139  min_top > kBlnBaselineOffset &&
140  max_top - kBlnBaselineOffset >= kBlnXHeight &&
141  misfit_dist > 0) {
142  // Compute the x-height position using proportionality between the
143  // actual height and expected height.
144  int min_xht = DivRounded(height * kBlnXHeight,
145  max_top - kBlnBaselineOffset);
146  int max_xht = DivRounded(height * kBlnXHeight,
147  min_top - kBlnBaselineOffset);
148  if (debug_x_ht_level >= 2) {
149  tprintf(" xht range min=%d, max=%d\n", min_xht, max_xht);
150  }
151  // The range of expected heights gets a vote equal to the distance
152  // of the actual top from the expected top.
153  for (int y = min_xht; y <= max_xht; ++y)
154  top_stats.add(y, misfit_dist);
155  } else if ((min_bottom > bottom + x_ht_acceptance_tolerance ||
156  bottom - x_ht_acceptance_tolerance > max_bottom) &&
157  bottom_shift == 0) {
158  // Get the range of required bottom shift.
159  int min_shift = min_bottom - bottom;
160  int max_shift = max_bottom - bottom;
161  if (debug_x_ht_level >= 2) {
162  tprintf(" bottom shift min=%d, max=%d\n", min_shift, max_shift);
163  }
164  // The range of expected shifts gets a vote equal to the min distance
165  // of the actual bottom from the expected bottom, spread over the
166  // range of its acceptance.
167  int misfit_weight = abs(min_shift);
168  if (max_shift > min_shift)
169  misfit_weight /= max_shift - min_shift;
170  for (int y = min_shift; y <= max_shift; ++y)
171  shift_stats.add(y, misfit_weight);
172  } else {
173  if (bottom_shift == 0) {
174  // Things with bottoms that are already ok need to say so, on the
175  // 1st iteration only.
176  shift_stats.add(0, kBlnBaselineOffset);
177  }
178  if (debug_x_ht_level >= 2) {
179  tprintf(" already OK\n");
180  }
181  }
182  }
183  }
184  if (shift_stats.get_total() > top_stats.get_total()) {
185  bottom_shift = IntCastRounded(shift_stats.median());
186  if (debug_x_ht_level >= 2) {
187  tprintf("Applying bottom shift=%d\n", bottom_shift);
188  }
189  }
190  } while (bottom_shift != 0 &&
191  top_stats.get_total() < shift_stats.get_total());
192  // Baseline shift is opposite sign to the bottom shift.
193  *baseline_shift = -bottom_shift / word_res->denorm.y_scale();
194  if (debug_x_ht_level >= 2) {
195  tprintf("baseline shift=%g\n", *baseline_shift);
196  }
197  if (top_stats.get_total() == 0)
198  return bottom_shift != 0 ? word_res->x_height : 0.0f;
199  // The new xheight is just the median vote, which is then scaled out
200  // of BLN space back to pixel space to get the x-height in pixel space.
201  float new_xht = top_stats.median();
202  if (debug_x_ht_level >= 2) {
203  tprintf("Median xht=%f\n", new_xht);
204  tprintf("Mode20:A: New x-height = %f (norm), %f (orig)\n",
205  new_xht, new_xht / word_res->denorm.y_scale());
206  }
207  // The xheight must change by at least x_ht_min_change to be used.
208  if (fabs(new_xht - kBlnXHeight) >= x_ht_min_change)
209  return new_xht / word_res->denorm.y_scale();
210  else
211  return bottom_shift != 0 ? word_res->x_height : 0.0f;
212 }
int UNICHAR_ID
Definition: unichar.h:33
#define MAX_UINT8
Definition: host.h:121
inT16 bottom() const
Definition: rect.h:61
#define MAX(x, y)
Definition: ndminx.h:24
int NumBlobs() const
Definition: blobs.h:425
GenericVector< TBLOB * > blobs
Definition: blobs.h:436
UNICHAR_ID unichar_id(int index) const
Definition: ratngs.h:313
TBOX bounding_box() const
Definition: blobs.cpp:482
#define tprintf(...)
Definition: tprintf.h:31
bool get_isdigit(UNICHAR_ID unichar_id) const
Definition: unicharset.h:469
float y_scale() const
Definition: normalis.h:272
#define INT_FEAT_RANGE
Definition: float2int.h:27
int DivRounded(int a, int b)
Definition: helpers.h:166
bool get_isalpha(UNICHAR_ID unichar_id) const
Definition: unicharset.h:448
Definition: statistc.h:33
const char * id_to_unichar(UNICHAR_ID id) const
Definition: unicharset.cpp:266
UNICHARSET unicharset
Definition: ccutil.h:70
WERD_CHOICE * best_choice
Definition: pageres.h:219
float x_height
Definition: pageres.h:295
const int kBlnXHeight
Definition: normalis.h:28
inT16 top() const
Definition: rect.h:54
int IntCastRounded(double x)
Definition: helpers.h:172
const int kBlnBaselineOffset
Definition: normalis.h:29
void get_top_bottom(UNICHAR_ID unichar_id, int *min_bottom, int *max_bottom, int *min_top, int *max_top) const
Definition: unicharset.h:525
Definition: blobs.h:261
const int kMaxCharTopRange
Definition: fixxht.cpp:66
DENORM denorm
Definition: pageres.h:190
TWERD * rebuild_word
Definition: pageres.h:244
void tesseract::Tesseract::convert_bad_unlv_chs ( WERD_RES word_res)

Definition at line 664 of file docqual.cpp.

664  {
665  int i;
666  UNICHAR_ID unichar_dash = word_res->uch_set->unichar_to_id("-");
667  UNICHAR_ID unichar_space = word_res->uch_set->unichar_to_id(" ");
668  UNICHAR_ID unichar_tilde = word_res->uch_set->unichar_to_id("~");
669  UNICHAR_ID unichar_pow = word_res->uch_set->unichar_to_id("^");
670  for (i = 0; i < word_res->reject_map.length(); ++i) {
671  if (word_res->best_choice->unichar_id(i) == unichar_tilde) {
672  word_res->best_choice->set_unichar_id(unichar_dash, i);
673  if (word_res->reject_map[i].accepted ())
674  word_res->reject_map[i].setrej_unlv_rej ();
675  }
676  if (word_res->best_choice->unichar_id(i) == unichar_pow) {
677  word_res->best_choice->set_unichar_id(unichar_space, i);
678  if (word_res->reject_map[i].accepted ())
679  word_res->reject_map[i].setrej_unlv_rej ();
680  }
681  }
682 }
int UNICHAR_ID
Definition: unichar.h:33
UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:194
UNICHAR_ID unichar_id(int index) const
Definition: ratngs.h:313
REJMAP reject_map
Definition: pageres.h:271
void set_unichar_id(UNICHAR_ID unichar_id, int index)
Definition: ratngs.h:357
inT32 length() const
Definition: rejctmap.h:236
WERD_CHOICE * best_choice
Definition: pageres.h:219
const UNICHARSET * uch_set
Definition: pageres.h:192
bool tesseract::Tesseract::ConvertStringToUnichars ( const char *  utf8,
GenericVector< UNICHAR_ID > *  class_ids 
)

Converts the space-delimited string of utf8 text to a vector of UNICHAR_ID.

Returns
false if an invalid UNICHAR_ID is encountered.

Definition at line 535 of file applybox.cpp.

536  {
537  for (int step = 0; *utf8 != '\0'; utf8 += step) {
538  const char* next_space = strchr(utf8, ' ');
539  if (next_space == NULL)
540  next_space = utf8 + strlen(utf8);
541  step = next_space - utf8;
542  UNICHAR_ID class_id = unicharset.unichar_to_id(utf8, step);
543  if (class_id == INVALID_UNICHAR_ID) {
544  return false;
545  }
546  while (utf8[step] == ' ')
547  ++step;
548  class_ids->push_back(class_id);
549  }
550  return true;
551 }
int UNICHAR_ID
Definition: unichar.h:33
UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:194
UNICHARSET unicharset
Definition: ccutil.h:70
int push_back(T object)
void tesseract::Tesseract::CorrectClassifyWords ( PAGE_RES page_res)

Creates a fake best_choice entry in each WERD_RES with the correct text.

Definition at line 772 of file applybox.cpp.

772  {
773  PAGE_RES_IT pr_it(page_res);
774  for (WERD_RES *word_res = pr_it.word(); word_res != NULL;
775  word_res = pr_it.forward()) {
776  WERD_CHOICE* choice = new WERD_CHOICE(word_res->uch_set,
777  word_res->correct_text.size());
778  for (int i = 0; i < word_res->correct_text.size(); ++i) {
779  // The part before the first space is the real ground truth, and the
780  // rest is the bounding box location and page number.
781  GenericVector<STRING> tokens;
782  word_res->correct_text[i].split(' ', &tokens);
783  UNICHAR_ID char_id = unicharset.unichar_to_id(tokens[0].string());
784  choice->append_unichar_id_space_allocated(char_id,
785  word_res->best_state[i],
786  0.0f, 0.0f);
787  }
788  word_res->ClearWordChoices();
789  word_res->LogNewRawChoice(choice);
790  word_res->LogNewCookedChoice(1, false, choice);
791  }
792 }
int UNICHAR_ID
Definition: unichar.h:33
UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:194
WERD * word
Definition: pageres.h:175
void append_unichar_id_space_allocated(UNICHAR_ID unichar_id, int blob_count, float rating, float certainty)
Definition: ratngs.h:450
UNICHARSET unicharset
Definition: ccutil.h:70
inT16 tesseract::Tesseract::count_alphanums ( const WERD_CHOICE word)

Definition at line 408 of file output.cpp.

408  {
409  int count = 0;
410  for (int i = 0; i < word.length(); ++i) {
411  if (word.unicharset()->get_isalpha(word.unichar_id(i)) ||
412  word.unicharset()->get_isdigit(word.unichar_id(i)))
413  count++;
414  }
415  return count;
416 }
int count(LIST var_list)
Definition: oldlist.cpp:108
const UNICHARSET * unicharset() const
Definition: ratngs.h:298
UNICHAR_ID unichar_id(int index) const
Definition: ratngs.h:313
int length() const
Definition: ratngs.h:301
bool get_isdigit(UNICHAR_ID unichar_id) const
Definition: unicharset.h:469
bool get_isalpha(UNICHAR_ID unichar_id) const
Definition: unicharset.h:448
inT16 tesseract::Tesseract::count_alphanums ( WERD_RES word)

Definition at line 558 of file reject.cpp.

558  {
559  int count = 0;
560  const WERD_CHOICE *best_choice = word_res->best_choice;
561  for (int i = 0; i < word_res->reject_map.length(); ++i) {
562  if ((word_res->reject_map[i].accepted()) &&
563  (word_res->uch_set->get_isalpha(best_choice->unichar_id(i)) ||
564  word_res->uch_set->get_isdigit(best_choice->unichar_id(i)))) {
565  count++;
566  }
567  }
568  return count;
569 }
int count(LIST var_list)
Definition: oldlist.cpp:108
UNICHAR_ID unichar_id(int index) const
Definition: ratngs.h:313
inT16 tesseract::Tesseract::count_alphas ( const WERD_CHOICE word)

Definition at line 398 of file output.cpp.

398  {
399  int count = 0;
400  for (int i = 0; i < word.length(); ++i) {
401  if (word.unicharset()->get_isalpha(word.unichar_id(i)))
402  count++;
403  }
404  return count;
405 }
int count(LIST var_list)
Definition: oldlist.cpp:108
const UNICHARSET * unicharset() const
Definition: ratngs.h:298
UNICHAR_ID unichar_id(int index) const
Definition: ratngs.h:313
int length() const
Definition: ratngs.h:301
bool get_isalpha(UNICHAR_ID unichar_id) const
Definition: unicharset.h:448
inT16 tesseract::Tesseract::count_outline_errs ( char  c,
inT16  outline_count 
)

Definition at line 131 of file docqual.cpp.

131  {
132  int expected_outline_count;
133 
134  if (STRING (outlines_odd).contains (c))
135  return 0; // Don't use this char
136  else if (STRING (outlines_2).contains (c))
137  expected_outline_count = 2;
138  else
139  expected_outline_count = 1;
140  return abs (outline_count - expected_outline_count);
141 }
Definition: strngs.h:44
int tesseract::Tesseract::CountMisfitTops ( WERD_RES word_res)

Definition at line 69 of file fixxht.cpp.

69  {
70  int bad_blobs = 0;
71  int num_blobs = word_res->rebuild_word->NumBlobs();
72  for (int blob_id = 0; blob_id < num_blobs; ++blob_id) {
73  TBLOB* blob = word_res->rebuild_word->blobs[blob_id];
74  UNICHAR_ID class_id = word_res->best_choice->unichar_id(blob_id);
75  if (unicharset.get_isalpha(class_id) || unicharset.get_isdigit(class_id)) {
76  int top = blob->bounding_box().top();
77  if (top >= INT_FEAT_RANGE)
78  top = INT_FEAT_RANGE - 1;
79  int min_bottom, max_bottom, min_top, max_top;
80  unicharset.get_top_bottom(class_id, &min_bottom, &max_bottom,
81  &min_top, &max_top);
82  if (max_top - min_top > kMaxCharTopRange)
83  continue;
84  bool bad = top < min_top - x_ht_acceptance_tolerance ||
85  top > max_top + x_ht_acceptance_tolerance;
86  if (bad)
87  ++bad_blobs;
88  if (debug_x_ht_level >= 1) {
89  tprintf("Class %s is %s with top %d vs limits of %d->%d, +/-%d\n",
90  unicharset.id_to_unichar(class_id),
91  bad ? "Misfit" : "OK", top, min_top, max_top,
92  static_cast<int>(x_ht_acceptance_tolerance));
93  }
94  }
95  }
96  return bad_blobs;
97 }
int UNICHAR_ID
Definition: unichar.h:33
int NumBlobs() const
Definition: blobs.h:425
GenericVector< TBLOB * > blobs
Definition: blobs.h:436
UNICHAR_ID unichar_id(int index) const
Definition: ratngs.h:313
TBOX bounding_box() const
Definition: blobs.cpp:482
#define tprintf(...)
Definition: tprintf.h:31
bool get_isdigit(UNICHAR_ID unichar_id) const
Definition: unicharset.h:469
#define INT_FEAT_RANGE
Definition: float2int.h:27
bool get_isalpha(UNICHAR_ID unichar_id) const
Definition: unicharset.h:448
const char * id_to_unichar(UNICHAR_ID id) const
Definition: unicharset.cpp:266
UNICHARSET unicharset
Definition: ccutil.h:70
WERD_CHOICE * best_choice
Definition: pageres.h:219
inT16 top() const
Definition: rect.h:54
void get_top_bottom(UNICHAR_ID unichar_id, int *min_bottom, int *max_bottom, int *min_top, int *max_top) const
Definition: unicharset.h:525
Definition: blobs.h:261
const int kMaxCharTopRange
Definition: fixxht.cpp:66
TWERD * rebuild_word
Definition: pageres.h:244
bool tesseract::Tesseract::create_cube_box_word ( Boxa *  char_boxes,
int  num_chars,
TBOX  word_box,
BoxWord box_word 
)

Definition at line 126 of file cube_control.cpp.

129  {
130  if (!box_word) {
131  if (cube_debug_level > 0) {
132  tprintf("Cube WARNING (create_cube_box_word): Invalid box_word.\n");
133  }
134  return false;
135  }
136 
137  // Find the x-coordinate of left-most char_box, which could be
138  // nonzero if the word image was padded before recognition took place.
139  int x_offset = -1;
140  for (int i = 0; i < num_chars; ++i) {
141  Box* char_box = boxaGetBox(char_boxes, i, L_CLONE);
142  if (x_offset < 0 || char_box->x < x_offset) {
143  x_offset = char_box->x;
144  }
145  boxDestroy(&char_box);
146  }
147 
148  for (int i = 0; i < num_chars; ++i) {
149  Box* char_box = boxaGetBox(char_boxes, i, L_CLONE);
150  TBOX tbox = char_box_to_tbox(char_box, word_box, x_offset);
151  boxDestroy(&char_box);
152  box_word->InsertBox(i, tbox);
153  }
154  return true;
155 }
TBOX char_box_to_tbox(Box *char_box, TBOX word_box, int x_offset)
#define tprintf(...)
Definition: tprintf.h:31
Definition: rect.h:30
void tesseract::Tesseract::cube_combine_word ( CubeObject cube_obj,
WERD_RES cube_word,
WERD_RES tess_word 
)

Definition at line 291 of file cube_control.cpp.

292  {
293  float combiner_prob = tess_cube_combiner_->CombineResults(tess_word,
294  cube_obj);
295  // If combiner probability is greater than tess/cube combiner
296  // classifier threshold, i.e. tesseract wins, then just return the
297  // tesseract result unchanged, as the combiner knows nothing about how
298  // correct the answer is. If cube and tesseract agree, then improve the
299  // scores before returning.
300  WERD_CHOICE* tess_best = tess_word->best_choice;
301  WERD_CHOICE* cube_best = cube_word->best_choice;
303  tprintf("Combiner prob = %g vs threshold %g\n",
304  combiner_prob, cube_cntxt_->Params()->CombinerClassifierThresh());
305  }
306  if (combiner_prob >=
307  cube_cntxt_->Params()->CombinerClassifierThresh()) {
308  if (tess_best->unichar_string() == cube_best->unichar_string()) {
309  // Cube and tess agree, so improve the scores.
310  tess_best->set_rating(tess_best->rating() / 2);
311  tess_best->set_certainty(tess_best->certainty() / 2);
312  }
313  return;
314  }
315  // Cube wins.
316  // It is better for the language combiner to have all tesseract scores,
317  // so put them in the cube result.
318  cube_best->set_rating(tess_best->rating());
319  cube_best->set_certainty(tess_best->certainty());
321  tprintf("Cube INFO: tesseract result replaced by cube: %s -> %s\n",
322  tess_best->unichar_string().string(),
323  cube_best->unichar_string().string());
324  }
325  tess_word->ConsumeWordResults(cube_word);
326 }
void set_certainty(float new_val)
Definition: ratngs.h:370
void ConsumeWordResults(WERD_RES *word)
Definition: pageres.cpp:757
void set_rating(float new_val)
Definition: ratngs.h:367
double CombinerClassifierThresh() const
Definition: tuning_params.h:63
#define tprintf(...)
Definition: tprintf.h:31
const STRING & unichar_string() const
Definition: ratngs.h:525
TuningParams * Params() const
float rating() const
Definition: ratngs.h:325
float CombineResults(WERD_RES *tess_res, CubeObject *cube_obj)
WERD_CHOICE * best_choice
Definition: pageres.h:219
const char * string() const
Definition: strngs.cpp:201
float certainty() const
Definition: ratngs.h:328
bool tesseract::Tesseract::cube_recognize ( CubeObject cube_obj,
BLOCK block,
WERD_RES word 
)

Definition at line 334 of file cube_control.cpp.

335  {
336  // Run cube
337  WordAltList *cube_alt_list = cube_obj->RecognizeWord();
338  if (!cube_alt_list || cube_alt_list->AltCount() <= 0) {
339  if (cube_debug_level > 0) {
340  tprintf("Cube returned nothing for word at:");
341  word->word->bounding_box().print();
342  }
343  word->SetupFake(unicharset);
344  return false;
345  }
346 
347  // Get cube's best result and its probability, mapped to tesseract's
348  // certainty range
349  char_32 *cube_best_32 = cube_alt_list->Alt(0);
350  double cube_prob = CubeUtils::Cost2Prob(cube_alt_list->AltCost(0));
351  float cube_certainty = convert_prob_to_tess_certainty(cube_prob);
352  string cube_best_str;
353  CubeUtils::UTF32ToUTF8(cube_best_32, &cube_best_str);
354 
355  // Retrieve Cube's character bounding boxes and CharSamples,
356  // corresponding to the most recent call to RecognizeWord().
357  Boxa *char_boxes = NULL;
358  CharSamp **char_samples = NULL;;
359  int num_chars;
360  if (!extract_cube_state(cube_obj, &num_chars, &char_boxes, &char_samples)
361  && cube_debug_level > 0) {
362  tprintf("Cube WARNING (Tesseract::cube_recognize): Cannot extract "
363  "cube state.\n");
364  word->SetupFake(unicharset);
365  return false;
366  }
367 
368  // Convert cube's character bounding boxes to a BoxWord.
369  BoxWord cube_box_word;
370  TBOX tess_word_box = word->word->bounding_box();
371  if (word->denorm.block() != NULL)
372  tess_word_box.rotate(word->denorm.block()->re_rotation());
373  bool box_word_success = create_cube_box_word(char_boxes, num_chars,
374  tess_word_box,
375  &cube_box_word);
376  boxaDestroy(&char_boxes);
377  if (!box_word_success) {
378  if (cube_debug_level > 0) {
379  tprintf("Cube WARNING (Tesseract::cube_recognize): Could not "
380  "create cube BoxWord\n");
381  }
382  word->SetupFake(unicharset);
383  return false;
384  }
385 
386  // Fill tesseract result's fields with cube results
387  fill_werd_res(cube_box_word, cube_best_str.c_str(), word);
388 
389  // Create cube's best choice.
390  BLOB_CHOICE** choices = new BLOB_CHOICE*[num_chars];
391  for (int i = 0; i < num_chars; ++i) {
392  UNICHAR_ID uch_id =
393  cube_cntxt_->CharacterSet()->UnicharID(char_samples[i]->StrLabel());
394  choices[i] = new BLOB_CHOICE(uch_id, -cube_certainty, cube_certainty,
395  -1, 0.0f, 0.0f, 0.0f, BCC_STATIC_CLASSIFIER);
396  }
397  word->FakeClassifyWord(num_chars, choices);
398  // within a word, cube recognizes the word in reading order.
400  delete [] choices;
401  delete [] char_samples;
402 
403  // Some sanity checks
404  ASSERT_HOST(word->best_choice->length() == word->reject_map.length());
405 
407  tprintf("Cube result: %s r=%g, c=%g\n",
408  word->best_choice->unichar_string().string(),
409  word->best_choice->rating(),
410  word->best_choice->certainty());
411  }
412  return true;
413 }
int UNICHAR_ID
Definition: unichar.h:33
void rotate(const FCOORD &vec)
Definition: rect.h:189
static void UTF32ToUTF8(const char_32 *utf32_str, string *str)
Definition: cube_utils.cpp:272
const BLOCK * block() const
Definition: normalis.h:275
CharSet * CharacterSet() const
WERD * word
Definition: pageres.h:175
int length() const
Definition: ratngs.h:301
static double Cost2Prob(int cost)
Definition: cube_utils.cpp:47
#define tprintf(...)
Definition: tprintf.h:31
REJMAP reject_map
Definition: pageres.h:271
TBOX bounding_box() const
Definition: werd.cpp:160
Definition: rect.h:30
const STRING & unichar_string() const
Definition: ratngs.h:525
void fill_werd_res(const BoxWord &cube_box_word, const char *cube_best_str, WERD_RES *tess_werd_res)
int UnicharID(const char_32 *str) const
Definition: char_set.h:80
bool extract_cube_state(CubeObject *cube_obj, int *num_chars, Boxa **char_boxes, CharSamp ***char_samples)
bool set_unichars_in_script_order(bool in_script_order)
Definition: ratngs.h:515
inT32 length() const
Definition: rejctmap.h:236
UNICHARSET unicharset
Definition: ccutil.h:70
float rating() const
Definition: ratngs.h:325
FCOORD re_rotation() const
Definition: ocrblock.h:138
void print() const
Definition: rect.h:270
WERD_CHOICE * best_choice
Definition: pageres.h:219
void SetupFake(const UNICHARSET &uch)
Definition: pageres.cpp:343
#define ASSERT_HOST(x)
Definition: errcode.h:84
signed int char_32
Definition: string_32.h:40
const char * string() const
Definition: strngs.cpp:201
void FakeClassifyWord(int blob_count, BLOB_CHOICE **choices)
Definition: pageres.cpp:872
DENORM denorm
Definition: pageres.h:190
bool create_cube_box_word(Boxa *char_boxes, int num_chars, TBOX word_box, BoxWord *box_word)
float certainty() const
Definition: ratngs.h:328
CubeObject * tesseract::Tesseract::cube_recognize_word ( BLOCK block,
WERD_RES word 
)

Definition at line 254 of file cube_control.cpp.

254  {
255  if (!cube_binary_ || !cube_cntxt_) {
256  if (cube_debug_level > 0 && !cube_binary_)
257  tprintf("Tesseract::run_cube(): NULL binary image.\n");
258  word->SetupFake(unicharset);
259  return NULL;
260  }
261  TBOX word_box = word->word->bounding_box();
262  if (block != NULL && (block->re_rotation().x() != 1.0f ||
263  block->re_rotation().y() != 0.0f)) {
264  // TODO(rays) We have to rotate the bounding box to get the true coords.
265  // This will be achieved in the future via DENORM.
266  // In the mean time, cube can't process this word.
267  if (cube_debug_level > 0) {
268  tprintf("Cube can't process rotated word at:");
269  word_box.print();
270  }
271  word->SetupFake(unicharset);
272  return NULL;
273  }
274  CubeObject* cube_obj = new tesseract::CubeObject(
275  cube_cntxt_, cube_binary_, word_box.left(),
276  pixGetHeight(cube_binary_) - word_box.top(),
277  word_box.width(), word_box.height());
278  if (!cube_recognize(cube_obj, block, word)) {
279  delete cube_obj;
280  return NULL;
281  }
282  return cube_obj;
283 }
bool cube_recognize(CubeObject *cube_obj, BLOCK *block, WERD_RES *word)
WERD * word
Definition: pageres.h:175
inT16 height() const
Definition: rect.h:104
#define tprintf(...)
Definition: tprintf.h:31
TBOX bounding_box() const
Definition: werd.cpp:160
Definition: rect.h:30
inT16 left() const
Definition: rect.h:68
float y() const
Definition: points.h:212
UNICHARSET unicharset
Definition: ccutil.h:70
FCOORD re_rotation() const
Definition: ocrblock.h:138
void print() const
Definition: rect.h:270
float x() const
Definition: points.h:209
inT16 top() const
Definition: rect.h:54
void SetupFake(const UNICHARSET &uch)
Definition: pageres.cpp:343
inT16 width() const
Definition: rect.h:111
void tesseract::Tesseract::cube_word_pass1 ( BLOCK block,
ROW row,
WERD_RES word 
)

Definition at line 243 of file cube_control.cpp.

243  {
244  CubeObject *cube_obj = cube_recognize_word(block, word);
245  delete cube_obj;
246 }
CubeObject * cube_recognize_word(BLOCK *block, WERD_RES *word)
void tesseract::Tesseract::debug_word ( PAGE_RES page_res,
const TBOX selection_box 
)

debug_word

Process the whole image, but load word_config_ for the selected word(s).

Definition at line 641 of file pgedit.cpp.

641  {
643  recog_all_words(page_res, NULL, &selection_box, word_config_.string(), 0);
644 }
bool recog_all_words(PAGE_RES *page_res, ETEXT_DESC *monitor, const TBOX *target_word_box, const char *word_config, int dopasses)
Definition: control.cpp:293
const char * string() const
Definition: strngs.cpp:201
void tesseract::Tesseract::dictionary_correction_pass ( PAGE_RES page_res)

Definition at line 2020 of file control.cpp.

2020  {
2021  PAGE_RES_IT word_it(page_res);
2022  for (WERD_RES* word = word_it.word(); word != NULL;
2023  word = word_it.forward()) {
2024  if (word->best_choices.singleton())
2025  continue; // There are no alternates.
2026 
2027  WERD_CHOICE* best = word->best_choice;
2028  if (word->tesseract->getDict().valid_word(*best) != 0)
2029  continue; // The best choice is in the dictionary.
2030 
2031  WERD_CHOICE_IT choice_it(&word->best_choices);
2032  for (choice_it.mark_cycle_pt(); !choice_it.cycled_list();
2033  choice_it.forward()) {
2034  WERD_CHOICE* alternate = choice_it.data();
2035  if (word->tesseract->getDict().valid_word(*alternate)) {
2036  // The alternate choice is in the dictionary.
2037  if (tessedit_bigram_debug) {
2038  tprintf("Dictionary correction replaces best choice '%s' with '%s'\n",
2039  best->unichar_string().string(),
2040  alternate->unichar_string().string());
2041  }
2042  // Replace the 'best' choice with a better choice.
2043  word->ReplaceBestChoice(alternate);
2044  break;
2045  }
2046  }
2047  }
2048 }
WERD * word
Definition: pageres.h:175
#define tprintf(...)
Definition: tprintf.h:31
const STRING & unichar_string() const
Definition: ratngs.h:525
const char * string() const
Definition: strngs.cpp:201
BOOL8 tesseract::Tesseract::digit_or_numeric_punct ( WERD_RES word,
int  char_position 
)

Definition at line 343 of file fixspace.cpp.

343  {
344  int i;
345  int offset;
346 
347  for (i = 0, offset = 0; i < char_position;
348  offset += word->best_choice->unichar_lengths()[i++]);
349  return (
350  word->uch_set->get_isdigit(
351  word->best_choice->unichar_string().string() + offset,
352  word->best_choice->unichar_lengths()[i]) ||
353  (word->best_choice->permuter() == NUMBER_PERM &&
355  word->best_choice->unichar_string().string()[offset])));
356 }
BOOL8 contains(const char c) const
Definition: strngs.cpp:192
Definition: strngs.h:44
const STRING & unichar_lengths() const
Definition: ratngs.h:532
bool get_isdigit(UNICHAR_ID unichar_id) const
Definition: unicharset.h:469
const STRING & unichar_string() const
Definition: ratngs.h:525
uinT8 permuter() const
Definition: ratngs.h:344
WERD_CHOICE * best_choice
Definition: pageres.h:219
const UNICHARSET * uch_set
Definition: pageres.h:192
const char * string() const
Definition: strngs.cpp:201
void tesseract::Tesseract::do_re_display ( BOOL8(tesseract::Tesseract::*)(PAGE_RES_IT *pr_it)  word_painter)

do_re_display()

Redisplay page

Definition at line 308 of file pgedit.cpp.

309  {
310  int block_count = 1;
311 
312  image_win->Clear();
313  if (display_image != 0) {
314  image_win->Image(pix_binary_, 0, 0);
315  }
316 
319  for (WERD_RES* word = pr_it.word(); word != NULL; word = pr_it.forward()) {
320  (this->*word_painter)(&pr_it);
321  if (display_baselines && pr_it.row() != pr_it.prev_row())
322  pr_it.row()->row->plot_baseline(image_win, ScrollView::GREEN);
323  if (display_blocks && pr_it.block() != pr_it.prev_block())
324  pr_it.block()->block->plot(image_win, block_count++, ScrollView::RED);
325  }
326  image_win->Update();
327 }
ScrollView * image_win
Definition: pgedit.cpp:107
void Brush(Color color)
Definition: scrollview.cpp:732
BOOL8 display_baselines
Definition: pgedit.cpp:126
WERD * word
Definition: pageres.h:175
static void Update()
Definition: scrollview.cpp:715
PAGE_RES * current_page_res
Definition: pgedit.cpp:128
void Image(struct Pix *image, int x_pos, int y_pos)
Definition: scrollview.cpp:773
BOOL8 display_image
Definition: pgedit.cpp:124
void Clear()
Definition: scrollview.cpp:595
BOOL8 display_blocks
Definition: pgedit.cpp:125
void tesseract::Tesseract::doc_and_block_rejection ( PAGE_RES_IT page_res_it,
BOOL8  good_quality_doc 
)

Definition at line 237 of file docqual.cpp.

239  {
240  inT16 block_no = 0;
241  inT16 row_no = 0;
242  BLOCK_RES *current_block;
243  ROW_RES *current_row;
244 
245  BOOL8 rej_word;
246  BOOL8 prev_word_rejected;
247  inT16 char_quality = 0;
248  inT16 accepted_char_quality;
249 
250  if (page_res_it.page_res->rej_count * 100.0 /
252  reject_whole_page(page_res_it);
254  tprintf("REJECT ALL #chars: %d #Rejects: %d; \n",
255  page_res_it.page_res->char_count,
256  page_res_it.page_res->rej_count);
257  }
258  } else {
260  tprintf("NO PAGE REJECTION #chars: %d # Rejects: %d; \n",
261  page_res_it.page_res->char_count,
262  page_res_it.page_res->rej_count);
263  }
264 
265  /* Walk blocks testing for block rejection */
266 
267  page_res_it.restart_page();
268  WERD_RES* word;
269  while ((word = page_res_it.word()) != NULL) {
270  current_block = page_res_it.block();
271  block_no = current_block->block->index();
272  if (current_block->char_count > 0 &&
273  (current_block->rej_count * 100.0 / current_block->char_count) >
276  tprintf("REJECTING BLOCK %d #chars: %d; #Rejects: %d\n",
277  block_no, current_block->char_count,
278  current_block->rej_count);
279  }
280  prev_word_rejected = FALSE;
281  while ((word = page_res_it.word()) != NULL &&
282  (page_res_it.block() == current_block)) {
284  rej_word = word->reject_map.reject_count() > 0 ||
286  if (rej_word && tessedit_dont_blkrej_good_wds &&
289  *word->uch_set,
290  word->best_choice->unichar_string().string(),
291  word->best_choice->unichar_lengths().string()) !=
292  AC_UNACCEPTABLE) {
293  word_char_quality(word, page_res_it.row()->row,
294  &char_quality,
295  &accepted_char_quality);
296  rej_word = char_quality != word->reject_map.length();
297  }
298  } else {
299  rej_word = TRUE;
300  }
301  if (rej_word) {
302  /*
303  Reject spacing if both current and prev words are rejected.
304  NOTE - this is NOT restricted to FUZZY spaces. - When tried this
305  generated more space errors.
306  */
308  prev_word_rejected &&
309  page_res_it.prev_row() == page_res_it.row() &&
310  word->word->space() == 1)
311  word->reject_spaces = TRUE;
313  }
314  prev_word_rejected = rej_word;
315  page_res_it.forward();
316  }
317  } else {
319  tprintf("NOT REJECTING BLOCK %d #chars: %d # Rejects: %d; \n",
320  block_no, page_res_it.block()->char_count,
321  page_res_it.block()->rej_count);
322  }
323 
324  /* Walk rows in block testing for row rejection */
325  row_no = 0;
326  while (page_res_it.word() != NULL &&
327  page_res_it.block() == current_block) {
328  current_row = page_res_it.row();
329  row_no++;
330  /* Reject whole row if:
331  fraction of chars on row which are rejected exceed a limit AND
332  fraction rejects which occur in WHOLE WERD rejects is LESS THAN a
333  limit
334  */
335  if (current_row->char_count > 0 &&
336  (current_row->rej_count * 100.0 / current_row->char_count) >
338  (current_row->whole_word_rej_count * 100.0 /
339  current_row->rej_count) <
342  tprintf("REJECTING ROW %d #chars: %d; #Rejects: %d\n",
343  row_no, current_row->char_count,
344  current_row->rej_count);
345  }
346  prev_word_rejected = FALSE;
347  while ((word = page_res_it.word()) != NULL &&
348  page_res_it.row () == current_row) {
349  /* Preserve words on good docs unless they are mostly rejected*/
350  if (!tessedit_row_rej_good_docs && good_quality_doc) {
351  rej_word = word->reject_map.reject_count() /
352  static_cast<float>(word->reject_map.length()) >
355  /* Preserve perfect words anyway */
356  rej_word = word->reject_map.reject_count() > 0 ||
358  if (rej_word && tessedit_dont_rowrej_good_wds &&
361  word->best_choice->unichar_string().string(),
362  word->best_choice->unichar_lengths().string()) !=
363  AC_UNACCEPTABLE) {
364  word_char_quality(word, page_res_it.row()->row,
365  &char_quality,
366  &accepted_char_quality);
367  rej_word = char_quality != word->reject_map.length();
368  }
369  } else {
370  rej_word = TRUE;
371  }
372  if (rej_word) {
373  /*
374  Reject spacing if both current and prev words are rejected.
375  NOTE - this is NOT restricted to FUZZY spaces. - When tried
376  this generated more space errors.
377  */
379  prev_word_rejected &&
380  page_res_it.prev_row() == page_res_it.row() &&
381  word->word->space () == 1)
382  word->reject_spaces = TRUE;
384  }
385  prev_word_rejected = rej_word;
386  page_res_it.forward();
387  }
388  } else {
390  tprintf("NOT REJECTING ROW %d #chars: %d # Rejects: %d; \n",
391  row_no, current_row->char_count, current_row->rej_count);
392  }
393  while (page_res_it.word() != NULL &&
394  page_res_it.row() == current_row)
395  page_res_it.forward();
396  }
397  }
398  }
399  }
400  }
401 }
bool tessedit_preserve_blk_rej_perfect_wds
#define TRUE
Definition: capi.h:45
double tessedit_reject_block_percent
inT32 char_count
Definition: pageres.h:100
BOOL8 reject_spaces
Definition: pageres.h:320
inT32 whole_word_rej_count
Definition: pageres.h:130
uinT8 space()
Definition: werd.h:104
int index() const
Definition: pdblock.h:67
void rej_word_block_rej()
Definition: rejctmap.cpp:506
double tessedit_reject_doc_percent
const STRING & unichar_lengths() const
Definition: ratngs.h:532
inT32 char_count
Definition: pageres.h:128
inT32 rej_count
Definition: pageres.h:101
ROW_RES * prev_row() const
Definition: pageres.h:730
WERD * word
Definition: pageres.h:175
WERD_RES * word() const
Definition: pageres.h:736
WERD_RES * forward()
Definition: pageres.h:716
inT32 rej_count
Definition: pageres.h:61
#define tprintf(...)
Definition: tprintf.h:31
REJMAP reject_map
Definition: pageres.h:271
ROW_RES * row() const
Definition: pageres.h:739
#define FALSE
Definition: capi.h:46
const STRING & unichar_string() const
Definition: ratngs.h:525
double tessedit_good_doc_still_rowrej_wd
double tessedit_whole_wd_rej_row_percent
void reject_whole_page(PAGE_RES_IT &page_res_it)
Definition: docqual.cpp:411
WERD_RES * restart_page()
Definition: pageres.h:683
short inT16
Definition: host.h:100
Unacceptable word.
Definition: control.h:36
inT32 char_count
Definition: pageres.h:60
inT32 rej_count
Definition: pageres.h:129
ROW * row
Definition: pageres.h:127
inT32 length() const
Definition: rejctmap.h:236
bool tessedit_preserve_row_rej_perfect_wds
BLOCK_RES * block() const
Definition: pageres.h:742
double tessedit_reject_row_percent
WERD_CHOICE * best_choice
Definition: pageres.h:219
const UNICHARSET * uch_set
Definition: pageres.h:192
void rej_word_row_rej()
Definition: rejctmap.cpp:515
void word_char_quality(WERD_RES *word, ROW *row, inT16 *match_count, inT16 *accepted_match_count)
Definition: docqual.cpp:97
unsigned char BOOL8
Definition: host.h:113
const char * string() const
Definition: strngs.cpp:201
inT16 reject_count()
Definition: rejctmap.h:242
ACCEPTABLE_WERD_TYPE acceptable_word_string(const UNICHARSET &char_set, const char *s, const char *lengths)
Definition: control.cpp:1668
BLOCK * block
Definition: pageres.h:99
PAGE_RES * page_res
Definition: pageres.h:661
void tesseract::Tesseract::dont_allow_1Il ( WERD_RES word)

Definition at line 526 of file reject.cpp.

526  {
527  int i = 0;
528  int offset;
529  int word_len = word->reject_map.length();
530  const char *s = word->best_choice->unichar_string().string();
531  const char *lengths = word->best_choice->unichar_lengths().string();
532  BOOL8 accepted_1Il = FALSE;
533 
534  for (i = 0, offset = 0; i < word_len;
535  offset += word->best_choice->unichar_lengths()[i++]) {
536  if (word->reject_map[i].accepted()) {
537  if (STRING(conflict_set_I_l_1).contains(s[offset])) {
538  accepted_1Il = TRUE;
539  } else {
540  if (word->uch_set->get_isalpha(s + offset, lengths[i]) ||
541  word->uch_set->get_isdigit(s + offset, lengths[i]))
542  return; // >=1 non 1Il ch accepted
543  }
544  }
545  }
546  if (!accepted_1Il)
547  return; //Nothing to worry about
548 
549  for (i = 0, offset = 0; i < word_len;
550  offset += word->best_choice->unichar_lengths()[i++]) {
551  if (STRING(conflict_set_I_l_1).contains(s[offset]) &&
552  word->reject_map[i].accepted())
553  word->reject_map[i].setrej_postNN_1Il();
554  }
555 }
BOOL8 contains(const char c) const
Definition: strngs.cpp:192
#define TRUE
Definition: capi.h:45
Definition: strngs.h:44
const STRING & unichar_lengths() const
Definition: ratngs.h:532
bool get_isdigit(UNICHAR_ID unichar_id) const
Definition: unicharset.h:469
REJMAP reject_map
Definition: pageres.h:271
#define FALSE
Definition: capi.h:46
const STRING & unichar_string() const
Definition: ratngs.h:525
bool get_isalpha(UNICHAR_ID unichar_id) const
Definition: unicharset.h:448
inT32 length() const
Definition: rejctmap.h:236
WERD_CHOICE * best_choice
Definition: pageres.h:219
const UNICHARSET * uch_set
Definition: pageres.h:192
unsigned char BOOL8
Definition: host.h:113
const char * string() const
Definition: strngs.cpp:201
void tesseract::Tesseract::dump_words ( WERD_RES_LIST &  perm,
inT16  score,
inT16  mode,
BOOL8  improved 
)

Definition at line 449 of file fixspace.cpp.

450  {
451  WERD_RES_IT word_res_it(&perm);
452 
453  if (debug_fix_space_level > 0) {
454  if (mode == 1) {
455  stats_.dump_words_str = "";
456  for (word_res_it.mark_cycle_pt(); !word_res_it.cycled_list();
457  word_res_it.forward()) {
458  if (!word_res_it.data()->part_of_combo) {
459  stats_.dump_words_str +=
460  word_res_it.data()->best_choice->unichar_string();
461  stats_.dump_words_str += ' ';
462  }
463  }
464  }
465 
466  if (debug_fix_space_level > 1) {
467  switch (mode) {
468  case 1:
469  tprintf("EXTRACTED (%d): \"", score);
470  break;
471  case 2:
472  tprintf("TESTED (%d): \"", score);
473  break;
474  case 3:
475  tprintf("RETURNED (%d): \"", score);
476  break;
477  }
478 
479  for (word_res_it.mark_cycle_pt(); !word_res_it.cycled_list();
480  word_res_it.forward()) {
481  if (!word_res_it.data()->part_of_combo) {
482  tprintf("%s/%1d ",
483  word_res_it.data()->best_choice->unichar_string().string(),
484  (int)word_res_it.data()->best_choice->permuter());
485  }
486  }
487  tprintf("\"\n");
488  } else if (improved) {
489  tprintf("FIX SPACING \"%s\" => \"", stats_.dump_words_str.string());
490  for (word_res_it.mark_cycle_pt(); !word_res_it.cycled_list();
491  word_res_it.forward()) {
492  if (!word_res_it.data()->part_of_combo) {
493  tprintf("%s/%1d ",
494  word_res_it.data()->best_choice->unichar_string().string(),
495  (int)word_res_it.data()->best_choice->permuter());
496  }
497  }
498  tprintf("\"\n");
499  }
500  }
501 }
#define tprintf(...)
Definition: tprintf.h:31
CMD_EVENTS mode
Definition: pgedit.cpp:116
const char * string() const
Definition: strngs.cpp:201
void tesseract::Tesseract::end_tesseract ( )

Definition at line 478 of file tessedit.cpp.

478  {
479  end_recog();
480 }
inT16 tesseract::Tesseract::eval_word_spacing ( WERD_RES_LIST &  word_res_list)

Definition at line 239 of file fixspace.cpp.

239  {
240  WERD_RES_IT word_res_it(&word_res_list);
241  inT16 total_score = 0;
242  inT16 word_count = 0;
243  inT16 done_word_count = 0;
244  inT16 word_len;
245  inT16 i;
246  inT16 offset;
247  WERD_RES *word; // current word
248  inT16 prev_word_score = 0;
249  BOOL8 prev_word_done = FALSE;
250  BOOL8 prev_char_1 = FALSE; // prev ch a "1/I/l"?
251  BOOL8 prev_char_digit = FALSE; // prev ch 2..9 or 0
252  BOOL8 current_char_1 = FALSE;
253  BOOL8 current_word_ok_so_far;
254  STRING punct_chars = "!\"`',.:;";
255  BOOL8 prev_char_punct = FALSE;
256  BOOL8 current_char_punct = FALSE;
257  BOOL8 word_done = FALSE;
258 
259  do {
260  word = word_res_it.data();
261  word_done = fixspace_thinks_word_done(word);
262  word_count++;
263  if (word->tess_failed) {
264  total_score += prev_word_score;
265  if (prev_word_done)
266  done_word_count++;
267  prev_word_score = 0;
268  prev_char_1 = FALSE;
269  prev_char_digit = FALSE;
270  prev_word_done = FALSE;
271  } else {
272  /*
273  Can we add the prev word score and potentially count this word?
274  Yes IF it didn't end in a 1 when the first char of this word is a digit
275  AND it didn't end in a digit when the first char of this word is a 1
276  */
277  word_len = word->reject_map.length();
278  current_word_ok_so_far = FALSE;
279  if (!((prev_char_1 && digit_or_numeric_punct(word, 0)) ||
280  (prev_char_digit && (
281  (word_done &&
282  word->best_choice->unichar_lengths().string()[0] == 1 &&
283  word->best_choice->unichar_string()[0] == '1') ||
284  (!word_done && STRING(conflict_set_I_l_1).contains(
285  word->best_choice->unichar_string()[0])))))) {
286  total_score += prev_word_score;
287  if (prev_word_done)
288  done_word_count++;
289  current_word_ok_so_far = word_done;
290  }
291 
292  if (current_word_ok_so_far) {
293  prev_word_done = TRUE;
294  prev_word_score = word_len;
295  } else {
296  prev_word_done = FALSE;
297  prev_word_score = 0;
298  }
299 
300  /* Add 1 to total score for every joined 1 regardless of context and
301  rejtn */
302  for (i = 0, prev_char_1 = FALSE; i < word_len; i++) {
303  current_char_1 = word->best_choice->unichar_string()[i] == '1';
304  if (prev_char_1 || (current_char_1 && (i > 0)))
305  total_score++;
306  prev_char_1 = current_char_1;
307  }
308 
309  /* Add 1 to total score for every joined punctuation regardless of context
310  and rejtn */
312  for (i = 0, offset = 0, prev_char_punct = FALSE; i < word_len;
313  offset += word->best_choice->unichar_lengths()[i++]) {
314  current_char_punct =
315  punct_chars.contains(word->best_choice->unichar_string()[offset]);
316  if (prev_char_punct || (current_char_punct && i > 0))
317  total_score++;
318  prev_char_punct = current_char_punct;
319  }
320  }
321  prev_char_digit = digit_or_numeric_punct(word, word_len - 1);
322  for (i = 0, offset = 0; i < word_len - 1;
323  offset += word->best_choice->unichar_lengths()[i++]);
324  prev_char_1 =
325  ((word_done && (word->best_choice->unichar_string()[offset] == '1'))
326  || (!word_done && STRING(conflict_set_I_l_1).contains(
327  word->best_choice->unichar_string()[offset])));
328  }
329  /* Find next word */
330  do {
331  word_res_it.forward();
332  } while (word_res_it.data()->part_of_combo);
333  } while (!word_res_it.at_first());
334  total_score += prev_word_score;
335  if (prev_word_done)
336  done_word_count++;
337  if (done_word_count == word_count)
338  return PERFECT_WERDS;
339  else
340  return total_score;
341 }
BOOL8 contains(const char c) const
Definition: strngs.cpp:192
#define TRUE
Definition: capi.h:45
Definition: strngs.h:44
const STRING & unichar_lengths() const
Definition: ratngs.h:532
BOOL8 digit_or_numeric_punct(WERD_RES *word, int char_position)
Definition: fixspace.cpp:343
REJMAP reject_map
Definition: pageres.h:271
BOOL8 tess_failed
Definition: pageres.h:272
#define FALSE
Definition: capi.h:46
const STRING & unichar_string() const
Definition: ratngs.h:525
BOOL8 fixspace_thinks_word_done(WERD_RES *word)
Definition: fixspace.cpp:503
short inT16
Definition: host.h:100
inT32 length() const
Definition: rejctmap.h:236
WERD_CHOICE * best_choice
Definition: pageres.h:219
#define PERFECT_WERDS
Definition: fixspace.cpp:33
unsigned char BOOL8
Definition: host.h:113
const char * string() const
Definition: strngs.cpp:201
bool tesseract::Tesseract::extract_cube_state ( CubeObject cube_obj,
int *  num_chars,
Boxa **  char_boxes,
CharSamp ***  char_samples 
)

Definition at line 75 of file cube_control.cpp.

78  {
79  if (!cube_obj) {
80  if (cube_debug_level > 0) {
81  tprintf("Cube WARNING (extract_cube_state): Invalid cube object "
82  "passed to extract_cube_state\n");
83  }
84  return false;
85  }
86 
87  // Note that the CubeObject accessors return either the deslanted or
88  // regular objects search object or beam search object, whichever
89  // was used in the last call to Recognize()
90  CubeSearchObject* cube_search_obj = cube_obj->SrchObj();
91  if (!cube_search_obj) {
92  if (cube_debug_level > 0) {
93  tprintf("Cube WARNING (Extract_cube_state): Could not retrieve "
94  "cube's search object in extract_cube_state.\n");
95  }
96  return false;
97  }
98  BeamSearch *beam_search_obj = cube_obj->BeamObj();
99  if (!beam_search_obj) {
100  if (cube_debug_level > 0) {
101  tprintf("Cube WARNING (Extract_cube_state): Could not retrieve "
102  "cube's beam search object in extract_cube_state.\n");
103  }
104  return false;
105  }
106 
107  // Get the character samples and bounding boxes by backtracking
108  // through the beam search path
109  int best_node_index = beam_search_obj->BestPresortedNodeIndex();
110  *char_samples = beam_search_obj->BackTrack(
111  cube_search_obj, best_node_index, num_chars, NULL, char_boxes);
112  if (!*char_samples)
113  return false;
114  return true;
115 }
#define tprintf(...)
Definition: tprintf.h:31
inT16 tesseract::Tesseract::failure_count ( WERD_RES word)

Definition at line 970 of file docqual.cpp.

970  {
971  const char *str = word->best_choice->unichar_string().string();
972  int tess_rejs = 0;
973 
974  for (; *str != '\0'; str++) {
975  if (*str == ' ')
976  tess_rejs++;
977  }
978  return tess_rejs;
979 }
const STRING & unichar_string() const
Definition: ratngs.h:525
WERD_CHOICE * best_choice
Definition: pageres.h:219
const char * string() const
Definition: strngs.cpp:201
void tesseract::Tesseract::fill_werd_res ( const BoxWord cube_box_word,
const char *  cube_best_str,
WERD_RES tess_werd_res 
)

Definition at line 421 of file cube_control.cpp.

423  {
424  delete tess_werd_res->box_word;
425  tess_werd_res->box_word = new BoxWord(cube_box_word);
426  tess_werd_res->box_word->ClipToOriginalWord(tess_werd_res->denorm.block(),
427  tess_werd_res->word);
428  // Fill text and remaining fields
429  tess_werd_res->word->set_text(cube_best_str);
430  tess_werd_res->tess_failed = FALSE;
431  tess_werd_res->tess_accepted = tess_acceptable_word(tess_werd_res);
432  // There is no output word, so we can' call AdaptableWord, but then I don't
433  // think we need to. Fudge the result with accepted.
434  tess_werd_res->tess_would_adapt = tess_werd_res->tess_accepted;
435 
436  // Set word to done, i.e., ignore all of tesseract's tests for rejection
437  tess_werd_res->done = tess_werd_res->tess_accepted;
438 }
BOOL8 tess_accepted
Definition: pageres.h:280
const BLOCK * block() const
Definition: normalis.h:275
WERD * word
Definition: pageres.h:175
tesseract::BoxWord * box_word
Definition: pageres.h:250
BOOL8 tess_failed
Definition: pageres.h:272
#define FALSE
Definition: capi.h:46
void ClipToOriginalWord(const BLOCK *block, WERD *original_word)
Definition: boxword.cpp:95
BOOL8 done
Definition: pageres.h:282
BOOL8 tess_would_adapt
Definition: pageres.h:281
DENORM denorm
Definition: pageres.h:190
bool tess_acceptable_word(WERD_RES *word)
Definition: tessbox.cpp:69
void set_text(const char *new_text)
Definition: werd.h:126
bool tesseract::Tesseract::FindSegmentation ( const GenericVector< UNICHAR_ID > &  target_text,
WERD_RES word_res 
)

Resegments the word to achieve the target_text from the classifier. Returns false if the re-segmentation fails. Uses brute-force combination of up to kMaxGroupSize adjacent blobs, and applies a full search on the classifier results to find the best classified segmentation. As a compromise to obtain better recall, 1-1 ambiguity substitutions ARE used.

Definition at line 559 of file applybox.cpp.

560  {
561  // Classify all required combinations of blobs and save results in choices.
562  int word_length = word_res->box_word->length();
564  new GenericVector<BLOB_CHOICE_LIST*>[word_length];
565  for (int i = 0; i < word_length; ++i) {
566  for (int j = 1; j <= kMaxGroupSize && i + j <= word_length; ++j) {
567  BLOB_CHOICE_LIST* match_result = classify_piece(
568  word_res->seam_array, i, i + j - 1, "Applybox",
569  word_res->chopped_word, word_res->blamer_bundle);
570  if (applybox_debug > 2) {
571  tprintf("%d+%d:", i, j);
572  print_ratings_list("Segment:", match_result, unicharset);
573  }
574  choices[i].push_back(match_result);
575  }
576  }
577  // Search the segmentation graph for the target text. Must be an exact
578  // match. Using wildcards makes it difficult to find the correct
579  // segmentation even when it is there.
580  word_res->best_state.clear();
581  GenericVector<int> search_segmentation;
582  float best_rating = 0.0f;
583  SearchForText(choices, 0, word_length, target_text, 0, 0.0f,
584  &search_segmentation, &best_rating, &word_res->best_state);
585  for (int i = 0; i < word_length; ++i)
586  choices[i].delete_data_pointers();
587  delete [] choices;
588  if (word_res->best_state.empty()) {
589  // Build the original segmentation and if it is the same length as the
590  // truth, assume it will do.
591  int blob_count = 1;
592  for (int s = 0; s < word_res->seam_array.size(); ++s) {
593  SEAM* seam = word_res->seam_array[s];
594  if (!seam->HasAnySplits()) {
595  word_res->best_state.push_back(blob_count);
596  blob_count = 1;
597  } else {
598  ++blob_count;
599  }
600  }
601  word_res->best_state.push_back(blob_count);
602  if (word_res->best_state.size() != target_text.size()) {
603  word_res->best_state.clear(); // No good. Original segmentation bad size.
604  return false;
605  }
606  }
607  word_res->correct_text.clear();
608  for (int i = 0; i < target_text.size(); ++i) {
609  word_res->correct_text.push_back(
610  STRING(unicharset.id_to_unichar(target_text[i])));
611  }
612  return true;
613 }
GenericVector< SEAM * > seam_array
Definition: pageres.h:203
bool HasAnySplits() const
Definition: seam.h:67
Definition: strngs.h:44
Definition: seam.h:44
BlamerBundle * blamer_bundle
Definition: pageres.h:230
bool empty() const
Definition: genericvector.h:84
tesseract::BoxWord * box_word
Definition: pageres.h:250
GenericVector< int > best_state
Definition: pageres.h:255
#define tprintf(...)
Definition: tprintf.h:31
TWERD * chopped_word
Definition: pageres.h:201
int size() const
Definition: genericvector.h:72
const char * id_to_unichar(UNICHAR_ID id) const
Definition: unicharset.cpp:266
int length() const
Definition: boxword.h:85
UNICHARSET unicharset
Definition: ccutil.h:70
GenericVector< STRING > correct_text
Definition: pageres.h:259
int push_back(T object)
const int kMaxGroupSize
Definition: applybox.cpp:40
virtual BLOB_CHOICE_LIST * classify_piece(const GenericVector< SEAM * > &seams, inT16 start, inT16 end, const char *description, TWERD *word, BlamerBundle *blamer_bundle)
Definition: pieces.cpp:57
void SearchForText(const GenericVector< BLOB_CHOICE_LIST * > *choices, int choices_pos, int choices_length, const GenericVector< UNICHAR_ID > &target_text, int text_index, float rating, GenericVector< int > *segmentation, float *best_rating, GenericVector< int > *best_segmentation)
Definition: applybox.cpp:629
void print_ratings_list(const char *msg, BLOB_CHOICE_LIST *ratings, const UNICHARSET &current_unicharset)
Definition: ratngs.cpp:819
inT16 tesseract::Tesseract::first_alphanum_index ( const char *  word,
const char *  word_lengths 
)

Definition at line 469 of file reject.cpp.

470  {
471  inT16 i;
472  inT16 offset;
473 
474  for (i = 0, offset = 0; word[offset] != '\0'; offset += word_lengths[i++]) {
475  if (unicharset.get_isalpha(word + offset, word_lengths[i]) ||
476  unicharset.get_isdigit(word + offset, word_lengths[i]))
477  return i;
478  }
479  return -1;
480 }
bool get_isdigit(UNICHAR_ID unichar_id) const
Definition: unicharset.h:469
bool get_isalpha(UNICHAR_ID unichar_id) const
Definition: unicharset.h:448
short inT16
Definition: host.h:100
UNICHARSET unicharset
Definition: ccutil.h:70
inT16 tesseract::Tesseract::first_alphanum_offset ( const char *  word,
const char *  word_lengths 
)

Definition at line 482 of file reject.cpp.

483  {
484  inT16 i;
485  inT16 offset;
486 
487  for (i = 0, offset = 0; word[offset] != '\0'; offset += word_lengths[i++]) {
488  if (unicharset.get_isalpha(word + offset, word_lengths[i]) ||
489  unicharset.get_isdigit(word + offset, word_lengths[i]))
490  return offset;
491  }
492  return -1;
493 }
bool get_isdigit(UNICHAR_ID unichar_id) const
Definition: unicharset.h:469
bool get_isalpha(UNICHAR_ID unichar_id) const
Definition: unicharset.h:448
short inT16
Definition: host.h:100
UNICHARSET unicharset
Definition: ccutil.h:70
void tesseract::Tesseract::fix_fuzzy_space_list ( WERD_RES_LIST &  best_perm,
ROW row,
BLOCK block 
)

Definition at line 145 of file fixspace.cpp.

147  {
148  inT16 best_score;
149  WERD_RES_LIST current_perm;
150  inT16 current_score;
151  BOOL8 improved = FALSE;
152 
153  best_score = eval_word_spacing(best_perm); // default score
154  dump_words(best_perm, best_score, 1, improved);
155 
156  if (best_score != PERFECT_WERDS)
157  initialise_search(best_perm, current_perm);
158 
159  while ((best_score != PERFECT_WERDS) && !current_perm.empty()) {
160  match_current_words(current_perm, row, block);
161  current_score = eval_word_spacing(current_perm);
162  dump_words(current_perm, current_score, 2, improved);
163  if (current_score > best_score) {
164  best_perm.clear();
165  best_perm.deep_copy(&current_perm, &WERD_RES::deep_copy);
166  best_score = current_score;
167  improved = TRUE;
168  }
169  if (current_score < PERFECT_WERDS)
170  transform_to_next_perm(current_perm);
171  }
172  dump_words(best_perm, best_score, 3, improved);
173 }
#define TRUE
Definition: capi.h:45
#define FALSE
Definition: capi.h:46
void dump_words(WERD_RES_LIST &perm, inT16 score, inT16 mode, BOOL8 improved)
Definition: fixspace.cpp:449
short inT16
Definition: host.h:100
#define PERFECT_WERDS
Definition: fixspace.cpp:33
unsigned char BOOL8
Definition: host.h:113
void initialise_search(WERD_RES_LIST &src_list, WERD_RES_LIST &new_list)
Definition: fixspace.cpp:177
static WERD_RES * deep_copy(const WERD_RES *src)
Definition: pageres.h:633
void match_current_words(WERD_RES_LIST &words, ROW *row, BLOCK *block)
Definition: fixspace.cpp:196
inT16 eval_word_spacing(WERD_RES_LIST &word_res_list)
Definition: fixspace.cpp:239
void transform_to_next_perm(WERD_RES_LIST &words)
Definition: fixspace.cpp:372
void tesseract::Tesseract::fix_fuzzy_spaces ( ETEXT_DESC monitor,
inT32  word_count,
PAGE_RES page_res 
)

Definition at line 48 of file fixspace.cpp.

50  {
51  BLOCK_RES_IT block_res_it;
52  ROW_RES_IT row_res_it;
53  WERD_RES_IT word_res_it_from;
54  WERD_RES_IT word_res_it_to;
55  WERD_RES *word_res;
56  WERD_RES_LIST fuzzy_space_words;
57  inT16 new_length;
58  BOOL8 prevent_null_wd_fixsp; // DON'T process blobless wds
59  inT32 word_index; // current word
60 
61  block_res_it.set_to_list(&page_res->block_res_list);
62  word_index = 0;
63  for (block_res_it.mark_cycle_pt(); !block_res_it.cycled_list();
64  block_res_it.forward()) {
65  row_res_it.set_to_list(&block_res_it.data()->row_res_list);
66  for (row_res_it.mark_cycle_pt(); !row_res_it.cycled_list();
67  row_res_it.forward()) {
68  word_res_it_from.set_to_list(&row_res_it.data()->word_res_list);
69  while (!word_res_it_from.at_last()) {
70  word_res = word_res_it_from.data();
71  while (!word_res_it_from.at_last() &&
72  !(word_res->combination ||
73  word_res_it_from.data_relative(1)->word->flag(W_FUZZY_NON) ||
74  word_res_it_from.data_relative(1)->word->flag(W_FUZZY_SP))) {
75  fix_sp_fp_word(word_res_it_from, row_res_it.data()->row,
76  block_res_it.data()->block);
77  word_res = word_res_it_from.forward();
78  word_index++;
79  if (monitor != NULL) {
80  monitor->ocr_alive = TRUE;
81  monitor->progress = 90 + 5 * word_index / word_count;
82  if (monitor->deadline_exceeded() ||
83  (monitor->cancel != NULL &&
84  (*monitor->cancel)(monitor->cancel_this, stats_.dict_words)))
85  return;
86  }
87  }
88 
89  if (!word_res_it_from.at_last()) {
90  word_res_it_to = word_res_it_from;
91  prevent_null_wd_fixsp =
92  word_res->word->cblob_list()->empty();
93  if (check_debug_pt(word_res, 60))
94  debug_fix_space_level.set_value(10);
95  word_res_it_to.forward();
96  word_index++;
97  if (monitor != NULL) {
98  monitor->ocr_alive = TRUE;
99  monitor->progress = 90 + 5 * word_index / word_count;
100  if (monitor->deadline_exceeded() ||
101  (monitor->cancel != NULL &&
102  (*monitor->cancel)(monitor->cancel_this, stats_.dict_words)))
103  return;
104  }
105  while (!word_res_it_to.at_last () &&
106  (word_res_it_to.data_relative(1)->word->flag(W_FUZZY_NON) ||
107  word_res_it_to.data_relative(1)->word->flag(W_FUZZY_SP))) {
108  if (check_debug_pt(word_res, 60))
109  debug_fix_space_level.set_value(10);
110  if (word_res->word->cblob_list()->empty())
111  prevent_null_wd_fixsp = TRUE;
112  word_res = word_res_it_to.forward();
113  }
114  if (check_debug_pt(word_res, 60))
115  debug_fix_space_level.set_value(10);
116  if (word_res->word->cblob_list()->empty())
117  prevent_null_wd_fixsp = TRUE;
118  if (prevent_null_wd_fixsp) {
119  word_res_it_from = word_res_it_to;
120  } else {
121  fuzzy_space_words.assign_to_sublist(&word_res_it_from,
122  &word_res_it_to);
123  fix_fuzzy_space_list(fuzzy_space_words,
124  row_res_it.data()->row,
125  block_res_it.data()->block);
126  new_length = fuzzy_space_words.length();
127  word_res_it_from.add_list_before(&fuzzy_space_words);
128  for (;
129  !word_res_it_from.at_last() && new_length > 0;
130  new_length--) {
131  word_res_it_from.forward();
132  }
133  }
134  if (test_pt)
135  debug_fix_space_level.set_value(0);
136  }
137  fix_sp_fp_word(word_res_it_from, row_res_it.data()->row,
138  block_res_it.data()->block);
139  // Last word in row
140  }
141  }
142  }
143 }
void fix_sp_fp_word(WERD_RES_IT &word_res_it, ROW *row, BLOCK *block)
Definition: fixspace.cpp:535
void * cancel_this
called whenever progress increases
Definition: ocrclass.h:127
#define TRUE
Definition: capi.h:45
volatile inT8 ocr_alive
true if not last
Definition: ocrclass.h:123
bool deadline_exceeded() const
Definition: ocrclass.h:158
int inT32
Definition: host.h:102
BLOCK_RES_LIST block_res_list
Definition: pageres.h:62
inT16 progress
chars in this buffer(0)
Definition: ocrclass.h:118
BOOL8 check_debug_pt(WERD_RES *word, int location)
Definition: control.cpp:1772
BOOL8 combination
Definition: pageres.h:318
short inT16
Definition: host.h:100
CANCEL_FUNC cancel
for errcode use
Definition: ocrclass.h:125
void fix_fuzzy_space_list(WERD_RES_LIST &best_perm, ROW *row, BLOCK *block)
Definition: fixspace.cpp:145
unsigned char BOOL8
Definition: host.h:113
void tesseract::Tesseract::fix_noisy_space_list ( WERD_RES_LIST &  best_perm,
ROW row,
BLOCK block 
)

Definition at line 569 of file fixspace.cpp.

570  {
571  inT16 best_score;
572  WERD_RES_IT best_perm_it(&best_perm);
573  WERD_RES_LIST current_perm;
574  WERD_RES_IT current_perm_it(&current_perm);
575  WERD_RES *old_word_res;
576  inT16 current_score;
577  BOOL8 improved = FALSE;
578 
579  best_score = fp_eval_word_spacing(best_perm); // default score
580 
581  dump_words(best_perm, best_score, 1, improved);
582 
583  old_word_res = best_perm_it.data();
584  // Even deep_copy doesn't copy the underlying WERD unless its combination
585  // flag is true!.
586  old_word_res->combination = TRUE; // Kludge to force deep copy
587  current_perm_it.add_to_end(WERD_RES::deep_copy(old_word_res));
588  old_word_res->combination = FALSE; // Undo kludge
589 
590  break_noisiest_blob_word(current_perm);
591 
592  while (best_score != PERFECT_WERDS && !current_perm.empty()) {
593  match_current_words(current_perm, row, block);
594  current_score = fp_eval_word_spacing(current_perm);
595  dump_words(current_perm, current_score, 2, improved);
596  if (current_score > best_score) {
597  best_perm.clear();
598  best_perm.deep_copy(&current_perm, &WERD_RES::deep_copy);
599  best_score = current_score;
600  improved = TRUE;
601  }
602  if (current_score < PERFECT_WERDS) {
603  break_noisiest_blob_word(current_perm);
604  }
605  }
606  dump_words(best_perm, best_score, 3, improved);
607 }
#define TRUE
Definition: capi.h:45
inT16 fp_eval_word_spacing(WERD_RES_LIST &word_res_list)
Definition: fixspace.cpp:830
#define FALSE
Definition: capi.h:46
void break_noisiest_blob_word(WERD_RES_LIST &words)
Definition: fixspace.cpp:615
BOOL8 combination
Definition: pageres.h:318
void dump_words(WERD_RES_LIST &perm, inT16 score, inT16 mode, BOOL8 improved)
Definition: fixspace.cpp:449
short inT16
Definition: host.h:100
#define PERFECT_WERDS
Definition: fixspace.cpp:33
unsigned char BOOL8
Definition: host.h:113
static WERD_RES * deep_copy(const WERD_RES *src)
Definition: pageres.h:633
void match_current_words(WERD_RES_LIST &words, ROW *row, BLOCK *block)
Definition: fixspace.cpp:196
void tesseract::Tesseract::fix_rep_char ( PAGE_RES_IT page_res_it)

fix_rep_char() The word is a repeated char. (Leader.) Find the repeated char character. Create the appropriate single-word or multi-word sequence according to the size of spaces in between blobs, and correct the classifications where some of the characters disagree with the majority.

Definition at line 1629 of file control.cpp.

1629  {
1630  WERD_RES *word_res = page_res_it->word();
1631  const WERD_CHOICE &word = *(word_res->best_choice);
1632 
1633  // Find the frequency of each unique character in the word.
1634  SortHelper<UNICHAR_ID> rep_ch(word.length());
1635  for (int i = 0; i < word.length(); ++i) {
1636  rep_ch.Add(word.unichar_id(i), 1);
1637  }
1638 
1639  // Find the most frequent result.
1640  UNICHAR_ID maxch_id = INVALID_UNICHAR_ID; // most common char
1641  int max_count = rep_ch.MaxCount(&maxch_id);
1642  // Find the best exemplar of a classifier result for maxch_id.
1643  BLOB_CHOICE* best_choice = FindBestMatchingChoice(maxch_id, word_res);
1644  if (best_choice == NULL) {
1645  tprintf("Failed to find a choice for %s, occurring %d times\n",
1646  word_res->uch_set->debug_str(maxch_id).string(), max_count);
1647  return;
1648  }
1649  word_res->done = TRUE;
1650 
1651  // Measure the mean space.
1652  int gap_count = 0;
1653  WERD* werd = word_res->word;
1654  C_BLOB_IT blob_it(werd->cblob_list());
1655  C_BLOB* prev_blob = blob_it.data();
1656  for (blob_it.forward(); !blob_it.at_first(); blob_it.forward()) {
1657  C_BLOB* blob = blob_it.data();
1658  int gap = blob->bounding_box().left();
1659  gap -= prev_blob->bounding_box().right();
1660  ++gap_count;
1661  prev_blob = blob;
1662  }
1663  // Just correct existing classification.
1664  CorrectRepcharChoices(best_choice, word_res);
1665  word_res->reject_map.initialise(word.length());
1666 }
int UNICHAR_ID
Definition: unichar.h:33
#define TRUE
Definition: capi.h:45
TBOX bounding_box() const
Definition: stepblob.cpp:250
STRING debug_str(UNICHAR_ID id) const
Definition: unicharset.cpp:318
Definition: werd.h:60
UNICHAR_ID unichar_id(int index) const
Definition: ratngs.h:313
WERD * word
Definition: pageres.h:175
int length() const
Definition: ratngs.h:301
WERD_RES * word() const
Definition: pageres.h:736
#define tprintf(...)
Definition: tprintf.h:31
REJMAP reject_map
Definition: pageres.h:271
inT16 left() const
Definition: rect.h:68
void Add(T value, int count)
Definition: sorthelper.h:65
WERD_CHOICE * best_choice
Definition: pageres.h:219
const UNICHARSET * uch_set
Definition: pageres.h:192
BOOL8 done
Definition: pageres.h:282
const char * string() const
Definition: strngs.cpp:201
void initialise(inT16 length)
Definition: rejctmap.cpp:318
C_BLOB_LIST * cblob_list()
Definition: werd.h:100
void tesseract::Tesseract::fix_sp_fp_word ( WERD_RES_IT &  word_res_it,
ROW row,
BLOCK block 
)

Definition at line 535 of file fixspace.cpp.

536  {
537  WERD_RES *word_res;
538  WERD_RES_LIST sub_word_list;
539  WERD_RES_IT sub_word_list_it(&sub_word_list);
540  inT16 blob_index;
541  inT16 new_length;
542  float junk;
543 
544  word_res = word_res_it.data();
545  if (word_res->word->flag(W_REP_CHAR) ||
546  word_res->combination ||
547  word_res->part_of_combo ||
548  !word_res->word->flag(W_DONT_CHOP))
549  return;
550 
551  blob_index = worst_noise_blob(word_res, &junk);
552  if (blob_index < 0)
553  return;
554 
555  if (debug_fix_space_level > 1) {
556  tprintf("FP fixspace working on \"%s\"\n",
557  word_res->best_choice->unichar_string().string());
558  }
559  word_res->word->rej_cblob_list()->sort(c_blob_comparator);
560  sub_word_list_it.add_after_stay_put(word_res_it.extract());
561  fix_noisy_space_list(sub_word_list, row, block);
562  new_length = sub_word_list.length();
563  word_res_it.add_list_before(&sub_word_list);
564  for (; !word_res_it.at_last() && new_length > 1; new_length--) {
565  word_res_it.forward();
566  }
567 }
BOOL8 flag(WERD_FLAGS mask) const
Definition: werd.h:128
WERD * word
Definition: pageres.h:175
void fix_noisy_space_list(WERD_RES_LIST &best_perm, ROW *row, BLOCK *block)
Definition: fixspace.cpp:569
#define tprintf(...)
Definition: tprintf.h:31
const STRING & unichar_string() const
Definition: ratngs.h:525
BOOL8 combination
Definition: pageres.h:318
short inT16
Definition: host.h:100
BOOL8 part_of_combo
Definition: pageres.h:319
inT16 worst_noise_blob(WERD_RES *word_res, float *worst_noise_score)
Definition: fixspace.cpp:680
WERD_CHOICE * best_choice
Definition: pageres.h:219
const char * string() const
Definition: strngs.cpp:201
int c_blob_comparator(const void *blob1p, const void *blob2p)
Definition: genblob.cpp:30
C_BLOB_LIST * rej_cblob_list()
Definition: werd.h:95
BOOL8 tesseract::Tesseract::fixspace_thinks_word_done ( WERD_RES word)

Definition at line 503 of file fixspace.cpp.

503  {
504  if (word->done)
505  return TRUE;
506 
507  /*
508  Use all the standard pass 2 conditions for mode 5 in set_done() in
509  reject.c BUT DON'T REJECT IF THE WERD IS AMBIGUOUS - FOR SPACING WE DON'T
510  CARE WHETHER WE HAVE of/at on/an etc.
511  */
512  if (fixsp_done_mode > 0 &&
513  (word->tess_accepted ||
514  (fixsp_done_mode == 2 && word->reject_map.reject_count() == 0) ||
515  fixsp_done_mode == 3) &&
516  (strchr(word->best_choice->unichar_string().string(), ' ') == NULL) &&
517  ((word->best_choice->permuter() == SYSTEM_DAWG_PERM) ||
518  (word->best_choice->permuter() == FREQ_DAWG_PERM) ||
519  (word->best_choice->permuter() == USER_DAWG_PERM) ||
520  (word->best_choice->permuter() == NUMBER_PERM))) {
521  return TRUE;
522  } else {
523  return FALSE;
524  }
525 }
#define TRUE
Definition: capi.h:45
BOOL8 tess_accepted
Definition: pageres.h:280
REJMAP reject_map
Definition: pageres.h:271
#define FALSE
Definition: capi.h:46
const STRING & unichar_string() const
Definition: ratngs.h:525
uinT8 permuter() const
Definition: ratngs.h:344
WERD_CHOICE * best_choice
Definition: pageres.h:219
BOOL8 done
Definition: pageres.h:282
const char * string() const
Definition: strngs.cpp:201
inT16 reject_count()
Definition: rejctmap.h:242
void tesseract::Tesseract::flip_0O ( WERD_RES word)

Definition at line 673 of file reject.cpp.

673  {
674  WERD_CHOICE *best_choice = word_res->best_choice;
675  int i;
676  TBOX out_box;
677 
678  if (!tessedit_flip_0O)
679  return;
680 
681  int num_blobs = word_res->rebuild_word->NumBlobs();
682  for (i = 0; i < best_choice->length() && i < num_blobs; ++i) {
683  TBLOB* blob = word_res->rebuild_word->blobs[i];
684  if (word_res->uch_set->get_isupper(best_choice->unichar_id(i)) ||
685  word_res->uch_set->get_isdigit(best_choice->unichar_id(i))) {
686  out_box = blob->bounding_box();
687  if ((out_box.top() < kBlnBaselineOffset + kBlnXHeight) ||
688  (out_box.bottom() > kBlnBaselineOffset + kBlnXHeight / 4))
689  return; //Beware words with sub/superscripts
690  }
691  }
692  UNICHAR_ID unichar_0 = word_res->uch_set->unichar_to_id("0");
693  UNICHAR_ID unichar_O = word_res->uch_set->unichar_to_id("O");
694  if (unichar_0 == INVALID_UNICHAR_ID ||
695  !word_res->uch_set->get_enabled(unichar_0) ||
696  unichar_O == INVALID_UNICHAR_ID ||
697  !word_res->uch_set->get_enabled(unichar_O)) {
698  return; // 0 or O are not present/enabled in unicharset
699  }
700  for (i = 1; i < best_choice->length(); ++i) {
701  if (best_choice->unichar_id(i) == unichar_0 ||
702  best_choice->unichar_id(i) == unichar_O) {
703  /* A0A */
704  if ((i+1) < best_choice->length() &&
705  non_O_upper(*word_res->uch_set, best_choice->unichar_id(i-1)) &&
706  non_O_upper(*word_res->uch_set, best_choice->unichar_id(i+1))) {
707  best_choice->set_unichar_id(unichar_O, i);
708  }
709  /* A00A */
710  if (non_O_upper(*word_res->uch_set, best_choice->unichar_id(i-1)) &&
711  (i+1) < best_choice->length() &&
712  (best_choice->unichar_id(i+1) == unichar_0 ||
713  best_choice->unichar_id(i+1) == unichar_O) &&
714  (i+2) < best_choice->length() &&
715  non_O_upper(*word_res->uch_set, best_choice->unichar_id(i+2))) {
716  best_choice->set_unichar_id(unichar_O, i);
717  i++;
718  }
719  /* AA0<non digit or end of word> */
720  if ((i > 1) &&
721  non_O_upper(*word_res->uch_set, best_choice->unichar_id(i-2)) &&
722  non_O_upper(*word_res->uch_set, best_choice->unichar_id(i-1)) &&
723  (((i+1) < best_choice->length() &&
724  !word_res->uch_set->get_isdigit(best_choice->unichar_id(i+1)) &&
725  !word_res->uch_set->eq(best_choice->unichar_id(i+1), "l") &&
726  !word_res->uch_set->eq(best_choice->unichar_id(i+1), "I")) ||
727  (i == best_choice->length() - 1))) {
728  best_choice->set_unichar_id(unichar_O, i);
729  }
730  /* 9O9 */
731  if (non_0_digit(*word_res->uch_set, best_choice->unichar_id(i-1)) &&
732  (i+1) < best_choice->length() &&
733  non_0_digit(*word_res->uch_set, best_choice->unichar_id(i+1))) {
734  best_choice->set_unichar_id(unichar_0, i);
735  }
736  /* 9OOO */
737  if (non_0_digit(*word_res->uch_set, best_choice->unichar_id(i-1)) &&
738  (i+2) < best_choice->length() &&
739  (best_choice->unichar_id(i+1) == unichar_0 ||
740  best_choice->unichar_id(i+1) == unichar_O) &&
741  (best_choice->unichar_id(i+2) == unichar_0 ||
742  best_choice->unichar_id(i+2) == unichar_O)) {
743  best_choice->set_unichar_id(unichar_0, i);
744  best_choice->set_unichar_id(unichar_0, i+1);
745  best_choice->set_unichar_id(unichar_0, i+2);
746  i += 2;
747  }
748  /* 9OO<non upper> */
749  if (non_0_digit(*word_res->uch_set, best_choice->unichar_id(i-1)) &&
750  (i+2) < best_choice->length() &&
751  (best_choice->unichar_id(i+1) == unichar_0 ||
752  best_choice->unichar_id(i+1) == unichar_O) &&
753  !word_res->uch_set->get_isupper(best_choice->unichar_id(i+2))) {
754  best_choice->set_unichar_id(unichar_0, i);
755  best_choice->set_unichar_id(unichar_0, i+1);
756  i++;
757  }
758  /* 9O<non upper> */
759  if (non_0_digit(*word_res->uch_set, best_choice->unichar_id(i-1)) &&
760  (i+1) < best_choice->length() &&
761  !word_res->uch_set->get_isupper(best_choice->unichar_id(i+1))) {
762  best_choice->set_unichar_id(unichar_0, i);
763  }
764  /* 9[.,]OOO.. */
765  if ((i > 1) &&
766  (word_res->uch_set->eq(best_choice->unichar_id(i-1), ".") ||
767  word_res->uch_set->eq(best_choice->unichar_id(i-1), ",")) &&
768  (word_res->uch_set->get_isdigit(best_choice->unichar_id(i-2)) ||
769  best_choice->unichar_id(i-2) == unichar_O)) {
770  if (best_choice->unichar_id(i-2) == unichar_O) {
771  best_choice->set_unichar_id(unichar_0, i-2);
772  }
773  while (i < best_choice->length() &&
774  (best_choice->unichar_id(i) == unichar_O ||
775  best_choice->unichar_id(i) == unichar_0)) {
776  best_choice->set_unichar_id(unichar_0, i);
777  i++;
778  }
779  i--;
780  }
781  }
782  }
783 }
int UNICHAR_ID
Definition: unichar.h:33
inT16 bottom() const
Definition: rect.h:61
UNICHAR_ID unichar_id(int index) const
Definition: ratngs.h:313
TBOX bounding_box() const
Definition: blobs.cpp:482
int length() const
Definition: ratngs.h:301
Definition: rect.h:30
BOOL8 non_0_digit(const UNICHARSET &ch_set, UNICHAR_ID unichar_id)
Definition: reject.cpp:789
void set_unichar_id(UNICHAR_ID unichar_id, int index)
Definition: ratngs.h:357
BOOL8 non_O_upper(const UNICHARSET &ch_set, UNICHAR_ID unichar_id)
Definition: reject.cpp:785
const int kBlnXHeight
Definition: normalis.h:28
inT16 top() const
Definition: rect.h:54
const int kBlnBaselineOffset
Definition: normalis.h:29
Definition: blobs.h:261
void tesseract::Tesseract::flip_hyphens ( WERD_RES word)

Definition at line 616 of file reject.cpp.

616  {
617  WERD_CHOICE *best_choice = word_res->best_choice;
618  int i;
619  int prev_right = -9999;
620  int next_left;
621  TBOX out_box;
622  float aspect_ratio;
623 
625  return;
626 
627  int num_blobs = word_res->rebuild_word->NumBlobs();
628  UNICHAR_ID unichar_dash = word_res->uch_set->unichar_to_id("-");
629  for (i = 0; i < best_choice->length() && i < num_blobs; ++i) {
630  TBLOB* blob = word_res->rebuild_word->blobs[i];
631  out_box = blob->bounding_box();
632  if (i + 1 == num_blobs)
633  next_left = 9999;
634  else
635  next_left = word_res->rebuild_word->blobs[i + 1]->bounding_box().left();
636  // Don't touch small or touching blobs - it is too dangerous.
637  if ((out_box.width() > 8 * word_res->denorm.x_scale()) &&
638  (out_box.left() > prev_right) && (out_box.right() < next_left)) {
639  aspect_ratio = out_box.width() / (float) out_box.height();
640  if (word_res->uch_set->eq(best_choice->unichar_id(i), ".")) {
641  if (aspect_ratio >= tessedit_upper_flip_hyphen &&
642  word_res->uch_set->contains_unichar_id(unichar_dash) &&
643  word_res->uch_set->get_enabled(unichar_dash)) {
644  /* Certain HYPHEN */
645  best_choice->set_unichar_id(unichar_dash, i);
646  if (word_res->reject_map[i].rejected())
647  word_res->reject_map[i].setrej_hyphen_accept();
648  }
649  if ((aspect_ratio > tessedit_lower_flip_hyphen) &&
650  word_res->reject_map[i].accepted())
651  //Suspected HYPHEN
652  word_res->reject_map[i].setrej_hyphen ();
653  }
654  else if (best_choice->unichar_id(i) == unichar_dash) {
655  if ((aspect_ratio >= tessedit_upper_flip_hyphen) &&
656  (word_res->reject_map[i].rejected()))
657  word_res->reject_map[i].setrej_hyphen_accept();
658  //Certain HYPHEN
659 
660  if ((aspect_ratio <= tessedit_lower_flip_hyphen) &&
661  (word_res->reject_map[i].accepted()))
662  //Suspected HYPHEN
663  word_res->reject_map[i].setrej_hyphen();
664  }
665  }
666  prev_right = out_box.right();
667  }
668 }
int UNICHAR_ID
Definition: unichar.h:33
UNICHAR_ID unichar_id(int index) const
Definition: ratngs.h:313
TBOX bounding_box() const
Definition: blobs.cpp:482
int length() const
Definition: ratngs.h:301
inT16 height() const
Definition: rect.h:104
Definition: rect.h:30
inT16 right() const
Definition: rect.h:75
inT16 left() const
Definition: rect.h:68
void set_unichar_id(UNICHAR_ID unichar_id, int index)
Definition: ratngs.h:357
Definition: blobs.h:261
inT16 width() const
Definition: rect.h:111
void tesseract::Tesseract::font_recognition_pass ( PAGE_RES page_res)

font_recognition_pass

Smooth the fonts for the document.

Definition at line 1963 of file control.cpp.

1963  {
1964  PAGE_RES_IT page_res_it(page_res);
1965  WERD_RES *word; // current word
1966  STATS doc_fonts(0, font_table_size_); // font counters
1967 
1968  // Gather font id statistics.
1969  for (page_res_it.restart_page(); page_res_it.word() != NULL;
1970  page_res_it.forward()) {
1971  word = page_res_it.word();
1972  if (word->fontinfo != NULL) {
1973  doc_fonts.add(word->fontinfo->universal_id, word->fontinfo_id_count);
1974  }
1975  if (word->fontinfo2 != NULL) {
1976  doc_fonts.add(word->fontinfo2->universal_id, word->fontinfo_id2_count);
1977  }
1978  }
1979  inT16 doc_font; // modal font
1980  inT8 doc_font_count; // modal font
1981  find_modal_font(&doc_fonts, &doc_font, &doc_font_count);
1982  if (doc_font_count == 0)
1983  return;
1984  // Get the modal font pointer.
1985  const FontInfo* modal_font = NULL;
1986  for (page_res_it.restart_page(); page_res_it.word() != NULL;
1987  page_res_it.forward()) {
1988  word = page_res_it.word();
1989  if (word->fontinfo != NULL && word->fontinfo->universal_id == doc_font) {
1990  modal_font = word->fontinfo;
1991  break;
1992  }
1993  if (word->fontinfo2 != NULL && word->fontinfo2->universal_id == doc_font) {
1994  modal_font = word->fontinfo2;
1995  break;
1996  }
1997  }
1998  ASSERT_HOST(modal_font != NULL);
1999 
2000  // Assign modal font to weak words.
2001  for (page_res_it.restart_page(); page_res_it.word() != NULL;
2002  page_res_it.forward()) {
2003  word = page_res_it.word();
2004  int length = word->best_choice->length();
2005 
2006  int count = word->fontinfo_id_count;
2007  if (!(count == length || (length > 3 && count >= length * 3 / 4))) {
2008  word->fontinfo = modal_font;
2009  // Counts only get 1 as it came from the doc.
2010  word->fontinfo_id_count = 1;
2011  word->italic = modal_font->is_italic() ? 1 : -1;
2012  word->bold = modal_font->is_bold() ? 1 : -1;
2013  }
2014  }
2015 }
bool is_italic() const
Definition: fontinfo.h:111
int count(LIST var_list)
Definition: oldlist.cpp:108
inT8 fontinfo_id2_count
Definition: pageres.h:291
SIGNED char inT8
Definition: host.h:98
inT8 italic
Definition: pageres.h:285
const FontInfo * fontinfo
Definition: pageres.h:288
WERD * word
Definition: pageres.h:175
int length() const
Definition: ratngs.h:301
short inT16
Definition: host.h:100
Definition: statistc.h:33
const FontInfo * fontinfo2
Definition: pageres.h:289
WERD_CHOICE * best_choice
Definition: pageres.h:219
#define ASSERT_HOST(x)
Definition: errcode.h:84
inT8 bold
Definition: pageres.h:286
bool is_bold() const
Definition: fontinfo.h:112
inT8 fontinfo_id_count
Definition: pageres.h:290
inT16 tesseract::Tesseract::fp_eval_word_spacing ( WERD_RES_LIST &  word_res_list)

Definition at line 830 of file fixspace.cpp.

830  {
831  WERD_RES_IT word_it(&word_res_list);
832  WERD_RES *word;
833  inT16 score = 0;
834  inT16 i;
835  float small_limit = kBlnXHeight * fixsp_small_outlines_size;
836 
837  for (word_it.mark_cycle_pt(); !word_it.cycled_list(); word_it.forward()) {
838  word = word_it.data();
839  if (word->rebuild_word == NULL)
840  continue; // Can't handle cube words.
841  if (word->done ||
842  word->tess_accepted ||
843  word->best_choice->permuter() == SYSTEM_DAWG_PERM ||
844  word->best_choice->permuter() == FREQ_DAWG_PERM ||
845  word->best_choice->permuter() == USER_DAWG_PERM ||
846  safe_dict_word(word) > 0) {
847  int num_blobs = word->rebuild_word->NumBlobs();
848  UNICHAR_ID space = word->uch_set->unichar_to_id(" ");
849  for (i = 0; i < word->best_choice->length() && i < num_blobs; ++i) {
850  TBLOB* blob = word->rebuild_word->blobs[i];
851  if (word->best_choice->unichar_id(i) == space ||
852  blob_noise_score(blob) < small_limit) {
853  score -= 1; // penalise possibly erroneous non-space
854  } else if (word->reject_map[i].accepted()) {
855  score++;
856  }
857  }
858  }
859  }
860  if (score < 0)
861  score = 0;
862  return score;
863 }
int UNICHAR_ID
Definition: unichar.h:33
int NumBlobs() const
Definition: blobs.h:425
BOOL8 tess_accepted
Definition: pageres.h:280
GenericVector< TBLOB * > blobs
Definition: blobs.h:436
UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:194
UNICHAR_ID unichar_id(int index) const
Definition: ratngs.h:313
int length() const
Definition: ratngs.h:301
float blob_noise_score(TBLOB *blob)
Definition: fixspace.cpp:760
REJMAP reject_map
Definition: pageres.h:271
short inT16
Definition: host.h:100
uinT8 permuter() const
Definition: ratngs.h:344
WERD_CHOICE * best_choice
Definition: pageres.h:219
const UNICHARSET * uch_set
Definition: pageres.h:192
const int kBlnXHeight
Definition: normalis.h:28
BOOL8 done
Definition: pageres.h:282
inT16 safe_dict_word(const WERD_RES *werd_res)
Definition: reject.cpp:607
Definition: blobs.h:261
TWERD * rebuild_word
Definition: pageres.h:244
GARBAGE_LEVEL tesseract::Tesseract::garbage_word ( WERD_RES word,
BOOL8  ok_dict_word 
)

Definition at line 684 of file docqual.cpp.

684  {
685  enum STATES
686  {
687  JUNK,
688  FIRST_UPPER,
689  FIRST_LOWER,
690  FIRST_NUM,
691  SUBSEQUENT_UPPER,
692  SUBSEQUENT_LOWER,
693  SUBSEQUENT_NUM
694  };
695  const char *str = word->best_choice->unichar_string().string();
696  const char *lengths = word->best_choice->unichar_lengths().string();
697  STATES state = JUNK;
698  int len = 0;
699  int isolated_digits = 0;
700  int isolated_alphas = 0;
701  int bad_char_count = 0;
702  int tess_rejs = 0;
703  int dodgy_chars = 0;
704  int ok_chars;
705  UNICHAR_ID last_char = -1;
706  int alpha_repetition_count = 0;
707  int longest_alpha_repetition_count = 0;
708  int longest_lower_run_len = 0;
709  int lower_string_count = 0;
710  int longest_upper_run_len = 0;
711  int upper_string_count = 0;
712  int total_alpha_count = 0;
713  int total_digit_count = 0;
714 
715  for (; *str != '\0'; str += *(lengths++)) {
716  len++;
717  if (word->uch_set->get_isupper (str, *lengths)) {
718  total_alpha_count++;
719  switch (state) {
720  case SUBSEQUENT_UPPER:
721  case FIRST_UPPER:
722  state = SUBSEQUENT_UPPER;
723  upper_string_count++;
724  if (longest_upper_run_len < upper_string_count)
725  longest_upper_run_len = upper_string_count;
726  if (last_char == word->uch_set->unichar_to_id(str, *lengths)) {
727  alpha_repetition_count++;
728  if (longest_alpha_repetition_count < alpha_repetition_count) {
729  longest_alpha_repetition_count = alpha_repetition_count;
730  }
731  }
732  else {
733  last_char = word->uch_set->unichar_to_id(str, *lengths);
734  alpha_repetition_count = 1;
735  }
736  break;
737  case FIRST_NUM:
738  isolated_digits++;
739  default:
740  state = FIRST_UPPER;
741  last_char = word->uch_set->unichar_to_id(str, *lengths);
742  alpha_repetition_count = 1;
743  upper_string_count = 1;
744  break;
745  }
746  }
747  else if (word->uch_set->get_islower (str, *lengths)) {
748  total_alpha_count++;
749  switch (state) {
750  case SUBSEQUENT_LOWER:
751  case FIRST_LOWER:
752  state = SUBSEQUENT_LOWER;
753  lower_string_count++;
754  if (longest_lower_run_len < lower_string_count)
755  longest_lower_run_len = lower_string_count;
756  if (last_char == word->uch_set->unichar_to_id(str, *lengths)) {
757  alpha_repetition_count++;
758  if (longest_alpha_repetition_count < alpha_repetition_count) {
759  longest_alpha_repetition_count = alpha_repetition_count;
760  }
761  }
762  else {
763  last_char = word->uch_set->unichar_to_id(str, *lengths);
764  alpha_repetition_count = 1;
765  }
766  break;
767  case FIRST_NUM:
768  isolated_digits++;
769  default:
770  state = FIRST_LOWER;
771  last_char = word->uch_set->unichar_to_id(str, *lengths);
772  alpha_repetition_count = 1;
773  lower_string_count = 1;
774  break;
775  }
776  }
777  else if (word->uch_set->get_isdigit (str, *lengths)) {
778  total_digit_count++;
779  switch (state) {
780  case FIRST_NUM:
781  state = SUBSEQUENT_NUM;
782  case SUBSEQUENT_NUM:
783  break;
784  case FIRST_UPPER:
785  case FIRST_LOWER:
786  isolated_alphas++;
787  default:
788  state = FIRST_NUM;
789  break;
790  }
791  }
792  else {
793  if (*lengths == 1 && *str == ' ')
794  tess_rejs++;
795  else
796  bad_char_count++;
797  switch (state) {
798  case FIRST_NUM:
799  isolated_digits++;
800  break;
801  case FIRST_UPPER:
802  case FIRST_LOWER:
803  isolated_alphas++;
804  default:
805  break;
806  }
807  state = JUNK;
808  }
809  }
810 
811  switch (state) {
812  case FIRST_NUM:
813  isolated_digits++;
814  break;
815  case FIRST_UPPER:
816  case FIRST_LOWER:
817  isolated_alphas++;
818  default:
819  break;
820  }
821 
823  total_alpha_count += total_digit_count - isolated_digits;
824  }
825 
826  if (crunch_leave_ok_strings && len >= 4 &&
827  2 * (total_alpha_count - isolated_alphas) > len &&
828  longest_alpha_repetition_count < crunch_long_repetitions) {
829  if ((crunch_accept_ok &&
830  acceptable_word_string(*word->uch_set, str, lengths) !=
831  AC_UNACCEPTABLE) ||
832  longest_lower_run_len > crunch_leave_lc_strings ||
833  longest_upper_run_len > crunch_leave_uc_strings)
834  return G_NEVER_CRUNCH;
835  }
836  if (word->reject_map.length() > 1 &&
837  strpbrk(str, " ") == NULL &&
838  (word->best_choice->permuter() == SYSTEM_DAWG_PERM ||
839  word->best_choice->permuter() == FREQ_DAWG_PERM ||
840  word->best_choice->permuter() == USER_DAWG_PERM ||
841  word->best_choice->permuter() == NUMBER_PERM ||
842  acceptable_word_string(*word->uch_set, str, lengths) !=
843  AC_UNACCEPTABLE || ok_dict_word))
844  return G_OK;
845 
846  ok_chars = len - bad_char_count - isolated_digits -
847  isolated_alphas - tess_rejs;
848 
849  if (crunch_debug > 3) {
850  tprintf("garbage_word: \"%s\"\n",
851  word->best_choice->unichar_string().string());
852  tprintf("LEN: %d bad: %d iso_N: %d iso_A: %d rej: %d\n",
853  len,
854  bad_char_count, isolated_digits, isolated_alphas, tess_rejs);
855  }
856  if (bad_char_count == 0 &&
857  tess_rejs == 0 &&
858  (len > isolated_digits + isolated_alphas || len <= 2))
859  return G_OK;
860 
861  if (tess_rejs > ok_chars ||
862  (tess_rejs > 0 && (bad_char_count + tess_rejs) * 2 > len))
863  return G_TERRIBLE;
864 
865  if (len > 4) {
866  dodgy_chars = 2 * tess_rejs + bad_char_count + isolated_digits +
867  isolated_alphas;
868  if (dodgy_chars > 5 || (dodgy_chars / (float) len) > 0.5)
869  return G_DODGY;
870  else
871  return G_OK;
872  } else {
873  dodgy_chars = 2 * tess_rejs + bad_char_count;
874  if ((len == 4 && dodgy_chars > 2) ||
875  (len == 3 && dodgy_chars > 2) || dodgy_chars >= len)
876  return G_DODGY;
877  else
878  return G_OK;
879  }
880 }
int UNICHAR_ID
Definition: unichar.h:33
bool get_isupper(UNICHAR_ID unichar_id) const
Definition: unicharset.h:462
UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:194
const STRING & unichar_lengths() const
Definition: ratngs.h:532
#define tprintf(...)
Definition: tprintf.h:31
bool get_isdigit(UNICHAR_ID unichar_id) const
Definition: unicharset.h:469
REJMAP reject_map
Definition: pageres.h:271
const STRING & unichar_string() const
Definition: ratngs.h:525
Unacceptable word.
Definition: control.h:36
bool get_islower(UNICHAR_ID unichar_id) const
Definition: unicharset.h:455
inT32 length() const
Definition: rejctmap.h:236
uinT8 permuter() const
Definition: ratngs.h:344
WERD_CHOICE * best_choice
Definition: pageres.h:219
const UNICHARSET * uch_set
Definition: pageres.h:192
const char * string() const
Definition: strngs.cpp:201
ACCEPTABLE_WERD_TYPE acceptable_word_string(const UNICHARSET &char_set, const char *s, const char *lengths)
Definition: control.cpp:1668
Definition: docqual.h:28
UNICHAR_ID tesseract::Tesseract::get_rep_char ( WERD_RES word)

Definition at line 283 of file output.cpp.

283  { // what char is repeated?
284  int i;
285  for (i = 0; ((i < word->reject_map.length()) &&
286  (word->reject_map[i].rejected())); ++i);
287 
288  if (i < word->reject_map.length()) {
289  return word->best_choice->unichar_id(i);
290  } else {
291  return word->uch_set->unichar_to_id(unrecognised_char.string());
292  }
293 }
UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:194
UNICHAR_ID unichar_id(int index) const
Definition: ratngs.h:313
REJMAP reject_map
Definition: pageres.h:271
inT32 length() const
Definition: rejctmap.h:236
WERD_CHOICE * best_choice
Definition: pageres.h:219
const UNICHARSET * uch_set
Definition: pageres.h:192
Tesseract* tesseract::Tesseract::get_sub_lang ( int  index) const
inline

Definition at line 258 of file tesseractclass.h.

258  {
259  return sub_langs_[index];
260  }
CubeRecoContext* tesseract::Tesseract::GetCubeRecoContext ( )
inline

Definition at line 1164 of file tesseractclass.h.

1164 { return cube_cntxt_; }
void tesseract::Tesseract::GetSubAndSuperscriptCandidates ( const WERD_RES word,
int *  num_rebuilt_leading,
ScriptPos leading_pos,
float *  leading_certainty,
int *  num_rebuilt_trailing,
ScriptPos trailing_pos,
float *  trailing_certainty,
float *  avg_certainty,
float *  unlikely_threshold 
)

Determine how many characters (rebuilt blobs) on each end of a given word might plausibly be superscripts so SubAndSuperscriptFix can try to re-recognize them. Even if we find no whole blobs at either end, we will set *unlikely_threshold to a certainty that might be used to select "bad enough" outlier characters. If *unlikely_threshold is set to 0, though, there's really no hope.

Parameters
[in]wordThe word to examine.
[out]num_rebuilt_leadingthe number of rebuilt blobs at the start of the word which are all up or down and seem badly classified.
[out]leading_pos"super" or "sub" (for debugging)
[out]leading_certaintythe worst certainty in the leading blobs.
[out]num_rebuilt_trailingthe number of rebuilt blobs at the end of the word which are all up or down and seem badly classified.
[out]trailing_pos"super" or "sub" (for debugging)
[out]trailing_certaintythe worst certainty in the trailing blobs.
[out]avg_certaintythe average certainty of "normal" blobs in the word.
[out]unlikely_thresholdthe threshold (on certainty) we used to select "bad enough" outlier characters.

Definition at line 253 of file superscript.cpp.

261  {
262  *avg_certainty = *unlikely_threshold = 0.0f;
263  *num_rebuilt_leading = *num_rebuilt_trailing = 0;
264  *leading_certainty = *trailing_certainty = 0.0f;
265 
266  int super_y_bottom =
268  int sub_y_top =
270 
271  // Step one: Get an average certainty for "normally placed" characters.
272 
273  // Counts here are of blobs in the rebuild_word / unichars in best_choice.
274  *leading_pos = *trailing_pos = SP_NORMAL;
275  int leading_outliers = 0;
276  int trailing_outliers = 0;
277  int num_normal = 0;
278  float normal_certainty_total = 0.0f;
279  float worst_normal_certainty = 0.0f;
280  ScriptPos last_pos = SP_NORMAL;
281  int num_blobs = word->rebuild_word->NumBlobs();
282  for (int b = 0; b < num_blobs; ++b) {
283  TBOX box = word->rebuild_word->blobs[b]->bounding_box();
284  ScriptPos pos = SP_NORMAL;
285  if (box.bottom() >= super_y_bottom) {
286  pos = SP_SUPERSCRIPT;
287  } else if (box.top() <= sub_y_top) {
288  pos = SP_SUBSCRIPT;
289  }
290  if (pos == SP_NORMAL) {
291  if (word->best_choice->unichar_id(b) != 0) {
292  float char_certainty = word->best_choice->certainty(b);
293  if (char_certainty < worst_normal_certainty) {
294  worst_normal_certainty = char_certainty;
295  }
296  num_normal++;
297  normal_certainty_total += char_certainty;
298  }
299  if (trailing_outliers == b) {
300  leading_outliers = trailing_outliers;
301  *leading_pos = last_pos;
302  }
303  trailing_outliers = 0;
304  } else {
305  if (last_pos == pos) {
306  trailing_outliers++;
307  } else {
308  trailing_outliers = 1;
309  }
310  }
311  last_pos = pos;
312  }
313  *trailing_pos = last_pos;
314  if (num_normal >= 3) { // throw out the worst as an outlier.
315  num_normal--;
316  normal_certainty_total -= worst_normal_certainty;
317  }
318  if (num_normal > 0) {
319  *avg_certainty = normal_certainty_total / num_normal;
320  *unlikely_threshold = superscript_worse_certainty * (*avg_certainty);
321  }
322  if (num_normal == 0 ||
323  (leading_outliers == 0 && trailing_outliers == 0)) {
324  return;
325  }
326 
327  // Step two: Try to split off bits of the word that are both outliers
328  // and have much lower certainty than average
329  // Calculate num_leading and leading_certainty.
330  for (*leading_certainty = 0.0f, *num_rebuilt_leading = 0;
331  *num_rebuilt_leading < leading_outliers;
332  (*num_rebuilt_leading)++) {
333  float char_certainty = word->best_choice->certainty(*num_rebuilt_leading);
334  if (char_certainty > *unlikely_threshold) {
335  break;
336  }
337  if (char_certainty < *leading_certainty) {
338  *leading_certainty = char_certainty;
339  }
340  }
341 
342  // Calculate num_trailing and trailing_certainty.
343  for (*trailing_certainty = 0.0f, *num_rebuilt_trailing = 0;
344  *num_rebuilt_trailing < trailing_outliers;
345  (*num_rebuilt_trailing)++) {
346  int blob_idx = num_blobs - 1 - *num_rebuilt_trailing;
347  float char_certainty = word->best_choice->certainty(blob_idx);
348  if (char_certainty > *unlikely_threshold) {
349  break;
350  }
351  if (char_certainty < *trailing_certainty) {
352  *trailing_certainty = char_certainty;
353  }
354  }
355 }
inT16 bottom() const
Definition: rect.h:61
int NumBlobs() const
Definition: blobs.h:425
GenericVector< TBLOB * > blobs
Definition: blobs.h:436
UNICHAR_ID unichar_id(int index) const
Definition: ratngs.h:313
Definition: rect.h:30
double superscript_worse_certainty
WERD_CHOICE * best_choice
Definition: pageres.h:219
const int kBlnXHeight
Definition: normalis.h:28
inT16 top() const
Definition: rect.h:54
const int kBlnBaselineOffset
Definition: normalis.h:29
float certainty() const
Definition: ratngs.h:328
TWERD * rebuild_word
Definition: pageres.h:244
int tesseract::Tesseract::ImageHeight ( ) const
inline

Definition at line 232 of file tesseractclass.h.

232  {
233  return pixGetHeight(pix_binary_);
234  }
int tesseract::Tesseract::ImageWidth ( ) const
inline

Definition at line 229 of file tesseractclass.h.

229  {
230  return pixGetWidth(pix_binary_);
231  }
bool tesseract::Tesseract::init_cube_objects ( bool  load_combiner,
TessdataManager tessdata_manager 
)

Definition at line 164 of file cube_control.cpp.

165  {
166  ASSERT_HOST(cube_cntxt_ == NULL);
167  ASSERT_HOST(tess_cube_combiner_ == NULL);
168 
169  // Create the cube context object
170  cube_cntxt_ = CubeRecoContext::Create(this, tessdata_manager, &unicharset);
171  if (cube_cntxt_ == NULL) {
172  if (cube_debug_level > 0) {
173  tprintf("Cube WARNING (Tesseract::init_cube_objects()): Failed to "
174  "instantiate CubeRecoContext\n");
175  }
176  return false;
177  }
178 
179  // Create the combiner object and load the combiner net for target languages.
180  if (load_combiner) {
181  tess_cube_combiner_ = new tesseract::TesseractCubeCombiner(cube_cntxt_);
182  if (!tess_cube_combiner_->LoadCombinerNet()) {
183  delete cube_cntxt_;
184  cube_cntxt_ = NULL;
185  delete tess_cube_combiner_;
186  tess_cube_combiner_ = NULL;
187  if (cube_debug_level > 0)
188  tprintf("Cube ERROR (Failed to instantiate TesseractCubeCombiner\n");
189  return false;
190  }
191  }
192  return true;
193 }
TessdataManager tessdata_manager
Definition: ccutil.h:69
#define tprintf(...)
Definition: tprintf.h:31
UNICHARSET unicharset
Definition: ccutil.h:70
#define ASSERT_HOST(x)
Definition: errcode.h:84
static CubeRecoContext * Create(Tesseract *tess_obj, TessdataManager *tessdata_manager, UNICHARSET *tess_unicharset)
FILE * tesseract::Tesseract::init_recog_training ( const STRING fname)

Definition at line 36 of file recogtraining.cpp.

36  {
38  tessedit_tess_adaption_mode.set_value(0); // turn off adaption
39  tessedit_enable_doc_dict.set_value(0); // turn off document dictionary
40  // Explore all segmentations.
42  }
43 
44  STRING output_fname = fname;
45  const char *lastdot = strrchr(output_fname.string(), '.');
46  if (lastdot != NULL) output_fname[lastdot - output_fname.string()] = '\0';
47  output_fname += ".txt";
48  FILE *output_file = open_file(output_fname.string(), "a+");
49  return output_file;
50 }
Definition: strngs.h:44
bool stopper_no_acceptable_choices
Definition: dict.h:623
Dict & getDict()
Definition: classify.h:65
FILE * open_file(const char *filename, const char *mode)
Definition: cutil.cpp:82
const char * string() const
Definition: strngs.cpp:201
int tesseract::Tesseract::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 
)

Definition at line 290 of file tessedit.cpp.

295  {
296  GenericVector<STRING> langs_to_load;
297  GenericVector<STRING> langs_not_to_load;
298  ParseLanguageString(language, &langs_to_load, &langs_not_to_load);
299 
300  sub_langs_.delete_data_pointers();
301  sub_langs_.clear();
302  // Find the first loadable lang and load into this.
303  // Add any languages that this language requires
304  bool loaded_primary = false;
305  // Load the rest into sub_langs_.
306  for (int lang_index = 0; lang_index < langs_to_load.size(); ++lang_index) {
307  if (!IsStrInList(langs_to_load[lang_index], langs_not_to_load)) {
308  const char *lang_str = langs_to_load[lang_index].string();
309  Tesseract *tess_to_init;
310  if (!loaded_primary) {
311  tess_to_init = this;
312  } else {
313  tess_to_init = new Tesseract;
314  }
315 
316  int result = tess_to_init->init_tesseract_internal(
317  arg0, textbase, lang_str, oem, configs, configs_size,
318  vars_vec, vars_values, set_only_non_debug_params);
319 
320  if (!loaded_primary) {
321  if (result < 0) {
322  tprintf("Failed loading language '%s'\n", lang_str);
323  } else {
325  tprintf("Loaded language '%s' as main language\n", lang_str);
326  ParseLanguageString(tess_to_init->tessedit_load_sublangs.string(),
327  &langs_to_load, &langs_not_to_load);
328  loaded_primary = true;
329  }
330  } else {
331  if (result < 0) {
332  tprintf("Failed loading language '%s'\n", lang_str);
333  delete tess_to_init;
334  } else {
336  tprintf("Loaded language '%s' as secondary language\n", lang_str);
337  sub_langs_.push_back(tess_to_init);
338  // Add any languages that this language requires
339  ParseLanguageString(tess_to_init->tessedit_load_sublangs.string(),
340  &langs_to_load, &langs_not_to_load);
341  }
342  }
343  }
344  }
345  if (!loaded_primary) {
346  tprintf("Tesseract couldn't load any languages!\n");
347  return -1; // Couldn't load any language!
348  }
349  if (!sub_langs_.empty()) {
350  // In multilingual mode word ratings have to be directly comparable,
351  // so use the same language model weights for all languages:
352  // use the primary language's params model if
353  // tessedit_use_primary_params_model is set,
354  // otherwise use default language model weights.
356  for (int s = 0; s < sub_langs_.size(); ++s) {
357  sub_langs_[s]->language_model_->getParamsModel().Copy(
359  }
360  tprintf("Using params model of the primary language\n");
363  }
364  } else {
366  for (int s = 0; s < sub_langs_.size(); ++s) {
367  sub_langs_[s]->language_model_->getParamsModel().Clear();
368  }
370  tprintf("Using default language params\n");
371  }
372  }
373 
375  return 0;
376 }
#define tprintf(...)
Definition: tprintf.h:31
int size() const
Definition: genericvector.h:72
void SetupUniversalFontIds()
Definition: tessedit.cpp:444
ParamsModel & getParamsModel()
void ParseLanguageString(const char *lang_str, GenericVector< STRING > *to_load, GenericVector< STRING > *not_to_load)
Definition: tessedit.cpp:254
LanguageModel * language_model_
Definition: wordrec.h:411
int tesseract::Tesseract::init_tesseract ( const char *  datapath,
const char *  language,
OcrEngineMode  oem 
)
inline

Definition at line 491 of file tesseractclass.h.

493  {
494  return init_tesseract(datapath, NULL, language, oem,
495  NULL, 0, NULL, NULL, false);
496  }
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)
Definition: tessedit.cpp:290
int tesseract::Tesseract::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 
)

Definition at line 394 of file tessedit.cpp.

399  {
400  if (!init_tesseract_lang_data(arg0, textbase, language, oem, configs,
401  configs_size, vars_vec, vars_values,
402  set_only_non_debug_params)) {
403  return -1;
404  }
407  return 0;
408  }
409  // If only Cube will be used, skip loading Tesseract classifier's
410  // pre-trained templates.
411  bool init_tesseract_classifier =
414  // If only Cube will be used and if it has its own Unicharset,
415  // skip initializing permuter and loading Tesseract Dawgs.
416  bool init_dict =
419  program_editup(textbase, init_tesseract_classifier, init_dict);
421  return 0; //Normal exit
422 }
TessdataManager tessdata_manager
Definition: ccutil.h:69
void program_editup(const char *textbase, bool init_classifier, bool init_permute)
Definition: tface.cpp:46
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)
Definition: tessedit.cpp:88
bool SeekToStart(TessdataType tessdata_type)
bool tesseract::Tesseract::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 
)

Definition at line 88 of file tessedit.cpp.

93  {
94  // Set the basename, compute the data directory.
95  main_setup(arg0, textbase);
96 
97  // Set the language data path prefix
98  lang = language != NULL ? language : "eng";
102 
103  // Initialize TessdataManager.
104  STRING tessdata_path = language_data_path_prefix + kTrainedDataSuffix;
105  if (!tessdata_manager.Init(tessdata_path.string(),
107  return false;
108  }
109 
110  // If a language specific config file (lang.config) exists, load it in.
117  tprintf("Loaded language config file\n");
118  }
119  }
120 
121  SetParamConstraint set_params_constraint = set_only_non_debug_params ?
123  // Load tesseract variables from config files. This is done after loading
124  // language-specific variables from [lang].traineddata file, so that custom
125  // config files can override values in [lang].traineddata file.
126  for (int i = 0; i < configs_size; ++i) {
127  read_config_file(configs[i], set_params_constraint);
128  }
129 
130  // Set params specified in vars_vec (done after setting params from config
131  // files, so that params in vars_vec can override those from files).
132  if (vars_vec != NULL && vars_values != NULL) {
133  for (int i = 0; i < vars_vec->size(); ++i) {
134  if (!ParamUtils::SetParam((*vars_vec)[i].string(),
135  (*vars_values)[i].string(),
136  set_params_constraint, this->params())) {
137  tprintf("Error setting param %s\n", (*vars_vec)[i].string());
138  exit(1);
139  }
140  }
141  }
142 
143  if (((STRING &)tessedit_write_params_to_file).length() > 0) {
144  FILE *params_file = fopen(tessedit_write_params_to_file.string(), "wb");
145  if (params_file != NULL) {
146  ParamUtils::PrintParams(params_file, this->params());
147  fclose(params_file);
149  tprintf("Wrote parameters to %s\n",
150  tessedit_write_params_to_file.string());
151  }
152  } else {
153  tprintf("Failed to open %s for writing params.\n",
154  tessedit_write_params_to_file.string());
155  }
156  }
157 
158  // Determine which ocr engine(s) should be loaded and used for recognition.
159  if (oem != OEM_DEFAULT) tessedit_ocr_engine_mode.set_value(oem);
161  tprintf("Loading Tesseract/Cube with tessedit_ocr_engine_mode %d\n",
162  static_cast<int>(tessedit_ocr_engine_mode));
163  }
164 
165  // If we are only loading the config file (and so not planning on doing any
166  // recognition) then there's nothing else do here.
169  tprintf("Returning after loading config file\n");
170  }
171  return true;
172  }
173 
174  // Load the unicharset
177  return false;
178  }
179  if (unicharset.size() > MAX_NUM_CLASSES) {
180  tprintf("Error: Size of unicharset is greater than MAX_NUM_CLASSES\n");
181  return false;
182  }
183  if (tessdata_manager_debug_level) tprintf("Loaded unicharset\n");
184  right_to_left_ = unicharset.major_right_to_left();
185 
186  // Setup initial unichar ambigs table and read universal ambigs.
187  UNICHARSET encoder_unicharset;
188  encoder_unicharset.CopyFrom(unicharset);
190  unichar_ambigs.LoadUniversal(encoder_unicharset, &unicharset);
191 
194  TFile ambigs_file;
195  ambigs_file.Open(tessdata_manager.GetDataFilePtr(),
198  encoder_unicharset,
199  &ambigs_file,
201  if (tessdata_manager_debug_level) tprintf("Loaded ambigs\n");
202  }
203 
204  // The various OcrEngineMode settings (see publictypes.h) determine which
205  // engine-specific data files need to be loaded. Currently everything needs
206  // the base tesseract data, which supplies other useful information, but
207  // alternative engines, such as cube and LSTM are optional.
208 #ifndef NO_CUBE_BUILD
212  tprintf("Loaded Cube w/out combiner\n");
216  tprintf("Loaded Cube with combiner\n");
217  }
218 #endif
219  // Init ParamsModel.
220  // Load pass1 and pass2 weights (for now these two sets are the same, but in
221  // the future separate sets of weights can be generated).
222  for (int p = ParamsModel::PTRAIN_PASS1;
225  static_cast<ParamsModel::PassEnum>(p));
230  return false;
231  }
232  }
233  }
235 
236  return true;
237 }
static bool ReadParamsFromFp(FILE *fp, inT64 end_offset, SetParamConstraint constraint, ParamsVectors *member_params)
Definition: params.cpp:65
STRING language_data_path_prefix
Definition: ccutil.h:68
void LoadUnicharAmbigs(const UNICHARSET &encoder_set, TFile *ambigs_file, int debug_level, bool use_ambigs_for_adaption, UNICHARSET *unicharset)
Definition: ambigs.cpp:74
static void PrintParams(FILE *fp, const ParamsVectors *member_params)
Definition: params.cpp:179
void CopyFrom(const UNICHARSET &src)
Definition: unicharset.cpp:423
void main_setup(const char *argv0, const char *basename)
CCUtil::main_setup - set location of tessdata and name of image.
Definition: mainblk.cpp:53
STRING lang
Definition: ccutil.h:67
static bool SetParam(const char *name, const char *value, SetParamConstraint constraint, ParamsVectors *member_params)
Definition: params.cpp:97
inT64 GetEndOffset(TessdataType tessdata_type) const
TessdataManager tessdata_manager
Definition: ccutil.h:69
bool load_from_file(const char *const filename, bool skip_fragments)
Definition: unicharset.h:345
Definition: strngs.h:44
bool Init(const char *data_file_name, int debug_level)
#define tprintf(...)
Definition: tprintf.h:31
bool use_ambigs_for_adaption
Definition: ccutil.h:91
UnicharAmbigs unichar_ambigs
Definition: ccutil.h:71
SetParamConstraint
Definition: params.h:36
int size() const
Definition: genericvector.h:72
FILE * GetDataFilePtr() const
int ambigs_debug_level
Definition: ccutil.h:87
bool init_cube_objects(bool load_combiner, TessdataManager *tessdata_manager)
void LoadUniversal(const UNICHARSET &encoder_set, UNICHARSET *unicharset)
Definition: ambigs.cpp:67
ParamsModel & getParamsModel()
UNICHARSET unicharset
Definition: ccutil.h:70
#define MAX_NUM_CLASSES
Definition: matchdefs.h:31
STRING datadir
Definition: ccutil.h:65
bool SeekToStart(TessdataType tessdata_type)
ParamsVectors * params()
Definition: ccutil.h:63
bool LoadFromFp(const char *lang, FILE *fp, inT64 end_offset)
void read_config_file(const char *filename, SetParamConstraint constraint)
Definition: tessedit.cpp:57
char * tessedit_write_params_to_file
void InitUnicharAmbigs(const UNICHARSET &unicharset, bool use_ambigs_for_adaption)
Definition: ambigs.cpp:53
void SetPass(PassEnum pass)
Definition: params_model.h:72
int size() const
Definition: unicharset.h:296
#define ASSERT_HOST(x)
Definition: errcode.h:84
const char * string() const
Definition: strngs.cpp:201
bool major_right_to_left() const
Definition: unicharset.cpp:931
LanguageModel * language_model_
Definition: wordrec.h:411
int tesseract::Tesseract::init_tesseract_lm ( const char *  arg0,
const char *  textbase,
const char *  language 
)

Definition at line 465 of file tessedit.cpp.

467  {
468  if (!init_tesseract_lang_data(arg0, textbase, language, OEM_TESSERACT_ONLY,
469  NULL, 0, NULL, NULL, false))
470  return -1;
473  getDict().FinishLoad();
475  return 0;
476 }
STRING lang
Definition: ccutil.h:67
TessdataManager tessdata_manager
Definition: ccutil.h:69
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)
Definition: tessedit.cpp:88
bool FinishLoad()
Definition: dict.cpp:306
void SetupForLoad(DawgCache *dawg_cache)
Definition: dict.cpp:206
void Load(const char *data_file_name, const STRING &lang)
Definition: dict.cpp:224
Dict & getDict()
Definition: classify.h:65
const STRING & GetDataFileName() const
static DawgCache * GlobalDawgCache()
Definition: dict.cpp:198
const char * string() const
Definition: strngs.cpp:201
void tesseract::Tesseract::join_words ( WERD_RES word,
WERD_RES word2,
BlamerBundle orig_bb 
) const

Definition at line 240 of file tfacepp.cpp.

242  {
243  TBOX prev_box = word->chopped_word->blobs.back()->bounding_box();
244  TBOX blob_box = word2->chopped_word->blobs[0]->bounding_box();
245  // Tack the word2 outputs onto the end of the word outputs.
246  word->chopped_word->blobs += word2->chopped_word->blobs;
247  word->rebuild_word->blobs += word2->rebuild_word->blobs;
248  word2->chopped_word->blobs.clear();
249  word2->rebuild_word->blobs.clear();
250  TPOINT split_pt;
251  split_pt.x = (prev_box.right() + blob_box.left()) / 2;
252  split_pt.y = (prev_box.top() + prev_box.bottom() +
253  blob_box.top() + blob_box.bottom()) / 4;
254  // Move the word2 seams onto the end of the word1 seam_array.
255  // Since the seam list is one element short, an empty seam marking the
256  // end of the last blob in the first word is needed first.
257  word->seam_array.push_back(new SEAM(0.0f, split_pt));
258  word->seam_array += word2->seam_array;
259  word2->seam_array.truncate(0);
260  // Fix widths and gaps.
261  word->blob_widths += word2->blob_widths;
262  word->blob_gaps += word2->blob_gaps;
263  // Fix the ratings matrix.
264  int rat1 = word->ratings->dimension();
265  int rat2 = word2->ratings->dimension();
266  word->ratings->AttachOnCorner(word2->ratings);
267  ASSERT_HOST(word->ratings->dimension() == rat1 + rat2);
268  word->best_state += word2->best_state;
269  // Append the word choices.
270  *word->raw_choice += *word2->raw_choice;
271 
272  // How many alt choices from each should we try to get?
273  const int kAltsPerPiece = 2;
274  // When do we start throwing away extra alt choices?
275  const int kTooManyAltChoices = 100;
276 
277  // Construct the cartesian product of the best_choices of word(1) and word2.
278  WERD_CHOICE_LIST joined_choices;
279  WERD_CHOICE_IT jc_it(&joined_choices);
280  WERD_CHOICE_IT bc1_it(&word->best_choices);
281  WERD_CHOICE_IT bc2_it(&word2->best_choices);
282  int num_word1_choices = word->best_choices.length();
283  int total_joined_choices = num_word1_choices;
284  // Nota Bene: For the main loop here, we operate only on the 2nd and greater
285  // word2 choices, and put them in the joined_choices list. The 1st word2
286  // choice gets added to the original word1 choices in-place after we have
287  // finished with them.
288  int bc2_index = 1;
289  for (bc2_it.forward(); !bc2_it.at_first(); bc2_it.forward(), ++bc2_index) {
290  if (total_joined_choices >= kTooManyAltChoices &&
291  bc2_index > kAltsPerPiece)
292  break;
293  int bc1_index = 0;
294  for (bc1_it.move_to_first(); bc1_index < num_word1_choices;
295  ++bc1_index, bc1_it.forward()) {
296  if (total_joined_choices >= kTooManyAltChoices &&
297  bc1_index > kAltsPerPiece)
298  break;
299  WERD_CHOICE *wc = new WERD_CHOICE(*bc1_it.data());
300  *wc += *bc2_it.data();
301  jc_it.add_after_then_move(wc);
302  ++total_joined_choices;
303  }
304  }
305  // Now that we've filled in as many alternates as we want, paste the best
306  // choice for word2 onto the original word alt_choices.
307  bc1_it.move_to_first();
308  bc2_it.move_to_first();
309  for (bc1_it.mark_cycle_pt(); !bc1_it.cycled_list(); bc1_it.forward()) {
310  *bc1_it.data() += *bc2_it.data();
311  }
312  bc1_it.move_to_last();
313  bc1_it.add_list_after(&joined_choices);
314 
315  // Restore the pointer to original blamer bundle and combine blamer
316  // information recorded in the splits.
317  if (orig_bb != NULL) {
318  orig_bb->JoinBlames(*word->blamer_bundle, *word2->blamer_bundle,
320  delete word->blamer_bundle;
321  word->blamer_bundle = orig_bb;
322  }
323  word->SetupBoxWord();
324  word->reject_map.initialise(word->box_word->length());
325  delete word2;
326 }
GenericVector< int > blob_gaps
Definition: pageres.h:208
int dimension() const
Definition: matrix.h:530
inT16 bottom() const
Definition: rect.h:61
GenericVector< SEAM * > seam_array
Definition: pageres.h:203
Definition: blobs.h:50
GenericVector< TBLOB * > blobs
Definition: blobs.h:436
Definition: seam.h:44
T & back() const
BlamerBundle * blamer_bundle
Definition: pageres.h:230
MATRIX * ratings
Definition: pageres.h:215
tesseract::BoxWord * box_word
Definition: pageres.h:250
WERD_CHOICE * raw_choice
Definition: pageres.h:224
TBOX bounding_box() const
Definition: blobs.cpp:482
void truncate(int size)
GenericVector< int > best_state
Definition: pageres.h:255
REJMAP reject_map
Definition: pageres.h:271
TWERD * chopped_word
Definition: pageres.h:201
Definition: rect.h:30
bool wordrec_debug_blamer
Definition: wordrec.h:167
inT16 right() const
Definition: rect.h:75
int length() const
Definition: boxword.h:85
inT16 left() const
Definition: rect.h:68
void AttachOnCorner(BandTriMatrix< T > *array2)
Definition: matrix.h:547
WERD_CHOICE_LIST best_choices
Definition: pageres.h:227
void JoinBlames(const BlamerBundle &bundle1, const BlamerBundle &bundle2, bool debug)
Definition: blamer.cpp:225
inT16 y
Definition: blobs.h:72
int push_back(T object)
inT16 top() const
Definition: rect.h:54
#define ASSERT_HOST(x)
Definition: errcode.h:84
inT16 x
Definition: blobs.h:71
void SetupBoxWord()
Definition: pageres.cpp:843
void initialise(inT16 length)
Definition: rejctmap.cpp:318
GenericVector< int > blob_widths
Definition: pageres.h:205
TWERD * rebuild_word
Definition: pageres.h:244
void tesseract::Tesseract::make_reject_map ( WERD_RES word,
ROW row,
inT16  pass 
)
void tesseract::Tesseract::match_current_words ( WERD_RES_LIST &  words,
ROW row,
BLOCK block 
)

Definition at line 196 of file fixspace.cpp.

197  {
198  WERD_RES_IT word_it(&words);
199  WERD_RES *word;
200  // Since we are not using PAGE_RES to iterate over words, we need to update
201  // prev_word_best_choice_ before calling classify_word_pass2().
202  prev_word_best_choice_ = NULL;
203  for (word_it.mark_cycle_pt(); !word_it.cycled_list(); word_it.forward()) {
204  word = word_it.data();
205  if ((!word->part_of_combo) && (word->box_word == NULL)) {
206  WordData word_data(block, row, word);
207  SetupWordPassN(2, &word_data);
208  classify_word_and_language(2, NULL, &word_data);
209  }
211  }
212 }
void classify_word_and_language(int pass_n, PAGE_RES_IT *pr_it, WordData *word_data)
Definition: control.cpp:1274
tesseract::BoxWord * box_word
Definition: pageres.h:250
WERD_CHOICE * prev_word_best_choice_
Definition: wordrec.h:416
BOOL8 part_of_combo
Definition: pageres.h:319
WERD_CHOICE * best_choice
Definition: pageres.h:219
void SetupWordPassN(int pass_n, WordData *word)
Definition: control.cpp:168
void tesseract::Tesseract::match_word_pass_n ( int  pass_n,
WERD_RES word,
ROW row,
BLOCK block 
)

match_word_pass2

Baseline normalize the word and pass it to Tess.

Definition at line 1554 of file control.cpp.

1555  {
1556  if (word->tess_failed) return;
1557  tess_segment_pass_n(pass_n, word);
1558 
1559  if (!word->tess_failed) {
1560  if (!word->word->flag (W_REP_CHAR)) {
1561  word->fix_quotes();
1563  word->fix_hyphens();
1564  /* Don't trust fix_quotes! - though I think I've fixed the bug */
1565  if (word->best_choice->length() != word->box_word->length()) {
1566  tprintf("POST FIX_QUOTES FAIL String:\"%s\"; Strlen=%d;"
1567  " #Blobs=%d\n",
1568  word->best_choice->debug_string().string(),
1569  word->best_choice->length(),
1570  word->box_word->length());
1571 
1572  }
1573  word->tess_accepted = tess_acceptable_word(word);
1574 
1575  // Also sets word->done flag
1576  make_reject_map(word, row, pass_n);
1577  }
1578  }
1579  set_word_fonts(word);
1580 
1581  ASSERT_HOST(word->raw_choice != NULL);
1582 }
BOOL8 flag(WERD_FLAGS mask) const
Definition: werd.h:128
BOOL8 tess_accepted
Definition: pageres.h:280
void fix_hyphens()
Definition: pageres.cpp:1041
WERD * word
Definition: pageres.h:175
tesseract::BoxWord * box_word
Definition: pageres.h:250
WERD_CHOICE * raw_choice
Definition: pageres.h:224
int length() const
Definition: ratngs.h:301
const STRING debug_string() const
Definition: ratngs.h:503
#define tprintf(...)
Definition: tprintf.h:31
BOOL8 tess_failed
Definition: pageres.h:272
void fix_quotes()
Definition: pageres.cpp:1012
int length() const
Definition: boxword.h:85
WERD_CHOICE * best_choice
Definition: pageres.h:219
#define ASSERT_HOST(x)
Definition: errcode.h:84
const char * string() const
Definition: strngs.cpp:201
void make_reject_map(WERD_RES *word, ROW *row, inT16 pass)
void set_word_fonts(WERD_RES *word)
Definition: control.cpp:1885
bool tess_acceptable_word(WERD_RES *word)
Definition: tessbox.cpp:69
void tess_segment_pass_n(int pass_n, WERD_RES *word)
Definition: tessbox.cpp:39
void tesseract::Tesseract::MaximallyChopWord ( const GenericVector< TBOX > &  boxes,
BLOCK block,
ROW row,
WERD_RES word_res 
)

Tests the chopper by exhaustively running chop_one_blob. The word_res will contain filled chopped_word, seam_array, denorm, box_word and best_state for the maximally chopped word.

Definition at line 253 of file applybox.cpp.

255  {
256  if (!word_res->SetupForRecognition(unicharset, this, BestPix(),
261  row, block)) {
262  word_res->CloneChoppedToRebuild();
263  return;
264  }
265  if (chop_debug) {
266  tprintf("Maximally chopping word at:");
267  word_res->word->bounding_box().print();
268  }
269  GenericVector<BLOB_CHOICE*> blob_choices;
270  ASSERT_HOST(!word_res->chopped_word->blobs.empty());
271  float rating = static_cast<float>(MAX_INT8);
272  for (int i = 0; i < word_res->chopped_word->NumBlobs(); ++i) {
273  // The rating and certainty are not quite arbitrary. Since
274  // select_blob_to_chop uses the worst certainty to choose, they all have
275  // to be different, so starting with MAX_INT8, subtract 1/8 for each blob
276  // in here, and then divide by e each time they are chopped, which
277  // should guarantee a set of unequal values for the whole tree of blobs
278  // produced, however much chopping is required. The chops are thus only
279  // limited by the ability of the chopper to find suitable chop points,
280  // and not by the value of the certainties.
281  BLOB_CHOICE* choice =
282  new BLOB_CHOICE(0, rating, -rating, -1, 0.0f, 0.0f, 0.0f, BCC_FAKE);
283  blob_choices.push_back(choice);
284  rating -= 0.125f;
285  }
286  const double e = exp(1.0); // The base of natural logs.
287  int blob_number;
288  int right_chop_index = 0;
290  // We only chop if the language is not fixed pitch like CJK.
291  SEAM* seam = NULL;
292  while ((seam = chop_one_blob(boxes, blob_choices, word_res,
293  &blob_number)) != NULL) {
294  word_res->InsertSeam(blob_number, seam);
295  BLOB_CHOICE* left_choice = blob_choices[blob_number];
296  rating = left_choice->rating() / e;
297  left_choice->set_rating(rating);
298  left_choice->set_certainty(-rating);
299  // combine confidence w/ serial #
300  BLOB_CHOICE* right_choice = new BLOB_CHOICE(++right_chop_index,
301  rating - 0.125f, -rating, -1,
302  0.0f, 0.0f, 0.0f, BCC_FAKE);
303  blob_choices.insert(right_choice, blob_number + 1);
304  }
305  }
306  word_res->CloneChoppedToRebuild();
307  word_res->FakeClassifyWord(blob_choices.size(), &blob_choices[0]);
308 }
int NumBlobs() const
Definition: blobs.h:425
GenericVector< TBLOB * > blobs
Definition: blobs.h:436
float rating() const
Definition: ratngs.h:79
Definition: seam.h:44
#define MAX_INT8
Definition: host.h:118
Pix * BestPix() const
bool empty() const
Definition: genericvector.h:84
WERD * word
Definition: pageres.h:175
void InsertSeam(int blob_number, SEAM *seam)
Definition: pageres.cpp:409
#define tprintf(...)
Definition: tprintf.h:31
TWERD * chopped_word
Definition: pageres.h:201
int size() const
Definition: genericvector.h:72
TBOX bounding_box() const
Definition: werd.cpp:160
bool classify_bln_numeric_mode
Definition: classify.h:500
SEAM * chop_one_blob(const GenericVector< TBOX > &boxes, const GenericVector< BLOB_CHOICE * > &blob_choices, WERD_RES *word_res, int *blob_number)
Definition: chopper.cpp:374
bool SetupForRecognition(const UNICHARSET &unicharset_in, tesseract::Tesseract *tesseract, Pix *pix, int norm_mode, const TBOX *norm_box, bool numeric_mode, bool use_body_size, bool allow_detailed_fx, ROW *row, const BLOCK *block)
Definition: pageres.cpp:294
void CloneChoppedToRebuild()
Definition: pageres.cpp:828
UNICHARSET unicharset
Definition: ccutil.h:70
void set_certainty(float newrat)
Definition: ratngs.h:150
void print() const
Definition: rect.h:270
int push_back(T object)
void insert(T t, int index)
#define ASSERT_HOST(x)
Definition: errcode.h:84
void set_rating(float newrat)
Definition: ratngs.h:147
void FakeClassifyWord(int blob_count, BLOB_CHOICE **choices)
Definition: pageres.cpp:872
bool assume_fixed_pitch_char_segment
Definition: wordrec.h:161
Pix** tesseract::Tesseract::mutable_pix_binary ( )
inline

Definition at line 191 of file tesseractclass.h.

191  {
192  pixDestroy(&pix_binary_);
193  return &pix_binary_;
194  }
Textord* tesseract::Tesseract::mutable_textord ( )
inline

Definition at line 248 of file tesseractclass.h.

248  {
249  return &textord_;
250  }
void tesseract::Tesseract::nn_match_word ( WERD_RES word,
ROW row 
)
void tesseract::Tesseract::nn_recover_rejects ( WERD_RES word,
ROW row 
)
BOOL8 tesseract::Tesseract::noise_outlines ( TWERD word)

Definition at line 982 of file docqual.cpp.

982  {
983  TBOX box; // BB of outline
984  inT16 outline_count = 0;
985  inT16 small_outline_count = 0;
986  inT16 max_dimension;
987  float small_limit = kBlnXHeight * crunch_small_outlines_size;
988 
989  for (int b = 0; b < word->NumBlobs(); ++b) {
990  TBLOB* blob = word->blobs[b];
991  for (TESSLINE* ol = blob->outlines; ol != NULL; ol = ol->next) {
992  outline_count++;
993  box = ol->bounding_box();
994  if (box.height() > box.width())
995  max_dimension = box.height();
996  else
997  max_dimension = box.width();
998  if (max_dimension < small_limit)
999  small_outline_count++;
1000  }
1001  }
1002  return small_outline_count >= outline_count;
1003 }
int NumBlobs() const
Definition: blobs.h:425
TESSLINE * outlines
Definition: blobs.h:377
GenericVector< TBLOB * > blobs
Definition: blobs.h:436
inT16 height() const
Definition: rect.h:104
Definition: rect.h:30
short inT16
Definition: host.h:100
const int kBlnXHeight
Definition: normalis.h:28
TESSLINE * next
Definition: blobs.h:258
Definition: blobs.h:261
inT16 width() const
Definition: rect.h:111
BOOL8 tesseract::Tesseract::non_0_digit ( const UNICHARSET ch_set,
UNICHAR_ID  unichar_id 
)

Definition at line 789 of file reject.cpp.

789  {
790  return ch_set.get_isdigit(unichar_id) && !ch_set.eq(unichar_id, "0");
791 }
bool get_isdigit(UNICHAR_ID unichar_id) const
Definition: unicharset.h:469
bool eq(UNICHAR_ID unichar_id, const char *const unichar_repr) const
Definition: unicharset.cpp:656
BOOL8 tesseract::Tesseract::non_O_upper ( const UNICHARSET ch_set,
UNICHAR_ID  unichar_id 
)

Definition at line 785 of file reject.cpp.

785  {
786  return ch_set.get_isupper(unichar_id) && !ch_set.eq(unichar_id, "O");
787 }
bool get_isupper(UNICHAR_ID unichar_id) const
Definition: unicharset.h:462
bool eq(UNICHAR_ID unichar_id, const char *const unichar_repr) const
Definition: unicharset.cpp:656
int tesseract::Tesseract::num_sub_langs ( ) const
inline

Definition at line 255 of file tesseractclass.h.

255  {
256  return sub_langs_.size();
257  }
BOOL8 tesseract::Tesseract::one_ell_conflict ( WERD_RES word_res,
BOOL8  update_map 
)

Definition at line 292 of file reject.cpp.

292  {
293  const char *word;
294  const char *lengths;
295  inT16 word_len; //its length
296  inT16 first_alphanum_index_;
297  inT16 first_alphanum_offset_;
298  inT16 i;
299  inT16 offset;
300  BOOL8 non_conflict_set_char; //non conf set a/n?
301  BOOL8 conflict = FALSE;
302  BOOL8 allow_1s;
303  ACCEPTABLE_WERD_TYPE word_type;
304  BOOL8 dict_perm_type;
305  BOOL8 dict_word_ok;
306  int dict_word_type;
307 
308  word = word_res->best_choice->unichar_string().string ();
309  lengths = word_res->best_choice->unichar_lengths().string();
310  word_len = strlen (lengths);
311  /*
312  If there are no occurrences of the conflict set characters then the word
313  is OK.
314  */
315  if (strpbrk (word, conflict_set_I_l_1.string ()) == NULL)
316  return FALSE;
317 
318  /*
319  There is a conflict if there are NO other (confirmed) alphanumerics apart
320  from those in the conflict set.
321  */
322 
323  for (i = 0, offset = 0, non_conflict_set_char = FALSE;
324  (i < word_len) && !non_conflict_set_char; offset += lengths[i++])
325  non_conflict_set_char =
326  (word_res->uch_set->get_isalpha(word + offset, lengths[i]) ||
327  word_res->uch_set->get_isdigit(word + offset, lengths[i])) &&
328  !STRING (conflict_set_I_l_1).contains (word[offset]);
329  if (!non_conflict_set_char) {
330  if (update_map)
331  reject_I_1_L(word_res);
332  return TRUE;
333  }
334 
335  /*
336  If the word is accepted by a dawg permuter, and the first alpha character
337  is "I" or "l", check to see if the alternative is also a dawg word. If it
338  is, then there is a potential error otherwise the word is ok.
339  */
340 
341  dict_perm_type = (word_res->best_choice->permuter () == SYSTEM_DAWG_PERM) ||
342  (word_res->best_choice->permuter () == USER_DAWG_PERM) ||
344  (word_res->best_choice->permuter () == DOC_DAWG_PERM)) ||
345  (word_res->best_choice->permuter () == FREQ_DAWG_PERM);
346  dict_word_type = dict_word(*(word_res->best_choice));
347  dict_word_ok = (dict_word_type > 0) &&
348  (rej_trust_doc_dawg || (dict_word_type != DOC_DAWG_PERM));
349 
350  if ((rej_1Il_use_dict_word && dict_word_ok) ||
351  (rej_1Il_trust_permuter_type && dict_perm_type) ||
352  (dict_perm_type && dict_word_ok)) {
353  first_alphanum_index_ = first_alphanum_index (word, lengths);
354  first_alphanum_offset_ = first_alphanum_offset (word, lengths);
355  if (lengths[first_alphanum_index_] == 1 &&
356  word[first_alphanum_offset_] == 'I') {
357  word_res->best_choice->unichar_string()[first_alphanum_offset_] = 'l';
358  if (safe_dict_word(word_res) > 0) {
359  word_res->best_choice->unichar_string()[first_alphanum_offset_] = 'I';
360  if (update_map)
361  word_res->reject_map[first_alphanum_index_].
362  setrej_1Il_conflict();
363  return TRUE;
364  }
365  else {
366  word_res->best_choice->unichar_string()[first_alphanum_offset_] = 'I';
367  return FALSE;
368  }
369  }
370 
371  if (lengths[first_alphanum_index_] == 1 &&
372  word[first_alphanum_offset_] == 'l') {
373  word_res->best_choice->unichar_string()[first_alphanum_offset_] = 'I';
374  if (safe_dict_word(word_res) > 0) {
375  word_res->best_choice->unichar_string()[first_alphanum_offset_] = 'l';
376  if (update_map)
377  word_res->reject_map[first_alphanum_index_].
378  setrej_1Il_conflict();
379  return TRUE;
380  }
381  else {
382  word_res->best_choice->unichar_string()[first_alphanum_offset_] = 'l';
383  return FALSE;
384  }
385  }
386  return FALSE;
387  }
388 
389  /*
390  NEW 1Il code. The old code relied on permuter types too much. In fact,
391  tess will use TOP_CHOICE permute for good things like "palette".
392  In this code the string is examined independently to see if it looks like
393  a well formed word.
394  */
395 
396  /*
397  REGARDLESS OF PERMUTER, see if flipping a leading I/l generates a
398  dictionary word.
399  */
400  first_alphanum_index_ = first_alphanum_index (word, lengths);
401  first_alphanum_offset_ = first_alphanum_offset (word, lengths);
402  if (lengths[first_alphanum_index_] == 1 &&
403  word[first_alphanum_offset_] == 'l') {
404  word_res->best_choice->unichar_string()[first_alphanum_offset_] = 'I';
405  if (safe_dict_word(word_res) > 0)
406  return FALSE;
407  else
408  word_res->best_choice->unichar_string()[first_alphanum_offset_] = 'l';
409  }
410  else if (lengths[first_alphanum_index_] == 1 &&
411  word[first_alphanum_offset_] == 'I') {
412  word_res->best_choice->unichar_string()[first_alphanum_offset_] = 'l';
413  if (safe_dict_word(word_res) > 0)
414  return FALSE;
415  else
416  word_res->best_choice->unichar_string()[first_alphanum_offset_] = 'I';
417  }
418  /*
419  For strings containing digits:
420  If there are no alphas OR the numeric permuter liked the word,
421  reject any non 1 conflict chs
422  Else reject all conflict chs
423  */
424  if (word_contains_non_1_digit (word, lengths)) {
425  allow_1s = (alpha_count (word, lengths) == 0) ||
426  (word_res->best_choice->permuter () == NUMBER_PERM);
427 
428  inT16 offset;
429  conflict = FALSE;
430  for (i = 0, offset = 0; word[offset] != '\0';
431  offset += word_res->best_choice->unichar_lengths()[i++]) {
432  if ((!allow_1s || (word[offset] != '1')) &&
433  STRING (conflict_set_I_l_1).contains (word[offset])) {
434  if (update_map)
435  word_res->reject_map[i].setrej_1Il_conflict ();
436  conflict = TRUE;
437  }
438  }
439  return conflict;
440  }
441  /*
442  For anything else. See if it conforms to an acceptable word type. If so,
443  treat accordingly.
444  */
445  word_type = acceptable_word_string(*word_res->uch_set, word, lengths);
446  if ((word_type == AC_LOWER_CASE) || (word_type == AC_INITIAL_CAP)) {
447  first_alphanum_index_ = first_alphanum_index (word, lengths);
448  first_alphanum_offset_ = first_alphanum_offset (word, lengths);
449  if (STRING (conflict_set_I_l_1).contains (word[first_alphanum_offset_])) {
450  if (update_map)
451  word_res->reject_map[first_alphanum_index_].
452  setrej_1Il_conflict ();
453  return TRUE;
454  }
455  else
456  return FALSE;
457  }
458  else if (word_type == AC_UPPER_CASE) {
459  return FALSE;
460  }
461  else {
462  if (update_map)
463  reject_I_1_L(word_res);
464  return TRUE;
465  }
466 }
inT16 alpha_count(const char *word, const char *word_lengths)
Definition: reject.cpp:495
BOOL8 contains(const char c) const
Definition: strngs.cpp:192
#define TRUE
Definition: capi.h:45
Definition: strngs.h:44
ALL upper case.
Definition: control.h:38
const STRING & unichar_lengths() const
Definition: ratngs.h:532
ALL but initial lc.
Definition: control.h:39
BOOL8 word_contains_non_1_digit(const char *word, const char *word_lengths)
Definition: reject.cpp:509
ALL lower case.
Definition: control.h:37
void reject_I_1_L(WERD_RES *word)
Definition: reject.cpp:191
bool get_isdigit(UNICHAR_ID unichar_id) const
Definition: unicharset.h:469
REJMAP reject_map
Definition: pageres.h:271
#define FALSE
Definition: capi.h:46
const STRING & unichar_string() const
Definition: ratngs.h:525
bool get_isalpha(UNICHAR_ID unichar_id) const
Definition: unicharset.h:448
inT16 first_alphanum_index(const char *word, const char *word_lengths)
Definition: reject.cpp:469
short inT16
Definition: host.h:100
ACCEPTABLE_WERD_TYPE
Definition: control.h:34
uinT8 permuter() const
Definition: ratngs.h:344
WERD_CHOICE * best_choice
Definition: pageres.h:219
const UNICHARSET * uch_set
Definition: pageres.h:192
inT16 first_alphanum_offset(const char *word, const char *word_lengths)
Definition: reject.cpp:482
unsigned char BOOL8
Definition: host.h:113
inT16 safe_dict_word(const WERD_RES *werd_res)
Definition: reject.cpp:607
const char * string() const
Definition: strngs.cpp:201
ACCEPTABLE_WERD_TYPE acceptable_word_string(const UNICHARSET &char_set, const char *s, const char *lengths)
Definition: control.cpp:1668
int dict_word(const WERD_CHOICE &word)
Definition: tface.cpp:128
void tesseract::Tesseract::output_pass ( PAGE_RES_IT page_res_it,
const TBOX target_word_box 
)

Definition at line 68 of file output.cpp.

70  {
71  BLOCK_RES *block_of_last_word;
72  BOOL8 force_eol; //During output
73  BLOCK *nextblock; //block of next word
74  WERD *nextword; //next word
75 
76  page_res_it.restart_page ();
77  block_of_last_word = NULL;
78  while (page_res_it.word () != NULL) {
79  check_debug_pt (page_res_it.word (), 120);
80 
81  if (target_word_box) {
82  TBOX current_word_box = page_res_it.word()->word->bounding_box();
83  FCOORD center_pt(
84  (current_word_box.right() + current_word_box.left()) / 2,
85  (current_word_box.bottom() + current_word_box.top()) / 2);
86  if (!target_word_box->contains(center_pt)) {
87  page_res_it.forward();
88  continue;
89  }
90  }
92  block_of_last_word != page_res_it.block ()) {
93  block_of_last_word = page_res_it.block ();
94  }
95 
96  force_eol = (tessedit_write_block_separators &&
97  (page_res_it.block () != page_res_it.next_block ())) ||
98  (page_res_it.next_word () == NULL);
99 
100  if (page_res_it.next_word () != NULL)
101  nextword = page_res_it.next_word ()->word;
102  else
103  nextword = NULL;
104  if (page_res_it.next_block () != NULL)
105  nextblock = page_res_it.next_block ()->block;
106  else
107  nextblock = NULL;
108  //regardless of tilde crunching
109  write_results(page_res_it,
110  determine_newline_type(page_res_it.word()->word,
111  page_res_it.block()->block,
112  nextword, nextblock), force_eol);
113  page_res_it.forward();
114  }
115 }
BLOCK_RES * next_block() const
Definition: pageres.h:751
char determine_newline_type(WERD *word, BLOCK *block, WERD *next_word, BLOCK *next_block)
Definition: output.cpp:245
inT16 bottom() const
Definition: rect.h:61
Definition: werd.h:60
Definition: points.h:189
WERD * word
Definition: pageres.h:175
WERD_RES * word() const
Definition: pageres.h:736
void write_results(PAGE_RES_IT &page_res_it, char newline_type, BOOL8 force_eol)
Definition: output.cpp:130
WERD_RES * forward()
Definition: pageres.h:716
BOOL8 check_debug_pt(WERD_RES *word, int location)
Definition: control.cpp:1772
WERD_RES * next_word() const
Definition: pageres.h:745
TBOX bounding_box() const
Definition: werd.cpp:160
Definition: rect.h:30
inT16 right() const
Definition: rect.h:75
WERD_RES * restart_page()
Definition: pageres.h:683
inT16 left() const
Definition: rect.h:68
BLOCK_RES * block() const
Definition: pageres.h:742
inT16 top() const
Definition: rect.h:54
unsigned char BOOL8
Definition: host.h:113
bool contains(const FCOORD pt) const
Definition: rect.h:323
Definition: ocrblock.h:30
BLOCK * block
Definition: pageres.h:99
void tesseract::Tesseract::ParseLanguageString ( const char *  lang_str,
GenericVector< STRING > *  to_load,
GenericVector< STRING > *  not_to_load 
)

Definition at line 254 of file tessedit.cpp.

256  {
257  STRING remains(lang_str);
258  while (remains.length() > 0) {
259  // Find the start of the lang code and which vector to add to.
260  const char* start = remains.string();
261  while (*start == '+')
262  ++start;
263  GenericVector<STRING>* target = to_load;
264  if (*start == '~') {
265  target = not_to_load;
266  ++start;
267  }
268  // Find the index of the end of the lang code in string start.
269  int end = strlen(start);
270  const char* plus = strchr(start, '+');
271  if (plus != NULL && plus - start < end)
272  end = plus - start;
273  STRING lang_code(start);
274  lang_code.truncate_at(end);
275  STRING next(start + end);
276  remains = next;
277  // Check whether lang_code is already in the target vector and add.
278  if (!IsStrInList(lang_code, *target)) {
280  tprintf("Adding language '%s' to list\n", lang_code.string());
281  target->push_back(lang_code);
282  }
283  }
284 }
Definition: strngs.h:44
#define tprintf(...)
Definition: tprintf.h:31
int push_back(T object)
void tesseract::Tesseract::pgeditor_main ( int  width,
int  height,
PAGE_RES page_res 
)

pgeditor_main()

Top level editor operation: Setup a new window and an according event handler

Definition at line 337 of file pgedit.cpp.

337  {
338  current_page_res = page_res;
339  if (current_page_res->block_res_list.empty())
340  return;
341 
342  recog_done = false;
343  stillRunning = true;
344 
345  build_image_window(width, height);
348 #ifndef GRAPHICS_DISABLED
349  pe = new ParamsEditor(this, image_win);
350 #endif
351  PGEventHandler pgEventHandler(this);
352 
353  image_win->AddEventHandler(&pgEventHandler);
355 
356  SVMenuNode* svMenuRoot = build_menu_new();
357 
358  svMenuRoot->BuildMenu(image_win);
359  image_win->SetVisible(true);
360 
362  image_win->AddEventHandler(NULL);
363 }
SVEvent * AwaitEvent(SVEventType type)
Definition: scrollview.cpp:449
SVMenuNode * build_menu_new()
Definition: pgedit.cpp:257
ScrollView * image_win
Definition: pgedit.cpp:107
BLOCK_RES_LIST block_res_list
Definition: pageres.h:62
BOOL8 word_set_display(PAGE_RES_IT *pr_it)
Definition: pgedit.cpp:946
bool recog_done
Definition: pgedit.cpp:118
void do_re_display(BOOL8(tesseract::Tesseract::*word_painter)(PAGE_RES_IT *pr_it))
Definition: pgedit.cpp:308
bool stillRunning
Definition: pgedit.cpp:109
void SetVisible(bool visible)
Definition: scrollview.cpp:555
BITS16 word_display_mode
Definition: pgedit.cpp:122
void BuildMenu(ScrollView *sv, bool menu_bar=true)
Definition: svmnode.cpp:121
void turn_on_bit(uinT8 bit_num)
Definition: bits16.h:37
void AddMessageBox()
Definition: scrollview.cpp:584
PAGE_RES * current_page_res
Definition: pgedit.cpp:128
void build_image_window(int width, int height)
Definition: pgedit.cpp:193
ParamsEditor * pe
Definition: pgedit.cpp:108
void AddEventHandler(SVEventHandler *listener)
Add an Event Listener to this ScrollView Window.
Definition: scrollview.cpp:418
Pix* tesseract::Tesseract::pix_binary ( ) const
inline

Definition at line 195 of file tesseractclass.h.

195  {
196  return pix_binary_;
197  }
Pix* tesseract::Tesseract::pix_grey ( ) const
inline

Definition at line 198 of file tesseractclass.h.

198  {
199  return pix_grey_;
200  }
Pix* tesseract::Tesseract::pix_original ( ) const
inline

Definition at line 205 of file tesseractclass.h.

205 { return pix_original_; }
BOOL8 tesseract::Tesseract::potential_word_crunch ( WERD_RES word,
GARBAGE_LEVEL  garbage_level,
BOOL8  ok_dict_word 
)

Definition at line 546 of file docqual.cpp.

548  {
549  float rating_per_ch;
550  int adjusted_len;
551  const char *str = word->best_choice->unichar_string().string();
552  const char *lengths = word->best_choice->unichar_lengths().string();
553  BOOL8 word_crunchable;
554  int poor_indicator_count = 0;
555 
556  word_crunchable = !crunch_leave_accept_strings ||
557  word->reject_map.length() < 3 ||
559  str, lengths) == AC_UNACCEPTABLE &&
560  !ok_dict_word);
561 
562  adjusted_len = word->reject_map.length();
563  if (adjusted_len > 10)
564  adjusted_len = 10;
565  rating_per_ch = word->best_choice->rating() / adjusted_len;
566 
567  if (rating_per_ch > crunch_pot_poor_rate) {
568  if (crunch_debug > 2) {
569  tprintf("Potential poor rating on \"%s\"\n",
570  word->best_choice->unichar_string().string());
571  }
572  poor_indicator_count++;
573  }
574 
575  if (word_crunchable &&
577  if (crunch_debug > 2) {
578  tprintf("Potential poor cert on \"%s\"\n",
579  word->best_choice->unichar_string().string());
580  }
581  poor_indicator_count++;
582  }
583 
584  if (garbage_level != G_OK) {
585  if (crunch_debug > 2) {
586  tprintf("Potential garbage on \"%s\"\n",
587  word->best_choice->unichar_string().string());
588  }
589  poor_indicator_count++;
590  }
591  return poor_indicator_count >= crunch_pot_indicators;
592 }
const STRING & unichar_lengths() const
Definition: ratngs.h:532
#define tprintf(...)
Definition: tprintf.h:31
REJMAP reject_map
Definition: pageres.h:271
const STRING & unichar_string() const
Definition: ratngs.h:525
Unacceptable word.
Definition: control.h:36
inT32 length() const
Definition: rejctmap.h:236
float rating() const
Definition: ratngs.h:325
WERD_CHOICE * best_choice
Definition: pageres.h:219
const UNICHARSET * uch_set
Definition: pageres.h:192
unsigned char BOOL8
Definition: host.h:113
const char * string() const
Definition: strngs.cpp:201
ACCEPTABLE_WERD_TYPE acceptable_word_string(const UNICHARSET &char_set, const char *s, const char *lengths)
Definition: control.cpp:1668
float certainty() const
Definition: ratngs.h:328
Definition: docqual.h:28
void tesseract::Tesseract::PreenXHeights ( BLOCK_LIST *  block_list)

Any row xheight that is significantly different from the median is set to the median.

Definition at line 193 of file applybox.cpp.

193  {
194  double median_xheight = MedianXHeight(block_list);
195  double max_deviation = kMaxXHeightDeviationFraction * median_xheight;
196  // Strip all fuzzy space markers to simplify the PAGE_RES.
197  BLOCK_IT b_it(block_list);
198  for (b_it.mark_cycle_pt(); !b_it.cycled_list(); b_it.forward()) {
199  BLOCK* block = b_it.data();
200  ROW_IT r_it(block->row_list());
201  for (r_it.mark_cycle_pt(); !r_it.cycled_list(); r_it.forward ()) {
202  ROW* row = r_it.data();
203  float diff = fabs(row->x_height() - median_xheight);
204  if (diff > max_deviation) {
205  if (applybox_debug) {
206  tprintf("row xheight=%g, but median xheight = %g\n",
207  row->x_height(), median_xheight);
208  }
209  row->set_x_height(static_cast<float>(median_xheight));
210  }
211  }
212  }
213 }
ROW_LIST * row_list()
get rows
Definition: ocrblock.h:120
Definition: ocrrow.h:32
float x_height() const
Definition: ocrrow.h:61
void set_x_height(float new_xheight)
Definition: ocrrow.h:64
#define tprintf(...)
Definition: tprintf.h:31
const double kMaxXHeightDeviationFraction
Definition: applybox.cpp:43
Definition: ocrblock.h:30
void tesseract::Tesseract::PrepareForPageseg ( )

Definition at line 694 of file tesseractclass.cpp.

694  {
696  pixDestroy(&cube_binary_);
697  cube_binary_ = pixClone(pix_binary());
698  // Find the max splitter strategy over all langs.
699  ShiroRekhaSplitter::SplitStrategy max_pageseg_strategy =
702  for (int i = 0; i < sub_langs_.size(); ++i) {
703  ShiroRekhaSplitter::SplitStrategy pageseg_strategy =
705  static_cast<inT32>(sub_langs_[i]->pageseg_devanagari_split_strategy));
706  if (pageseg_strategy > max_pageseg_strategy)
707  max_pageseg_strategy = pageseg_strategy;
708  // Clone the cube image to all the sub langs too.
709  pixDestroy(&sub_langs_[i]->cube_binary_);
710  sub_langs_[i]->cube_binary_ = pixClone(pix_binary());
711  pixDestroy(&sub_langs_[i]->pix_binary_);
712  sub_langs_[i]->pix_binary_ = pixClone(pix_binary());
713  }
714  // Perform shiro-rekha (top-line) splitting and replace the current image by
715  // the newly splitted image.
716  splitter_.set_orig_pix(pix_binary());
717  splitter_.set_pageseg_split_strategy(max_pageseg_strategy);
718  if (splitter_.Split(true)) {
719  ASSERT_HOST(splitter_.splitted_image());
720  pixDestroy(&pix_binary_);
721  pix_binary_ = pixClone(splitter_.splitted_image());
722  }
723 }
void set_pageseg_split_strategy(SplitStrategy strategy)
void set_use_cjk_fp_model(bool flag)
Definition: textord.h:95
int inT32
Definition: host.h:102
Pix * pix_binary() const
bool Split(bool split_for_pageseg)
#define ASSERT_HOST(x)
Definition: errcode.h:84
void tesseract::Tesseract::PrepareForTessOCR ( BLOCK_LIST *  block_list,
Tesseract osd_tess,
OSResults osr 
)

Definition at line 730 of file tesseractclass.cpp.

731  {
732  // Find the max splitter strategy over all langs.
733  ShiroRekhaSplitter::SplitStrategy max_ocr_strategy =
735  static_cast<inT32>(ocr_devanagari_split_strategy));
736  for (int i = 0; i < sub_langs_.size(); ++i) {
737  ShiroRekhaSplitter::SplitStrategy ocr_strategy =
739  static_cast<inT32>(sub_langs_[i]->ocr_devanagari_split_strategy));
740  if (ocr_strategy > max_ocr_strategy)
741  max_ocr_strategy = ocr_strategy;
742  }
743  // Utilize the segmentation information available.
744  splitter_.set_segmentation_block_list(block_list);
745  splitter_.set_ocr_split_strategy(max_ocr_strategy);
746  // Run the splitter for OCR
747  bool split_for_ocr = splitter_.Split(false);
748  // Restore pix_binary to the binarized original pix for future reference.
749  ASSERT_HOST(splitter_.orig_pix());
750  pixDestroy(&pix_binary_);
751  pix_binary_ = pixClone(splitter_.orig_pix());
752  // If the pageseg and ocr strategies are different, refresh the block list
753  // (from the last SegmentImage call) with blobs from the real image to be used
754  // for OCR.
755  if (splitter_.HasDifferentSplitStrategies()) {
756  BLOCK block("", TRUE, 0, 0, 0, 0, pixGetWidth(pix_binary_),
757  pixGetHeight(pix_binary_));
758  Pix* pix_for_ocr = split_for_ocr ? splitter_.splitted_image() :
759  splitter_.orig_pix();
760  extract_edges(pix_for_ocr, &block);
761  splitter_.RefreshSegmentationWithNewBlobs(block.blob_list());
762  }
763  // The splitter isn't needed any more after this, so save memory by clearing.
764  splitter_.Clear();
765 }
#define TRUE
Definition: capi.h:45
void set_segmentation_block_list(BLOCK_LIST *block_list)
void RefreshSegmentationWithNewBlobs(C_BLOB_LIST *new_blobs)
int inT32
Definition: host.h:102
bool Split(bool split_for_pageseg)
void set_ocr_split_strategy(SplitStrategy strategy)
#define ASSERT_HOST(x)
Definition: errcode.h:84
Definition: ocrblock.h:30
void extract_edges(Pix *pix, BLOCK *block)
Definition: edgblob.cpp:334
void tesseract::Tesseract::PrerecAllWordsPar ( const GenericVector< WordData > &  words)

Definition at line 36 of file par_control.cpp.

36  {
37  // Prepare all the blobs.
39  for (int w = 0; w < words.size(); ++w) {
40  if (words[w].word->ratings != NULL &&
41  words[w].word->ratings->get(0, 0) == NULL) {
42  for (int s = 0; s < words[w].lang_words.size(); ++s) {
43  Tesseract* sub = s < sub_langs_.size() ? sub_langs_[s] : this;
44  const WERD_RES& word = *words[w].lang_words[s];
45  for (int b = 0; b < word.chopped_word->NumBlobs(); ++b) {
46  blobs.push_back(BlobData(b, sub, word));
47  }
48  }
49  }
50  }
51  // Pre-classify all the blobs.
52  if (tessedit_parallelize > 1) {
53  for (int b = 0; b < blobs.size(); ++b) {
54  *blobs[b].choices =
55  blobs[b].tesseract->classify_blob(blobs[b].blob, "par", White, NULL);
56  }
57  } else {
58  // TODO(AMD) parallelize this.
59  for (int b = 0; b < blobs.size(); ++b) {
60  *blobs[b].choices =
61  blobs[b].tesseract->classify_blob(blobs[b].blob, "par", White, NULL);
62  }
63  }
64 }
int NumBlobs() const
Definition: blobs.h:425
T & get(int index) const
TWERD * chopped_word
Definition: pageres.h:201
Definition: callcpp.h:34
int size() const
Definition: genericvector.h:72
int push_back(T object)
BOOL8 tesseract::Tesseract::process_cmd_win_event ( inT32  cmd_event,
char *  new_value 
)

Definition at line 397 of file pgedit.cpp.

400  {
401  char msg[160];
402  BOOL8 exit = FALSE;
403 
404  color_mode = CM_RAINBOW;
405 
406  // Run recognition on the full page if needed.
407  switch (cmd_event) {
408  case BLAMER_CMD_EVENT:
412  case SHOW_BOLD_CMD_EVENT:
418  if (!recog_done) {
419  recog_all_words(current_page_res, NULL, NULL, NULL, 0);
420  recog_done = true;
421  }
422  break;
423  default:
424  break;
425  }
426 
427  switch (cmd_event) {
428  case NULL_CMD_EVENT:
429  break;
430 
432  case DUMP_WERD_CMD_EVENT:
435  case RECOG_WERDS:
436  case RECOG_PSEUDO:
437  case SHOW_BLOB_FEATURES:
438  mode =(CMD_EVENTS) cmd_event;
439  break;
442  word_config_ = image_win->ShowInputDialog("Config File Name");
443  break;
445  if (new_value[0] == 'T')
447  else
450  break;
451  case BLAMER_CMD_EVENT:
452  if (new_value[0] == 'T')
454  else
458  break;
460  if (new_value[0] == 'T')
462  else
465  break;
466  case POLYGONAL_CMD_EVENT:
467  if (new_value[0] == 'T')
469  else
472  break;
473  case BL_NORM_CMD_EVENT:
474  if (new_value[0] == 'T')
476  else
479  break;
480  case BITMAP_CMD_EVENT:
481  if (new_value[0] == 'T')
483  else
486  break;
489  break;
490  case IMAGE_CMD_EVENT:
491  display_image =(new_value[0] == 'T');
493  break;
494  case BLOCKS_CMD_EVENT:
495  display_blocks =(new_value[0] == 'T');
497  break;
498  case BASELINES_CMD_EVENT:
499  display_baselines =(new_value[0] == 'T');
501  break;
503  color_mode = CM_SUBSCRIPT;
505  break;
507  color_mode = CM_SUPERSCRIPT;
509  break;
511  color_mode = CM_ITALIC;
513  break;
514  case SHOW_BOLD_CMD_EVENT:
515  color_mode = CM_BOLD;
517  break;
519  color_mode = CM_UNDERLINE;
521  break;
523  color_mode = CM_FIXEDPITCH;
525  break;
527  color_mode = CM_SERIF;
529  break;
531  color_mode = CM_SMALLCAPS;
533  break;
535  color_mode = CM_DROPCAPS;
537  break;
538  case REFRESH_CMD_EVENT:
540  break;
541  case QUIT_CMD_EVENT:
542  exit = TRUE;
544  break;
545 
546  default:
547  sprintf(msg, "Unrecognised event " INT32FORMAT "(%s)",
548  cmd_event, new_value);
549  image_win->AddMessage(msg);
550  break;
551  }
552  return exit;
553 }
void AddMessage(const char *format,...)
Definition: scrollview.cpp:567
#define TRUE
Definition: capi.h:45
ScrollView * image_win
Definition: pgedit.cpp:107
static void Exit()
Definition: scrollview.cpp:589
BOOL8 display_baselines
Definition: pgedit.cpp:126
BOOL8 word_set_display(PAGE_RES_IT *pr_it)
Definition: pgedit.cpp:946
bool recog_done
Definition: pgedit.cpp:118
void do_re_display(BOOL8(tesseract::Tesseract::*word_painter)(PAGE_RES_IT *pr_it))
Definition: pgedit.cpp:308
#define FALSE
Definition: capi.h:46
CMD_EVENTS mode
Definition: pgedit.cpp:116
Definition: werd.h:50
BITS16 word_display_mode
Definition: pgedit.cpp:122
void turn_on_bit(uinT8 bit_num)
Definition: bits16.h:37
PAGE_RES * current_page_res
Definition: pgedit.cpp:128
#define INT32FORMAT
Definition: host.h:115
bool recog_all_words(PAGE_RES *page_res, ETEXT_DESC *monitor, const TBOX *target_word_box, const char *word_config, int dopasses)
Definition: control.cpp:293
unsigned char BOOL8
Definition: host.h:113
Definition: werd.h:55
BOOL8 display_image
Definition: pgedit.cpp:124
Definition: werd.h:51
BOOL8 word_display(PAGE_RES_IT *pr_it)
Definition: pgedit.cpp:761
BOOL8 display_blocks
Definition: pgedit.cpp:125
void turn_off_bit(uinT8 bit_num)
Definition: bits16.h:42
char * ShowInputDialog(const char *msg)
Definition: scrollview.cpp:740
void tesseract::Tesseract::process_image_event ( const SVEvent event)

process_image_event()

User has done something in the image window - mouse down or up. Work out what it is and do something with it. If DOWN - just remember where it was. If UP - for each word in the selected area do the operation defined by the current mode.

Definition at line 565 of file pgedit.cpp.

566  {
567  // The following variable should remain static, since it is used by
568  // debug editor, which uses a single Tesseract instance.
569  static ICOORD down;
570  ICOORD up;
571  TBOX selection_box;
572  char msg[80];
573 
574  switch(event.type) {
575 
576  case SVET_SELECTION:
577  if (event.type == SVET_SELECTION) {
578  down.set_x(event.x + event.x_size);
579  down.set_y(event.y + event.y_size);
580  if (mode == SHOW_POINT_CMD_EVENT)
581  show_point(current_page_res, event.x, event.y);
582  }
583 
584  up.set_x(event.x);
585  up.set_y(event.y);
586 
587  selection_box = TBOX(down, up);
588 
589  switch(mode) {
593  selection_box,
595  break;
596  case DUMP_WERD_CMD_EVENT:
598  selection_box,
600  break;
603  selection_box,
605  break;
607  debug_word(current_page_res, selection_box);
608  break;
610  break; // ignore up event
611 
612  case RECOG_WERDS:
613  image_win->AddMessage("Recogging selected words");
615  selection_box,
617  break;
618  case RECOG_PSEUDO:
619  image_win->AddMessage("Recogging selected blobs");
620  recog_pseudo_word(current_page_res, selection_box);
621  break;
622  case SHOW_BLOB_FEATURES:
623  blob_feature_display(current_page_res, selection_box);
624  break;
625 
626  default:
627  sprintf(msg, "Mode %d not yet implemented", mode);
628  image_win->AddMessage(msg);
629  break;
630  }
631  default:
632  break;
633  }
634 }
void AddMessage(const char *format,...)
Definition: scrollview.cpp:567
ScrollView * image_win
Definition: pgedit.cpp:107
SVEventType type
Definition: scrollview.h:64
void show_point(PAGE_RES *page_res, float x, float y)
Definition: pgedit.cpp:655
int y
Definition: scrollview.h:67
void set_x(inT16 xin)
rewrite function
Definition: points.h:61
BOOL8 word_dumper(PAGE_RES_IT *pr_it)
Definition: pgedit.cpp:922
BOOL8 word_bln_display(PAGE_RES_IT *pr_it)
Definition: pgedit.cpp:729
Definition: rect.h:30
void process_selected_words(PAGE_RES *page_res, TBOX &selection_box, BOOL8(tesseract::Tesseract::*word_processor)(PAGE_RES_IT *pr_it))
Definition: pagewalk.cpp:30
CMD_EVENTS mode
Definition: pgedit.cpp:116
void blob_feature_display(PAGE_RES *page_res, const TBOX &selection_box)
Definition: pgedit.cpp:960
BOOL8 recog_interactive(PAGE_RES_IT *pr_it)
Definition: control.cpp:81
void set_y(inT16 yin)
rewrite function
Definition: points.h:65
PAGE_RES * current_page_res
Definition: pgedit.cpp:128
integer coordinate
Definition: points.h:30
BOOL8 word_blank_and_set_display(PAGE_RES_IT *pr_its)
Definition: pgedit.cpp:717
int x_size
Definition: scrollview.h:68
int y_size
Definition: scrollview.h:69
int x
Definition: scrollview.h:66
void debug_word(PAGE_RES *page_res, const TBOX &selection_box)
Definition: pgedit.cpp:641
void recog_pseudo_word(PAGE_RES *page_res, TBOX &selection_box)
Definition: control.cpp:66
void tesseract::Tesseract::process_selected_words ( PAGE_RES page_res,
TBOX selection_box,
BOOL8(tesseract::Tesseract::*)(PAGE_RES_IT *pr_it)  word_processor 
)

Definition at line 30 of file pagewalk.cpp.

33  {
34  for (PAGE_RES_IT page_res_it(page_res); page_res_it.word() != NULL;
35  page_res_it.forward()) {
36  WERD* word = page_res_it.word()->word;
37  if (word->bounding_box().overlap(selection_box)) {
38  if (!(this->*word_processor)(&page_res_it))
39  return;
40  }
41  }
42 }
bool overlap(const TBOX &box) const
Definition: rect.h:345
Definition: werd.h:60
WERD_RES * word() const
Definition: pageres.h:736
TBOX bounding_box() const
Definition: werd.cpp:160
bool tesseract::Tesseract::ProcessTargetWord ( const TBOX word_box,
const TBOX target_word_box,
const char *  word_config,
int  pass 
)

Definition at line 115 of file control.cpp.

118  {
119  if (word_config != NULL) {
120  if (word_box.major_overlap(target_word_box)) {
121  if (backup_config_file_ == NULL) {
122  backup_config_file_ = kBackUpConfigFile;
123  FILE* config_fp = fopen(backup_config_file_, "wb");
124  ParamUtils::PrintParams(config_fp, params());
125  fclose(config_fp);
126  ParamUtils::ReadParamsFile(word_config,
128  params());
129  }
130  } else {
131  if (backup_config_file_ != NULL) {
132  ParamUtils::ReadParamsFile(backup_config_file_,
134  params());
135  backup_config_file_ = NULL;
136  }
137  }
138  } else if (pass > 1 && !word_box.major_overlap(target_word_box)) {
139  return false;
140  }
141  return true;
142 }
static void PrintParams(FILE *fp, const ParamsVectors *member_params)
Definition: params.cpp:179
static bool ReadParamsFile(const char *file, SetParamConstraint constraint, ParamsVectors *member_params)
Definition: params.cpp:40
const char *const kBackUpConfigFile
Definition: control.cpp:53
ParamsVectors * params()
Definition: ccutil.h:63
bool major_overlap(const TBOX &box) const
Definition: rect.h:358
void tesseract::Tesseract::quality_based_rejection ( PAGE_RES_IT page_res_it,
BOOL8  good_quality_doc 
)

Definition at line 143 of file docqual.cpp.

144  {
145  if ((tessedit_good_quality_unrej && good_quality_doc))
146  unrej_good_quality_words(page_res_it);
147  doc_and_block_rejection(page_res_it, good_quality_doc);
148  if (unlv_tilde_crunching) {
149  tilde_crunch(page_res_it);
150  tilde_delete(page_res_it);
151  }
152 }
void doc_and_block_rejection(PAGE_RES_IT &page_res_it, BOOL8 good_quality_doc)
Definition: docqual.cpp:237
void tilde_crunch(PAGE_RES_IT &page_res_it)
Definition: docqual.cpp:422
void tilde_delete(PAGE_RES_IT &page_res_it)
Definition: docqual.cpp:594
void unrej_good_quality_words(PAGE_RES_IT &page_res_it)
Definition: docqual.cpp:165
void tesseract::Tesseract::read_config_file ( const char *  filename,
SetParamConstraint  constraint 
)

Definition at line 57 of file tessedit.cpp.

58  {
59  STRING path = datadir;
60  path += "configs/";
61  path += filename;
62  FILE* fp;
63  if ((fp = fopen(path.string(), "rb")) != NULL) {
64  fclose(fp);
65  } else {
66  path = datadir;
67  path += "tessconfigs/";
68  path += filename;
69  if ((fp = fopen(path.string(), "rb")) != NULL) {
70  fclose(fp);
71  } else {
72  path = filename;
73  }
74  }
75  ParamUtils::ReadParamsFile(path.string(), constraint, this->params());
76 }
static bool ReadParamsFile(const char *file, SetParamConstraint constraint, ParamsVectors *member_params)
Definition: params.cpp:40
Definition: strngs.h:44
STRING datadir
Definition: ccutil.h:65
ParamsVectors * params()
Definition: ccutil.h:63
const char * string() const
Definition: strngs.cpp:201
bool tesseract::Tesseract::ReassignDiacritics ( int  pass,
PAGE_RES_IT pr_it,
bool *  make_next_word_fuzzy 
)

Definition at line 916 of file control.cpp.

917  {
918  *make_next_word_fuzzy = false;
919  WERD* real_word = pr_it->word()->word;
920  if (real_word->rej_cblob_list()->empty() ||
921  real_word->cblob_list()->empty() ||
922  real_word->rej_cblob_list()->length() > noise_maxperword)
923  return false;
924  real_word->rej_cblob_list()->sort(&C_BLOB::SortByXMiddle);
925  // Get the noise outlines into a vector with matching bool map.
926  GenericVector<C_OUTLINE*> outlines;
927  real_word->GetNoiseOutlines(&outlines);
928  GenericVector<bool> word_wanted;
929  GenericVector<bool> overlapped_any_blob;
930  GenericVector<C_BLOB*> target_blobs;
931  AssignDiacriticsToOverlappingBlobs(outlines, pass, real_word, pr_it,
932  &word_wanted, &overlapped_any_blob,
933  &target_blobs);
934  // Filter the outlines that overlapped any blob and put them into the word
935  // now. This simplifies the remaining task and also makes it more accurate
936  // as it has more completed blobs to work on.
937  GenericVector<bool> wanted;
938  GenericVector<C_BLOB*> wanted_blobs;
939  GenericVector<C_OUTLINE*> wanted_outlines;
940  int num_overlapped = 0;
941  int num_overlapped_used = 0;
942  for (int i = 0; i < overlapped_any_blob.size(); ++i) {
943  if (overlapped_any_blob[i]) {
944  ++num_overlapped;
945  if (word_wanted[i]) ++num_overlapped_used;
946  wanted.push_back(word_wanted[i]);
947  wanted_blobs.push_back(target_blobs[i]);
948  wanted_outlines.push_back(outlines[i]);
949  outlines[i] = NULL;
950  }
951  }
952  real_word->AddSelectedOutlines(wanted, wanted_blobs, wanted_outlines, NULL);
953  AssignDiacriticsToNewBlobs(outlines, pass, real_word, pr_it, &word_wanted,
954  &target_blobs);
955  int non_overlapped = 0;
956  int non_overlapped_used = 0;
957  for (int i = 0; i < word_wanted.size(); ++i) {
958  if (word_wanted[i]) ++non_overlapped_used;
959  if (outlines[i] != NULL) ++non_overlapped_used;
960  }
961  if (debug_noise_removal) {
962  tprintf("Used %d/%d overlapped %d/%d non-overlaped diacritics on word:",
963  num_overlapped_used, num_overlapped, non_overlapped_used,
964  non_overlapped);
965  real_word->bounding_box().print();
966  }
967  // Now we have decided which outlines we want, put them into the real_word.
968  if (real_word->AddSelectedOutlines(word_wanted, target_blobs, outlines,
969  make_next_word_fuzzy)) {
970  pr_it->MakeCurrentWordFuzzy();
971  }
972  // TODO(rays) Parts of combos have a deep copy of the real word, and need
973  // to have their noise outlines moved/assigned in the same way!!
974  return num_overlapped_used != 0 || non_overlapped_used != 0;
975 }
static int SortByXMiddle(const void *v1, const void *v2)
Definition: stepblob.h:119
Definition: werd.h:60
WERD * word
Definition: pageres.h:175
WERD_RES * word() const
Definition: pageres.h:736
#define tprintf(...)
Definition: tprintf.h:31
int size() const
Definition: genericvector.h:72
TBOX bounding_box() const
Definition: werd.cpp:160
void MakeCurrentWordFuzzy()
Definition: pageres.cpp:1483
bool AddSelectedOutlines(const GenericVector< bool > &wanted, const GenericVector< C_BLOB * > &target_blobs, const GenericVector< C_OUTLINE * > &outlines, bool *make_next_word_fuzzy)
Definition: werd.cpp:548
void print() const
Definition: rect.h:270
void GetNoiseOutlines(GenericVector< C_OUTLINE * > *outlines)
Definition: werd.cpp:530
void AssignDiacriticsToOverlappingBlobs(const GenericVector< C_OUTLINE * > &outlines, int pass, WERD *real_word, PAGE_RES_IT *pr_it, GenericVector< bool > *word_wanted, GenericVector< bool > *overlapped_any_blob, GenericVector< C_BLOB * > *target_blobs)
Definition: control.cpp:982
int push_back(T object)
void AssignDiacriticsToNewBlobs(const GenericVector< C_OUTLINE * > &outlines, int pass, WERD *real_word, PAGE_RES_IT *pr_it, GenericVector< bool > *word_wanted, GenericVector< C_BLOB * > *target_blobs)
Definition: control.cpp:1035
C_BLOB_LIST * cblob_list()
Definition: werd.h:100
C_BLOB_LIST * rej_cblob_list()
Definition: werd.h:95
bool tesseract::Tesseract::recog_all_words ( PAGE_RES page_res,
ETEXT_DESC monitor,
const TBOX target_word_box,
const char *  word_config,
int  dopasses 
)

recog_all_words()

Walk the page_res, recognizing all the words. If monitor is not null, it is used as a progress monitor/timeout/cancel. If dopasses is 0, all recognition passes are run, 1 just pass 1, 2 passes2 and higher. If target_word_box is not null, special things are done to words that overlap the target_word_box: if word_config is not null, the word config file is read for just the target word(s), otherwise, on pass 2 and beyond ONLY the target words are processed (Jetsoft modification.) Returns false if we cancelled prematurely.

Parameters
page_respage structure
monitorprogress monitor
word_configword_config file
target_word_boxspecifies just to extract a rectangle
dopasses0 - all, 1 just pass 1, 2 passes 2 and higher

Definition at line 293 of file control.cpp.

297  {
298  PAGE_RES_IT page_res_it(page_res);
299 
301  tessedit_test_adaption.set_value (TRUE);
302  tessedit_minimal_rejection.set_value (TRUE);
303  }
304 
305  if (dopasses==0 || dopasses==1) {
306  page_res_it.restart_page();
307  // ****************** Pass 1 *******************
308 
309  // If the adaptive classifier is full switch to one we prepared earlier,
310  // ie on the previous page. If the current adaptive classifier is non-empty,
311  // prepare a backup starting at this page, in case it fills up. Do all this
312  // independently for each language.
313  if (AdaptiveClassifierIsFull()) {
315  } else if (!AdaptiveClassifierIsEmpty()) {
317  }
318  // Now check the sub-langs as well.
319  for (int i = 0; i < sub_langs_.size(); ++i) {
320  if (sub_langs_[i]->AdaptiveClassifierIsFull()) {
321  sub_langs_[i]->SwitchAdaptiveClassifier();
322  } else if (!sub_langs_[i]->AdaptiveClassifierIsEmpty()) {
323  sub_langs_[i]->StartBackupAdaptiveClassifier();
324  }
325  }
326  // Set up all words ready for recognition, so that if parallelism is on
327  // all the input and output classes are ready to run the classifier.
329  SetupAllWordsPassN(1, target_word_box, word_config, page_res, &words);
330  if (tessedit_parallelize) {
331  PrerecAllWordsPar(words);
332  }
333 
334  stats_.word_count = words.size();
335 
336  stats_.dict_words = 0;
337  stats_.doc_blob_quality = 0;
338  stats_.doc_outline_errs = 0;
339  stats_.doc_char_quality = 0;
340  stats_.good_char_count = 0;
341  stats_.doc_good_char_quality = 0;
342 
343  most_recently_used_ = this;
344  // Run pass 1 word recognition.
345  if (!RecogAllWordsPassN(1, monitor, &page_res_it, &words)) return false;
346  // Pass 1 post-processing.
347  for (page_res_it.restart_page(); page_res_it.word() != NULL;
348  page_res_it.forward()) {
349  if (page_res_it.word()->word->flag(W_REP_CHAR)) {
350  fix_rep_char(&page_res_it);
351  continue;
352  }
353 
354  // Count dict words.
355  if (page_res_it.word()->best_choice->permuter() == USER_DAWG_PERM)
356  ++(stats_.dict_words);
357 
358  // Update misadaption log (we only need to do it on pass 1, since
359  // adaption only happens on this pass).
360  if (page_res_it.word()->blamer_bundle != NULL &&
361  page_res_it.word()->blamer_bundle->misadaption_debug().length() > 0) {
362  page_res->misadaption_log.push_back(
363  page_res_it.word()->blamer_bundle->misadaption_debug());
364  }
365  }
366  }
367 
368  if (dopasses == 1) return true;
369 
370  // ****************** Pass 2 *******************
372  AnyTessLang()) {
373  page_res_it.restart_page();
375  SetupAllWordsPassN(2, target_word_box, word_config, page_res, &words);
376  if (tessedit_parallelize) {
377  PrerecAllWordsPar(words);
378  }
379  most_recently_used_ = this;
380  // Run pass 2 word recognition.
381  if (!RecogAllWordsPassN(2, monitor, &page_res_it, &words)) return false;
382  }
383 
384  // The next passes can only be run if tesseract has been used, as cube
385  // doesn't set all the necessary outputs in WERD_RES.
386  if (AnyTessLang()) {
387  // ****************** Pass 3 *******************
388  // Fix fuzzy spaces.
390 
393  fix_fuzzy_spaces(monitor, stats_.word_count, page_res);
394 
395  // ****************** Pass 4 *******************
398 
399  // ****************** Pass 5,6 *******************
400  rejection_passes(page_res, monitor, target_word_box, word_config);
401 
402 #ifndef NO_CUBE_BUILD
403  // ****************** Pass 7 *******************
404  // Cube combiner.
405  // If cube is loaded and its combiner is present, run it.
407  run_cube_combiner(page_res);
408  }
409 #endif
410 
411  // ****************** Pass 8 *******************
412  font_recognition_pass(page_res);
413 
414  // ****************** Pass 9 *******************
415  // Check the correctness of the final results.
416  blamer_pass(page_res);
417  script_pos_pass(page_res);
418  }
419 
420  // Write results pass.
422  // This is now redundant, but retained commented so show how to obtain
423  // bounding boxes and style information.
424 
425  // changed by jetsoft
426  // needed for dll to output memory structure
427  if ((dopasses == 0 || dopasses == 2) && (monitor || tessedit_write_unlv))
428  output_pass(page_res_it, target_word_box);
429  // end jetsoft
430  PageSegMode pageseg_mode = static_cast<PageSegMode>(
431  static_cast<int>(tessedit_pageseg_mode));
432  textord_.CleanupSingleRowResult(pageseg_mode, page_res);
433 
434  // Remove empty words, as these mess up the result iterators.
435  for (page_res_it.restart_page(); page_res_it.word() != NULL;
436  page_res_it.forward()) {
437  WERD_RES* word = page_res_it.word();
438  if (word->best_choice == NULL || word->best_choice->length() == 0)
439  page_res_it.DeleteCurrentWord();
440  }
441 
442  if (monitor != NULL) {
443  monitor->progress = 100;
444  }
445  return true;
446 }
void CleanupSingleRowResult(PageSegMode pageseg_mode, PAGE_RES *page_res)
Definition: textord.cpp:323
void dictionary_correction_pass(PAGE_RES *page_res)
Definition: control.cpp:2020
#define TRUE
Definition: capi.h:45
void run_cube_combiner(PAGE_RES *page_res)
GenericVector< STRING > misadaption_log
Definition: pageres.h:73
bool AdaptiveClassifierIsFull() const
Definition: classify.h:284
bool RecogAllWordsPassN(int pass_n, ETEXT_DESC *monitor, PAGE_RES_IT *pr_it, GenericVector< WordData > *words)
Definition: control.cpp:204
void fix_rep_char(PAGE_RES_IT *page_res_it)
Definition: control.cpp:1629
inT16 progress
chars in this buffer(0)
Definition: ocrclass.h:118
WERD * word
Definition: pageres.h:175
int length() const
Definition: ratngs.h:301
void fix_fuzzy_spaces(ETEXT_DESC *monitor, inT32 word_count, PAGE_RES *page_res)
Definition: fixspace.cpp:48
void output_pass(PAGE_RES_IT &page_res_it, const TBOX *target_word_box)
Definition: output.cpp:68
#define LOC_FUZZY_SPACE
Definition: errcode.h:50
void blamer_pass(PAGE_RES *page_res)
Definition: control.cpp:692
int size() const
Definition: genericvector.h:72
void set_global_loc_code(int loc_code)
Definition: globaloc.cpp:79
void bigram_correction_pass(PAGE_RES *page_res)
Definition: control.cpp:448
void SetupAllWordsPassN(int pass_n, const TBOX *target_word_box, const char *word_config, PAGE_RES *page_res, GenericVector< WordData > *words)
Definition: control.cpp:145
bool AnyTessLang() const
void SwitchAdaptiveClassifier()
Definition: adaptmatch.cpp:628
WERD_CHOICE * best_choice
Definition: pageres.h:219
bool AdaptiveClassifierIsEmpty() const
Definition: classify.h:285
int push_back(T object)
bool tessedit_enable_bigram_correction
void PrerecAllWordsPar(const GenericVector< WordData > &words)
Definition: par_control.cpp:36
bool right_to_left() const
#define LOC_WRITE_RESULTS
Definition: errcode.h:54
void StartBackupAdaptiveClassifier()
Definition: adaptmatch.cpp:644
void script_pos_pass(PAGE_RES *page_res)
Definition: control.cpp:716
void font_recognition_pass(PAGE_RES *page_res)
Definition: control.cpp:1963
void rejection_passes(PAGE_RES *page_res, ETEXT_DESC *monitor, const TBOX *target_word_box, const char *word_config)
Definition: control.cpp:596
BOOL8 tesseract::Tesseract::recog_interactive ( PAGE_RES_IT pr_it)

Recognize a single word in interactive mode.

Parameters
pr_itthe page results iterator

Definition at line 81 of file control.cpp.

81  {
82  inT16 char_qual;
83  inT16 good_char_qual;
84 
85  WordData word_data(*pr_it);
86  SetupWordPassN(2, &word_data);
87  classify_word_and_language(2, pr_it, &word_data);
89  WERD_RES* word_res = pr_it->word();
90  word_char_quality(word_res, pr_it->row()->row, &char_qual, &good_char_qual);
91  tprintf("\n%d chars; word_blob_quality: %d; outline_errs: %d; "
92  "char_quality: %d; good_char_quality: %d\n",
93  word_res->reject_map.length(),
94  word_blob_quality(word_res, pr_it->row()->row),
95  word_outline_errs(word_res), char_qual, good_char_qual);
96  }
97  return TRUE;
98 }
#define TRUE
Definition: capi.h:45
void classify_word_and_language(int pass_n, PAGE_RES_IT *pr_it, WordData *word_data)
Definition: control.cpp:1274
inT16 word_outline_errs(WERD_RES *word)
Definition: docqual.cpp:77
WERD_RES * word() const
Definition: pageres.h:736
#define tprintf(...)
Definition: tprintf.h:31
REJMAP reject_map
Definition: pageres.h:271
inT16 word_blob_quality(WERD_RES *word, ROW *row)
Definition: docqual.cpp:65
ROW_RES * row() const
Definition: pageres.h:739
short inT16
Definition: host.h:100
ROW * row
Definition: pageres.h:127
inT32 length() const
Definition: rejctmap.h:236
void word_char_quality(WERD_RES *word, ROW *row, inT16 *match_count, inT16 *accepted_match_count)
Definition: docqual.cpp:97
void SetupWordPassN(int pass_n, WordData *word)
Definition: control.cpp:168
void tesseract::Tesseract::recog_pseudo_word ( PAGE_RES page_res,
TBOX selection_box 
)

Definition at line 66 of file control.cpp.

67  {
68  PAGE_RES_IT* it = make_pseudo_word(page_res, selection_box);
69  if (it != NULL) {
71  it->DeleteCurrentWord();
72  delete it;
73  }
74 }
PAGE_RES_IT * make_pseudo_word(PAGE_RES *page_res, const TBOX &selection_box)
Definition: werdit.cpp:31
BOOL8 recog_interactive(PAGE_RES_IT *pr_it)
Definition: control.cpp:81
void DeleteCurrentWord()
Definition: pageres.cpp:1450
void tesseract::Tesseract::recog_training_segmented ( const STRING fname,
PAGE_RES page_res,
volatile ETEXT_DESC monitor,
FILE *  output_file 
)

Definition at line 79 of file recogtraining.cpp.

82  {
83  STRING box_fname = fname;
84  const char *lastdot = strrchr(box_fname.string(), '.');
85  if (lastdot != NULL) box_fname[lastdot - box_fname.string()] = '\0';
86  box_fname += ".box";
87  // ReadNextBox() will close box_file
88  FILE *box_file = open_file(box_fname.string(), "r");
89 
90  PAGE_RES_IT page_res_it;
91  page_res_it.page_res = page_res;
92  page_res_it.restart_page();
93  STRING label;
94 
95  // Process all the words on this page.
96  TBOX tbox; // tesseract-identified box
97  TBOX bbox; // box from the box file
98  bool keep_going;
99  int line_number = 0;
100  int examined_words = 0;
101  do {
102  keep_going = read_t(&page_res_it, &tbox);
103  keep_going &= ReadNextBox(applybox_page, &line_number, box_file, &label,
104  &bbox);
105  // Align bottom left points of the TBOXes.
106  while (keep_going &&
107  !NearlyEqual<int>(tbox.bottom(), bbox.bottom(), kMaxBoxEdgeDiff)) {
108  if (bbox.bottom() < tbox.bottom()) {
109  page_res_it.forward();
110  keep_going = read_t(&page_res_it, &tbox);
111  } else {
112  keep_going = ReadNextBox(applybox_page, &line_number, box_file, &label,
113  &bbox);
114  }
115  }
116  while (keep_going &&
117  !NearlyEqual<int>(tbox.left(), bbox.left(), kMaxBoxEdgeDiff)) {
118  if (bbox.left() > tbox.left()) {
119  page_res_it.forward();
120  keep_going = read_t(&page_res_it, &tbox);
121  } else {
122  keep_going = ReadNextBox(applybox_page, &line_number, box_file, &label,
123  &bbox);
124  }
125  }
126  // OCR the word if top right points of the TBOXes are similar.
127  if (keep_going &&
128  NearlyEqual<int>(tbox.right(), bbox.right(), kMaxBoxEdgeDiff) &&
129  NearlyEqual<int>(tbox.top(), bbox.top(), kMaxBoxEdgeDiff)) {
130  ambigs_classify_and_output(label.string(), &page_res_it, output_file);
131  examined_words++;
132  }
133  page_res_it.forward();
134  } while (keep_going);
135 
136  // Set up scripts on all of the words that did not get sent to
137  // ambigs_classify_and_output. They all should have, but if all the
138  // werd_res's don't get uch_sets, tesseract will crash when you try
139  // to iterate over them. :-(
140  int total_words = 0;
141  for (page_res_it.restart_page(); page_res_it.block() != NULL;
142  page_res_it.forward()) {
143  if (page_res_it.word()) {
144  if (page_res_it.word()->uch_set == NULL)
145  page_res_it.word()->SetupFake(unicharset);
146  total_words++;
147  }
148  }
149  if (examined_words < 0.85 * total_words) {
150  tprintf("TODO(antonova): clean up recog_training_segmented; "
151  " It examined only a small fraction of the ambigs image.\n");
152  }
153  tprintf("recog_training_segmented: examined %d / %d words.\n",
154  examined_words, total_words);
155 }
void ambigs_classify_and_output(const char *label, PAGE_RES_IT *pr_it, FILE *output_file)
inT16 bottom() const
Definition: rect.h:61
Definition: strngs.h:44
#define tprintf(...)
Definition: tprintf.h:31
Definition: rect.h:30
inT16 right() const
Definition: rect.h:75
inT16 left() const
Definition: rect.h:68
UNICHARSET unicharset
Definition: ccutil.h:70
bool read_t(PAGE_RES_IT *page_res_it, TBOX *tbox)
const inT16 kMaxBoxEdgeDiff
inT16 top() const
Definition: rect.h:54
FILE * open_file(const char *filename, const char *mode)
Definition: cutil.cpp:82
const char * string() const
Definition: strngs.cpp:201
PAGE_RES * page_res
Definition: pageres.h:661
bool ReadNextBox(int *line_number, FILE *box_file, STRING *utf8_str, TBOX *bounding_box)
Definition: boxread.cpp:117
void tesseract::Tesseract::recog_word ( WERD_RES word)

Definition at line 46 of file tfacepp.cpp.

46  {
47  if (wordrec_skip_no_truth_words && (word->blamer_bundle == NULL ||
49  if (classify_debug_level) tprintf("No truth for word - skipping\n");
50  word->tess_failed = true;
51  return;
52  }
55  word->SetupBoxWord();
56  if (word->best_choice->length() != word->box_word->length()) {
57  tprintf("recog_word ASSERT FAIL String:\"%s\"; "
58  "Strlen=%d; #Blobs=%d\n",
59  word->best_choice->debug_string().string(),
60  word->best_choice->length(), word->box_word->length());
61  }
62  ASSERT_HOST(word->best_choice->length() == word->box_word->length());
63  // Check that the ratings matrix size matches the sum of all the
64  // segmentation states.
65  if (!word->StatesAllValid()) {
66  tprintf("Not all words have valid states relative to ratings matrix!!");
67  word->DebugWordChoices(true, NULL);
68  ASSERT_HOST(word->StatesAllValid());
69  }
71  /* Override the permuter type if a straight dictionary check disagrees. */
72  uinT8 perm_type = word->best_choice->permuter();
73  if ((perm_type != SYSTEM_DAWG_PERM) &&
74  (perm_type != FREQ_DAWG_PERM) && (perm_type != USER_DAWG_PERM)) {
75  uinT8 real_dict_perm_type = dict_word(*word->best_choice);
76  if (((real_dict_perm_type == SYSTEM_DAWG_PERM) ||
77  (real_dict_perm_type == FREQ_DAWG_PERM) ||
78  (real_dict_perm_type == USER_DAWG_PERM)) &&
80  word->best_choice->unichar_lengths().string()) > 0)) {
81  word->best_choice->set_permuter(real_dict_perm_type); // use dict perm
82  }
83  }
85  perm_type != word->best_choice->permuter()) {
86  tprintf("Permuter Type Flipped from %d to %d\n",
87  perm_type, word->best_choice->permuter());
88  }
89  }
90  // Factored out from control.cpp
91  ASSERT_HOST((word->best_choice == NULL) == (word->raw_choice == NULL));
92  if (word->best_choice == NULL || word->best_choice->length() == 0 ||
93  static_cast<int>(strspn(word->best_choice->unichar_string().string(),
94  " ")) == word->best_choice->length()) {
95  word->tess_failed = true;
96  word->reject_map.initialise(word->box_word->length());
98  } else {
99  word->tess_failed = false;
100  }
101 }
inT16 alpha_count(const char *word, const char *word_lengths)
Definition: reject.cpp:495
bool wordrec_skip_no_truth_words
Definition: wordrec.h:166
GenericVector< TBLOB * > blobs
Definition: blobs.h:436
const STRING & unichar_lengths() const
Definition: ratngs.h:532
BlamerBundle * blamer_bundle
Definition: pageres.h:230
unsigned char uinT8
Definition: host.h:99
bool empty() const
Definition: genericvector.h:84
tesseract::BoxWord * box_word
Definition: pageres.h:250
WERD_CHOICE * raw_choice
Definition: pageres.h:224
int length() const
Definition: ratngs.h:301
const STRING debug_string() const
Definition: ratngs.h:503
#define tprintf(...)
Definition: tprintf.h:31
REJMAP reject_map
Definition: pageres.h:271
TWERD * chopped_word
Definition: pageres.h:201
void recog_word_recursive(WERD_RES *word)
Definition: tfacepp.cpp:110
BOOL8 tess_failed
Definition: pageres.h:272
const STRING & unichar_string() const
Definition: ratngs.h:525
int length() const
Definition: boxword.h:85
uinT8 permuter() const
Definition: ratngs.h:344
void set_permuter(uinT8 perm)
Definition: ratngs.h:373
void DebugWordChoices(bool debug, const char *word_to_debug)
Definition: pageres.cpp:471
WERD_CHOICE * best_choice
Definition: pageres.h:219
#define ASSERT_HOST(x)
Definition: errcode.h:84
const char * string() const
Definition: strngs.cpp:201
bool StatesAllValid()
Definition: pageres.cpp:449
void SetupBoxWord()
Definition: pageres.cpp:843
void rej_word_tess_failure()
Definition: rejctmap.cpp:425
IncorrectResultReason incorrect_result_reason() const
Definition: blamer.h:106
void initialise(inT16 length)
Definition: rejctmap.cpp:318
int dict_word(const WERD_CHOICE &word)
Definition: tface.cpp:128
void tesseract::Tesseract::recog_word_recursive ( WERD_RES word)

Definition at line 110 of file tfacepp.cpp.

110  {
111  int word_length = word->chopped_word->NumBlobs(); // no of blobs
112  if (word_length > MAX_UNDIVIDED_LENGTH) {
113  return split_and_recog_word(word);
114  }
115  cc_recog(word);
116  word_length = word->rebuild_word->NumBlobs(); // No of blobs in output.
117 
118  // Do sanity checks and minor fixes on best_choice.
119  if (word->best_choice->length() > word_length) {
120  word->best_choice->make_bad(); // should never happen
121  tprintf("recog_word: Discarded long string \"%s\""
122  " (%d characters vs %d blobs)\n",
123  word->best_choice->unichar_string().string(),
124  word->best_choice->length(), word_length);
125  tprintf("Word is at:");
126  word->word->bounding_box().print();
127  }
128  if (word->best_choice->length() < word_length) {
129  UNICHAR_ID space_id = unicharset.unichar_to_id(" ");
130  while (word->best_choice->length() < word_length) {
131  word->best_choice->append_unichar_id(space_id, 1, 0.0,
132  word->best_choice->certainty());
133  }
134  }
135 }
int UNICHAR_ID
Definition: unichar.h:33
void cc_recog(WERD_RES *word)
Definition: tface.cpp:113
void append_unichar_id(UNICHAR_ID unichar_id, int blob_count, float rating, float certainty)
Definition: ratngs.cpp:446
int NumBlobs() const
Definition: blobs.h:425
UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:194
void make_bad()
Set the fields in this choice to be default (bad) values.
Definition: ratngs.h:441
WERD * word
Definition: pageres.h:175
int length() const
Definition: ratngs.h:301
#define tprintf(...)
Definition: tprintf.h:31
TWERD * chopped_word
Definition: pageres.h:201
TBOX bounding_box() const
Definition: werd.cpp:160
const STRING & unichar_string() const
Definition: ratngs.h:525
void split_and_recog_word(WERD_RES *word)
Definition: tfacepp.cpp:144
UNICHARSET unicharset
Definition: ccutil.h:70
void print() const
Definition: rect.h:270
WERD_CHOICE * best_choice
Definition: pageres.h:219
#define MAX_UNDIVIDED_LENGTH
Definition: tfacepp.cpp:35
const char * string() const
Definition: strngs.cpp:201
float certainty() const
Definition: ratngs.h:328
TWERD * rebuild_word
Definition: pageres.h:244
bool tesseract::Tesseract::RecogAllWordsPassN ( int  pass_n,
ETEXT_DESC monitor,
PAGE_RES_IT pr_it,
GenericVector< WordData > *  words 
)

Definition at line 204 of file control.cpp.

206  {
207  // TODO(rays) Before this loop can be parallelized (it would yield a massive
208  // speed-up) all remaining member globals need to be converted to local/heap
209  // (eg set_pass1 and set_pass2) and an intermediate adaption pass needs to be
210  // added. The results will be significantly different with adaption on, and
211  // deterioration will need investigation.
212  pr_it->restart_page();
213  for (int w = 0; w < words->size(); ++w) {
214  WordData* word = &(*words)[w];
215  if (w > 0) word->prev_word = &(*words)[w - 1];
216  if (monitor != NULL) {
217  monitor->ocr_alive = TRUE;
218  if (pass_n == 1) {
219  monitor->progress = 70 * w / words->size();
220  if (monitor->progress_callback != NULL) {
221  TBOX box = pr_it->word()->word->bounding_box();
222  (*monitor->progress_callback)(monitor->progress, box.left(),
223  box.right(), box.top(), box.bottom());
224  }
225  } else {
226  monitor->progress = 70 + 30 * w / words->size();
227  if (monitor->progress_callback != NULL) {
228  (*monitor->progress_callback)(monitor->progress, 0, 0, 0, 0);
229  }
230  }
231  if (monitor->deadline_exceeded() ||
232  (monitor->cancel != NULL && (*monitor->cancel)(monitor->cancel_this,
233  words->size()))) {
234  // Timeout. Fake out the rest of the words.
235  for (; w < words->size(); ++w) {
236  (*words)[w].word->SetupFake(unicharset);
237  }
238  return false;
239  }
240  }
241  if (word->word->tess_failed) {
242  int s;
243  for (s = 0; s < word->lang_words.size() &&
244  word->lang_words[s]->tess_failed; ++s) {}
245  // If all are failed, skip it. Image words are skipped by this test.
246  if (s > word->lang_words.size()) continue;
247  }
248  // Sync pr_it with the wth WordData.
249  while (pr_it->word() != NULL && pr_it->word() != word->word)
250  pr_it->forward();
251  ASSERT_HOST(pr_it->word() != NULL);
252  bool make_next_word_fuzzy = false;
253  if (ReassignDiacritics(pass_n, pr_it, &make_next_word_fuzzy)) {
254  // Needs to be setup again to see the new outlines in the chopped_word.
255  SetupWordPassN(pass_n, word);
256  }
257 
258  classify_word_and_language(pass_n, pr_it, word);
260  tprintf("Pass%d: %s [%s]\n", pass_n,
261  word->word->best_choice->unichar_string().string(),
262  word->word->best_choice->debug_string().string());
263  }
264  pr_it->forward();
265  if (make_next_word_fuzzy && pr_it->word() != NULL) {
266  pr_it->MakeCurrentWordFuzzy();
267  }
268  }
269  return true;
270 }
void * cancel_this
called whenever progress increases
Definition: ocrclass.h:127
#define TRUE
Definition: capi.h:45
inT16 bottom() const
Definition: rect.h:61
void classify_word_and_language(int pass_n, PAGE_RES_IT *pr_it, WordData *word_data)
Definition: control.cpp:1274
volatile inT8 ocr_alive
true if not last
Definition: ocrclass.h:123
bool deadline_exceeded() const
Definition: ocrclass.h:158
inT16 progress
chars in this buffer(0)
Definition: ocrclass.h:118
WERD * word
Definition: pageres.h:175
WERD_RES * word() const
Definition: pageres.h:736
WERD_RES * forward()
Definition: pageres.h:716
#define tprintf(...)
Definition: tprintf.h:31
bool ReassignDiacritics(int pass, PAGE_RES_IT *pr_it, bool *make_next_word_fuzzy)
Definition: control.cpp:916
int size() const
Definition: genericvector.h:72
TBOX bounding_box() const
Definition: werd.cpp:160
Definition: rect.h:30
inT16 right() const
Definition: rect.h:75
WERD_RES * restart_page()
Definition: pageres.h:683
void MakeCurrentWordFuzzy()
Definition: pageres.cpp:1483
inT16 left() const
Definition: rect.h:68
UNICHARSET unicharset
Definition: ccutil.h:70
CANCEL_FUNC cancel
for errcode use
Definition: ocrclass.h:125
inT16 top() const
Definition: rect.h:54
#define ASSERT_HOST(x)
Definition: errcode.h:84
PROGRESS_FUNC progress_callback
returns true to cancel
Definition: ocrclass.h:126
void SetupWordPassN(int pass_n, WordData *word)
Definition: control.cpp:168
void tesseract::Tesseract::recognize_page ( STRING image_name)
void tesseract::Tesseract::reject_edge_blobs ( WERD_RES word)

Definition at line 263 of file reject.cpp.

263  {
264  TBOX word_box = word->word->bounding_box();
265  // Use the box_word as it is already denormed back to image coordinates.
266  int blobcount = word->box_word->length();
267 
268  if (word_box.left() < tessedit_image_border ||
269  word_box.bottom() < tessedit_image_border ||
270  word_box.right() + tessedit_image_border > ImageWidth() - 1 ||
271  word_box.top() + tessedit_image_border > ImageHeight() - 1) {
272  ASSERT_HOST(word->reject_map.length() == blobcount);
273  for (int blobindex = 0; blobindex < blobcount; blobindex++) {
274  TBOX blob_box = word->box_word->BlobBox(blobindex);
275  if (blob_box.left() < tessedit_image_border ||
276  blob_box.bottom() < tessedit_image_border ||
277  blob_box.right() + tessedit_image_border > ImageWidth() - 1 ||
278  blob_box.top() + tessedit_image_border > ImageHeight() - 1) {
279  word->reject_map[blobindex].setrej_edge_char();
280  // Close to edge
281  }
282  }
283  }
284 }
inT16 bottom() const
Definition: rect.h:61
WERD * word
Definition: pageres.h:175
tesseract::BoxWord * box_word
Definition: pageres.h:250
REJMAP reject_map
Definition: pageres.h:271
const TBOX & BlobBox(int index) const
Definition: boxword.h:86
TBOX bounding_box() const
Definition: werd.cpp:160
Definition: rect.h:30
inT16 right() const
Definition: rect.h:75
int length() const
Definition: boxword.h:85
inT16 left() const
Definition: rect.h:68
inT32 length() const
Definition: rejctmap.h:236
inT16 top() const
Definition: rect.h:54
#define ASSERT_HOST(x)
Definition: errcode.h:84
int ImageWidth() const
int ImageHeight() const
void tesseract::Tesseract::reject_I_1_L ( WERD_RES word)

Definition at line 191 of file reject.cpp.

191  {
192  inT16 i;
193  inT16 offset;
194 
195  for (i = 0, offset = 0; word->best_choice->unichar_string()[offset] != '\0';
196  offset += word->best_choice->unichar_lengths()[i], i += 1) {
198  contains (word->best_choice->unichar_string()[offset])) {
199  //rej 1Il conflict
200  word->reject_map[i].setrej_1Il_conflict ();
201  }
202  }
203 }
Definition: strngs.h:44
const STRING & unichar_lengths() const
Definition: ratngs.h:532
REJMAP reject_map
Definition: pageres.h:271
const STRING & unichar_string() const
Definition: ratngs.h:525
short inT16
Definition: host.h:100
WERD_CHOICE * best_choice
Definition: pageres.h:219
void tesseract::Tesseract::reject_mostly_rejects ( WERD_RES word)

Definition at line 573 of file reject.cpp.

573  {
574  /* Reject the whole of the word if the fraction of rejects exceeds a limit */
575 
576  if ((float) word->reject_map.reject_count() / word->reject_map.length() >=
579 }
void rej_word_mostly_rej()
Definition: rejctmap.cpp:479
double rej_whole_of_mostly_reject_word_fract
REJMAP reject_map
Definition: pageres.h:271
inT32 length() const
Definition: rejctmap.h:236
inT16 reject_count()
Definition: rejctmap.h:242
void tesseract::Tesseract::rejection_passes ( PAGE_RES page_res,
ETEXT_DESC monitor,
const TBOX target_word_box,
const char *  word_config 
)

Definition at line 596 of file control.cpp.

599  {
600  PAGE_RES_IT page_res_it(page_res);
601  // ****************** Pass 5 *******************
602  // Gather statistics on rejects.
603  int word_index = 0;
604  while (!tessedit_test_adaption && page_res_it.word() != NULL) {
606  WERD_RES* word = page_res_it.word();
607  word_index++;
608  if (monitor != NULL) {
609  monitor->ocr_alive = TRUE;
610  monitor->progress = 95 + 5 * word_index / stats_.word_count;
611  }
612  if (word->rebuild_word == NULL) {
613  // Word was not processed by tesseract.
614  page_res_it.forward();
615  continue;
616  }
617  check_debug_pt(word, 70);
618 
619  // changed by jetsoft
620  // specific to its needs to extract one word when need
621  if (target_word_box &&
623  *target_word_box, word_config, 4)) {
624  page_res_it.forward();
625  continue;
626  }
627  // end jetsoft
628 
629  page_res_it.rej_stat_word();
630  int chars_in_word = word->reject_map.length();
631  int rejects_in_word = word->reject_map.reject_count();
632 
633  int blob_quality = word_blob_quality(word, page_res_it.row()->row);
634  stats_.doc_blob_quality += blob_quality;
635  int outline_errs = word_outline_errs(word);
636  stats_.doc_outline_errs += outline_errs;
637  inT16 all_char_quality;
638  inT16 accepted_all_char_quality;
639  word_char_quality(word, page_res_it.row()->row,
640  &all_char_quality, &accepted_all_char_quality);
641  stats_.doc_char_quality += all_char_quality;
642  uinT8 permuter_type = word->best_choice->permuter();
643  if ((permuter_type == SYSTEM_DAWG_PERM) ||
644  (permuter_type == FREQ_DAWG_PERM) ||
645  (permuter_type == USER_DAWG_PERM)) {
646  stats_.good_char_count += chars_in_word - rejects_in_word;
647  stats_.doc_good_char_quality += accepted_all_char_quality;
648  }
649  check_debug_pt(word, 80);
651  (blob_quality == 0) && (outline_errs >= chars_in_word))
653  check_debug_pt(word, 90);
654  page_res_it.forward();
655  }
656 
658  tprintf
659  ("QUALITY: num_chs= %d num_rejs= %d %5.3f blob_qual= %d %5.3f"
660  " outline_errs= %d %5.3f char_qual= %d %5.3f good_ch_qual= %d %5.3f\n",
661  page_res->char_count, page_res->rej_count,
662  page_res->rej_count / static_cast<float>(page_res->char_count),
663  stats_.doc_blob_quality,
664  stats_.doc_blob_quality / static_cast<float>(page_res->char_count),
665  stats_.doc_outline_errs,
666  stats_.doc_outline_errs / static_cast<float>(page_res->char_count),
667  stats_.doc_char_quality,
668  stats_.doc_char_quality / static_cast<float>(page_res->char_count),
669  stats_.doc_good_char_quality,
670  (stats_.good_char_count > 0) ?
671  (stats_.doc_good_char_quality /
672  static_cast<float>(stats_.good_char_count)) : 0.0);
673  }
674  BOOL8 good_quality_doc =
675  ((page_res->rej_count / static_cast<float>(page_res->char_count)) <=
676  quality_rej_pc) &&
677  (stats_.doc_blob_quality / static_cast<float>(page_res->char_count) >=
678  quality_blob_pc) &&
679  (stats_.doc_outline_errs / static_cast<float>(page_res->char_count) <=
681  (stats_.doc_char_quality / static_cast<float>(page_res->char_count) >=
683 
684  // ****************** Pass 6 *******************
685  // Do whole document or whole block rejection pass
686  if (!tessedit_test_adaption) {
688  quality_based_rejection(page_res_it, good_quality_doc);
689  }
690 }
#define TRUE
Definition: capi.h:45
void quality_based_rejection(PAGE_RES_IT &page_res_it, BOOL8 good_quality_doc)
Definition: docqual.cpp:143
volatile inT8 ocr_alive
true if not last
Definition: ocrclass.h:123
unsigned char uinT8
Definition: host.h:99
inT16 word_outline_errs(WERD_RES *word)
Definition: docqual.cpp:77
inT16 progress
chars in this buffer(0)
Definition: ocrclass.h:118
WERD * word
Definition: pageres.h:175
inT32 rej_count
Definition: pageres.h:61
#define tprintf(...)
Definition: tprintf.h:31
REJMAP reject_map
Definition: pageres.h:271
BOOL8 check_debug_pt(WERD_RES *word, int location)
Definition: control.cpp:1772
inT16 word_blob_quality(WERD_RES *word, ROW *row)
Definition: docqual.cpp:65
TBOX bounding_box() const
Definition: werd.cpp:160
void set_global_loc_code(int loc_code)
Definition: globaloc.cpp:79
#define LOC_MM_ADAPT
Definition: errcode.h:52
short inT16
Definition: host.h:100
inT32 char_count
Definition: pageres.h:60
inT32 length() const
Definition: rejctmap.h:236
uinT8 permuter() const
Definition: ratngs.h:344
#define LOC_DOC_BLK_REJ
Definition: errcode.h:53
WERD_CHOICE * best_choice
Definition: pageres.h:219
void word_char_quality(WERD_RES *word, ROW *row, inT16 *match_count, inT16 *accepted_match_count)
Definition: docqual.cpp:97
unsigned char BOOL8
Definition: host.h:113
inT16 reject_count()
Definition: rejctmap.h:242
TWERD * rebuild_word
Definition: pageres.h:244
bool ProcessTargetWord(const TBOX &word_box, const TBOX &target_word_box, const char *word_config, int pass)
Definition: control.cpp:115
void rej_word_bad_quality()
Definition: rejctmap.cpp:488
BOOL8 tesseract::Tesseract::repeated_nonalphanum_wd ( WERD_RES word,
ROW row 
)

Definition at line 582 of file reject.cpp.

582  {
583  inT16 char_quality;
584  inT16 accepted_char_quality;
585 
586  if (word->best_choice->unichar_lengths().length() <= 1)
587  return FALSE;
588 
590  contains(word->best_choice->unichar_string()[0]))
591  return FALSE;
592 
593  UNICHAR_ID uch_id = word->best_choice->unichar_id(0);
594  for (int i = 1; i < word->best_choice->length(); ++i) {
595  if (word->best_choice->unichar_id(i) != uch_id) return FALSE;
596  }
597 
598  word_char_quality(word, row, &char_quality, &accepted_char_quality);
599 
600  if ((word->best_choice->unichar_lengths().length () == char_quality) &&
601  (char_quality == accepted_char_quality))
602  return TRUE;
603  else
604  return FALSE;
605 }
int UNICHAR_ID
Definition: unichar.h:33
#define TRUE
Definition: capi.h:45
Definition: strngs.h:44
const STRING & unichar_lengths() const
Definition: ratngs.h:532
char * ok_repeated_ch_non_alphanum_wds
UNICHAR_ID unichar_id(int index) const
Definition: ratngs.h:313
int length() const
Definition: ratngs.h:301
#define FALSE
Definition: capi.h:46
const STRING & unichar_string() const
Definition: ratngs.h:525
short inT16
Definition: host.h:100
inT32 length() const
Definition: strngs.cpp:196
WERD_CHOICE * best_choice
Definition: pageres.h:219
void word_char_quality(WERD_RES *word, ROW *row, inT16 *match_count, inT16 *accepted_match_count)
Definition: docqual.cpp:97
void tesseract::Tesseract::ReportFailedBox ( int  boxfile_lineno,
TBOX  box,
const char *  box_ch,
const char *  err_msg 
)

Logs a bad box by line in the box file and box coords.

Definition at line 764 of file applybox.cpp.

765  {
766  tprintf("APPLY_BOXES: boxfile line %d/%s ((%d,%d),(%d,%d)): %s\n",
767  boxfile_lineno + 1, box_ch,
768  box.left(), box.bottom(), box.right(), box.top(), err_msg);
769 }
inT16 bottom() const
Definition: rect.h:61
#define tprintf(...)
Definition: tprintf.h:31
inT16 right() const
Definition: rect.h:75
inT16 left() const
Definition: rect.h:68
inT16 top() const
Definition: rect.h:54
void tesseract::Tesseract::ReportXhtFixResult ( bool  accept_new_word,
float  new_x_ht,
WERD_RES word,
WERD_RES new_word 
)

Definition at line 1387 of file control.cpp.

1388  {
1389  tprintf("New XHT Match:%s = %s ",
1390  word->best_choice->unichar_string().string(),
1391  word->best_choice->debug_string().string());
1392  word->reject_map.print(debug_fp);
1393  tprintf(" -> %s = %s ",
1394  new_word->best_choice->unichar_string().string(),
1395  new_word->best_choice->debug_string().string());
1396  new_word->reject_map.print(debug_fp);
1397  tprintf(" %s->%s %s %s\n",
1398  word->guessed_x_ht ? "GUESS" : "CERT",
1399  new_word->guessed_x_ht ? "GUESS" : "CERT",
1400  new_x_ht > 0.1 ? "STILL DOUBT" : "OK",
1401  accept_new_word ? "ACCEPTED" : "");
1402 }
FILE * debug_fp
Definition: tessvars.cpp:24
const STRING debug_string() const
Definition: ratngs.h:503
#define tprintf(...)
Definition: tprintf.h:31
REJMAP reject_map
Definition: pageres.h:271
const STRING & unichar_string() const
Definition: ratngs.h:525
void print(FILE *fp)
Definition: rejctmap.cpp:394
WERD_CHOICE * best_choice
Definition: pageres.h:219
BOOL8 guessed_x_ht
Definition: pageres.h:292
const char * string() const
Definition: strngs.cpp:201
void tesseract::Tesseract::ReSegmentByClassification ( PAGE_RES page_res)

Resegments the words by running the classifier in an attempt to find the correct segmentation that produces the required string.

Definition at line 509 of file applybox.cpp.

509  {
510  PAGE_RES_IT pr_it(page_res);
511  WERD_RES* word_res;
512  for (; (word_res = pr_it.word()) != NULL; pr_it.forward()) {
513  WERD* word = word_res->word;
514  if (word->text() == NULL || word->text()[0] == '\0')
515  continue; // Ignore words that have no text.
516  // Convert the correct text to a vector of UNICHAR_ID
517  GenericVector<UNICHAR_ID> target_text;
518  if (!ConvertStringToUnichars(word->text(), &target_text)) {
519  tprintf("APPLY_BOX: FAILURE: can't find class_id for '%s'\n",
520  word->text());
521  pr_it.DeleteCurrentWord();
522  continue;
523  }
524  if (!FindSegmentation(target_text, word_res)) {
525  tprintf("APPLY_BOX: FAILURE: can't find segmentation for '%s'\n",
526  word->text());
527  pr_it.DeleteCurrentWord();
528  continue;
529  }
530  }
531 }
const char * text() const
Definition: werd.h:125
Definition: werd.h:60
WERD * word
Definition: pageres.h:175
#define tprintf(...)
Definition: tprintf.h:31
bool FindSegmentation(const GenericVector< UNICHAR_ID > &target_text, WERD_RES *word_res)
Definition: applybox.cpp:559
bool ConvertStringToUnichars(const char *utf8, GenericVector< UNICHAR_ID > *class_ids)
Definition: applybox.cpp:535
bool tesseract::Tesseract::ResegmentCharBox ( PAGE_RES page_res,
const TBOX prev_box,
const TBOX box,
const TBOX next_box,
const char *  correct_text 
)

Gather consecutive blobs that match the given box into the best_state and corresponding correct_text.

Fights over which box owns which blobs are settled by pre-chopping and applying the blobs to box or next_box with the least non-overlap.

Returns
false if the box was in error, which can only be caused by failing to find an appropriate blob for a box.

This means that occasionally, blobs may be incorrectly segmented if the chopper fails to find a suitable chop point.

Definition at line 340 of file applybox.cpp.

342  {
343  if (applybox_debug > 1) {
344  tprintf("\nAPPLY_BOX: in ResegmentCharBox() for %s\n", correct_text);
345  }
346  PAGE_RES_IT page_res_it(page_res);
347  WERD_RES* word_res;
348  for (word_res = page_res_it.word(); word_res != NULL;
349  word_res = page_res_it.forward()) {
350  if (!word_res->box_word->bounding_box().major_overlap(box))
351  continue;
352  if (applybox_debug > 1) {
353  tprintf("Checking word box:");
354  word_res->box_word->bounding_box().print();
355  }
356  int word_len = word_res->box_word->length();
357  for (int i = 0; i < word_len; ++i) {
358  TBOX char_box = TBOX();
359  int blob_count = 0;
360  for (blob_count = 0; i + blob_count < word_len; ++blob_count) {
361  TBOX blob_box = word_res->box_word->BlobBox(i + blob_count);
362  if (!blob_box.major_overlap(box))
363  break;
364  if (word_res->correct_text[i + blob_count].length() > 0)
365  break; // Blob is claimed already.
366  double current_box_miss_metric = BoxMissMetric(blob_box, box);
367  double next_box_miss_metric = BoxMissMetric(blob_box, next_box);
368  if (applybox_debug > 2) {
369  tprintf("Checking blob:");
370  blob_box.print();
371  tprintf("Current miss metric = %g, next = %g\n",
372  current_box_miss_metric, next_box_miss_metric);
373  }
374  if (current_box_miss_metric > next_box_miss_metric)
375  break; // Blob is a better match for next box.
376  char_box += blob_box;
377  }
378  if (blob_count > 0) {
379  if (applybox_debug > 1) {
380  tprintf("Index [%d, %d) seem good.\n", i, i + blob_count);
381  }
382  if (!char_box.almost_equal(box, 3) &&
383  (box.x_gap(next_box) < -3 ||
384  (prev_box != NULL && prev_box->x_gap(box) < -3))) {
385  return false;
386  }
387  // We refine just the box_word, best_state and correct_text here.
388  // The rebuild_word is made in TidyUp.
389  // blob_count blobs are put together to match the box. Merge the
390  // box_word boxes, save the blob_count in the state and the text.
391  word_res->box_word->MergeBoxes(i, i + blob_count);
392  word_res->best_state[i] = blob_count;
393  word_res->correct_text[i] = correct_text;
394  if (applybox_debug > 2) {
395  tprintf("%d Blobs match: blob box:", blob_count);
396  word_res->box_word->BlobBox(i).print();
397  tprintf("Matches box:");
398  box.print();
399  tprintf("With next box:");
400  next_box.print();
401  }
402  // Eliminated best_state and correct_text entries for the consumed
403  // blobs.
404  for (int j = 1; j < blob_count; ++j) {
405  word_res->best_state.remove(i + 1);
406  word_res->correct_text.remove(i + 1);
407  }
408  // Assume that no box spans multiple source words, so we are done with
409  // this box.
410  if (applybox_debug > 1) {
411  tprintf("Best state = ");
412  for (int j = 0; j < word_res->best_state.size(); ++j) {
413  tprintf("%d ", word_res->best_state[j]);
414  }
415  tprintf("\n");
416  tprintf("Correct text = [[ ");
417  for (int j = 0; j < word_res->correct_text.size(); ++j) {
418  tprintf("%s ", word_res->correct_text[j].string());
419  }
420  tprintf("]]\n");
421  }
422  return true;
423  }
424  }
425  }
426  if (applybox_debug > 0) {
427  tprintf("FAIL!\n");
428  }
429  return false; // Failure.
430 }
WERD * word
Definition: pageres.h:175
tesseract::BoxWord * box_word
Definition: pageres.h:250
void MergeBoxes(int start, int end)
Definition: boxword.cpp:134
GenericVector< int > best_state
Definition: pageres.h:255
#define tprintf(...)
Definition: tprintf.h:31
const TBOX & BlobBox(int index) const
Definition: boxword.h:86
int size() const
Definition: genericvector.h:72
Definition: rect.h:30
int length() const
Definition: boxword.h:85
void print() const
Definition: rect.h:270
void remove(int index)
bool major_overlap(const TBOX &box) const
Definition: rect.h:358
GenericVector< STRING > correct_text
Definition: pageres.h:259
int x_gap(const TBOX &box) const
Definition: rect.h:217
int length() const
Definition: genericvector.h:79
bool almost_equal(const TBOX &box, int tolerance) const
Definition: rect.cpp:258
const TBOX & bounding_box() const
Definition: boxword.h:82
bool tesseract::Tesseract::ResegmentWordBox ( BLOCK_LIST *  block_list,
const TBOX box,
const TBOX next_box,
const char *  correct_text 
)

Consume all source blobs that strongly overlap the given box, putting them into a new word, with the correct_text label. Fights over which box owns which blobs are settled by applying the blobs to box or next_box with the least non-overlap.

Returns
false if the box was in error, which can only be caused by failing to find an overlapping blob for a box.

Definition at line 438 of file applybox.cpp.

440  {
441  if (applybox_debug > 1) {
442  tprintf("\nAPPLY_BOX: in ResegmentWordBox() for %s\n", correct_text);
443  }
444  WERD* new_word = NULL;
445  BLOCK_IT b_it(block_list);
446  for (b_it.mark_cycle_pt(); !b_it.cycled_list(); b_it.forward()) {
447  BLOCK* block = b_it.data();
448  if (!box.major_overlap(block->bounding_box()))
449  continue;
450  ROW_IT r_it(block->row_list());
451  for (r_it.mark_cycle_pt(); !r_it.cycled_list(); r_it.forward()) {
452  ROW* row = r_it.data();
453  if (!box.major_overlap(row->bounding_box()))
454  continue;
455  WERD_IT w_it(row->word_list());
456  for (w_it.mark_cycle_pt(); !w_it.cycled_list(); w_it.forward()) {
457  WERD* word = w_it.data();
458  if (applybox_debug > 2) {
459  tprintf("Checking word:");
460  word->bounding_box().print();
461  }
462  if (word->text() != NULL && word->text()[0] != '\0')
463  continue; // Ignore words that are already done.
464  if (!box.major_overlap(word->bounding_box()))
465  continue;
466  C_BLOB_IT blob_it(word->cblob_list());
467  for (blob_it.mark_cycle_pt(); !blob_it.cycled_list();
468  blob_it.forward()) {
469  C_BLOB* blob = blob_it.data();
470  TBOX blob_box = blob->bounding_box();
471  if (!blob_box.major_overlap(box))
472  continue;
473  double current_box_miss_metric = BoxMissMetric(blob_box, box);
474  double next_box_miss_metric = BoxMissMetric(blob_box, next_box);
475  if (applybox_debug > 2) {
476  tprintf("Checking blob:");
477  blob_box.print();
478  tprintf("Current miss metric = %g, next = %g\n",
479  current_box_miss_metric, next_box_miss_metric);
480  }
481  if (current_box_miss_metric > next_box_miss_metric)
482  continue; // Blob is a better match for next box.
483  if (applybox_debug > 2) {
484  tprintf("Blob match: blob:");
485  blob_box.print();
486  tprintf("Matches box:");
487  box.print();
488  tprintf("With next box:");
489  next_box.print();
490  }
491  if (new_word == NULL) {
492  // Make a new word with a single blob.
493  new_word = word->shallow_copy();
494  new_word->set_text(correct_text);
495  w_it.add_to_end(new_word);
496  }
497  C_BLOB_IT new_blob_it(new_word->cblob_list());
498  new_blob_it.add_to_end(blob_it.extract());
499  }
500  }
501  }
502  }
503  if (new_word == NULL && applybox_debug > 0) tprintf("FAIL!\n");
504  return new_word != NULL;
505 }
TBOX bounding_box() const
Definition: stepblob.cpp:250
const char * text() const
Definition: werd.h:125
ROW_LIST * row_list()
get rows
Definition: ocrblock.h:120
Definition: ocrrow.h:32
Definition: werd.h:60
WERD_LIST * word_list()
Definition: ocrrow.h:52
TBOX bounding_box() const
Definition: ocrrow.h:85
#define tprintf(...)
Definition: tprintf.h:31
TBOX bounding_box() const
Definition: werd.cpp:160
Definition: rect.h:30
void bounding_box(ICOORD &bottom_left, ICOORD &top_right) const
get box
Definition: pdblock.h:59
void print() const
Definition: rect.h:270
bool major_overlap(const TBOX &box) const
Definition: rect.h:358
WERD * shallow_copy()
Definition: werd.cpp:352
Definition: ocrblock.h:30
C_BLOB_LIST * cblob_list()
Definition: werd.h:100
void set_text(const char *new_text)
Definition: werd.h:126
void tesseract::Tesseract::ResetAdaptiveClassifier ( )

Definition at line 664 of file tesseractclass.cpp.

664  {
666  for (int i = 0; i < sub_langs_.size(); ++i) {
667  sub_langs_[i]->ResetAdaptiveClassifierInternal();
668  }
669 }
void ResetAdaptiveClassifierInternal()
Definition: adaptmatch.cpp:613
void tesseract::Tesseract::ResetDocumentDictionary ( )

Definition at line 672 of file tesseractclass.cpp.

672  {
674  for (int i = 0; i < sub_langs_.size(); ++i) {
675  sub_langs_[i]->getDict().ResetDocumentDictionary();
676  }
677 }
void ResetDocumentDictionary()
Definition: dict.h:308
Dict & getDict()
Definition: classify.h:65
const FCOORD& tesseract::Tesseract::reskew ( ) const
inline

Definition at line 187 of file tesseractclass.h.

187  {
188  return reskew_;
189  }
int tesseract::Tesseract::RetryWithLanguage ( const WordData word_data,
WordRecognizer  recognizer,
WERD_RES **  in_word,
PointerVector< WERD_RES > *  best_words 
)

Definition at line 875 of file control.cpp.

878  {
879  bool debug = classify_debug_level || cube_debug_level;
880  if (debug) {
881  tprintf("Trying word using lang %s, oem %d\n",
882  lang.string(), static_cast<int>(tessedit_ocr_engine_mode));
883  }
884  // Run the recognizer on the word.
885  PointerVector<WERD_RES> new_words;
886  (this->*recognizer)(word_data, in_word, &new_words);
887  if (new_words.empty()) {
888  // Transfer input word to new_words, as the classifier must have put
889  // the result back in the input.
890  new_words.push_back(*in_word);
891  *in_word = NULL;
892  }
893  if (debug) {
894  for (int i = 0; i < new_words.size(); ++i)
895  new_words[i]->DebugTopChoice("Lang result");
896  }
897  // Initial version is a bit of a hack based on better certainty and rating
898  // (to reduce false positives from cube) or a dictionary vs non-dictionary
899  // word.
900  return SelectBestWords(classify_max_rating_ratio,
902  debug, &new_words, best_words);
903 }
STRING lang
Definition: ccutil.h:67
#define tprintf(...)
Definition: tprintf.h:31
double classify_max_rating_ratio
Definition: classify.h:402
double classify_max_certainty_margin
Definition: classify.h:404
const char * string() const
Definition: strngs.cpp:201
bool tesseract::Tesseract::right_to_left ( ) const
inline

Definition at line 252 of file tesseractclass.h.

252  {
253  return right_to_left_;
254  }
void tesseract::Tesseract::run_cube_combiner ( PAGE_RES page_res)

Definition at line 201 of file cube_control.cpp.

201  {
202  if (page_res == NULL || tess_cube_combiner_ == NULL)
203  return;
204  PAGE_RES_IT page_res_it(page_res);
205  // Iterate through the word results and call cube on each word.
206  for (page_res_it.restart_page(); page_res_it.word () != NULL;
207  page_res_it.forward()) {
208  BLOCK* block = page_res_it.block()->block;
209  if (block->poly_block() != NULL && !block->poly_block()->IsText())
210  continue; // Don't deal with non-text blocks.
211  WERD_RES* word = page_res_it.word();
212  // Skip cube entirely if tesseract's certainty is greater than threshold.
213  int combiner_run_thresh = convert_prob_to_tess_certainty(
214  cube_cntxt_->Params()->CombinerRunThresh());
215  if (word->best_choice->certainty() >= combiner_run_thresh) {
216  continue;
217  }
218  // Use the same language as Tesseract used for the word.
219  Tesseract* lang_tess = word->tesseract;
220 
221  // Setup a trial WERD_RES in which to classify with cube.
222  WERD_RES cube_word;
223  cube_word.InitForRetryRecognition(*word);
224  cube_word.SetupForRecognition(lang_tess->unicharset, this, BestPix(),
226  NULL, false, false, false,
227  page_res_it.row()->row,
228  page_res_it.block()->block);
229  CubeObject *cube_obj = lang_tess->cube_recognize_word(
230  page_res_it.block()->block, &cube_word);
231  if (cube_obj != NULL)
232  lang_tess->cube_combine_word(cube_obj, &cube_word, word);
233  delete cube_obj;
234  }
235 }
double CombinerRunThresh() const
Definition: tuning_params.h:62
tesseract::Tesseract * tesseract
Definition: pageres.h:266
Pix * BestPix() const
WERD * word
Definition: pageres.h:175
bool SetupForRecognition(const UNICHARSET &unicharset_in, tesseract::Tesseract *tesseract, Pix *pix, int norm_mode, const TBOX *norm_box, bool numeric_mode, bool use_body_size, bool allow_detailed_fx, ROW *row, const BLOCK *block)
Definition: pageres.cpp:294
TuningParams * Params() const
WERD_CHOICE * best_choice
Definition: pageres.h:219
void InitForRetryRecognition(const WERD_RES &source)
Definition: pageres.cpp:269
bool IsText() const
Definition: polyblk.h:52
Definition: ocrblock.h:30
float certainty() const
Definition: ratngs.h:328
POLY_BLOCK * poly_block() const
Definition: pdblock.h:55
bool tesseract::Tesseract::RunOldFixXht ( WERD_RES word,
BLOCK block,
ROW row 
)
inT16 tesseract::Tesseract::safe_dict_word ( const WERD_RES werd_res)

Definition at line 607 of file reject.cpp.

607  {
608  const WERD_CHOICE &word = *werd_res->best_choice;
609  int dict_word_type = werd_res->tesseract->dict_word(word);
610  return dict_word_type == DOC_DAWG_PERM ? 0 : dict_word_type;
611 }
tesseract::Tesseract * tesseract
Definition: pageres.h:266
WERD_CHOICE * best_choice
Definition: pageres.h:219
int dict_word(const WERD_CHOICE &word)
Definition: tface.cpp:128
Pix* tesseract::Tesseract::scaled_color ( ) const
inline

Definition at line 235 of file tesseractclass.h.

235  {
236  return scaled_color_;
237  }
int tesseract::Tesseract::scaled_factor ( ) const
inline

Definition at line 238 of file tesseractclass.h.

238  {
239  return scaled_factor_;
240  }
void tesseract::Tesseract::script_pos_pass ( PAGE_RES page_res)

Definition at line 716 of file control.cpp.

716  {
717  PAGE_RES_IT page_res_it(page_res);
718  for (page_res_it.restart_page(); page_res_it.word() != NULL;
719  page_res_it.forward()) {
720  WERD_RES* word = page_res_it.word();
721  if (word->word->flag(W_REP_CHAR)) {
722  page_res_it.forward();
723  continue;
724  }
725  float x_height = page_res_it.block()->block->x_height();
726  float word_x_height = word->x_height;
727  if (word_x_height < word->best_choice->min_x_height() ||
728  word_x_height > word->best_choice->max_x_height()) {
729  word_x_height = (word->best_choice->min_x_height() +
730  word->best_choice->max_x_height()) / 2.0f;
731  }
732  // Test for small caps. Word capheight must be close to block xheight,
733  // and word must contain no lower case letters, and at least one upper case.
734  double small_cap_xheight = x_height * kXHeightCapRatio;
735  double small_cap_delta = (x_height - small_cap_xheight) / 2.0;
736  if (word->uch_set->script_has_xheight() &&
737  small_cap_xheight - small_cap_delta <= word_x_height &&
738  word_x_height <= small_cap_xheight + small_cap_delta) {
739  // Scan for upper/lower.
740  int num_upper = 0;
741  int num_lower = 0;
742  for (int i = 0; i < word->best_choice->length(); ++i) {
743  if (word->uch_set->get_isupper(word->best_choice->unichar_id(i)))
744  ++num_upper;
745  else if (word->uch_set->get_islower(word->best_choice->unichar_id(i)))
746  ++num_lower;
747  }
748  if (num_upper > 0 && num_lower == 0)
749  word->small_caps = true;
750  }
751  word->SetScriptPositions();
752  }
753 }
BOOL8 flag(WERD_FLAGS mask) const
Definition: werd.h:128
bool get_isupper(UNICHAR_ID unichar_id) const
Definition: unicharset.h:462
float max_x_height() const
Definition: ratngs.h:337
UNICHAR_ID unichar_id(int index) const
Definition: ratngs.h:313
WERD * word
Definition: pageres.h:175
int length() const
Definition: ratngs.h:301
void SetScriptPositions()
Definition: pageres.cpp:853
bool get_islower(UNICHAR_ID unichar_id) const
Definition: unicharset.h:455
WERD_CHOICE * best_choice
Definition: pageres.h:219
const UNICHARSET * uch_set
Definition: pageres.h:192
float x_height
Definition: pageres.h:295
bool script_has_xheight() const
Definition: unicharset.h:848
bool small_caps
Definition: pageres.h:283
float min_x_height() const
Definition: ratngs.h:334
static const double kXHeightCapRatio
Definition: ccstruct.h:37
void tesseract::Tesseract::SearchForText ( const GenericVector< BLOB_CHOICE_LIST * > *  choices,
int  choices_pos,
int  choices_length,
const GenericVector< UNICHAR_ID > &  target_text,
int  text_index,
float  rating,
GenericVector< int > *  segmentation,
float *  best_rating,
GenericVector< int > *  best_segmentation 
)

Recursive helper to find a match to the target_text (from text_index position) in the choices (from choices_pos position).

Parameters
choicesis an array of GenericVectors, of length choices_length, with each element representing a starting position in the word, and the GenericVector holding classification results for a sequence of consecutive blobs, with index 0 being a single blob, index 1 being 2 blobs etc.
choices_pos
choices_length
target_text
text_index
rating
segmentation
best_rating
best_segmentation

Definition at line 629 of file applybox.cpp.

635  {
637  for (int length = 1; length <= choices[choices_pos].size(); ++length) {
638  // Rating of matching choice or worst choice if no match.
639  float choice_rating = 0.0f;
640  // Find the corresponding best BLOB_CHOICE.
641  BLOB_CHOICE_IT choice_it(choices[choices_pos][length - 1]);
642  for (choice_it.mark_cycle_pt(); !choice_it.cycled_list();
643  choice_it.forward()) {
644  BLOB_CHOICE* choice = choice_it.data();
645  choice_rating = choice->rating();
646  UNICHAR_ID class_id = choice->unichar_id();
647  if (class_id == target_text[text_index]) {
648  break;
649  }
650  // Search ambigs table.
651  if (class_id < table.size() && table[class_id] != NULL) {
652  AmbigSpec_IT spec_it(table[class_id]);
653  for (spec_it.mark_cycle_pt(); !spec_it.cycled_list();
654  spec_it.forward()) {
655  const AmbigSpec *ambig_spec = spec_it.data();
656  // We'll only do 1-1.
657  if (ambig_spec->wrong_ngram[1] == INVALID_UNICHAR_ID &&
658  ambig_spec->correct_ngram_id == target_text[text_index])
659  break;
660  }
661  if (!spec_it.cycled_list())
662  break; // Found an ambig.
663  }
664  }
665  if (choice_it.cycled_list())
666  continue; // No match.
667  segmentation->push_back(length);
668  if (choices_pos + length == choices_length &&
669  text_index + 1 == target_text.size()) {
670  // This is a complete match. If the rating is good record a new best.
671  if (applybox_debug > 2) {
672  tprintf("Complete match, rating = %g, best=%g, seglength=%d, best=%d\n",
673  rating + choice_rating, *best_rating, segmentation->size(),
674  best_segmentation->size());
675  }
676  if (best_segmentation->empty() || rating + choice_rating < *best_rating) {
677  *best_segmentation = *segmentation;
678  *best_rating = rating + choice_rating;
679  }
680  } else if (choices_pos + length < choices_length &&
681  text_index + 1 < target_text.size()) {
682  if (applybox_debug > 3) {
683  tprintf("Match found for %d=%s:%s, at %d+%d, recursing...\n",
684  target_text[text_index],
685  unicharset.id_to_unichar(target_text[text_index]),
686  choice_it.data()->unichar_id() == target_text[text_index]
687  ? "Match" : "Ambig",
688  choices_pos, length);
689  }
690  SearchForText(choices, choices_pos + length, choices_length, target_text,
691  text_index + 1, rating + choice_rating, segmentation,
692  best_rating, best_segmentation);
693  if (applybox_debug > 3) {
694  tprintf("End recursion for %d=%s\n", target_text[text_index],
695  unicharset.id_to_unichar(target_text[text_index]));
696  }
697  }
698  segmentation->truncate(segmentation->size() - 1);
699  }
700 }
int UNICHAR_ID
Definition: unichar.h:33
const UnicharAmbigsVector & dang_ambigs() const
Definition: ambigs.h:154
float rating() const
Definition: ratngs.h:79
bool empty() const
Definition: genericvector.h:84
void truncate(int size)
#define tprintf(...)
Definition: tprintf.h:31
int size() const
Definition: genericvector.h:72
Dict & getDict()
Definition: classify.h:65
const UnicharAmbigs & getUnicharAmbigs() const
Definition: dict.h:103
const char * id_to_unichar(UNICHAR_ID id) const
Definition: unicharset.cpp:266
UNICHARSET unicharset
Definition: ccutil.h:70
int push_back(T object)
void SearchForText(const GenericVector< BLOB_CHOICE_LIST * > *choices, int choices_pos, int choices_length, const GenericVector< UNICHAR_ID > &target_text, int text_index, float rating, GenericVector< int > *segmentation, float *best_rating, GenericVector< int > *best_segmentation)
Definition: applybox.cpp:629
GenericVector< AmbigSpec_LIST * > UnicharAmbigsVector
Definition: ambigs.h:143
UNICHAR_ID unichar_id() const
Definition: ratngs.h:76
int tesseract::Tesseract::SegmentPage ( const STRING input_file,
BLOCK_LIST *  blocks,
Tesseract osd_tess,
OSResults osr 
)

Segment the page according to the current value of tessedit_pageseg_mode. pix_binary_ is used as the source image and should not be NULL. On return the blocks list owns all the constructed page layout.

Definition at line 102 of file pagesegmain.cpp.

103  {
104  ASSERT_HOST(pix_binary_ != NULL);
105  int width = pixGetWidth(pix_binary_);
106  int height = pixGetHeight(pix_binary_);
107  // Get page segmentation mode.
108  PageSegMode pageseg_mode = static_cast<PageSegMode>(
109  static_cast<int>(tessedit_pageseg_mode));
110  // If a UNLV zone file can be found, use that instead of segmentation.
111  if (!PSM_COL_FIND_ENABLED(pageseg_mode) &&
112  input_file != NULL && input_file->length() > 0) {
113  STRING name = *input_file;
114  const char* lastdot = strrchr(name.string(), '.');
115  if (lastdot != NULL)
116  name[lastdot - name.string()] = '\0';
117  read_unlv_file(name, width, height, blocks);
118  }
119  if (blocks->empty()) {
120  // No UNLV file present. Work according to the PageSegMode.
121  // First make a single block covering the whole image.
122  BLOCK_IT block_it(blocks);
123  BLOCK* block = new BLOCK("", TRUE, 0, 0, 0, 0, width, height);
125  block_it.add_to_end(block);
126  } else {
127  // UNLV file present. Use PSM_SINGLE_BLOCK.
128  pageseg_mode = PSM_SINGLE_BLOCK;
129  }
130  // The diacritic_blobs holds noise blobs that may be diacritics. They
131  // are separated out on areas of the image that seem noisy and short-circuit
132  // the layout process, going straight from the initial partition creation
133  // right through to after word segmentation, where they are added to the
134  // rej_cblobs list of the most appropriate word. From there classification
135  // will determine whether they are used.
136  BLOBNBOX_LIST diacritic_blobs;
137  int auto_page_seg_ret_val = 0;
138  TO_BLOCK_LIST to_blocks;
139  if (PSM_OSD_ENABLED(pageseg_mode) || PSM_BLOCK_FIND_ENABLED(pageseg_mode) ||
140  PSM_SPARSE(pageseg_mode)) {
141  auto_page_seg_ret_val = AutoPageSeg(
142  pageseg_mode, blocks, &to_blocks,
143  enable_noise_removal ? &diacritic_blobs : NULL, osd_tess, osr);
144  if (pageseg_mode == PSM_OSD_ONLY)
145  return auto_page_seg_ret_val;
146  // To create blobs from the image region bounds uncomment this line:
147  // to_blocks.clear(); // Uncomment to go back to the old mode.
148  } else {
149  deskew_ = FCOORD(1.0f, 0.0f);
150  reskew_ = FCOORD(1.0f, 0.0f);
151  if (pageseg_mode == PSM_CIRCLE_WORD) {
152  Pix* pixcleaned = RemoveEnclosingCircle(pix_binary_);
153  if (pixcleaned != NULL) {
154  pixDestroy(&pix_binary_);
155  pix_binary_ = pixcleaned;
156  }
157  }
158  }
159 
160  if (auto_page_seg_ret_val < 0) {
161  return -1;
162  }
163 
164  if (blocks->empty()) {
166  tprintf("Empty page\n");
167  return 0; // AutoPageSeg found an empty page.
168  }
169  bool splitting =
171  bool cjk_mode = textord_use_cjk_fp_model;
172 
173  textord_.TextordPage(pageseg_mode, reskew_, width, height, pix_binary_,
174  pix_thresholds_, pix_grey_, splitting || cjk_mode,
175  &diacritic_blobs, blocks, &to_blocks);
176  return auto_page_seg_ret_val;
177 }
int AutoPageSeg(PageSegMode pageseg_mode, BLOCK_LIST *blocks, TO_BLOCK_LIST *to_blocks, BLOBNBOX_LIST *diacritic_blobs, Tesseract *osd_tess, OSResults *osr)
bool PSM_SPARSE(int pageseg_mode)
Definition: publictypes.h:188
Orientation and script detection only.
Definition: publictypes.h:152
#define TRUE
Definition: capi.h:45
Assume a single uniform block of text. (Default.)
Definition: publictypes.h:160
Definition: strngs.h:44
Definition: points.h:189
int textord_debug_tabfind
Definition: alignedblob.cpp:27
#define tprintf(...)
Definition: tprintf.h:31
void set_right_to_left(bool value)
Definition: ocrblock.h:86
inT32 length() const
Definition: strngs.cpp:196
void TextordPage(PageSegMode pageseg_mode, const FCOORD &reskew, int width, int height, Pix *binary_pix, Pix *thresholds_pix, Pix *grey_pix, bool use_box_bottoms, BLOBNBOX_LIST *diacritic_blobs, BLOCK_LIST *blocks, TO_BLOCK_LIST *to_blocks)
Definition: textord.cpp:233
bool PSM_BLOCK_FIND_ENABLED(int pageseg_mode)
Definition: publictypes.h:191
bool PSM_COL_FIND_ENABLED(int pageseg_mode)
Definition: publictypes.h:185
bool right_to_left() const
#define ASSERT_HOST(x)
Definition: errcode.h:84
const char * string() const
Definition: strngs.cpp:201
Treat the image as a single word in a circle.
Definition: publictypes.h:163
bool PSM_OSD_ENABLED(int pageseg_mode)
Definition: publictypes.h:179
Definition: ocrblock.h:30
bool read_unlv_file(STRING name, inT32 xsize, inT32 ysize, BLOCK_LIST *blocks)
Definition: blread.cpp:36
bool tesseract::Tesseract::SelectGoodDiacriticOutlines ( int  pass,
float  certainty_threshold,
PAGE_RES_IT pr_it,
C_BLOB blob,
const GenericVector< C_OUTLINE * > &  outlines,
int  num_outlines,
GenericVector< bool > *  ok_outlines 
)

Definition at line 1111 of file control.cpp.

1114  {
1115  STRING best_str;
1116  float target_cert = certainty_threshold;
1117  if (blob != NULL) {
1118  float target_c2;
1119  target_cert = ClassifyBlobAsWord(pass, pr_it, blob, &best_str, &target_c2);
1120  if (debug_noise_removal) {
1121  tprintf("No Noise blob classified as %s=%g(%g) at:", best_str.string(),
1122  target_cert, target_c2);
1123  blob->bounding_box().print();
1124  }
1125  target_cert -= (target_cert - certainty_threshold) * noise_cert_factor;
1126  }
1127  GenericVector<bool> test_outlines = *ok_outlines;
1128  // Start with all the outlines in.
1129  STRING all_str;
1130  GenericVector<bool> best_outlines = *ok_outlines;
1131  float best_cert = ClassifyBlobPlusOutlines(test_outlines, outlines, pass,
1132  pr_it, blob, &all_str);
1133  if (debug_noise_removal) {
1134  TBOX ol_box;
1135  for (int i = 0; i < test_outlines.size(); ++i) {
1136  if (test_outlines[i]) ol_box += outlines[i]->bounding_box();
1137  }
1138  tprintf("All Noise blob classified as %s=%g, delta=%g at:",
1139  all_str.string(), best_cert, best_cert - target_cert);
1140  ol_box.print();
1141  }
1142  // Iteratively zero out the bit that improves the certainty the most, until
1143  // we get past the threshold, have zero bits, or fail to improve.
1144  int best_index = 0; // To zero out.
1145  while (num_outlines > 1 && best_index >= 0 &&
1146  (blob == NULL || best_cert < target_cert || blob != NULL)) {
1147  // Find the best bit to zero out.
1148  best_index = -1;
1149  for (int i = 0; i < outlines.size(); ++i) {
1150  if (test_outlines[i]) {
1151  test_outlines[i] = false;
1152  STRING str;
1153  float cert = ClassifyBlobPlusOutlines(test_outlines, outlines, pass,
1154  pr_it, blob, &str);
1155  if (debug_noise_removal) {
1156  TBOX ol_box;
1157  for (int j = 0; j < outlines.size(); ++j) {
1158  if (test_outlines[j]) ol_box += outlines[j]->bounding_box();
1159  tprintf("%d", test_outlines[j]);
1160  }
1161  tprintf(" blob classified as %s=%g, delta=%g) at:", str.string(),
1162  cert, cert - target_cert);
1163  ol_box.print();
1164  }
1165  if (cert > best_cert) {
1166  best_cert = cert;
1167  best_index = i;
1168  best_outlines = test_outlines;
1169  }
1170  test_outlines[i] = true;
1171  }
1172  }
1173  if (best_index >= 0) {
1174  test_outlines[best_index] = false;
1175  --num_outlines;
1176  }
1177  }
1178  if (best_cert >= target_cert) {
1179  // Save the best combination.
1180  *ok_outlines = best_outlines;
1181  if (debug_noise_removal) {
1182  tprintf("%s noise combination ", blob ? "Adding" : "New");
1183  for (int i = 0; i < best_outlines.size(); ++i) {
1184  tprintf("%d", best_outlines[i]);
1185  }
1186  tprintf(" yields certainty %g, beating target of %g\n", best_cert,
1187  target_cert);
1188  }
1189  return true;
1190  }
1191  return false;
1192 }
TBOX bounding_box() const
Definition: stepblob.cpp:250
float ClassifyBlobAsWord(int pass_n, PAGE_RES_IT *pr_it, C_BLOB *blob, STRING *best_str, float *c2)
Definition: control.cpp:1238
Definition: strngs.h:44
#define tprintf(...)
Definition: tprintf.h:31
float ClassifyBlobPlusOutlines(const GenericVector< bool > &ok_outlines, const GenericVector< C_OUTLINE * > &outlines, int pass_n, PAGE_RES_IT *pr_it, C_BLOB *blob, STRING *best_str)
Definition: control.cpp:1196
int size() const
Definition: genericvector.h:72
Definition: rect.h:30
void print() const
Definition: rect.h:270
const char * string() const
Definition: strngs.cpp:201
void tesseract::Tesseract::set_done ( WERD_RES word,
inT16  pass 
)
void tesseract::Tesseract::set_pix_grey ( Pix *  grey_pix)
inline

Definition at line 201 of file tesseractclass.h.

201  {
202  pixDestroy(&pix_grey_);
203  pix_grey_ = grey_pix;
204  }
void tesseract::Tesseract::set_pix_original ( Pix *  original_pix)
inline

Definition at line 207 of file tesseractclass.h.

207  {
208  pixDestroy(&pix_original_);
209  pix_original_ = original_pix;
210  }
void tesseract::Tesseract::set_pix_thresholds ( Pix *  thresholds)
inline

Definition at line 219 of file tesseractclass.h.

219  {
220  pixDestroy(&pix_thresholds_);
221  pix_thresholds_ = thresholds;
222  }
void tesseract::Tesseract::set_source_resolution ( int  ppi)
inline

Definition at line 226 of file tesseractclass.h.

226  {
227  source_resolution_ = ppi;
228  }
void tesseract::Tesseract::set_unlv_suspects ( WERD_RES word)

Definition at line 305 of file output.cpp.

305  {
306  int len = word_res->reject_map.length();
307  const WERD_CHOICE &word = *(word_res->best_choice);
308  const UNICHARSET &uchset = *word.unicharset();
309  int i;
310  float rating_per_ch;
311 
312  if (suspect_level == 0) {
313  for (i = 0; i < len; i++) {
314  if (word_res->reject_map[i].rejected())
315  word_res->reject_map[i].setrej_minimal_rej_accept();
316  }
317  return;
318  }
319 
320  if (suspect_level >= 3)
321  return; //Use defaults
322 
323  /* NOW FOR LEVELS 1 and 2 Find some stuff to unreject*/
324 
325  if (safe_dict_word(word_res) &&
326  (count_alphas(word) > suspect_short_words)) {
327  /* Unreject alphas in dictionary words */
328  for (i = 0; i < len; ++i) {
329  if (word_res->reject_map[i].rejected() &&
330  uchset.get_isalpha(word.unichar_id(i)))
331  word_res->reject_map[i].setrej_minimal_rej_accept();
332  }
333  }
334 
335  rating_per_ch = word.rating() / word_res->reject_map.length();
336 
337  if (rating_per_ch >= suspect_rating_per_ch)
338  return; // Don't touch bad ratings
339 
340  if ((word_res->tess_accepted) || (rating_per_ch < suspect_accept_rating)) {
341  /* Unreject any Tess Acceptable word - but NOT tess reject chs*/
342  for (i = 0; i < len; ++i) {
343  if (word_res->reject_map[i].rejected() &&
344  (!uchset.eq(word.unichar_id(i), " ")))
345  word_res->reject_map[i].setrej_minimal_rej_accept();
346  }
347  }
348 
349  for (i = 0; i < len; i++) {
350  if (word_res->reject_map[i].rejected()) {
351  if (word_res->reject_map[i].flag(R_DOC_REJ))
352  word_res->reject_map[i].setrej_minimal_rej_accept();
353  if (word_res->reject_map[i].flag(R_BLOCK_REJ))
354  word_res->reject_map[i].setrej_minimal_rej_accept();
355  if (word_res->reject_map[i].flag(R_ROW_REJ))
356  word_res->reject_map[i].setrej_minimal_rej_accept();
357  }
358  }
359 
360  if (suspect_level == 2)
361  return;
362 
363  if (!suspect_constrain_1Il ||
364  (word_res->reject_map.length() <= suspect_short_words)) {
365  for (i = 0; i < len; i++) {
366  if (word_res->reject_map[i].rejected()) {
367  if ((word_res->reject_map[i].flag(R_1IL_CONFLICT) ||
368  word_res->reject_map[i].flag(R_POSTNN_1IL)))
369  word_res->reject_map[i].setrej_minimal_rej_accept();
370 
371  if (!suspect_constrain_1Il &&
372  word_res->reject_map[i].flag(R_MM_REJECT))
373  word_res->reject_map[i].setrej_minimal_rej_accept();
374  }
375  }
376  }
377 
378  if (acceptable_word_string(*word_res->uch_set,
379  word.unichar_string().string(),
380  word.unichar_lengths().string()) !=
381  AC_UNACCEPTABLE ||
383  word.unichar_lengths().string())) {
384  if (word_res->reject_map.length() > suspect_short_words) {
385  for (i = 0; i < len; i++) {
386  if (word_res->reject_map[i].rejected() &&
387  (!word_res->reject_map[i].perm_rejected() ||
388  word_res->reject_map[i].flag (R_1IL_CONFLICT) ||
389  word_res->reject_map[i].flag (R_POSTNN_1IL) ||
390  word_res->reject_map[i].flag (R_MM_REJECT))) {
391  word_res->reject_map[i].setrej_minimal_rej_accept();
392  }
393  }
394  }
395  }
396 }
const STRING & unichar_lengths() const
Definition: ratngs.h:532
const UNICHARSET * unicharset() const
Definition: ratngs.h:298
UNICHAR_ID unichar_id(int index) const
Definition: ratngs.h:313
const STRING & unichar_string() const
Definition: ratngs.h:525
bool get_isalpha(UNICHAR_ID unichar_id) const
Definition: unicharset.h:448
Unacceptable word.
Definition: control.h:36
inT16 count_alphas(const WERD_CHOICE &word)
Definition: output.cpp:398
float rating() const
Definition: ratngs.h:325
BOOL8 acceptable_number_string(const char *s, const char *lengths)
Definition: output.cpp:419
inT16 safe_dict_word(const WERD_RES *werd_res)
Definition: reject.cpp:607
const char * string() const
Definition: strngs.cpp:201
bool eq(UNICHAR_ID unichar_id, const char *const unichar_repr) const
Definition: unicharset.cpp:656
ACCEPTABLE_WERD_TYPE acceptable_word_string(const UNICHARSET &char_set, const char *s, const char *lengths)
Definition: control.cpp:1668
void tesseract::Tesseract::set_word_fonts ( WERD_RES word)

set_word_fonts

Get the fonts for the word.

Definition at line 1885 of file control.cpp.

1885  {
1886  // Don't try to set the word fonts for a cube word, as the configs
1887  // will be meaningless.
1888  if (word->chopped_word == NULL) return;
1889  ASSERT_HOST(word->best_choice != NULL);
1890 
1891  int fontinfo_size = get_fontinfo_table().size();
1892  if (fontinfo_size == 0) return;
1893  GenericVector<int> font_total_score;
1894  font_total_score.init_to_size(fontinfo_size, 0);
1895 
1896  word->italic = 0;
1897  word->bold = 0;
1898  // Compute the font scores for the word
1899  if (tessedit_debug_fonts) {
1900  tprintf("Examining fonts in %s\n",
1901  word->best_choice->debug_string().string());
1902  }
1903  for (int b = 0; b < word->best_choice->length(); ++b) {
1904  BLOB_CHOICE* choice = word->GetBlobChoice(b);
1905  if (choice == NULL) continue;
1906  const GenericVector<ScoredFont>& fonts = choice->fonts();
1907  for (int f = 0; f < fonts.size(); ++f) {
1908  int fontinfo_id = fonts[f].fontinfo_id;
1909  if (0 <= fontinfo_id && fontinfo_id < fontinfo_size) {
1910  font_total_score[fontinfo_id] += fonts[f].score;
1911  }
1912  }
1913  }
1914  // Find the top and 2nd choice for the word.
1915  int score1 = 0, score2 = 0;
1916  inT16 font_id1 = -1, font_id2 = -1;
1917  for (int f = 0; f < fontinfo_size; ++f) {
1918  if (tessedit_debug_fonts && font_total_score[f] > 0) {
1919  tprintf("Font %s, total score = %d\n",
1920  fontinfo_table_.get(f).name, font_total_score[f]);
1921  }
1922  if (font_total_score[f] > score1) {
1923  score2 = score1;
1924  font_id2 = font_id1;
1925  score1 = font_total_score[f];
1926  font_id1 = f;
1927  } else if (font_total_score[f] > score2) {
1928  score2 = font_total_score[f];
1929  font_id2 = f;
1930  }
1931  }
1932  word->fontinfo = font_id1 >= 0 ? &fontinfo_table_.get(font_id1) : NULL;
1933  word->fontinfo2 = font_id2 >= 0 ? &fontinfo_table_.get(font_id2) : NULL;
1934  // Each score has a limit of MAX_UINT16, so divide by that to get the number
1935  // of "votes" for that font, ie number of perfect scores.
1936  word->fontinfo_id_count = ClipToRange(score1 / MAX_UINT16, 1, MAX_INT8);
1937  word->fontinfo_id2_count = ClipToRange(score2 / MAX_UINT16, 0, MAX_INT8);
1938  if (score1 > 0) {
1939  FontInfo fi = fontinfo_table_.get(font_id1);
1940  if (tessedit_debug_fonts) {
1941  if (word->fontinfo_id2_count > 0) {
1942  tprintf("Word modal font=%s, score=%d, 2nd choice %s/%d\n",
1943  fi.name, word->fontinfo_id_count,
1944  fontinfo_table_.get(font_id2).name,
1945  word->fontinfo_id2_count);
1946  } else {
1947  tprintf("Word modal font=%s, score=%d. No 2nd choice\n",
1948  fi.name, word->fontinfo_id_count);
1949  }
1950  }
1951  word->italic = (fi.is_italic() ? 1 : -1) * word->fontinfo_id_count;
1952  word->bold = (fi.is_bold() ? 1 : -1) * word->fontinfo_id_count;
1953  }
1954 }
bool is_italic() const
Definition: fontinfo.h:111
inT8 fontinfo_id2_count
Definition: pageres.h:291
inT8 italic
Definition: pageres.h:285
const FontInfo * fontinfo
Definition: pageres.h:288
#define MAX_INT8
Definition: host.h:118
void init_to_size(int size, T t)
BLOB_CHOICE * GetBlobChoice(int index) const
Definition: pageres.cpp:742
UnicityTable< FontInfo > fontinfo_table_
Definition: classify.h:488
int length() const
Definition: ratngs.h:301
#define MAX_UINT16
Definition: host.h:122
const STRING debug_string() const
Definition: ratngs.h:503
#define tprintf(...)
Definition: tprintf.h:31
TWERD * chopped_word
Definition: pageres.h:201
const GenericVector< tesseract::ScoredFont > & fonts() const
Definition: ratngs.h:91
int size() const
Definition: genericvector.h:72
short inT16
Definition: host.h:100
T ClipToRange(const T &x, const T &lower_bound, const T &upper_bound)
Definition: helpers.h:115
UnicityTable< FontInfo > & get_fontinfo_table()
Definition: classify.h:345
const FontInfo * fontinfo2
Definition: pageres.h:289
WERD_CHOICE * best_choice
Definition: pageres.h:219
#define ASSERT_HOST(x)
Definition: errcode.h:84
inT8 bold
Definition: pageres.h:286
const char * string() const
Definition: strngs.cpp:201
bool is_bold() const
Definition: fontinfo.h:112
inT8 fontinfo_id_count
Definition: pageres.h:290
void tesseract::Tesseract::SetBlackAndWhitelist ( )

Definition at line 679 of file tesseractclass.cpp.

679  {
680  // Set the white and blacklists (if any)
682  tessedit_char_whitelist.string(),
683  tessedit_char_unblacklist.string());
684  // Black and white lists should apply to all loaded classifiers.
685  for (int i = 0; i < sub_langs_.size(); ++i) {
686  sub_langs_[i]->unicharset.set_black_and_whitelist(
688  tessedit_char_unblacklist.string());
689  }
690 }
void set_black_and_whitelist(const char *blacklist, const char *whitelist, const char *unblacklist)
Definition: unicharset.cpp:948
UNICHARSET unicharset
Definition: ccutil.h:70
void tesseract::Tesseract::SetEquationDetect ( EquationDetect detector)

Definition at line 658 of file tesseractclass.cpp.

658  {
659  equ_detect_ = detector;
660  equ_detect_->SetLangTesseract(this);
661 }
void SetLangTesseract(Tesseract *lang_tesseract)
void tesseract::Tesseract::SetScaledColor ( int  factor,
Pix *  color 
)
inline

Definition at line 241 of file tesseractclass.h.

241  {
242  scaled_factor_ = factor;
243  scaled_color_ = color;
244  }
void tesseract::Tesseract::SetupAllWordsPassN ( int  pass_n,
const TBOX target_word_box,
const char *  word_config,
PAGE_RES page_res,
GenericVector< WordData > *  words 
)

If tesseract is to be run, sets the words up ready for it.

Definition at line 145 of file control.cpp.

149  {
150  // Prepare all the words.
151  PAGE_RES_IT page_res_it(page_res);
152  for (page_res_it.restart_page(); page_res_it.word() != NULL;
153  page_res_it.forward()) {
154  if (target_word_box == NULL ||
155  ProcessTargetWord(page_res_it.word()->word->bounding_box(),
156  *target_word_box, word_config, 1)) {
157  words->push_back(WordData(page_res_it));
158  }
159  }
160  // Setup all the words for recognition with polygonal approximation.
161  for (int w = 0; w < words->size(); ++w) {
162  SetupWordPassN(pass_n, &(*words)[w]);
163  if (w > 0) (*words)[w].prev_word = &(*words)[w - 1];
164  }
165 }
int size() const
Definition: genericvector.h:72
int push_back(T object)
bool ProcessTargetWord(const TBOX &word_box, const TBOX &target_word_box, const char *word_config, int pass)
Definition: control.cpp:115
void SetupWordPassN(int pass_n, WordData *word)
Definition: control.cpp:168
PAGE_RES * tesseract::Tesseract::SetupApplyBoxes ( const GenericVector< TBOX > &  boxes,
BLOCK_LIST *  block_list 
)

Builds a PAGE_RES from the block_list in the way required for ApplyBoxes: All fuzzy spaces are removed, and all the words are maximally chopped.

Definition at line 217 of file applybox.cpp.

218  {
219  PreenXHeights(block_list);
220  // Strip all fuzzy space markers to simplify the PAGE_RES.
221  BLOCK_IT b_it(block_list);
222  for (b_it.mark_cycle_pt(); !b_it.cycled_list(); b_it.forward()) {
223  BLOCK* block = b_it.data();
224  ROW_IT r_it(block->row_list());
225  for (r_it.mark_cycle_pt(); !r_it.cycled_list(); r_it.forward ()) {
226  ROW* row = r_it.data();
227  WERD_IT w_it(row->word_list());
228  for (w_it.mark_cycle_pt(); !w_it.cycled_list(); w_it.forward()) {
229  WERD* word = w_it.data();
230  if (word->cblob_list()->empty()) {
231  delete w_it.extract();
232  } else {
233  word->set_flag(W_FUZZY_SP, false);
234  word->set_flag(W_FUZZY_NON, false);
235  }
236  }
237  }
238  }
239  PAGE_RES* page_res = new PAGE_RES(false, block_list, NULL);
240  PAGE_RES_IT pr_it(page_res);
241  WERD_RES* word_res;
242  while ((word_res = pr_it.word()) != NULL) {
243  MaximallyChopWord(boxes, pr_it.block()->block,
244  pr_it.row()->row, word_res);
245  pr_it.forward();
246  }
247  return page_res;
248 }
void PreenXHeights(BLOCK_LIST *block_list)
Definition: applybox.cpp:193
void set_flag(WERD_FLAGS mask, BOOL8 value)
Definition: werd.h:129
ROW_LIST * row_list()
get rows
Definition: ocrblock.h:120
Definition: ocrrow.h:32
Definition: werd.h:60
WERD * word
Definition: pageres.h:175
WERD_LIST * word_list()
Definition: ocrrow.h:52
Definition: ocrblock.h:30
void MaximallyChopWord(const GenericVector< TBOX > &boxes, BLOCK *block, ROW *row, WERD_RES *word_res)
Definition: applybox.cpp:253
C_BLOB_LIST * cblob_list()
Definition: werd.h:100
ColumnFinder * tesseract::Tesseract::SetupPageSegAndDetectOrientation ( PageSegMode  pageseg_mode,
BLOCK_LIST *  blocks,
Tesseract osd_tess,
OSResults osr,
TO_BLOCK_LIST *  to_blocks,
Pix **  photo_mask_pix,
Pix **  music_mask_pix 
)

Sets up auto page segmentation, determines the orientation, and corrects it. Somewhat arbitrary chunk of functionality, factored out of AutoPageSeg to facilitate testing. photo_mask_pix is a pointer to a NULL pointer that will be filled on return with the leptonica photo mask, which must be pixDestroyed by the caller. to_blocks is an empty list that will be filled with (usually a single) block that is used during layout analysis. This ugly API is required because of the possibility of a unlv zone file. TODO(rays) clean this up. See AutoPageSeg for other arguments. The returned ColumnFinder must be deleted after use.

Definition at line 302 of file pagesegmain.cpp.

305  {
306  int vertical_x = 0;
307  int vertical_y = 1;
308  TabVector_LIST v_lines;
309  TabVector_LIST h_lines;
310  ICOORD bleft(0, 0);
311 
312  ASSERT_HOST(pix_binary_ != NULL);
314  pixWrite("tessinput.png", pix_binary_, IFF_PNG);
315  }
316  // Leptonica is used to find the rule/separator lines in the input.
317  LineFinder::FindAndRemoveLines(source_resolution_,
318  textord_tabfind_show_vlines, pix_binary_,
319  &vertical_x, &vertical_y, music_mask_pix,
320  &v_lines, &h_lines);
322  pixWrite("tessnolines.png", pix_binary_, IFF_PNG);
323  // Leptonica is used to find a mask of the photo regions in the input.
324  *photo_mask_pix = ImageFind::FindImages(pix_binary_);
326  pixWrite("tessnoimages.png", pix_binary_, IFF_PNG);
327  if (!PSM_COL_FIND_ENABLED(pageseg_mode)) v_lines.clear();
328 
329  // The rest of the algorithm uses the usual connected components.
330  textord_.find_components(pix_binary_, blocks, to_blocks);
331 
332  TO_BLOCK_IT to_block_it(to_blocks);
333  // There must be exactly one input block.
334  // TODO(rays) handle new textline finding with a UNLV zone file.
335  ASSERT_HOST(to_blocks->singleton());
336  TO_BLOCK* to_block = to_block_it.data();
337  TBOX blkbox = to_block->block->bounding_box();
338  ColumnFinder* finder = NULL;
339 
340  if (to_block->line_size >= 2) {
341  finder = new ColumnFinder(static_cast<int>(to_block->line_size),
342  blkbox.botleft(), blkbox.topright(),
343  source_resolution_, textord_use_cjk_fp_model,
345  &v_lines, &h_lines, vertical_x, vertical_y);
346 
347  finder->SetupAndFilterNoise(pageseg_mode, *photo_mask_pix, to_block);
348 
349  if (equ_detect_) {
350  equ_detect_->LabelSpecialText(to_block);
351  }
352 
353  BLOBNBOX_CLIST osd_blobs;
354  // osd_orientation is the number of 90 degree rotations to make the
355  // characters upright. (See osdetect.h for precise definition.)
356  // We want the text lines horizontal, (vertical text indicates vertical
357  // textlines) which may conflict (eg vertically written CJK).
358  int osd_orientation = 0;
359  bool vertical_text = textord_tabfind_force_vertical_text ||
360  pageseg_mode == PSM_SINGLE_BLOCK_VERT_TEXT;
361  if (!vertical_text && textord_tabfind_vertical_text &&
362  PSM_ORIENTATION_ENABLED(pageseg_mode)) {
363  vertical_text =
364  finder->IsVerticallyAlignedText(textord_tabfind_vertical_text_ratio,
365  to_block, &osd_blobs);
366  }
367  if (PSM_OSD_ENABLED(pageseg_mode) && osd_tess != NULL && osr != NULL) {
368  GenericVector<int> osd_scripts;
369  if (osd_tess != this) {
370  // We are running osd as part of layout analysis, so constrain the
371  // scripts to those allowed by *this.
372  AddAllScriptsConverted(unicharset, osd_tess->unicharset, &osd_scripts);
373  for (int s = 0; s < sub_langs_.size(); ++s) {
374  AddAllScriptsConverted(sub_langs_[s]->unicharset,
375  osd_tess->unicharset, &osd_scripts);
376  }
377  }
378  os_detect_blobs(&osd_scripts, &osd_blobs, osr, osd_tess);
379  if (pageseg_mode == PSM_OSD_ONLY) {
380  delete finder;
381  return NULL;
382  }
383  osd_orientation = osr->best_result.orientation_id;
384  double osd_score = osr->orientations[osd_orientation];
385  double osd_margin = min_orientation_margin * 2;
386  for (int i = 0; i < 4; ++i) {
387  if (i != osd_orientation &&
388  osd_score - osr->orientations[i] < osd_margin) {
389  osd_margin = osd_score - osr->orientations[i];
390  }
391  }
392  int best_script_id = osr->best_result.script_id;
393  const char* best_script_str =
394  osd_tess->unicharset.get_script_from_script_id(best_script_id);
395  bool cjk = best_script_id == osd_tess->unicharset.han_sid() ||
396  best_script_id == osd_tess->unicharset.hiragana_sid() ||
397  best_script_id == osd_tess->unicharset.katakana_sid() ||
398  strcmp("Japanese", best_script_str) == 0 ||
399  strcmp("Korean", best_script_str) == 0 ||
400  strcmp("Hangul", best_script_str) == 0;
401  if (cjk) {
402  finder->set_cjk_script(true);
403  }
404  if (osd_margin < min_orientation_margin) {
405  // The margin is weak.
406  if (!cjk && !vertical_text && osd_orientation == 2) {
407  // upside down latin text is improbable with such a weak margin.
408  tprintf("OSD: Weak margin (%.2f), horiz textlines, not CJK: "
409  "Don't rotate.\n", osd_margin);
410  osd_orientation = 0;
411  } else {
412  tprintf(
413  "OSD: Weak margin (%.2f) for %d blob text block, "
414  "but using orientation anyway: %d\n",
415  osd_margin, osd_blobs.length(), osd_orientation);
416  }
417  }
418  }
419  osd_blobs.shallow_clear();
420  finder->CorrectOrientation(to_block, vertical_text, osd_orientation);
421  }
422 
423  return finder;
424 }
Orientation and script detection only.
Definition: publictypes.h:152
int script_id
Definition: osdetect.h:42
static Pix * FindImages(Pix *pix)
Definition: imagefind.cpp:65
OSBestResult best_result
Definition: osdetect.h:79
float orientations[4]
Definition: osdetect.h:74
const ICOORD & botleft() const
Definition: rect.h:88
double textord_tabfind_aligned_gap_fraction
void find_components(Pix *pix, BLOCK_LIST *blocks, TO_BLOCK_LIST *to_blocks)
Definition: tordmain.cpp:205
#define tprintf(...)
Definition: tprintf.h:31
static void FindAndRemoveLines(int resolution, bool debug, Pix *pix, int *vertical_x, int *vertical_y, Pix **pix_music_mask, TabVector_LIST *v_lines, TabVector_LIST *h_lines)
Definition: linefind.cpp:243
Definition: rect.h:30
double textord_tabfind_vertical_text_ratio
int os_detect_blobs(const GenericVector< int > *allowed_scripts, BLOBNBOX_CLIST *blob_list, OSResults *osr, tesseract::Tesseract *tess)
Definition: osdetect.cpp:276
int orientation_id
Definition: osdetect.h:41
UNICHARSET unicharset
Definition: ccutil.h:70
integer coordinate
Definition: points.h:30
bool PSM_COL_FIND_ENABLED(int pageseg_mode)
Definition: publictypes.h:185
bool textord_tabfind_force_vertical_text
#define ASSERT_HOST(x)
Definition: errcode.h:84
bool PSM_OSD_ENABLED(int pageseg_mode)
Definition: publictypes.h:179
bool PSM_ORIENTATION_ENABLED(int pageseg_mode)
Definition: publictypes.h:182
const ICOORD & topright() const
Definition: rect.h:100
int LabelSpecialText(TO_BLOCK *to_block)
void tesseract::Tesseract::SetupUniversalFontIds ( )

Definition at line 444 of file tessedit.cpp.

444  {
445  // Note that we can get away with bitwise copying FontInfo in
446  // all_fonts, as it is a temporary structure and we avoid setting the
447  // delete callback.
448  UnicityTable<FontInfo> all_fonts;
450 
451  // Create the universal ID table.
452  CollectFonts(get_fontinfo_table(), &all_fonts);
453  for (int i = 0; i < sub_langs_.size(); ++i) {
454  CollectFonts(sub_langs_[i]->get_fontinfo_table(), &all_fonts);
455  }
456  // Assign ids from the table to each font table.
457  AssignIds(all_fonts, &get_fontinfo_table());
458  for (int i = 0; i < sub_langs_.size(); ++i) {
459  AssignIds(all_fonts, &sub_langs_[i]->get_fontinfo_table());
460  }
461  font_table_size_ = all_fonts.size();
462 }
void set_compare_callback(TessResultCallback2< bool, T const &, T const & > *cb)
int size() const
Return the size used.
UnicityTable< FontInfo > & get_fontinfo_table()
Definition: classify.h:345
bool CompareFontInfo(const FontInfo &fi1, const FontInfo &fi2)
Definition: fontinfo.cpp:120
_ConstTessMemberResultCallback_0_0< false, R, T1 >::base * NewPermanentTessCallback(const T1 *obj, R(T2::*member)() const)
Definition: tesscallback.h:116
void tesseract::Tesseract::SetupWordPassN ( int  pass_n,
WordData word 
)

Definition at line 168 of file control.cpp.

168  {
169  if (pass_n == 1 || !word->word->done) {
170  if (pass_n == 1) {
171  word->word->SetupForRecognition(unicharset, this, BestPix(),
176  word->row, word->block);
177  } else if (pass_n == 2) {
178  // TODO(rays) Should we do this on pass1 too?
179  word->word->caps_height = 0.0;
180  if (word->word->x_height == 0.0f)
181  word->word->x_height = word->row->x_height();
182  }
183  word->lang_words.truncate(0);
184  for (int s = 0; s <= sub_langs_.size(); ++s) {
185  // The sub_langs_.size() entry is for the master language.
186  Tesseract* lang_t = s < sub_langs_.size() ? sub_langs_[s] : this;
187  WERD_RES* word_res = new WERD_RES;
188  word_res->InitForRetryRecognition(*word->word);
189  word->lang_words.push_back(word_res);
190  // Cube doesn't get setup for pass2.
191  if (pass_n == 1 || lang_t->tessedit_ocr_engine_mode != OEM_CUBE_ONLY) {
192  word_res->SetupForRecognition(
193  lang_t->unicharset, lang_t, BestPix(),
194  lang_t->tessedit_ocr_engine_mode, NULL,
195  lang_t->classify_bln_numeric_mode,
196  lang_t->textord_use_cjk_fp_model,
197  lang_t->poly_allow_detailed_fx, word->row, word->block);
198  }
199  }
200  }
201 }
Pix * BestPix() const
bool classify_bln_numeric_mode
Definition: classify.h:500
bool SetupForRecognition(const UNICHARSET &unicharset_in, tesseract::Tesseract *tesseract, Pix *pix, int norm_mode, const TBOX *norm_box, bool numeric_mode, bool use_body_size, bool allow_detailed_fx, ROW *row, const BLOCK *block)
Definition: pageres.cpp:294
UNICHARSET unicharset
Definition: ccutil.h:70
void InitForRetryRecognition(const WERD_RES &source)
Definition: pageres.cpp:269
void tesseract::Tesseract::SetupWordScripts ( BLOCK_LIST *  blocks)
int tesseract::Tesseract::source_resolution ( ) const
inline

Definition at line 223 of file tesseractclass.h.

223  {
224  return source_resolution_;
225  }
void tesseract::Tesseract::split_and_recog_word ( WERD_RES word)

Definition at line 144 of file tfacepp.cpp.

144  {
145  // Find the biggest blob gap in the chopped_word.
146  int bestgap = -MAX_INT32;
147  int split_index = 0;
148  for (int b = 1; b < word->chopped_word->NumBlobs(); ++b) {
149  TBOX prev_box = word->chopped_word->blobs[b - 1]->bounding_box();
150  TBOX blob_box = word->chopped_word->blobs[b]->bounding_box();
151  int gap = blob_box.left() - prev_box.right();
152  if (gap > bestgap) {
153  bestgap = gap;
154  split_index = b;
155  }
156  }
157  ASSERT_HOST(split_index > 0);
158 
159  WERD_RES *word2 = NULL;
160  BlamerBundle *orig_bb = NULL;
161  split_word(word, split_index, &word2, &orig_bb);
162 
163  // Recognize the first part of the word.
164  recog_word_recursive(word);
165  // Recognize the second part of the word.
166  recog_word_recursive(word2);
167 
168  join_words(word, word2, orig_bb);
169 }
int NumBlobs() const
Definition: blobs.h:425
#define MAX_INT32
Definition: host.h:120
GenericVector< TBLOB * > blobs
Definition: blobs.h:436
TWERD * chopped_word
Definition: pageres.h:201
Definition: rect.h:30
void recog_word_recursive(WERD_RES *word)
Definition: tfacepp.cpp:110
inT16 right() const
Definition: rect.h:75
void join_words(WERD_RES *word, WERD_RES *word2, BlamerBundle *orig_bb) const
Definition: tfacepp.cpp:240
inT16 left() const
Definition: rect.h:68
#define ASSERT_HOST(x)
Definition: errcode.h:84
void split_word(WERD_RES *word, int split_pt, WERD_RES **right_piece, BlamerBundle **orig_blamer_bundle) const
Definition: tfacepp.cpp:182
void tesseract::Tesseract::split_word ( WERD_RES word,
int  split_pt,
WERD_RES **  right_piece,
BlamerBundle **  orig_blamer_bundle 
) const

Definition at line 182 of file tfacepp.cpp.

185  {
186  ASSERT_HOST(split_pt >0 && split_pt < word->chopped_word->NumBlobs());
187 
188  // Save a copy of the blamer bundle so we can try to reconstruct it below.
189  BlamerBundle *orig_bb =
190  word->blamer_bundle ? new BlamerBundle(*word->blamer_bundle) : NULL;
191 
192  WERD_RES *word2 = new WERD_RES(*word);
193 
194  // blow away the copied chopped_word, as we want to work with
195  // the blobs from the input chopped_word so seam_arrays can be merged.
196  TWERD *chopped = word->chopped_word;
197  TWERD *chopped2 = new TWERD;
198  chopped2->blobs.reserve(chopped->NumBlobs() - split_pt);
199  for (int i = split_pt; i < chopped->NumBlobs(); ++i) {
200  chopped2->blobs.push_back(chopped->blobs[i]);
201  }
202  chopped->blobs.truncate(split_pt);
203  word->chopped_word = NULL;
204  delete word2->chopped_word;
205  word2->chopped_word = NULL;
206 
207  const UNICHARSET &unicharset = *word->uch_set;
208  word->ClearResults();
209  word2->ClearResults();
210  word->chopped_word = chopped;
211  word2->chopped_word = chopped2;
212  word->SetupBasicsFromChoppedWord(unicharset);
213  word2->SetupBasicsFromChoppedWord(unicharset);
214 
215  // Try to adjust the blamer bundle.
216  if (orig_bb != NULL) {
217  // TODO(rays) Looks like a leak to me.
218  // orig_bb should take, rather than copy.
219  word->blamer_bundle = new BlamerBundle();
220  word2->blamer_bundle = new BlamerBundle();
221  orig_bb->SplitBundle(chopped->blobs.back()->bounding_box().right(),
222  word2->chopped_word->blobs[0]->bounding_box().left(),
224  word->blamer_bundle, word2->blamer_bundle);
225  }
226 
227  *right_piece = word2;
228  *orig_blamer_bundle = orig_bb;
229 }
void ClearResults()
Definition: pageres.cpp:1141
int NumBlobs() const
Definition: blobs.h:425
GenericVector< TBLOB * > blobs
Definition: blobs.h:436
T & back() const
BlamerBundle * blamer_bundle
Definition: pageres.h:230
void reserve(int size)
TBOX bounding_box() const
Definition: blobs.cpp:482
void SetupBasicsFromChoppedWord(const UNICHARSET &unicharset_in)
Definition: pageres.cpp:334
void truncate(int size)
TWERD * chopped_word
Definition: pageres.h:201
bool wordrec_debug_blamer
Definition: wordrec.h:167
inT16 right() const
Definition: rect.h:75
UNICHARSET unicharset
Definition: ccutil.h:70
Definition: blobs.h:395
const UNICHARSET * uch_set
Definition: pageres.h:192
int push_back(T object)
#define ASSERT_HOST(x)
Definition: errcode.h:84
bool tesseract::Tesseract::SubAndSuperscriptFix ( WERD_RES word)

Attempt to split off any high (or low) bits at the ends of the word with poor certainty and recognize them separately. If the certainty gets much better and other sanity checks pass, acccept.

This superscript fix is meant to be called in the second pass of recognition when we have tried once and already have a preliminary answer for word.

Returns
Whether we modified the given word.

Definition at line 101 of file superscript.cpp.

101  {
102  if (word->tess_failed || word->word->flag(W_REP_CHAR) ||
103  !word->best_choice) {
104  return false;
105  }
106  int num_leading, num_trailing;
107  ScriptPos sp_leading, sp_trailing;
108  float leading_certainty, trailing_certainty;
109  float avg_certainty, unlikely_threshold;
110 
111  // Calculate the number of whole suspicious characters at the edges.
113  word, &num_leading, &sp_leading, &leading_certainty,
114  &num_trailing, &sp_trailing, &trailing_certainty,
115  &avg_certainty, &unlikely_threshold);
116 
117  const char *leading_pos = sp_leading == SP_SUBSCRIPT ? "sub" : "super";
118  const char *trailing_pos = sp_trailing == SP_SUBSCRIPT ? "sub" : "super";
119 
120  int num_blobs = word->best_choice->length();
121 
122  // Calculate the remainder (partial characters) at the edges.
123  // This accounts for us having classified the best version of
124  // a word as [speaker?'] when it was instead [speaker.^{21}]
125  // (that is we accidentally thought the 2 was attached to the period).
126  int num_remainder_leading = 0, num_remainder_trailing = 0;
127  if (num_leading + num_trailing < num_blobs && unlikely_threshold < 0.0) {
128  int super_y_bottom =
130  int sub_y_top =
132  int last_word_char = num_blobs - 1 - num_trailing;
133  float last_char_certainty = word->best_choice->certainty(last_word_char);
134  if (word->best_choice->unichar_id(last_word_char) != 0 &&
135  last_char_certainty <= unlikely_threshold) {
136  ScriptPos rpos;
137  YOutlierPieces(word, last_word_char, super_y_bottom, sub_y_top,
138  NULL, NULL, &rpos, &num_remainder_trailing);
139  if (num_trailing > 0 && rpos != sp_trailing) num_remainder_trailing = 0;
140  if (num_remainder_trailing > 0 &&
141  last_char_certainty < trailing_certainty) {
142  trailing_certainty = last_char_certainty;
143  }
144  }
145  bool another_blob_available = (num_remainder_trailing == 0) ||
146  num_leading + num_trailing + 1 < num_blobs;
147  int first_char_certainty = word->best_choice->certainty(num_leading);
148  if (another_blob_available &&
149  word->best_choice->unichar_id(num_leading) != 0 &&
150  first_char_certainty <= unlikely_threshold) {
151  ScriptPos lpos;
152  YOutlierPieces(word, num_leading, super_y_bottom, sub_y_top,
153  &lpos, &num_remainder_leading, NULL, NULL);
154  if (num_leading > 0 && lpos != sp_leading) num_remainder_leading = 0;
155  if (num_remainder_leading > 0 &&
156  first_char_certainty < leading_certainty) {
157  leading_certainty = first_char_certainty;
158  }
159  }
160  }
161 
162  // If nothing to do, bail now.
163  if (num_leading + num_trailing +
164  num_remainder_leading + num_remainder_trailing == 0) {
165  return false;
166  }
167 
168  if (superscript_debug >= 1) {
169  tprintf("Candidate for superscript detection: %s (",
170  word->best_choice->unichar_string().string());
171  if (num_leading || num_remainder_leading) {
172  tprintf("%d.%d %s-leading ", num_leading, num_remainder_leading,
173  leading_pos);
174  }
175  if (num_trailing || num_remainder_trailing) {
176  tprintf("%d.%d %s-trailing ", num_trailing, num_remainder_trailing,
177  trailing_pos);
178  }
179  tprintf(")\n");
180  }
181  if (superscript_debug >= 3) {
182  word->best_choice->print();
183  }
184  if (superscript_debug >= 2) {
185  tprintf(" Certainties -- Average: %.2f Unlikely thresh: %.2f ",
186  avg_certainty, unlikely_threshold);
187  if (num_leading)
188  tprintf("Orig. leading (min): %.2f ", leading_certainty);
189  if (num_trailing)
190  tprintf("Orig. trailing (min): %.2f ", trailing_certainty);
191  tprintf("\n");
192  }
193 
194  // We've now calculated the number of rebuilt blobs we want to carve off.
195  // However, split_word() works from TBLOBs in chopped_word, so we need to
196  // convert to those.
197  int num_chopped_leading =
198  LeadingUnicharsToChopped(word, num_leading) + num_remainder_leading;
199  int num_chopped_trailing =
200  TrailingUnicharsToChopped(word, num_trailing) + num_remainder_trailing;
201 
202  int retry_leading = 0;
203  int retry_trailing = 0;
204  bool is_good = false;
205  WERD_RES *revised = TrySuperscriptSplits(
206  num_chopped_leading, leading_certainty, sp_leading,
207  num_chopped_trailing, trailing_certainty, sp_trailing,
208  word, &is_good, &retry_leading, &retry_trailing);
209  if (is_good) {
210  word->ConsumeWordResults(revised);
211  } else if (retry_leading || retry_trailing) {
212  int retry_chopped_leading =
213  LeadingUnicharsToChopped(revised, retry_leading);
214  int retry_chopped_trailing =
215  TrailingUnicharsToChopped(revised, retry_trailing);
216  WERD_RES *revised2 = TrySuperscriptSplits(
217  retry_chopped_leading, leading_certainty, sp_leading,
218  retry_chopped_trailing, trailing_certainty, sp_trailing,
219  revised, &is_good, &retry_leading, &retry_trailing);
220  if (is_good) {
221  word->ConsumeWordResults(revised2);
222  }
223  delete revised2;
224  }
225  delete revised;
226  return is_good;
227 }
BOOL8 flag(WERD_FLAGS mask) const
Definition: werd.h:128
void ConsumeWordResults(WERD_RES *word)
Definition: pageres.cpp:757
WERD_RES * TrySuperscriptSplits(int num_chopped_leading, float leading_certainty, ScriptPos leading_pos, int num_chopped_trailing, float trailing_certainty, ScriptPos trailing_pos, WERD_RES *word, bool *is_good, int *retry_leading, int *retry_trailing)
UNICHAR_ID unichar_id(int index) const
Definition: ratngs.h:313
WERD * word
Definition: pageres.h:175
int length() const
Definition: ratngs.h:301
#define tprintf(...)
Definition: tprintf.h:31
BOOL8 tess_failed
Definition: pageres.h:272
void GetSubAndSuperscriptCandidates(const WERD_RES *word, int *num_rebuilt_leading, ScriptPos *leading_pos, float *leading_certainty, int *num_rebuilt_trailing, ScriptPos *trailing_pos, float *trailing_certainty, float *avg_certainty, float *unlikely_threshold)
const STRING & unichar_string() const
Definition: ratngs.h:525
WERD_CHOICE * best_choice
Definition: pageres.h:219
void YOutlierPieces(WERD_RES *word, int rebuilt_blob_index, int super_y_bottom, int sub_y_top, ScriptPos *leading_pos, int *num_leading_outliers, ScriptPos *trailing_pos, int *num_trailing_outliers)
Definition: superscript.cpp:46
const int kBlnXHeight
Definition: normalis.h:28
const int kBlnBaselineOffset
Definition: normalis.h:29
const char * string() const
Definition: strngs.cpp:201
void print() const
Definition: ratngs.h:564
float certainty() const
Definition: ratngs.h:328
BOOL8 tesseract::Tesseract::terrible_word_crunch ( WERD_RES word,
GARBAGE_LEVEL  garbage_level 
)

Definition at line 508 of file docqual.cpp.

509  {
510  float rating_per_ch;
511  int adjusted_len;
512  int crunch_mode = 0;
513 
514  if ((word->best_choice->unichar_string().length () == 0) ||
515  (strspn (word->best_choice->unichar_string().string(), " ") ==
516  word->best_choice->unichar_string().length ()))
517  crunch_mode = 1;
518  else {
519  adjusted_len = word->reject_map.length ();
520  if (adjusted_len > crunch_rating_max)
521  adjusted_len = crunch_rating_max;
522  rating_per_ch = word->best_choice->rating () / adjusted_len;
523 
524  if (rating_per_ch > crunch_terrible_rating)
525  crunch_mode = 2;
526  else if (crunch_terrible_garbage && (garbage_level == G_TERRIBLE))
527  crunch_mode = 3;
528  else if ((word->best_choice->certainty () < crunch_poor_garbage_cert) &&
529  (garbage_level != G_OK))
530  crunch_mode = 4;
531  else if ((rating_per_ch > crunch_poor_garbage_rate) &&
532  (garbage_level != G_OK))
533  crunch_mode = 5;
534  }
535  if (crunch_mode > 0) {
536  if (crunch_debug > 2) {
537  tprintf ("Terrible_word_crunch (%d) on \"%s\"\n",
538  crunch_mode, word->best_choice->unichar_string().string());
539  }
540  return TRUE;
541  }
542  else
543  return FALSE;
544 }
#define TRUE
Definition: capi.h:45
#define tprintf(...)
Definition: tprintf.h:31
REJMAP reject_map
Definition: pageres.h:271
#define FALSE
Definition: capi.h:46
const STRING & unichar_string() const
Definition: ratngs.h:525
inT32 length() const
Definition: strngs.cpp:196
inT32 length() const
Definition: rejctmap.h:236
float rating() const
Definition: ratngs.h:325
WERD_CHOICE * best_choice
Definition: pageres.h:219
const char * string() const
Definition: strngs.cpp:201
float certainty() const
Definition: ratngs.h:328
Definition: docqual.h:28
bool tesseract::Tesseract::tess_acceptable_word ( WERD_RES word)

Definition at line 69 of file tessbox.cpp.

69  {
70  return getDict().AcceptableResult(word);
71 }
bool AcceptableResult(WERD_RES *word)
Definition: stopper.cpp:110
Dict & getDict()
Definition: classify.h:65
void tesseract::Tesseract::tess_add_doc_word ( WERD_CHOICE word_choice)

Definition at line 79 of file tessbox.cpp.

79  {
80  getDict().add_document_word(*word_choice);
81 }
Dict & getDict()
Definition: classify.h:65
void add_document_word(const WERD_CHOICE &best_choice)
Adds a word found on this document to the document specific dictionary.
Definition: dict.cpp:592
void tesseract::Tesseract::tess_segment_pass_n ( int  pass_n,
WERD_RES word 
)

Definition at line 39 of file tessbox.cpp.

39  {
40  int saved_enable_assoc = 0;
41  int saved_chop_enable = 0;
42 
43  if (word->word->flag(W_DONT_CHOP)) {
44  saved_enable_assoc = wordrec_enable_assoc;
45  saved_chop_enable = chop_enable;
46  wordrec_enable_assoc.set_value(0);
47  chop_enable.set_value(0);
48  }
49  if (pass_n == 1)
50  set_pass1();
51  else
52  set_pass2();
53  recog_word(word);
54  if (word->best_choice == NULL)
55  word->SetupFake(*word->uch_set);
56  if (word->word->flag(W_DONT_CHOP)) {
57  wordrec_enable_assoc.set_value(saved_enable_assoc);
58  chop_enable.set_value(saved_chop_enable);
59  }
60 }
void recog_word(WERD_RES *word)
Definition: tfacepp.cpp:46
BOOL8 flag(WERD_FLAGS mask) const
Definition: werd.h:128
WERD * word
Definition: pageres.h:175
bool wordrec_enable_assoc
Definition: wordrec.h:130
WERD_CHOICE * best_choice
Definition: pageres.h:219
const UNICHARSET * uch_set
Definition: pageres.h:192
void SetupFake(const UNICHARSET &uch)
Definition: pageres.cpp:343
void set_pass2()
Definition: tface.cpp:101
void set_pass1()
Definition: tface.cpp:89
bool tesseract::Tesseract::TestNewNormalization ( int  original_misfits,
float  baseline_shift,
float  new_x_ht,
WERD_RES word,
BLOCK block,
ROW row 
)

Definition at line 1442 of file control.cpp.

1444  {
1445  bool accept_new_x_ht = false;
1446  WERD_RES new_x_ht_word(word->word);
1447  if (word->blamer_bundle != NULL) {
1448  new_x_ht_word.blamer_bundle = new BlamerBundle();
1449  new_x_ht_word.blamer_bundle->CopyTruth(*(word->blamer_bundle));
1450  }
1451  new_x_ht_word.x_height = new_x_ht;
1452  new_x_ht_word.baseline_shift = baseline_shift;
1453  new_x_ht_word.caps_height = 0.0;
1454  new_x_ht_word.SetupForRecognition(
1457  poly_allow_detailed_fx, row, block);
1458  match_word_pass_n(2, &new_x_ht_word, row, block);
1459  if (!new_x_ht_word.tess_failed) {
1460  int new_misfits = CountMisfitTops(&new_x_ht_word);
1461  if (debug_x_ht_level >= 1) {
1462  tprintf("Old misfits=%d with x-height %f, new=%d with x-height %f\n",
1463  original_misfits, word->x_height,
1464  new_misfits, new_x_ht);
1465  tprintf("Old rating= %f, certainty=%f, new=%f, %f\n",
1466  word->best_choice->rating(), word->best_choice->certainty(),
1467  new_x_ht_word.best_choice->rating(),
1468  new_x_ht_word.best_choice->certainty());
1469  }
1470  // The misfits must improve and either the rating or certainty.
1471  accept_new_x_ht = new_misfits < original_misfits &&
1472  (new_x_ht_word.best_choice->certainty() >
1473  word->best_choice->certainty() ||
1474  new_x_ht_word.best_choice->rating() <
1475  word->best_choice->rating());
1476  if (debug_x_ht_level >= 1) {
1477  ReportXhtFixResult(accept_new_x_ht, new_x_ht, word, &new_x_ht_word);
1478  }
1479  }
1480  if (accept_new_x_ht) {
1481  word->ConsumeWordResults(&new_x_ht_word);
1482  return true;
1483  }
1484  return false;
1485 }
void ConsumeWordResults(WERD_RES *word)
Definition: pageres.cpp:757
Pix * BestPix() const
BlamerBundle * blamer_bundle
Definition: pageres.h:230
WERD * word
Definition: pageres.h:175
int CountMisfitTops(WERD_RES *word_res)
Definition: fixxht.cpp:69
#define tprintf(...)
Definition: tprintf.h:31
bool classify_bln_numeric_mode
Definition: classify.h:500
UNICHARSET unicharset
Definition: ccutil.h:70
float rating() const
Definition: ratngs.h:325
WERD_CHOICE * best_choice
Definition: pageres.h:219
float x_height
Definition: pageres.h:295
void ReportXhtFixResult(bool accept_new_word, float new_x_ht, WERD_RES *word, WERD_RES *new_word)
Definition: control.cpp:1387
void match_word_pass_n(int pass_n, WERD_RES *word, ROW *row, BLOCK *block)
Definition: control.cpp:1554
float certainty() const
Definition: ratngs.h:328
const Textord& tesseract::Tesseract::textord ( ) const
inline

Definition at line 245 of file tesseractclass.h.

245  {
246  return textord_;
247  }
void tesseract::Tesseract::TidyUp ( PAGE_RES page_res)
  • Counts up the labelled words and the blobs within.
  • Deletes all unused or emptied words, counting the unused ones.
  • Resets W_BOL and W_EOL flags correctly.
  • Builds the rebuild_word and rebuilds the box_word and the best_choice.

Definition at line 706 of file applybox.cpp.

706  {
707  int ok_blob_count = 0;
708  int bad_blob_count = 0;
709  int ok_word_count = 0;
710  int unlabelled_words = 0;
711  PAGE_RES_IT pr_it(page_res);
712  WERD_RES* word_res;
713  for (; (word_res = pr_it.word()) != NULL; pr_it.forward()) {
714  int ok_in_word = 0;
715  int blob_count = word_res->correct_text.size();
716  WERD_CHOICE* word_choice = new WERD_CHOICE(word_res->uch_set, blob_count);
717  word_choice->set_permuter(TOP_CHOICE_PERM);
718  for (int c = 0; c < blob_count; ++c) {
719  if (word_res->correct_text[c].length() > 0) {
720  ++ok_in_word;
721  }
722  // Since we only need a fake word_res->best_choice, the actual
723  // unichar_ids do not matter. Which is fortunate, since TidyUp()
724  // can be called while training Tesseract, at the stage where
725  // unicharset is not meaningful yet.
727  INVALID_UNICHAR_ID, word_res->best_state[c], 1.0f, -1.0f);
728  }
729  if (ok_in_word > 0) {
730  ok_blob_count += ok_in_word;
731  bad_blob_count += word_res->correct_text.size() - ok_in_word;
732  word_res->LogNewRawChoice(word_choice);
733  word_res->LogNewCookedChoice(1, false, word_choice);
734  } else {
735  ++unlabelled_words;
736  if (applybox_debug > 0) {
737  tprintf("APPLY_BOXES: Unlabelled word at :");
738  word_res->word->bounding_box().print();
739  }
740  pr_it.DeleteCurrentWord();
741  delete word_choice;
742  }
743  }
744  pr_it.restart_page();
745  for (; (word_res = pr_it.word()) != NULL; pr_it.forward()) {
746  // Denormalize back to a BoxWord.
747  word_res->RebuildBestState();
748  word_res->SetupBoxWord();
749  word_res->word->set_flag(W_BOL, pr_it.prev_row() != pr_it.row());
750  word_res->word->set_flag(W_EOL, pr_it.next_row() != pr_it.row());
751  }
752  if (applybox_debug > 0) {
753  tprintf(" Found %d good blobs.\n", ok_blob_count);
754  if (bad_blob_count > 0) {
755  tprintf(" Leaving %d unlabelled blobs in %d words.\n",
756  bad_blob_count, ok_word_count);
757  }
758  if (unlabelled_words > 0)
759  tprintf(" %d remaining unlabelled words deleted.\n", unlabelled_words);
760  }
761 }
Definition: werd.h:36
void set_flag(WERD_FLAGS mask, BOOL8 value)
Definition: werd.h:129
bool LogNewRawChoice(WERD_CHOICE *word_choice)
Definition: pageres.cpp:596
WERD * word
Definition: pageres.h:175
void append_unichar_id_space_allocated(UNICHAR_ID unichar_id, int blob_count, float rating, float certainty)
Definition: ratngs.h:450
GenericVector< int > best_state
Definition: pageres.h:255
#define tprintf(...)
Definition: tprintf.h:31
int size() const
Definition: genericvector.h:72
TBOX bounding_box() const
Definition: werd.cpp:160
bool LogNewCookedChoice(int max_num_choices, bool debug, WERD_CHOICE *word_choice)
Definition: pageres.cpp:612
void set_permuter(uinT8 perm)
Definition: ratngs.h:373
void print() const
Definition: rect.h:270
Definition: werd.h:35
const UNICHARSET * uch_set
Definition: pageres.h:192
GenericVector< STRING > correct_text
Definition: pageres.h:259
void RebuildBestState()
Definition: pageres.cpp:800
int length() const
Definition: genericvector.h:79
void SetupBoxWord()
Definition: pageres.cpp:843
void tesseract::Tesseract::tilde_crunch ( PAGE_RES_IT page_res_it)

Definition at line 422 of file docqual.cpp.

422  {
423  WERD_RES *word;
424  GARBAGE_LEVEL garbage_level;
425  PAGE_RES_IT copy_it;
426  BOOL8 prev_potential_marked = FALSE;
427  BOOL8 found_terrible_word = FALSE;
428  BOOL8 ok_dict_word;
429 
430  page_res_it.restart_page();
431  while (page_res_it.word() != NULL) {
432  POLY_BLOCK* pb = page_res_it.block()->block->poly_block();
433  if (pb != NULL && !pb->IsText()) {
434  page_res_it.forward();
435  continue;
436  }
437  word = page_res_it.word();
438 
440  convert_bad_unlv_chs(word);
441 
443  word->merge_tess_fails();
444 
445  if (word->reject_map.accept_count () != 0) {
446  found_terrible_word = FALSE;
447  //Forget earlier potential crunches
448  prev_potential_marked = FALSE;
449  }
450  else {
451  ok_dict_word = safe_dict_word(word);
452  garbage_level = garbage_word (word, ok_dict_word);
453 
454  if ((garbage_level != G_NEVER_CRUNCH) &&
455  (terrible_word_crunch (word, garbage_level))) {
456  if (crunch_debug > 0) {
457  tprintf ("T CRUNCHING: \"%s\"\n",
458  word->best_choice->unichar_string().string());
459  }
461  if (prev_potential_marked) {
462  while (copy_it.word () != word) {
463  if (crunch_debug > 0) {
464  tprintf ("P1 CRUNCHING: \"%s\"\n",
465  copy_it.word()->best_choice->unichar_string().string());
466  }
467  copy_it.word ()->unlv_crunch_mode = CR_KEEP_SPACE;
468  copy_it.forward ();
469  }
470  prev_potential_marked = FALSE;
471  }
472  found_terrible_word = TRUE;
473  }
474  else if ((garbage_level != G_NEVER_CRUNCH) &&
475  (potential_word_crunch (word,
476  garbage_level, ok_dict_word))) {
477  if (found_terrible_word) {
478  if (crunch_debug > 0) {
479  tprintf ("P2 CRUNCHING: \"%s\"\n",
480  word->best_choice->unichar_string().string());
481  }
483  }
484  else if (!prev_potential_marked) {
485  copy_it = page_res_it;
486  prev_potential_marked = TRUE;
487  if (crunch_debug > 1) {
488  tprintf ("P3 CRUNCHING: \"%s\"\n",
489  word->best_choice->unichar_string().string());
490  }
491  }
492  }
493  else {
494  found_terrible_word = FALSE;
495  //Forget earlier potential crunches
496  prev_potential_marked = FALSE;
497  if (crunch_debug > 2) {
498  tprintf ("NO CRUNCH: \"%s\"\n",
499  word->best_choice->unichar_string().string());
500  }
501  }
502  }
503  page_res_it.forward ();
504  }
505 }
#define TRUE
Definition: capi.h:45
inT16 accept_count()
Definition: rejctmap.cpp:331
GARBAGE_LEVEL garbage_word(WERD_RES *word, BOOL8 ok_dict_word)
Definition: docqual.cpp:684
BOOL8 potential_word_crunch(WERD_RES *word, GARBAGE_LEVEL garbage_level, BOOL8 ok_dict_word)
Definition: docqual.cpp:546
BOOL8 terrible_word_crunch(WERD_RES *word, GARBAGE_LEVEL garbage_level)
Definition: docqual.cpp:508
CRUNCH_MODE unlv_crunch_mode
Definition: pageres.h:294
WERD_RES * word() const
Definition: pageres.h:736
WERD_RES * forward()
Definition: pageres.h:716
void merge_tess_fails()
Definition: pageres.cpp:1061
#define tprintf(...)
Definition: tprintf.h:31
REJMAP reject_map
Definition: pageres.h:271
#define FALSE
Definition: capi.h:46
const STRING & unichar_string() const
Definition: ratngs.h:525
bool crunch_early_convert_bad_unlv_chs
WERD_RES * restart_page()
Definition: pageres.h:683
BLOCK_RES * block() const
Definition: pageres.h:742
WERD_CHOICE * best_choice
Definition: pageres.h:219
bool IsText() const
Definition: polyblk.h:52
unsigned char BOOL8
Definition: host.h:113
inT16 safe_dict_word(const WERD_RES *werd_res)
Definition: reject.cpp:607
const char * string() const
Definition: strngs.cpp:201
void convert_bad_unlv_chs(WERD_RES *word_res)
Definition: docqual.cpp:664
GARBAGE_LEVEL
Definition: docqual.h:25
BLOCK * block
Definition: pageres.h:99
POLY_BLOCK * poly_block() const
Definition: pdblock.h:55
void tesseract::Tesseract::tilde_delete ( PAGE_RES_IT page_res_it)

Definition at line 594 of file docqual.cpp.

594  {
595  WERD_RES *word;
596  PAGE_RES_IT copy_it;
597  BOOL8 deleting_from_bol = FALSE;
598  BOOL8 marked_delete_point = FALSE;
599  inT16 debug_delete_mode;
600  CRUNCH_MODE delete_mode;
601  inT16 x_debug_delete_mode;
602  CRUNCH_MODE x_delete_mode;
603 
604  page_res_it.restart_page();
605  while (page_res_it.word() != NULL) {
606  word = page_res_it.word();
607 
608  delete_mode = word_deletable (word, debug_delete_mode);
609  if (delete_mode != CR_NONE) {
610  if (word->word->flag (W_BOL) || deleting_from_bol) {
611  if (crunch_debug > 0) {
612  tprintf ("BOL CRUNCH DELETING(%d): \"%s\"\n",
613  debug_delete_mode,
614  word->best_choice->unichar_string().string());
615  }
616  word->unlv_crunch_mode = delete_mode;
617  deleting_from_bol = TRUE;
618  } else if (word->word->flag(W_EOL)) {
619  if (marked_delete_point) {
620  while (copy_it.word() != word) {
621  x_delete_mode = word_deletable (copy_it.word (),
622  x_debug_delete_mode);
623  if (crunch_debug > 0) {
624  tprintf ("EOL CRUNCH DELETING(%d): \"%s\"\n",
625  x_debug_delete_mode,
626  copy_it.word()->best_choice->unichar_string().string());
627  }
628  copy_it.word ()->unlv_crunch_mode = x_delete_mode;
629  copy_it.forward ();
630  }
631  }
632  if (crunch_debug > 0) {
633  tprintf ("EOL CRUNCH DELETING(%d): \"%s\"\n",
634  debug_delete_mode,
635  word->best_choice->unichar_string().string());
636  }
637  word->unlv_crunch_mode = delete_mode;
638  deleting_from_bol = FALSE;
639  marked_delete_point = FALSE;
640  }
641  else {
642  if (!marked_delete_point) {
643  copy_it = page_res_it;
644  marked_delete_point = TRUE;
645  }
646  }
647  }
648  else {
649  deleting_from_bol = FALSE;
650  //Forget earlier potential crunches
651  marked_delete_point = FALSE;
652  }
653  /*
654  The following step has been left till now as the tess fails are used to
655  determine if the word is deletable.
656  */
658  word->merge_tess_fails();
659  page_res_it.forward ();
660  }
661 }
Definition: werd.h:36
BOOL8 flag(WERD_FLAGS mask) const
Definition: werd.h:128
#define TRUE
Definition: capi.h:45
CRUNCH_MODE
Definition: pageres.h:145
CRUNCH_MODE unlv_crunch_mode
Definition: pageres.h:294
WERD * word
Definition: pageres.h:175
WERD_RES * word() const
Definition: pageres.h:736
WERD_RES * forward()
Definition: pageres.h:716
void merge_tess_fails()
Definition: pageres.cpp:1061
#define tprintf(...)
Definition: tprintf.h:31
#define FALSE
Definition: capi.h:46
const STRING & unichar_string() const
Definition: ratngs.h:525
WERD_RES * restart_page()
Definition: pageres.h:683
short inT16
Definition: host.h:100
Definition: werd.h:35
WERD_CHOICE * best_choice
Definition: pageres.h:219
unsigned char BOOL8
Definition: host.h:113
const char * string() const
Definition: strngs.cpp:201
CRUNCH_MODE word_deletable(WERD_RES *word, inT16 &delete_mode)
Definition: docqual.cpp:899
bool tesseract::Tesseract::TrainedXheightFix ( WERD_RES word,
BLOCK block,
ROW row 
)

Definition at line 1408 of file control.cpp.

1408  {
1409  int original_misfits = CountMisfitTops(word);
1410  if (original_misfits == 0)
1411  return false;
1412  float baseline_shift = 0.0f;
1413  float new_x_ht = ComputeCompatibleXheight(word, &baseline_shift);
1414  if (baseline_shift != 0.0f) {
1415  // Try the shift on its own first.
1416  if (!TestNewNormalization(original_misfits, baseline_shift, word->x_height,
1417  word, block, row))
1418  return false;
1419  original_misfits = CountMisfitTops(word);
1420  if (original_misfits > 0) {
1421  float new_baseline_shift;
1422  // Now recompute the new x_height.
1423  new_x_ht = ComputeCompatibleXheight(word, &new_baseline_shift);
1424  if (new_x_ht >= kMinRefitXHeightFraction * word->x_height) {
1425  // No test of return value here, as we are definitely making a change
1426  // to the word by shifting the baseline.
1427  TestNewNormalization(original_misfits, baseline_shift, new_x_ht,
1428  word, block, row);
1429  }
1430  }
1431  return true;
1432  } else if (new_x_ht >= kMinRefitXHeightFraction * word->x_height) {
1433  return TestNewNormalization(original_misfits, 0.0f, new_x_ht,
1434  word, block, row);
1435  } else {
1436  return false;
1437  }
1438 }
float ComputeCompatibleXheight(WERD_RES *word_res, float *baseline_shift)
Definition: fixxht.cpp:101
const double kMinRefitXHeightFraction
Definition: control.cpp:56
int CountMisfitTops(WERD_RES *word_res)
Definition: fixxht.cpp:69
bool TestNewNormalization(int original_misfits, float baseline_shift, float new_x_ht, WERD_RES *word, BLOCK *block, ROW *row)
Definition: control.cpp:1442
float x_height
Definition: pageres.h:295
WERD_RES * tesseract::Tesseract::TrySuperscriptSplits ( int  num_chopped_leading,
float  leading_certainty,
ScriptPos  leading_pos,
int  num_chopped_trailing,
float  trailing_certainty,
ScriptPos  trailing_pos,
WERD_RES word,
bool *  is_good,
int *  retry_rebuild_leading,
int *  retry_rebuild_trailing 
)

Try splitting off the given number of (chopped) blobs from the front and back of the given word and recognizing the pieces.

Parameters
[in]num_chopped_leadinghow many chopped blobs from the left end of the word to chop off and try recognizing as a superscript (or subscript)
[in]leading_certaintythe (minimum) certainty had by the characters in the original leading section.
[in]leading_pos"super" or "sub" (for debugging)
[in]num_chopped_trailinghow many chopped blobs from the right end of the word to chop off and try recognizing as a superscript (or subscript)
[in]trailing_certaintythe (minimum) certainty had by the characters in the original trailing section.
[in]trailing_pos"super" or "sub" (for debugging)
[in]wordthe word to try to chop up.
[out]is_gooddo we believe our result?
[out]retry_rebuild_leading,retry_rebuild_trailingIf non-zero, and !is_good, then the caller may have luck trying to split the returned word with this number of (rebuilt) leading and trailing blobs / unichars.
Returns
A word which is the result of re-recognizing as asked.

Definition at line 382 of file superscript.cpp.

388  {
389  int num_chopped = word->chopped_word->NumBlobs();
390 
391  *retry_rebuild_leading = *retry_rebuild_trailing = 0;
392 
393  // Chop apart the word into up to three pieces.
394 
395  BlamerBundle *bb0 = NULL;
396  BlamerBundle *bb1 = NULL;
397  WERD_RES *prefix = NULL;
398  WERD_RES *core = NULL;
399  WERD_RES *suffix = NULL;
400  if (num_chopped_leading > 0) {
401  prefix = new WERD_RES(*word);
402  split_word(prefix, num_chopped_leading, &core, &bb0);
403  } else {
404  core = new WERD_RES(*word);
405  }
406 
407  if (num_chopped_trailing > 0) {
408  int split_pt = num_chopped - num_chopped_trailing - num_chopped_leading;
409  split_word(core, split_pt, &suffix, &bb1);
410  }
411 
412  // Recognize the pieces in turn.
413  int saved_cp_multiplier = classify_class_pruner_multiplier;
414  int saved_im_multiplier = classify_integer_matcher_multiplier;
415  if (prefix) {
416  // Turn off Tesseract's y-position penalties for the leading superscript.
419 
420  // Adjust our expectations about the baseline for this prefix.
421  if (superscript_debug >= 3) {
422  tprintf(" recognizing first %d chopped blobs\n", num_chopped_leading);
423  }
424  recog_word_recursive(prefix);
425  if (superscript_debug >= 2) {
426  tprintf(" The leading bits look like %s %s\n",
427  ScriptPosToString(leading_pos),
428  prefix->best_choice->unichar_string().string());
429  }
430 
431  // Restore the normal y-position penalties.
432  classify_class_pruner_multiplier.set_value(saved_cp_multiplier);
433  classify_integer_matcher_multiplier.set_value(saved_im_multiplier);
434  }
435 
436  if (superscript_debug >= 3) {
437  tprintf(" recognizing middle %d chopped blobs\n",
438  num_chopped - num_chopped_leading - num_chopped_trailing);
439  }
440 
441  if (suffix) {
442  // Turn off Tesseract's y-position penalties for the trailing superscript.
445 
446  if (superscript_debug >= 3) {
447  tprintf(" recognizing last %d chopped blobs\n", num_chopped_trailing);
448  }
449  recog_word_recursive(suffix);
450  if (superscript_debug >= 2) {
451  tprintf(" The trailing bits look like %s %s\n",
452  ScriptPosToString(trailing_pos),
453  suffix->best_choice->unichar_string().string());
454  }
455 
456  // Restore the normal y-position penalties.
457  classify_class_pruner_multiplier.set_value(saved_cp_multiplier);
458  classify_integer_matcher_multiplier.set_value(saved_im_multiplier);
459  }
460 
461  // Evaluate whether we think the results are believably better
462  // than what we already had.
463  bool good_prefix = !prefix || BelievableSuperscript(
464  superscript_debug >= 1, *prefix,
465  superscript_bettered_certainty * leading_certainty,
466  retry_rebuild_leading, NULL);
467  bool good_suffix = !suffix || BelievableSuperscript(
468  superscript_debug >= 1, *suffix,
469  superscript_bettered_certainty * trailing_certainty,
470  NULL, retry_rebuild_trailing);
471 
472  *is_good = good_prefix && good_suffix;
473  if (!*is_good && !*retry_rebuild_leading && !*retry_rebuild_trailing) {
474  // None of it is any good. Quit now.
475  delete core;
476  delete prefix;
477  delete suffix;
478  return NULL;
479  }
480  recog_word_recursive(core);
481 
482  // Now paste the results together into core.
483  if (suffix) {
484  suffix->SetAllScriptPositions(trailing_pos);
485  join_words(core, suffix, bb1);
486  }
487  if (prefix) {
488  prefix->SetAllScriptPositions(leading_pos);
489  join_words(prefix, core, bb0);
490  core = prefix;
491  prefix = NULL;
492  }
493 
494  if (superscript_debug >= 1) {
495  tprintf("%s superscript fix: %s\n", *is_good ? "ACCEPT" : "REJECT",
496  core->best_choice->unichar_string().string());
497  }
498  return core;
499 }
double superscript_bettered_certainty
int NumBlobs() const
Definition: blobs.h:425
bool BelievableSuperscript(bool debug, const WERD_RES &word, float certainty_threshold, int *left_ok, int *right_ok) const
#define tprintf(...)
Definition: tprintf.h:31
TWERD * chopped_word
Definition: pageres.h:201
void recog_word_recursive(WERD_RES *word)
Definition: tfacepp.cpp:110
const STRING & unichar_string() const
Definition: ratngs.h:525
void join_words(WERD_RES *word, WERD_RES *word2, BlamerBundle *orig_bb) const
Definition: tfacepp.cpp:240
int classify_class_pruner_multiplier
Definition: classify.h:465
void SetAllScriptPositions(tesseract::ScriptPos position)
Definition: pageres.cpp:860
WERD_CHOICE * best_choice
Definition: pageres.h:219
const char * string() const
Definition: strngs.cpp:201
int classify_integer_matcher_multiplier
Definition: classify.h:469
void split_word(WERD_RES *word, int split_pt, WERD_RES **right_piece, BlamerBundle **orig_blamer_bundle) const
Definition: tfacepp.cpp:182
const char * ScriptPosToString(enum ScriptPos script_pos)
Definition: ratngs.cpp:180
void tesseract::Tesseract::unrej_good_chs ( WERD_RES word,
ROW row 
)

Definition at line 120 of file docqual.cpp.

120  {
121  if (word->bln_boxes == NULL ||
122  word->rebuild_word == NULL || word->rebuild_word->blobs.empty())
123  return;
124 
125  DocQualCallbacks cb(word);
127  *word->rebuild_word,
129 }
tesseract::BoxWord * bln_boxes
Definition: pageres.h:184
GenericVector< TBLOB * > blobs
Definition: blobs.h:436
bool empty() const
Definition: genericvector.h:84
void ProcessMatchedBlobs(const TWERD &other, TessCallback1< int > *cb) const
Definition: boxword.cpp:193
void AcceptIfGoodQuality(int index)
Definition: docqual.cpp:49
TWERD * rebuild_word
Definition: pageres.h:244
_ConstTessMemberResultCallback_0_0< false, R, T1 >::base * NewPermanentTessCallback(const T1 *obj, R(T2::*member)() const)
Definition: tesscallback.h:116
void tesseract::Tesseract::unrej_good_quality_words ( PAGE_RES_IT page_res_it)

Definition at line 165 of file docqual.cpp.

166  {
167  WERD_RES *word;
168  ROW_RES *current_row;
169  BLOCK_RES *current_block;
170  int i;
171 
172  page_res_it.restart_page ();
173  while (page_res_it.word () != NULL) {
174  check_debug_pt (page_res_it.word (), 100);
175  if (bland_unrej) {
176  word = page_res_it.word ();
177  for (i = 0; i < word->reject_map.length (); i++) {
178  if (word->reject_map[i].accept_if_good_quality ())
179  word->reject_map[i].setrej_quality_accept ();
180  }
181  page_res_it.forward ();
182  }
183  else if ((page_res_it.row ()->char_count > 0) &&
184  ((page_res_it.row ()->rej_count /
185  (float) page_res_it.row ()->char_count) <=
187  word = page_res_it.word ();
191  word->best_choice->unichar_string().string(),
193  != AC_UNACCEPTABLE)) {
194  unrej_good_chs(word, page_res_it.row ()->row);
195  }
196  page_res_it.forward ();
197  }
198  else {
199  /* Skip to end of dodgy row */
200  current_row = page_res_it.row ();
201  while ((page_res_it.word () != NULL) &&
202  (page_res_it.row () == current_row))
203  page_res_it.forward ();
204  }
205  check_debug_pt (page_res_it.word (), 110);
206  }
207  page_res_it.restart_page ();
208  page_res_it.page_res->char_count = 0;
209  page_res_it.page_res->rej_count = 0;
210  current_block = NULL;
211  current_row = NULL;
212  while (page_res_it.word () != NULL) {
213  if (current_block != page_res_it.block ()) {
214  current_block = page_res_it.block ();
215  current_block->char_count = 0;
216  current_block->rej_count = 0;
217  }
218  if (current_row != page_res_it.row ()) {
219  current_row = page_res_it.row ();
220  current_row->char_count = 0;
221  current_row->rej_count = 0;
222  current_row->whole_word_rej_count = 0;
223  }
224  page_res_it.rej_stat_word ();
225  page_res_it.forward ();
226  }
227 }
inT32 char_count
Definition: pageres.h:100
inT32 whole_word_rej_count
Definition: pageres.h:130
void rej_stat_word()
Definition: pageres.cpp:1674
const STRING & unichar_lengths() const
Definition: ratngs.h:532
inT32 char_count
Definition: pageres.h:128
inT32 rej_count
Definition: pageres.h:101
void unrej_good_chs(WERD_RES *word, ROW *row)
Definition: docqual.cpp:120
WERD_RES * word() const
Definition: pageres.h:736
WERD_RES * forward()
Definition: pageres.h:716
inT32 rej_count
Definition: pageres.h:61
REJMAP reject_map
Definition: pageres.h:271
BOOL8 check_debug_pt(WERD_RES *word, int location)
Definition: control.cpp:1772
ROW_RES * row() const
Definition: pageres.h:739
const STRING & unichar_string() const
Definition: ratngs.h:525
BOOL8 quality_recoverable_rejects()
Definition: rejctmap.cpp:354
WERD_RES * restart_page()
Definition: pageres.h:683
Unacceptable word.
Definition: control.h:36
inT32 char_count
Definition: pageres.h:60
inT32 rej_count
Definition: pageres.h:129
ROW * row
Definition: pageres.h:127
inT32 length() const
Definition: rejctmap.h:236
BLOCK_RES * block() const
Definition: pageres.h:742
WERD_CHOICE * best_choice
Definition: pageres.h:219
const UNICHARSET * uch_set
Definition: pageres.h:192
const char * string() const
Definition: strngs.cpp:201
ACCEPTABLE_WERD_TYPE acceptable_word_string(const UNICHARSET &char_set, const char *s, const char *lengths)
Definition: control.cpp:1668
PAGE_RES * page_res
Definition: pageres.h:661
BOOL8 tesseract::Tesseract::word_adaptable ( WERD_RES word,
uinT16  mode 
)

Definition at line 45 of file adaptions.cpp.

47  {
49  tprintf("Running word_adaptable() for %s rating %.4f certainty %.4f\n",
50  word->best_choice == NULL ? "" :
52  word->best_choice->rating(), word->best_choice->certainty());
53  }
54 
55  BOOL8 status = FALSE;
56  BITS16 flags(mode);
57 
58  enum MODES
59  {
60  ADAPTABLE_WERD,
61  ACCEPTABLE_WERD,
62  CHECK_DAWGS,
63  CHECK_SPACES,
64  CHECK_ONE_ELL_CONFLICT,
65  CHECK_AMBIG_WERD
66  };
67 
68  /*
69  0: NO adaption
70  */
71  if (mode == 0) {
72  if (tessedit_adaption_debug) tprintf("adaption disabled\n");
73  return FALSE;
74  }
75 
76  if (flags.bit (ADAPTABLE_WERD)) {
77  status |= word->tess_would_adapt; // result of Classify::AdaptableWord()
78  if (tessedit_adaption_debug && !status) {
79  tprintf("tess_would_adapt bit is false\n");
80  }
81  }
82 
83  if (flags.bit (ACCEPTABLE_WERD)) {
84  status |= word->tess_accepted;
85  if (tessedit_adaption_debug && !status) {
86  tprintf("tess_accepted bit is false\n");
87  }
88  }
89 
90  if (!status) { // If not set then
91  return FALSE; // ignore other checks
92  }
93 
94  if (flags.bit (CHECK_DAWGS) &&
95  (word->best_choice->permuter () != SYSTEM_DAWG_PERM) &&
96  (word->best_choice->permuter () != FREQ_DAWG_PERM) &&
97  (word->best_choice->permuter () != USER_DAWG_PERM) &&
98  (word->best_choice->permuter () != NUMBER_PERM)) {
99  if (tessedit_adaption_debug) tprintf("word not in dawgs\n");
100  return FALSE;
101  }
102 
103  if (flags.bit (CHECK_ONE_ELL_CONFLICT) && one_ell_conflict (word, FALSE)) {
104  if (tessedit_adaption_debug) tprintf("word has ell conflict\n");
105  return FALSE;
106  }
107 
108  if (flags.bit (CHECK_SPACES) &&
109  (strchr(word->best_choice->unichar_string().string(), ' ') != NULL)) {
110  if (tessedit_adaption_debug) tprintf("word contains spaces\n");
111  return FALSE;
112  }
113 
114  if (flags.bit (CHECK_AMBIG_WERD) &&
116  if (tessedit_adaption_debug) tprintf("word is ambiguous\n");
117  return FALSE;
118  }
119 
121  tprintf("returning status %d\n", status);
122  }
123  return status;
124 }
BOOL8 tess_accepted
Definition: pageres.h:280
BOOL8 one_ell_conflict(WERD_RES *word_res, BOOL8 update_map)
Definition: reject.cpp:292
bool dangerous_ambig_found() const
Definition: ratngs.h:361
#define tprintf(...)
Definition: tprintf.h:31
#define FALSE
Definition: capi.h:46
const STRING & unichar_string() const
Definition: ratngs.h:525
CMD_EVENTS mode
Definition: pgedit.cpp:116
float rating() const
Definition: ratngs.h:325
uinT8 permuter() const
Definition: ratngs.h:344
WERD_CHOICE * best_choice
Definition: pageres.h:219
Definition: bits16.h:25
unsigned char BOOL8
Definition: host.h:113
BOOL8 tess_would_adapt
Definition: pageres.h:281
const char * string() const
Definition: strngs.cpp:201
float certainty() const
Definition: ratngs.h:328
BOOL8 tesseract::Tesseract::word_blank_and_set_display ( PAGE_RES_IT pr_its)

Definition at line 717 of file pgedit.cpp.

717  {
718  pr_it->word()->word->bounding_box().plot(image_win, ScrollView::BLACK,
720  return word_set_display(pr_it);
721 }
ScrollView * image_win
Definition: pgedit.cpp:107
BOOL8 word_set_display(PAGE_RES_IT *pr_it)
Definition: pgedit.cpp:946
BOOL8 tesseract::Tesseract::word_bln_display ( PAGE_RES_IT pr_it)

word_bln_display()

Normalize word and display in word window

Definition at line 729 of file pgedit.cpp.

729  {
730  WERD_RES* word_res = pr_it->word();
731  if (word_res->chopped_word == NULL) {
732  // Setup word normalization parameters.
733  word_res->SetupForRecognition(unicharset, this, BestPix(),
738  pr_it->row()->row, pr_it->block()->block);
739  }
742  1.0, 0.0f, -1000.0f, 1000.0f);
743  C_BLOB_IT it(word_res->word->cblob_list());
745  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
746  it.data()->plot_normed(word_res->denorm, color, ScrollView::BROWN,
748  color = WERD::NextColor(color);
749  }
751  return TRUE;
752 }
#define TRUE
Definition: capi.h:45
Pix * BestPix() const
WERD * word
Definition: pageres.h:175
WERD_RES * word() const
Definition: pageres.h:736
TWERD * chopped_word
Definition: pageres.h:201
ROW_RES * row() const
Definition: pageres.h:739
bool classify_bln_numeric_mode
Definition: classify.h:500
static ScrollView::Color NextColor(ScrollView::Color colour)
Definition: werd.cpp:306
bool SetupForRecognition(const UNICHARSET &unicharset_in, tesseract::Tesseract *tesseract, Pix *pix, int norm_mode, const TBOX *norm_box, bool numeric_mode, bool use_body_size, bool allow_detailed_fx, ROW *row, const BLOCK *block)
Definition: pageres.cpp:294
ROW * row
Definition: pageres.h:127
UNICHARSET unicharset
Definition: ccutil.h:70
void display_bln_lines(ScrollView *window, ScrollView::Color colour, float scale_factor, float y_offset, float minx, float maxx)
Definition: pgedit.cpp:210
static void Update()
Definition: scrollview.cpp:715
BLOCK_RES * block() const
Definition: pageres.h:742
ScrollView * bln_word_window_handle()
Definition: pgedit.cpp:172
void Clear()
Definition: scrollview.cpp:595
DENORM denorm
Definition: pageres.h:190
BLOCK * block
Definition: pageres.h:99
C_BLOB_LIST * cblob_list()
Definition: werd.h:100
inT16 tesseract::Tesseract::word_blob_quality ( WERD_RES word,
ROW row 
)

Definition at line 65 of file docqual.cpp.

65  {
66  if (word->bln_boxes == NULL ||
67  word->rebuild_word == NULL || word->rebuild_word->blobs.empty())
68  return 0;
69 
70  DocQualCallbacks cb(word);
72  *word->rebuild_word,
74  return cb.match_count;
75 }
tesseract::BoxWord * bln_boxes
Definition: pageres.h:184
GenericVector< TBLOB * > blobs
Definition: blobs.h:436
bool empty() const
Definition: genericvector.h:84
void CountMatchingBlobs(int index)
Definition: docqual.cpp:39
void ProcessMatchedBlobs(const TWERD &other, TessCallback1< int > *cb) const
Definition: boxword.cpp:193
TWERD * rebuild_word
Definition: pageres.h:244
_ConstTessMemberResultCallback_0_0< false, R, T1 >::base * NewPermanentTessCallback(const T1 *obj, R(T2::*member)() const)
Definition: tesscallback.h:116
void tesseract::Tesseract::word_char_quality ( WERD_RES word,
ROW row,
inT16 match_count,
inT16 accepted_match_count 
)

Definition at line 97 of file docqual.cpp.

100  {
101  if (word->bln_boxes == NULL || word->rebuild_word == NULL ||
102  word->rebuild_word->blobs.empty()) {
103  *match_count = 0;
104  *accepted_match_count = 0;
105  return;
106  }
107 
108  DocQualCallbacks cb(word);
110  *word->rebuild_word,
112  *match_count = cb.match_count;
113  *accepted_match_count = cb.accepted_match_count;
114 }
tesseract::BoxWord * bln_boxes
Definition: pageres.h:184
void CountAcceptedBlobs(int index)
Definition: docqual.cpp:43
GenericVector< TBLOB * > blobs
Definition: blobs.h:436
bool empty() const
Definition: genericvector.h:84
void ProcessMatchedBlobs(const TWERD &other, TessCallback1< int > *cb) const
Definition: boxword.cpp:193
TWERD * rebuild_word
Definition: pageres.h:244
_ConstTessMemberResultCallback_0_0< false, R, T1 >::base * NewPermanentTessCallback(const T1 *obj, R(T2::*member)() const)
Definition: tesscallback.h:116
BOOL8 tesseract::Tesseract::word_contains_non_1_digit ( const char *  word,
const char *  word_lengths 
)

Definition at line 509 of file reject.cpp.

510  {
511  inT16 i;
512  inT16 offset;
513 
514  for (i = 0, offset = 0; word[offset] != '\0'; offset += word_lengths[i++]) {
515  if (unicharset.get_isdigit (word + offset, word_lengths[i]) &&
516  (word_lengths[i] != 1 || word[offset] != '1'))
517  return TRUE;
518  }
519  return FALSE;
520 }
#define TRUE
Definition: capi.h:45
bool get_isdigit(UNICHAR_ID unichar_id) const
Definition: unicharset.h:469
#define FALSE
Definition: capi.h:46
short inT16
Definition: host.h:100
UNICHARSET unicharset
Definition: ccutil.h:70
CRUNCH_MODE tesseract::Tesseract::word_deletable ( WERD_RES word,
inT16 delete_mode 
)

Definition at line 899 of file docqual.cpp.

899  {
900  int word_len = word->reject_map.length ();
901  float rating_per_ch;
902  TBOX box; //BB of word
903 
904  if (word->unlv_crunch_mode == CR_NONE) {
905  delete_mode = 0;
906  return CR_NONE;
907  }
908 
909  if (word_len == 0) {
910  delete_mode = 1;
911  return CR_DELETE;
912  }
913 
914  if (word->rebuild_word != NULL) {
915  // Cube leaves rebuild_word NULL.
916  box = word->rebuild_word->bounding_box();
917  if (box.height () < crunch_del_min_ht * kBlnXHeight) {
918  delete_mode = 4;
919  return CR_DELETE;
920  }
921 
922  if (noise_outlines(word->rebuild_word)) {
923  delete_mode = 5;
924  return CR_DELETE;
925  }
926  }
927 
928  if ((failure_count (word) * 1.5) > word_len) {
929  delete_mode = 2;
930  return CR_LOOSE_SPACE;
931  }
932 
933  if (word->best_choice->certainty () < crunch_del_cert) {
934  delete_mode = 7;
935  return CR_LOOSE_SPACE;
936  }
937 
938  rating_per_ch = word->best_choice->rating () / word_len;
939 
940  if (rating_per_ch > crunch_del_rating) {
941  delete_mode = 8;
942  return CR_LOOSE_SPACE;
943  }
944 
946  delete_mode = 9;
947  return CR_LOOSE_SPACE;
948  }
949 
950  if (box.bottom () >
952  delete_mode = 10;
953  return CR_LOOSE_SPACE;
954  }
955 
956  if (box.height () > crunch_del_max_ht * kBlnXHeight) {
957  delete_mode = 11;
958  return CR_LOOSE_SPACE;
959  }
960 
961  if (box.width () < crunch_del_min_width * kBlnXHeight) {
962  delete_mode = 3;
963  return CR_LOOSE_SPACE;
964  }
965 
966  delete_mode = 0;
967  return CR_NONE;
968 }
inT16 failure_count(WERD_RES *word)
Definition: docqual.cpp:970
inT16 bottom() const
Definition: rect.h:61
TBOX bounding_box() const
Definition: blobs.cpp:881
CRUNCH_MODE unlv_crunch_mode
Definition: pageres.h:294
inT16 height() const
Definition: rect.h:104
REJMAP reject_map
Definition: pageres.h:271
Definition: rect.h:30
inT32 length() const
Definition: rejctmap.h:236
float rating() const
Definition: ratngs.h:325
WERD_CHOICE * best_choice
Definition: pageres.h:219
BOOL8 noise_outlines(TWERD *word)
Definition: docqual.cpp:982
const int kBlnXHeight
Definition: normalis.h:28
inT16 top() const
Definition: rect.h:54
const int kBlnBaselineOffset
Definition: normalis.h:29
inT16 width() const
Definition: rect.h:111
float certainty() const
Definition: ratngs.h:328
TWERD * rebuild_word
Definition: pageres.h:244
BOOL8 tesseract::Tesseract::word_display ( PAGE_RES_IT pr_it)

word_display() Word Processor

Display a word according to its display modes

Definition at line 761 of file pgedit.cpp.

761  {
762  WERD_RES* word_res = pr_it->word();
763  WERD* word = word_res->word;
764  TBOX word_bb; // word bounding box
765  int word_height; // ht of word BB
766  BOOL8 displayed_something = FALSE;
767  float shift; // from bot left
768  C_BLOB_IT c_it; // cblob iterator
769 
770  if (color_mode != CM_RAINBOW && word_res->box_word != NULL) {
771  BoxWord* box_word = word_res->box_word;
772  WERD_CHOICE* best_choice = word_res->best_choice;
773  int length = box_word->length();
774  if (word_res->fontinfo == NULL) return false;
775  const FontInfo& font_info = *word_res->fontinfo;
776  for (int i = 0; i < length; ++i) {
778  switch (color_mode) {
779  case CM_SUBSCRIPT:
780  if (best_choice->BlobPosition(i) == SP_SUBSCRIPT)
781  color = ScrollView::RED;
782  break;
783  case CM_SUPERSCRIPT:
784  if (best_choice->BlobPosition(i) == SP_SUPERSCRIPT)
785  color = ScrollView::RED;
786  break;
787  case CM_ITALIC:
788  if (font_info.is_italic())
789  color = ScrollView::RED;
790  break;
791  case CM_BOLD:
792  if (font_info.is_bold())
793  color = ScrollView::RED;
794  break;
795  case CM_FIXEDPITCH:
796  if (font_info.is_fixed_pitch())
797  color = ScrollView::RED;
798  break;
799  case CM_SERIF:
800  if (font_info.is_serif())
801  color = ScrollView::RED;
802  break;
803  case CM_SMALLCAPS:
804  if (word_res->small_caps)
805  color = ScrollView::RED;
806  break;
807  case CM_DROPCAPS:
808  if (best_choice->BlobPosition(i) == SP_DROPCAP)
809  color = ScrollView::RED;
810  break;
811  // TODO(rays) underline is currently completely unsupported.
812  case CM_UNDERLINE:
813  default:
814  break;
815  }
816  image_win->Pen(color);
817  TBOX box = box_word->BlobBox(i);
818  image_win->Rectangle(box.left(), box.bottom(), box.right(), box.top());
819  }
820  return true;
821  }
822  /*
823  Note the double coercions of(COLOUR)((inT32)editor_image_word_bb_color)
824  etc. are to keep the compiler happy.
825  */
826  // display bounding box
827  if (word->display_flag(DF_BOX)) {
828  word->bounding_box().plot(image_win,
832  editor_image_word_bb_color));
833 
836  image_win->Pen(c);
837  c_it.set_to_list(word->cblob_list());
838  for (c_it.mark_cycle_pt(); !c_it.cycled_list(); c_it.forward())
839  c_it.data()->bounding_box().plot(image_win);
840  displayed_something = TRUE;
841  }
842 
843  // display edge steps
844  if (word->display_flag(DF_EDGE_STEP)) { // edgesteps available
845  word->plot(image_win); // rainbow colors
846  displayed_something = TRUE;
847  }
848 
849  // display poly approx
850  if (word->display_flag(DF_POLYGONAL)) {
851  // need to convert
853  tword->plot(image_win);
854  delete tword;
855  displayed_something = TRUE;
856  }
857 
858  // Display correct text and blamer information.
859  STRING text;
860  STRING blame;
861  if (word->display_flag(DF_TEXT) && word->text() != NULL) {
862  text = word->text();
863  }
864  if (word->display_flag(DF_BLAMER) &&
865  !(word_res->blamer_bundle != NULL &&
867  text = "";
868  const BlamerBundle *blamer_bundle = word_res->blamer_bundle;
869  if (blamer_bundle == NULL) {
870  text += "NULL";
871  } else {
872  text = blamer_bundle->TruthString();
873  }
874  text += " -> ";
875  STRING best_choice_str;
876  if (word_res->best_choice == NULL) {
877  best_choice_str = "NULL";
878  } else {
879  word_res->best_choice->string_and_lengths(&best_choice_str, NULL);
880  }
881  text += best_choice_str;
882  IncorrectResultReason reason = (blamer_bundle == NULL) ?
883  IRR_PAGE_LAYOUT : blamer_bundle->incorrect_result_reason();
884  ASSERT_HOST(reason < IRR_NUM_REASONS)
885  blame += " [";
886  blame += BlamerBundle::IncorrectReasonName(reason);
887  blame += "]";
888  }
889  if (text.length() > 0) {
890  word_bb = word->bounding_box();
892  word_height = word_bb.height();
893  int text_height = 0.50 * word_height;
894  if (text_height > 20) text_height = 20;
895  image_win->TextAttributes("Arial", text_height, false, false, false);
896  shift = (word_height < word_bb.width()) ? 0.25 * word_height : 0.0f;
897  image_win->Text(word_bb.left() + shift,
898  word_bb.bottom() + 0.25 * word_height, text.string());
899  if (blame.length() > 0) {
900  image_win->Text(word_bb.left() + shift,
901  word_bb.bottom() + 0.25 * word_height - text_height,
902  blame.string());
903  }
904 
905  displayed_something = TRUE;
906  }
907 
908  if (!displayed_something) // display BBox anyway
909  word->bounding_box().plot(image_win,
910  (ScrollView::Color)((inT32) editor_image_word_bb_color),
912  editor_image_word_bb_color));
913  return TRUE;
914 }
bool is_italic() const
Definition: fontinfo.h:111
#define TRUE
Definition: capi.h:45
void TextAttributes(const char *font, int pixel_size, bool bold, bool italic, bool underlined)
Definition: scrollview.cpp:641
ScrollView * image_win
Definition: pgedit.cpp:107
tesseract::ScriptPos BlobPosition(int index) const
Definition: ratngs.h:320
void plot(ScrollView *fd) const
Definition: rect.h:278
inT16 bottom() const
Definition: rect.h:61
const char * text() const
Definition: werd.h:125
const FontInfo * fontinfo
Definition: pageres.h:288
Definition: strngs.h:44
void string_and_lengths(STRING *word_str, STRING *word_lengths_str) const
Definition: ratngs.cpp:427
BlamerBundle * blamer_bundle
Definition: pageres.h:230
Definition: werd.h:60
int inT32
Definition: host.h:102
int editor_image_blob_bb_color
Definition: pgedit.cpp:138
WERD * word
Definition: pageres.h:175
STRING TruthString() const
Definition: blamer.h:100
tesseract::BoxWord * box_word
Definition: pageres.h:250
int length() const
Definition: ratngs.h:301
inT16 height() const
Definition: rect.h:104
WERD_RES * word() const
Definition: pageres.h:736
void Pen(Color color)
Definition: scrollview.cpp:726
TBOX bounding_box() const
Definition: werd.cpp:160
Definition: rect.h:30
#define FALSE
Definition: capi.h:46
BOOL8 display_flag(uinT8 flag) const
Definition: werd.h:131
inT16 right() const
Definition: rect.h:75
void Rectangle(int x1, int y1, int x2, int y2)
Definition: scrollview.cpp:606
Definition: werd.h:50
IncorrectResultReason
Definition: blamer.h:37
inT16 left() const
Definition: rect.h:68
bool is_serif() const
Definition: fontinfo.h:114
Definition: blobs.h:395
WERD_CHOICE * best_choice
Definition: pageres.h:219
int editor_image_word_bb_color
Definition: pgedit.cpp:136
bool is_fixed_pitch() const
Definition: fontinfo.h:113
inT16 top() const
Definition: rect.h:54
unsigned char BOOL8
Definition: host.h:113
void Text(int x, int y, const char *mystring)
Definition: scrollview.cpp:658
#define ASSERT_HOST(x)
Definition: errcode.h:84
const char * string() const
Definition: strngs.cpp:201
bool is_bold() const
Definition: fontinfo.h:112
Definition: werd.h:55
bool small_caps
Definition: pageres.h:283
Definition: werd.h:51
void plot(ScrollView *window)
Definition: blobs.cpp:918
void plot(ScrollView *window, ScrollView::Color colour)
Definition: werd.cpp:297
inT16 width() const
Definition: rect.h:111
static TWERD * PolygonalCopy(bool allow_detailed_fx, WERD *src)
Definition: blobs.cpp:793
IncorrectResultReason incorrect_result_reason() const
Definition: blamer.h:106
C_BLOB_LIST * cblob_list()
Definition: werd.h:100
BOOL8 tesseract::Tesseract::word_dumper ( PAGE_RES_IT pr_it)

word_dumper()

Dump members to the debug window

Definition at line 922 of file pgedit.cpp.

922  {
923  if (pr_it->block()->block != NULL) {
924  tprintf("\nBlock data...\n");
925  pr_it->block()->block->print(NULL, FALSE);
926  }
927  tprintf("\nRow data...\n");
928  pr_it->row()->row->print(NULL);
929  tprintf("\nWord data...\n");
930  WERD_RES* word_res = pr_it->word();
931  word_res->word->print();
932  if (word_res->blamer_bundle != NULL && wordrec_debug_blamer &&
934  tprintf("Current blamer debug: %s\n",
935  word_res->blamer_bundle->debug().string());
936  }
937  return TRUE;
938 }
const STRING & debug() const
Definition: blamer.h:116
#define TRUE
Definition: capi.h:45
void print(FILE *fp)
Definition: ocrrow.cpp:167
BlamerBundle * blamer_bundle
Definition: pageres.h:230
WERD * word
Definition: pageres.h:175
WERD_RES * word() const
Definition: pageres.h:736
#define tprintf(...)
Definition: tprintf.h:31
ROW_RES * row() const
Definition: pageres.h:739
#define FALSE
Definition: capi.h:46
bool wordrec_debug_blamer
Definition: wordrec.h:167
ROW * row
Definition: pageres.h:127
BLOCK_RES * block() const
Definition: pageres.h:742
void print()
Definition: werd.cpp:266
const char * string() const
Definition: strngs.cpp:201
void print(FILE *fp, BOOL8 dump)
dump whole table
Definition: ocrblock.cpp:196
BLOCK * block
Definition: pageres.h:99
IncorrectResultReason incorrect_result_reason() const
Definition: blamer.h:106
inT16 tesseract::Tesseract::word_outline_errs ( WERD_RES word)

Definition at line 77 of file docqual.cpp.

77  {
78  inT16 i = 0;
79  inT16 err_count = 0;
80 
81  if (word->rebuild_word != NULL) {
82  for (int b = 0; b < word->rebuild_word->NumBlobs(); ++b) {
83  TBLOB* blob = word->rebuild_word->blobs[b];
84  err_count += count_outline_errs(word->best_choice->unichar_string()[i],
85  blob->NumOutlines());
86  i++;
87  }
88  }
89  return err_count;
90 }
int NumBlobs() const
Definition: blobs.h:425
GenericVector< TBLOB * > blobs
Definition: blobs.h:436
inT16 count_outline_errs(char c, inT16 outline_count)
Definition: docqual.cpp:131
const STRING & unichar_string() const
Definition: ratngs.h:525
short inT16
Definition: host.h:100
WERD_CHOICE * best_choice
Definition: pageres.h:219
int NumOutlines() const
Definition: blobs.cpp:469
Definition: blobs.h:261
TWERD * rebuild_word
Definition: pageres.h:244
BOOL8 tesseract::Tesseract::word_set_display ( PAGE_RES_IT pr_it)

word_set_display() Word processor

Display word according to current display mode settings

Definition at line 946 of file pgedit.cpp.

946  {
947  WERD* word = pr_it->word()->word;
955  return word_display(pr_it);
956 }
void set_display_flag(uinT8 flag, BOOL8 value)
Definition: werd.h:132
Definition: werd.h:60
BOOL8 bit(uinT8 bit_num) const
Definition: bits16.h:56
WERD * word
Definition: pageres.h:175
WERD_RES * word() const
Definition: pageres.h:736
Definition: werd.h:50
BITS16 word_display_mode
Definition: pgedit.cpp:122
Definition: werd.h:55
Definition: werd.h:51
BOOL8 word_display(PAGE_RES_IT *pr_it)
Definition: pgedit.cpp:761
inT16 tesseract::Tesseract::worst_noise_blob ( WERD_RES word_res,
float *  worst_noise_score 
)

Definition at line 680 of file fixspace.cpp.

681  {
682  float noise_score[512];
683  int i;
684  int min_noise_blob; // 1st contender
685  int max_noise_blob; // last contender
686  int non_noise_count;
687  int worst_noise_blob; // Worst blob
688  float small_limit = kBlnXHeight * fixsp_small_outlines_size;
689  float non_noise_limit = kBlnXHeight * 0.8;
690 
691  if (word_res->rebuild_word == NULL)
692  return -1; // Can't handle cube words.
693 
694  // Normalised.
695  int blob_count = word_res->box_word->length();
696  ASSERT_HOST(blob_count <= 512);
697  if (blob_count < 5)
698  return -1; // too short to split
699 
700  /* Get the noise scores for all blobs */
701 
702  #ifndef SECURE_NAMES
703  if (debug_fix_space_level > 5)
704  tprintf("FP fixspace Noise metrics for \"%s\": ",
705  word_res->best_choice->unichar_string().string());
706  #endif
707 
708  for (i = 0; i < blob_count && i < word_res->rebuild_word->NumBlobs(); i++) {
709  TBLOB* blob = word_res->rebuild_word->blobs[i];
710  if (word_res->reject_map[i].accepted())
711  noise_score[i] = non_noise_limit;
712  else
713  noise_score[i] = blob_noise_score(blob);
714 
715  if (debug_fix_space_level > 5)
716  tprintf("%1.1f ", noise_score[i]);
717  }
718  if (debug_fix_space_level > 5)
719  tprintf("\n");
720 
721  /* Now find the worst one which is far enough away from the end of the word */
722 
723  non_noise_count = 0;
724  for (i = 0; i < blob_count && non_noise_count < fixsp_non_noise_limit; i++) {
725  if (noise_score[i] >= non_noise_limit) {
726  non_noise_count++;
727  }
728  }
729  if (non_noise_count < fixsp_non_noise_limit)
730  return -1;
731 
732  min_noise_blob = i;
733 
734  non_noise_count = 0;
735  for (i = blob_count - 1; i >= 0 && non_noise_count < fixsp_non_noise_limit;
736  i--) {
737  if (noise_score[i] >= non_noise_limit) {
738  non_noise_count++;
739  }
740  }
741  if (non_noise_count < fixsp_non_noise_limit)
742  return -1;
743 
744  max_noise_blob = i;
745 
746  if (min_noise_blob > max_noise_blob)
747  return -1;
748 
749  *worst_noise_score = small_limit;
750  worst_noise_blob = -1;
751  for (i = min_noise_blob; i <= max_noise_blob; i++) {
752  if (noise_score[i] < *worst_noise_score) {
753  worst_noise_blob = i;
754  *worst_noise_score = noise_score[i];
755  }
756  }
757  return worst_noise_blob;
758 }
int NumBlobs() const
Definition: blobs.h:425
GenericVector< TBLOB * > blobs
Definition: blobs.h:436
tesseract::BoxWord * box_word
Definition: pageres.h:250
float blob_noise_score(TBLOB *blob)
Definition: fixspace.cpp:760
#define tprintf(...)
Definition: tprintf.h:31
REJMAP reject_map
Definition: pageres.h:271
const STRING & unichar_string() const
Definition: ratngs.h:525
int length() const
Definition: boxword.h:85
inT16 worst_noise_blob(WERD_RES *word_res, float *worst_noise_score)
Definition: fixspace.cpp:680
WERD_CHOICE * best_choice
Definition: pageres.h:219
const int kBlnXHeight
Definition: normalis.h:28
#define ASSERT_HOST(x)
Definition: errcode.h:84
const char * string() const
Definition: strngs.cpp:201
Definition: blobs.h:261
TWERD * rebuild_word
Definition: pageres.h:244
void tesseract::Tesseract::write_results ( PAGE_RES_IT page_res_it,
char  newline_type,
BOOL8  force_eol 
)

Definition at line 130 of file output.cpp.

132  { // override tilde crunch?
133  WERD_RES *word = page_res_it.word();
134  const UNICHARSET &uchset = *word->uch_set;
135  int i;
136  BOOL8 need_reject = FALSE;
137  UNICHAR_ID space = uchset.unichar_to_id(" ");
138 
139  if ((word->unlv_crunch_mode != CR_NONE ||
140  word->best_choice->length() == 0) &&
142  if ((word->unlv_crunch_mode != CR_DELETE) &&
143  (!stats_.tilde_crunch_written ||
144  ((word->unlv_crunch_mode == CR_KEEP_SPACE) &&
145  (word->word->space () > 0) &&
146  !word->word->flag (W_FUZZY_NON) &&
147  !word->word->flag (W_FUZZY_SP)))) {
148  if (!word->word->flag (W_BOL) &&
149  (word->word->space () > 0) &&
150  !word->word->flag (W_FUZZY_NON) &&
151  !word->word->flag (W_FUZZY_SP)) {
152  stats_.last_char_was_tilde = false;
153  }
154  need_reject = TRUE;
155  }
156  if ((need_reject && !stats_.last_char_was_tilde) ||
157  (force_eol && stats_.write_results_empty_block)) {
158  /* Write a reject char - mark as rejected unless zero_rejection mode */
159  stats_.last_char_was_tilde = TRUE;
160  stats_.tilde_crunch_written = true;
161  stats_.last_char_was_newline = false;
162  stats_.write_results_empty_block = false;
163  }
164 
165  if ((word->word->flag (W_EOL) && !stats_.last_char_was_newline) || force_eol) {
166  stats_.tilde_crunch_written = false;
167  stats_.last_char_was_newline = true;
168  stats_.last_char_was_tilde = false;
169  }
170 
171  if (force_eol)
172  stats_.write_results_empty_block = true;
173  return;
174  }
175 
176  /* NORMAL PROCESSING of non tilde crunched words */
177 
178  stats_.tilde_crunch_written = false;
179  if (newline_type)
180  stats_.last_char_was_newline = true;
181  else
182  stats_.last_char_was_newline = false;
183  stats_.write_results_empty_block = force_eol; // about to write a real word
184 
185  if (unlv_tilde_crunching &&
186  stats_.last_char_was_tilde &&
187  (word->word->space() == 0) &&
189  (word->best_choice->unichar_id(0) == space)) {
190  /* Prevent adjacent tilde across words - we know that adjacent tildes within
191  words have been removed */
192  word->MergeAdjacentBlobs(0);
193  }
194  if (newline_type ||
196  stats_.last_char_was_tilde = false;
197  else {
198  if (word->reject_map.length () > 0) {
199  if (word->best_choice->unichar_id(word->reject_map.length() - 1) == space)
200  stats_.last_char_was_tilde = true;
201  else
202  stats_.last_char_was_tilde = false;
203  }
204  else if (word->word->space () > 0)
205  stats_.last_char_was_tilde = false;
206  /* else it is unchanged as there are no output chars */
207  }
208 
209  ASSERT_HOST (word->best_choice->length() == word->reject_map.length());
210 
211  set_unlv_suspects(word);
212  check_debug_pt (word, 120);
214  tprintf ("Dict word: \"%s\": %d\n",
215  word->best_choice->debug_string().string(),
216  dict_word(*(word->best_choice)));
217  }
218  if (!word->word->flag(W_REP_CHAR) || !tessedit_write_rep_codes) {
220  /* OVERRIDE ALL REJECTION MECHANISMS - ONLY REJECT TESS FAILURES */
221  for (i = 0; i < word->best_choice->length(); ++i) {
222  if (word->reject_map[i].rejected())
223  word->reject_map[i].setrej_minimal_rej_accept();
224  }
225  }
227  /* OVERRIDE ALL REJECTION MECHANISMS - ONLY REJECT TESS FAILURES */
228  for (i = 0; i < word->best_choice->length(); ++i) {
229  if ((word->best_choice->unichar_id(i) != space) &&
230  word->reject_map[i].rejected())
231  word->reject_map[i].setrej_minimal_rej_accept();
232  }
233  }
234  }
235 }
Definition: werd.h:36
BOOL8 flag(WERD_FLAGS mask) const
Definition: werd.h:128
int UNICHAR_ID
Definition: unichar.h:33
#define TRUE
Definition: capi.h:45
void set_unlv_suspects(WERD_RES *word)
Definition: output.cpp:305
uinT8 space()
Definition: werd.h:104
UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:194
CRUNCH_MODE unlv_crunch_mode
Definition: pageres.h:294
UNICHAR_ID unichar_id(int index) const
Definition: ratngs.h:313
WERD * word
Definition: pageres.h:175
int length() const
Definition: ratngs.h:301
WERD_RES * word() const
Definition: pageres.h:736
const STRING debug_string() const
Definition: ratngs.h:503
#define tprintf(...)
Definition: tprintf.h:31
REJMAP reject_map
Definition: pageres.h:271
BOOL8 check_debug_pt(WERD_RES *word, int location)
Definition: control.cpp:1772
#define FALSE
Definition: capi.h:46
inT32 length() const
Definition: rejctmap.h:236
Definition: werd.h:35
WERD_CHOICE * best_choice
Definition: pageres.h:219
const UNICHARSET * uch_set
Definition: pageres.h:192
unsigned char BOOL8
Definition: host.h:113
#define ASSERT_HOST(x)
Definition: errcode.h:84
const char * string() const
Definition: strngs.cpp:201
void MergeAdjacentBlobs(int index)
Definition: pageres.cpp:968
int dict_word(const WERD_CHOICE &word)
Definition: tface.cpp:128

Member Data Documentation

int tesseract::Tesseract::applybox_debug = 1

"Debug level"

Definition at line 821 of file tesseractclass.h.

char* tesseract::Tesseract::applybox_exposure_pattern = ".exp"

"Exposure value follows this pattern in the image" " filename. The name of the image files are expected" " to be in the form [lang].[fontname].exp[num].tif"

Definition at line 826 of file tesseractclass.h.

bool tesseract::Tesseract::applybox_learn_chars_and_char_frags_mode = false

"Learn both character fragments (as is done in the" " special low exposure mode) as well as unfragmented" " characters."

Definition at line 830 of file tesseractclass.h.

bool tesseract::Tesseract::applybox_learn_ngrams_mode = false

"Each bounding box is assumed to contain ngrams. Only" " learn the ngrams whose outlines overlap horizontally."

Definition at line 833 of file tesseractclass.h.

int tesseract::Tesseract::applybox_page = 0

"Page number to apply boxes from"

Definition at line 822 of file tesseractclass.h.

double tesseract::Tesseract::bestrate_pruning_factor = 2.0

"Multiplying factor of" " current best rate to prune other hypotheses"

Definition at line 1107 of file tesseractclass.h.

int tesseract::Tesseract::bidi_debug = 0

"Debug level for BiDi"

Definition at line 820 of file tesseractclass.h.

bool tesseract::Tesseract::bland_unrej = false

"unrej potential with no chekcs"

Definition at line 933 of file tesseractclass.h.

char* tesseract::Tesseract::chs_leading_punct = "('`\""

"Leading punctuation"

Definition at line 873 of file tesseractclass.h.

char* tesseract::Tesseract::chs_trailing_punct1 = ").,;:?!"

"1st Trailing punctuation"

Definition at line 874 of file tesseractclass.h.

char* tesseract::Tesseract::chs_trailing_punct2 = ")'`\""

"2nd Trailing punctuation"

Definition at line 875 of file tesseractclass.h.

char* tesseract::Tesseract::conflict_set_I_l_1 = "Il1[]"

"Il1 conflict set"

Definition at line 1047 of file tesseractclass.h.

bool tesseract::Tesseract::crunch_accept_ok = true

"Use acceptability in okstring"

Definition at line 962 of file tesseractclass.h.

int tesseract::Tesseract::crunch_debug = 0

"As it says"

Definition at line 971 of file tesseractclass.h.

double tesseract::Tesseract::crunch_del_cert = -10.0

"POTENTIAL crunch cert lt this"

Definition at line 951 of file tesseractclass.h.

double tesseract::Tesseract::crunch_del_high_word = 1.5

"Del if word gt xht x this above bl"

Definition at line 956 of file tesseractclass.h.

double tesseract::Tesseract::crunch_del_low_word = 0.5

"Del if word gt xht x this below bl"

Definition at line 957 of file tesseractclass.h.

double tesseract::Tesseract::crunch_del_max_ht = 3.0

"Del if word ht gt xht x this"

Definition at line 953 of file tesseractclass.h.

double tesseract::Tesseract::crunch_del_min_ht = 0.7

"Del if word ht lt xht x this"

Definition at line 952 of file tesseractclass.h.

double tesseract::Tesseract::crunch_del_min_width = 3.0

"Del if word width lt xht x this"

Definition at line 954 of file tesseractclass.h.

double tesseract::Tesseract::crunch_del_rating = 60

"POTENTIAL crunch rating lt this"

Definition at line 950 of file tesseractclass.h.

bool tesseract::Tesseract::crunch_early_convert_bad_unlv_chs = false

"Take out ~^ early?"

Definition at line 941 of file tesseractclass.h.

bool tesseract::Tesseract::crunch_early_merge_tess_fails = true

"Before word crunch?"

Definition at line 940 of file tesseractclass.h.

bool tesseract::Tesseract::crunch_include_numerals = false

"Fiddle alpha figures"

Definition at line 965 of file tesseractclass.h.

bool tesseract::Tesseract::crunch_leave_accept_strings = false

"Don't pot crunch sensible strings"

Definition at line 964 of file tesseractclass.h.

int tesseract::Tesseract::crunch_leave_lc_strings = 4

"Don't crunch words with long lower case strings"

Definition at line 967 of file tesseractclass.h.

bool tesseract::Tesseract::crunch_leave_ok_strings = true

"Don't touch sensible strings"

Definition at line 961 of file tesseractclass.h.

int tesseract::Tesseract::crunch_leave_uc_strings = 4

"Don't crunch words with long lower case strings"

Definition at line 969 of file tesseractclass.h.

int tesseract::Tesseract::crunch_long_repetitions = 3

"Crunch words with long repetitions"

Definition at line 970 of file tesseractclass.h.

double tesseract::Tesseract::crunch_poor_garbage_cert = -9.0

"crunch garbage cert lt this"

Definition at line 945 of file tesseractclass.h.

double tesseract::Tesseract::crunch_poor_garbage_rate = 60

"crunch garbage rating lt this"

Definition at line 946 of file tesseractclass.h.

bool tesseract::Tesseract::crunch_pot_garbage = true

"POTENTIAL crunch garbage"

Definition at line 949 of file tesseractclass.h.

int tesseract::Tesseract::crunch_pot_indicators = 1

"How many potential indicators needed"

Definition at line 960 of file tesseractclass.h.

double tesseract::Tesseract::crunch_pot_poor_cert = -8.0

"POTENTIAL crunch cert lt this"

Definition at line 948 of file tesseractclass.h.

double tesseract::Tesseract::crunch_pot_poor_rate = 40

"POTENTIAL crunch rating lt this"

Definition at line 947 of file tesseractclass.h.

int tesseract::Tesseract::crunch_rating_max = 10

"For adj length in rating per ch"

Definition at line 959 of file tesseractclass.h.

double tesseract::Tesseract::crunch_small_outlines_size = 0.6

"Small if lt xht x this"

Definition at line 958 of file tesseractclass.h.

bool tesseract::Tesseract::crunch_terrible_garbage = true

"As it says"

Definition at line 943 of file tesseractclass.h.

double tesseract::Tesseract::crunch_terrible_rating = 80.0

"crunch rating lt this"

Definition at line 942 of file tesseractclass.h.

int tesseract::Tesseract::cube_debug_level = 1

"Print cube debug info."

Definition at line 897 of file tesseractclass.h.

bool tesseract::Tesseract::debug_acceptable_wds = false

"Dump word pass/fail chk"

Definition at line 872 of file tesseractclass.h.

int tesseract::Tesseract::debug_fix_space_level = 0

"Contextual fixspace debug"

Definition at line 977 of file tesseractclass.h.

int tesseract::Tesseract::debug_noise_removal = 0

"Debug reassignment of small outlines"

Definition at line 856 of file tesseractclass.h.

int tesseract::Tesseract::debug_x_ht_level = 0

"Reestimate debug"

Definition at line 871 of file tesseractclass.h.

bool tesseract::Tesseract::docqual_excuse_outline_errs = false

"Allow outline errs in unrejection?"

Definition at line 901 of file tesseractclass.h.

bool tesseract::Tesseract::enable_new_segsearch = false

"Enable new segmentation search path."

Definition at line 1147 of file tesseractclass.h.

bool tesseract::Tesseract::enable_noise_removal = true

"Remove and conditionally reassign small outlines when they" " confuse layout analysis, determining diacritics vs noise"

Definition at line 855 of file tesseractclass.h.

char* tesseract::Tesseract::file_type = ".tif"

"Filename extension"

Definition at line 1054 of file tesseractclass.h.

int tesseract::Tesseract::fixsp_done_mode = 1

"What constitues done for spacing"

Definition at line 976 of file tesseractclass.h.

int tesseract::Tesseract::fixsp_non_noise_limit = 1

"How many non-noise blbs either side?"

Definition at line 973 of file tesseractclass.h.

double tesseract::Tesseract::fixsp_small_outlines_size = 0.28

"Small if lt xht x this"

Definition at line 974 of file tesseractclass.h.

double tesseract::Tesseract::heuristic_max_char_wh_ratio = 2.0

"max char width-to-height ratio allowed in segmentation"

Definition at line 1145 of file tesseractclass.h.

double tesseract::Tesseract::heuristic_segcost_rating_base = 1.25

"base factor for adding segmentation cost into word rating." "It's a multiplying factor, the larger the value above 1, " "the bigger the effect of segmentation cost."

Definition at line 1136 of file tesseractclass.h.

double tesseract::Tesseract::heuristic_weight_rating = 1

"weight associated with char rating in combined cost of state"

Definition at line 1138 of file tesseractclass.h.

double tesseract::Tesseract::heuristic_weight_seamcut = 0

"weight associated with seam cut in combined cost of state"

Definition at line 1143 of file tesseractclass.h.

double tesseract::Tesseract::heuristic_weight_width = 1000.0

"weight associated with width evidence in combined cost of" " state"

Definition at line 1141 of file tesseractclass.h.

bool tesseract::Tesseract::hocr_font_info = false

"Add font info to hocr output"

Definition at line 939 of file tesseractclass.h.

bool tesseract::Tesseract::include_page_breaks = false

"Include page separator string in output text after each " "image/page."

Definition at line 1087 of file tesseractclass.h.

bool tesseract::Tesseract::interactive_display_mode = false

"Run interactively?"

Definition at line 1053 of file tesseractclass.h.

int tesseract::Tesseract::language_model_fixed_length_choices_depth = 3

"Depth of blob choice lists to explore" " when fixed length dawgs are on"

Definition at line 1130 of file tesseractclass.h.

bool tesseract::Tesseract::load_fixed_length_dawgs = true

"Load fixed length" " dawgs (e.g. for non-space delimited languages)"

Definition at line 1103 of file tesseractclass.h.

double tesseract::Tesseract::min_orientation_margin = 7.0

"Min acceptable orientation margin"

Definition at line 1065 of file tesseractclass.h.

int tesseract::Tesseract::min_sane_x_ht_pixels = 8

"Reject any x-ht lt or eq than this"

Definition at line 1048 of file tesseractclass.h.

bool tesseract::Tesseract::ngram_permuter_activated = false

"Activate character-level n-gram-based permuter"

Definition at line 1126 of file tesseractclass.h.

double tesseract::Tesseract::noise_cert_basechar = -8.0

"Hingepoint for base char certainty"

Definition at line 859 of file tesseractclass.h.

double tesseract::Tesseract::noise_cert_disjoint = -2.5

"Hingepoint for disjoint certainty"

Definition at line 862 of file tesseractclass.h.

double tesseract::Tesseract::noise_cert_factor = 0.375

"Scaling on certainty diff from Hingepoint"

Definition at line 868 of file tesseractclass.h.

double tesseract::Tesseract::noise_cert_punc = -2.5

"Threshold for new punc char certainty"

Definition at line 865 of file tesseractclass.h.

int tesseract::Tesseract::noise_maxperblob = 8

"Max diacritics to apply to a blob"

Definition at line 869 of file tesseractclass.h.

int tesseract::Tesseract::noise_maxperword = 16

"Max diacritics to apply to a word"

Definition at line 870 of file tesseractclass.h.

char* tesseract::Tesseract::numeric_punctuation = ".,"

"Punct. chs expected WITHIN numbers"

Definition at line 979 of file tesseractclass.h.

int tesseract::Tesseract::ocr_devanagari_split_strategy = tesseract::ShiroRekhaSplitter::NO_SPLIT

"Whether to use the top-line splitting process for Devanagari " "documents while performing ocr."

Definition at line 815 of file tesseractclass.h.

char* tesseract::Tesseract::ok_repeated_ch_non_alphanum_wds = "-?*\075"

"Allow NN to unrej"

Definition at line 1046 of file tesseractclass.h.

char* tesseract::Tesseract::outlines_2 = "ij!?%\":;"

"Non standard number of outlines"

Definition at line 899 of file tesseractclass.h.

char* tesseract::Tesseract::outlines_odd = "%| "

"Non standard number of outlines"

Definition at line 898 of file tesseractclass.h.

char* tesseract::Tesseract::page_separator = "\f"

"Page separator (default is form feed control character)"

Definition at line 1089 of file tesseractclass.h.

int tesseract::Tesseract::pageseg_devanagari_split_strategy = tesseract::ShiroRekhaSplitter::NO_SPLIT

"Whether to use the top-line splitting process for Devanagari " "documents while performing page-segmentation."

Definition at line 811 of file tesseractclass.h.

int tesseract::Tesseract::paragraph_debug_level = 0

"Print paragraph debug info."

Definition at line 893 of file tesseractclass.h.

bool tesseract::Tesseract::paragraph_text_based = true

"Run paragraph detection on the post-text-recognition " "(more accurate)"

Definition at line 896 of file tesseractclass.h.

bool tesseract::Tesseract::permute_chartype_word = 0

"Turn on character type (property) consistency permuter"

Definition at line 1119 of file tesseractclass.h.

bool tesseract::Tesseract::permute_debug = 0

"char permutation debug"

Definition at line 1105 of file tesseractclass.h.

bool tesseract::Tesseract::permute_fixed_length_dawg = 0

"Turn on fixed-length phrasebook search permuter"

Definition at line 1117 of file tesseractclass.h.

bool tesseract::Tesseract::permute_only_top = false

"Run only the top choice permuter"

Definition at line 1127 of file tesseractclass.h.

bool tesseract::Tesseract::permute_script_word = 0

"Turn on word script consistency permuter"

Definition at line 1109 of file tesseractclass.h.

bool tesseract::Tesseract::poly_allow_detailed_fx = false

"Allow feature extractors to see the original outline"

Definition at line 1069 of file tesseractclass.h.

bool tesseract::Tesseract::preserve_interword_spaces = false

"Preserve multiple interword spaces"

Definition at line 1084 of file tesseractclass.h.

double tesseract::Tesseract::quality_blob_pc = 0.0

"good_quality_doc gte good blobs limit"

Definition at line 877 of file tesseractclass.h.

double tesseract::Tesseract::quality_char_pc = 0.95

"good_quality_doc gte good char limit"

Definition at line 880 of file tesseractclass.h.

int tesseract::Tesseract::quality_min_initial_alphas_reqd = 2

"alphas in a good word"

Definition at line 881 of file tesseractclass.h.

double tesseract::Tesseract::quality_outline_pc = 1.0

"good_quality_doc lte outline error limit"

Definition at line 879 of file tesseractclass.h.

double tesseract::Tesseract::quality_rej_pc = 0.08

"good_quality_doc lte rejection limit"

Definition at line 876 of file tesseractclass.h.

double tesseract::Tesseract::quality_rowrej_pc = 1.1

"good_quality_doc gte good char limit"

Definition at line 935 of file tesseractclass.h.

bool tesseract::Tesseract::rej_1Il_trust_permuter_type = true

"Don't double check"

Definition at line 1037 of file tesseractclass.h.

bool tesseract::Tesseract::rej_1Il_use_dict_word = false

"Use dictword test"

Definition at line 1036 of file tesseractclass.h.

bool tesseract::Tesseract::rej_alphas_in_number_perm = false

"Extend permuter check"

Definition at line 1042 of file tesseractclass.h.

bool tesseract::Tesseract::rej_trust_doc_dawg = false

"Use DOC dawg in 11l conf. detector"

Definition at line 1035 of file tesseractclass.h.

bool tesseract::Tesseract::rej_use_good_perm = true

"Individual rejection control"

Definition at line 1040 of file tesseractclass.h.

bool tesseract::Tesseract::rej_use_sensible_wd = false

"Extend permuter check"

Definition at line 1041 of file tesseractclass.h.

bool tesseract::Tesseract::rej_use_tess_accepted = true

"Individual rejection control"

Definition at line 1038 of file tesseractclass.h.

bool tesseract::Tesseract::rej_use_tess_blanks = true

"Individual rejection control"

Definition at line 1039 of file tesseractclass.h.

double tesseract::Tesseract::rej_whole_of_mostly_reject_word_fract = 0.85

"if >this fract"

Definition at line 1043 of file tesseractclass.h.

int tesseract::Tesseract::segment_debug = 0

"Debug the whole segmentation process"

Definition at line 1104 of file tesseractclass.h.

double tesseract::Tesseract::segment_reward_chartype = 0.97

"Score multipler for char type consistency within a word. "

Definition at line 1121 of file tesseractclass.h.

double tesseract::Tesseract::segment_reward_ngram_best_choice = 0.99

"Score multipler for ngram permuter's best choice" " (only used in the Han script path)."

Definition at line 1124 of file tesseractclass.h.

double tesseract::Tesseract::segment_reward_script = 0.95

"Score multipler for script consistency within a word. " "Being a 'reward' factor, it should be <= 1. " "Smaller value implies bigger reward."

Definition at line 1115 of file tesseractclass.h.

bool tesseract::Tesseract::segment_segcost_rating = 0

"incorporate segmentation cost in word rating?"

Definition at line 1111 of file tesseractclass.h.

double tesseract::Tesseract::segsearch_max_fixed_pitch_char_wh_ratio = 2.0

"Maximum character width-to-height ratio for" "fixed pitch fonts"

Definition at line 1150 of file tesseractclass.h.

double tesseract::Tesseract::subscript_max_y_top = 0.5

"Maximum top of a character measured as a multiple of x-height " "above the baseline for us to reconsider whether it's a " "subscript."

Definition at line 998 of file tesseractclass.h.

double tesseract::Tesseract::superscript_bettered_certainty = 0.97

"What reduction in " "badness do we think sufficient to choose a superscript over " "what we'd thought. For example, a value of 0.6 means we want " "to reduce badness of certainty by 40%"

Definition at line 990 of file tesseractclass.h.

int tesseract::Tesseract::superscript_debug = 0

"Debug level for sub & superscript fixer"

Definition at line 983 of file tesseractclass.h.

double tesseract::Tesseract::superscript_min_y_bottom = 0.3

"Minimum bottom of a character measured as a multiple of " "x-height above the baseline for us to reconsider whether it's " "a superscript."

Definition at line 1002 of file tesseractclass.h.

double tesseract::Tesseract::superscript_scaledown_ratio = 0.4

"A superscript scaled down more than this is unbelievably " "small. For example, 0.3 means we expect the font size to " "be no smaller than 30% of the text line font size."

Definition at line 994 of file tesseractclass.h.

double tesseract::Tesseract::superscript_worse_certainty = 2.0

"How many times worse " "certainty does a superscript position glyph need to be for us " "to try classifying it as a char with a different baseline?"

Definition at line 986 of file tesseractclass.h.

double tesseract::Tesseract::suspect_accept_rating = -999.9

"Accept good rating limit"

Definition at line 1020 of file tesseractclass.h.

bool tesseract::Tesseract::suspect_constrain_1Il = false

"UNLV keep 1Il chars rejected"

Definition at line 1018 of file tesseractclass.h.

int tesseract::Tesseract::suspect_level = 99

"Suspect marker level"

Definition at line 1014 of file tesseractclass.h.

double tesseract::Tesseract::suspect_rating_per_ch = 999.9

"Don't touch bad rating limit"

Definition at line 1019 of file tesseractclass.h.

int tesseract::Tesseract::suspect_short_words = 2

"Don't Suspect dict wds longer than this"

Definition at line 1017 of file tesseractclass.h.

int tesseract::Tesseract::suspect_space_level = 100

"Min suspect level for rejecting spaces"

Definition at line 1016 of file tesseractclass.h.

int tesseract::Tesseract::tessdata_manager_debug_level = 0

"Debug level for TessdataManager functions."

Definition at line 1057 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_adaption_debug = false

"Generate and print debug information for adaption"

Definition at line 819 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_ambigs_training = false

"Perform training for ambiguities"

Definition at line 807 of file tesseractclass.h.

int tesseract::Tesseract::tessedit_bigram_debug = 0

"Amount of debug output for bigram " "correction."

Definition at line 852 of file tesseractclass.h.

char* tesseract::Tesseract::tessedit_char_blacklist = ""

"Blacklist of chars not to recognize"

Definition at line 801 of file tesseractclass.h.

char* tesseract::Tesseract::tessedit_char_unblacklist = ""

"List of chars to override tessedit_char_blacklist"

Definition at line 805 of file tesseractclass.h.

char* tesseract::Tesseract::tessedit_char_whitelist = ""

"Whitelist of chars to recognize"

Definition at line 803 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_consistent_reps = true

"Force all rep chars the same"

Definition at line 1027 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_create_boxfile = false

"Output text with boxes"

Definition at line 1049 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_create_hocr = false

"Write .html hOCR output file"

Definition at line 1009 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_create_pdf = false

"Write .pdf output file"

Definition at line 1011 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_create_tsv = false

"Write .tsv output file"

Definition at line 1010 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_create_txt = false

"Write .txt output file"

Definition at line 1008 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_debug_block_rejection = false

"Block and Row stats"

Definition at line 846 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_debug_doc_rejection = false

"Page stats"

Definition at line 930 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_debug_fonts = false

"Output font info per char"

Definition at line 845 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_debug_quality_metrics = false

"Output data to debug file"

Definition at line 932 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_display_outwords = false

"Draw output words"

Definition at line 834 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_dont_blkrej_good_wds = false

"Use word segmentation quality metric"

Definition at line 919 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_dont_rowrej_good_wds = false

"Use word segmentation quality metric"

Definition at line 921 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_dump_choices = false

"Dump char choices"

Definition at line 835 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_dump_pageseg_images = false

"Dump intermediate images made during page segmentation"

Definition at line 791 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_enable_bigram_correction = true

"Enable correction based on the word bigram dictionary."

Definition at line 848 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_enable_dict_correction = false

"Enable single word correction based on the dictionary."

Definition at line 850 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_enable_doc_dict = true

"Add words to the document dictionary"

Definition at line 844 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_fix_fuzzy_spaces = true

"Try to improve fuzzy spaces"

Definition at line 838 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_fix_hyphens = true

"Crunch double hyphens?"

Definition at line 841 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_flip_0O = true

"Contextual 0O O0 flips"

Definition at line 1030 of file tesseractclass.h.

double tesseract::Tesseract::tessedit_good_doc_still_rowrej_wd = 1.1

"rej good doc wd if more than this fraction rejected"

Definition at line 927 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_good_quality_unrej = true

"Reduce rejection on good docs"

Definition at line 903 of file tesseractclass.h.

int tesseract::Tesseract::tessedit_image_border = 2

"Rej blbs near image edge limit"

Definition at line 1044 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_init_config_only = false

"Only initialize with the config file. Useful if the instance is " "not going to be used for OCR but say only for layout analysis."

Definition at line 1072 of file tesseractclass.h.

char* tesseract::Tesseract::tessedit_load_sublangs = ""

"List of languages to load with this one"

Definition at line 1059 of file tesseractclass.h.

double tesseract::Tesseract::tessedit_lower_flip_hyphen = 1.5

"Aspect ratio dot/hyphen test"

Definition at line 1032 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_make_boxes_from_boxes = false

"Generate more boxes from boxed chars"

Definition at line 789 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_matcher_log = false

"Log matcher activity"

Definition at line 887 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_minimal_rej_pass1 = false

"Do minimal rejection on pass 1 output"

Definition at line 885 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_minimal_rejection = false

"Only reject tess failures"

Definition at line 1021 of file tesseractclass.h.

int tesseract::Tesseract::tessedit_ocr_engine_mode = tesseract::OEM_TESSERACT_ONLY

"Which OCR engine(s) to run (Tesseract, Cube, both). Defaults" " to loading and running only Tesseract (no Cube, no combiner)." " (Values from OcrEngineMode enum in tesseractclass.h)"

Definition at line 799 of file tesseractclass.h.

int tesseract::Tesseract::tessedit_ok_mode = 5

"Acceptance decision algorithm"

Definition at line 1101 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_override_permuter = true

"According to dict_word"

Definition at line 1055 of file tesseractclass.h.

int tesseract::Tesseract::tessedit_page_number = -1

"-1 -> All pages, else specifc page to process"

Definition at line 1051 of file tesseractclass.h.

int tesseract::Tesseract::tessedit_pageseg_mode = PSM_SINGLE_BLOCK

"Page seg mode: 0=osd only, 1=auto+osd, 2=auto, 3=col, 4=block," " 5=line, 6=word, 7=char" " (Values from PageSegMode enum in publictypes.h)"

Definition at line 795 of file tesseractclass.h.

int tesseract::Tesseract::tessedit_parallelize = 0

"Run in parallel where possible"

Definition at line 1082 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_prefer_joined_punct = false

"Reward punctation joins"

Definition at line 975 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_preserve_blk_rej_perfect_wds = true

"Only rej partially rejected words in block rejection"

Definition at line 915 of file tesseractclass.h.

int tesseract::Tesseract::tessedit_preserve_min_wd_len = 2

"Only preserve wds longer than this"

Definition at line 923 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_preserve_row_rej_perfect_wds = true

"Only rej partially rejected words in row rejection"

Definition at line 917 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_redo_xheight = true

"Check/Correct x-height"

Definition at line 842 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_reject_bad_qual_wds = true

"Reject all bad quality wds"

Definition at line 929 of file tesseractclass.h.

double tesseract::Tesseract::tessedit_reject_block_percent = 45.00

"%rej allowed before rej whole block"

Definition at line 908 of file tesseractclass.h.

double tesseract::Tesseract::tessedit_reject_doc_percent = 65.00

"%rej allowed before rej whole doc"

Definition at line 906 of file tesseractclass.h.

int tesseract::Tesseract::tessedit_reject_mode = 0

"Rejection algorithm"

Definition at line 1028 of file tesseractclass.h.

double tesseract::Tesseract::tessedit_reject_row_percent = 40.00

"%rej allowed before rej whole row"

Definition at line 910 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_rejection_debug = false

"Adaption debug"

Definition at line 1029 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_resegment_from_boxes = false

"Take segmentation and labeling from box file"

Definition at line 783 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_resegment_from_line_boxes = false

"Conversion of word/line box file to char box file"

Definition at line 785 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_row_rej_good_docs = true

"Apply row rejection to good docs"

Definition at line 925 of file tesseractclass.h.

int tesseract::Tesseract::tessedit_tess_adaption_mode = 0x27

"Adaptation decision algorithm for tess"

Definition at line 883 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_test_adaption = false

"Test adaption criteria"

Definition at line 886 of file tesseractclass.h.

int tesseract::Tesseract::tessedit_test_adaption_mode = 3

"Adaptation decision algorithm for tess"

Definition at line 889 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_timing_debug = false

"Print timing stats"

Definition at line 836 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_train_from_boxes = false

"Generate training data from boxed chars"

Definition at line 787 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_unrej_any_wd = false

"Don't bother with word plausibility"

Definition at line 840 of file tesseractclass.h.

double tesseract::Tesseract::tessedit_upper_flip_hyphen = 1.8

"Aspect ratio dot/hyphen test"

Definition at line 1034 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_use_primary_params_model = false

"In multilingual mode use params model of the primary language"

Definition at line 1061 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_use_reject_spaces = true

"Reject spaces?"

Definition at line 904 of file tesseractclass.h.

double tesseract::Tesseract::tessedit_whole_wd_rej_row_percent = 70.00

"Number of row rejects in whole word rejects" "which prevents whole row rejection"

Definition at line 913 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_word_for_word = false

"Make output have exactly one word per WERD"

Definition at line 1024 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_write_block_separators = false

"Write block separators in output"

Definition at line 1004 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_write_images = false

"Capture the image from the IPE"

Definition at line 1052 of file tesseractclass.h.

char* tesseract::Tesseract::tessedit_write_params_to_file = ""

"Write all parameters to the given file."

Definition at line 817 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_write_rep_codes = false

"Write repetition char code"

Definition at line 1006 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_write_unlv = false

"Write .unlv output file"

Definition at line 1007 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_zero_kelvin_rejection = false

"Don't reject ANYTHING AT ALL"

Definition at line 1026 of file tesseractclass.h.

bool tesseract::Tesseract::tessedit_zero_rejection = false

"Don't reject ANYTHING"

Definition at line 1022 of file tesseractclass.h.

bool tesseract::Tesseract::test_pt = false

"Test for point"

Definition at line 890 of file tesseractclass.h.

double tesseract::Tesseract::test_pt_x = 99999.99

"xcoord"

Definition at line 891 of file tesseractclass.h.

double tesseract::Tesseract::test_pt_y = 99999.99

"ycoord"

Definition at line 892 of file tesseractclass.h.

bool tesseract::Tesseract::textord_equation_detect = false

"Turn on equation detector"

Definition at line 1073 of file tesseractclass.h.

double tesseract::Tesseract::textord_tabfind_aligned_gap_fraction = 0.75

"Fraction of height used as a minimum gap for aligned blobs."

Definition at line 1081 of file tesseractclass.h.

bool tesseract::Tesseract::textord_tabfind_force_vertical_text = false

"Force using vertical text page mode"

Definition at line 1076 of file tesseractclass.h.

bool tesseract::Tesseract::textord_tabfind_show_vlines = false

"Debug line finding"

Definition at line 1066 of file tesseractclass.h.

bool tesseract::Tesseract::textord_tabfind_vertical_horizontal_mix = true

"find horizontal lines such as headers in vertical page mode"

Definition at line 1100 of file tesseractclass.h.

bool tesseract::Tesseract::textord_tabfind_vertical_text = true

"Enable vertical detection"

Definition at line 1074 of file tesseractclass.h.

double tesseract::Tesseract::textord_tabfind_vertical_text_ratio = 0.5

"Fraction of textlines deemed vertical to use vertical page " "mode"

Definition at line 1079 of file tesseractclass.h.

bool tesseract::Tesseract::textord_use_cjk_fp_model = FALSE

"Use CJK fixed pitch model"

Definition at line 1067 of file tesseractclass.h.

bool tesseract::Tesseract::unlv_tilde_crunching = true

"Mark v.bad words for tilde crunch"

Definition at line 937 of file tesseractclass.h.

char* tesseract::Tesseract::unrecognised_char = "|"

"Output char for unidentified blobs"

Definition at line 1013 of file tesseractclass.h.

bool tesseract::Tesseract::use_new_state_cost = FALSE

"use new state cost heuristics for segmentation state evaluation"

Definition at line 1132 of file tesseractclass.h.

int tesseract::Tesseract::x_ht_acceptance_tolerance = 8

"Max allowed deviation of blob top outside of font data"

Definition at line 981 of file tesseractclass.h.

int tesseract::Tesseract::x_ht_min_change = 8

"Min change in xht before actually trying it"

Definition at line 982 of file tesseractclass.h.


The documentation for this class was generated from the following files: