1 /********************************************************************** 2 * File: topitch.h (Formerly to_pitch.h) 3 * Description: Code to determine fixed pitchness and the pitch if fixed. 4 * Author: Ray Smith 5 * 6 * (C) Copyright 1993, Hewlett-Packard Ltd. 7 ** Licensed under the Apache License, Version 2.0 (the "License"); 8 ** you may not use this file except in compliance with the License. 9 ** You may obtain a copy of the License at 10 ** http://www.apache.org/licenses/LICENSE-2.0 11 ** Unless required by applicable law or agreed to in writing, software 12 ** distributed under the License is distributed on an "AS IS" BASIS, 13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 ** See the License for the specific language governing permissions and 15 ** limitations under the License. 16 * 17 **********************************************************************/ 18 19 #ifndef TOPITCH_H 20 #define TOPITCH_H 21 22 #include "blobbox.h" 23 24 namespace tesseract { 25 26 class Tesseract; 27 28 extern BOOL_VAR_H(textord_debug_pitch_test); 29 extern BOOL_VAR_H(textord_debug_pitch_metric); 30 extern BOOL_VAR_H(textord_show_row_cuts); 31 extern BOOL_VAR_H(textord_show_page_cuts); 32 extern BOOL_VAR_H(textord_blockndoc_fixed); 33 extern BOOL_VAR_H(textord_fast_pitch_test); 34 extern double_VAR_H(textord_projection_scale); 35 extern double_VAR_H(textord_balance_factor); 36 37 void compute_fixed_pitch(ICOORD page_tr, // top right 38 TO_BLOCK_LIST *port_blocks, // input list 39 float gradient, // page skew 40 FCOORD rotation, // for drawing 41 bool testing_on); // correct orientation 42 void fix_row_pitch( // get some value 43 TO_ROW *bad_row, // row to fix 44 TO_BLOCK *bad_block, // block of bad_row 45 TO_BLOCK_LIST *blocks, // blocks to scan 46 int32_t row_target, // number of row 47 int32_t block_target // number of block 48 ); 49 void compute_block_pitch(TO_BLOCK *block, // input list 50 FCOORD rotation, // for drawing 51 int32_t block_index, // block number 52 bool testing_on); // correct orientation 53 bool compute_rows_pitch( // find line stats 54 TO_BLOCK *block, // block to do 55 int32_t block_index, // block number 56 bool testing_on // correct orientation 57 ); 58 bool try_doc_fixed( // determine pitch 59 ICOORD page_tr, // top right 60 TO_BLOCK_LIST *port_blocks, // input list 61 float gradient // page skew 62 ); 63 bool try_block_fixed( // find line stats 64 TO_BLOCK *block, // block to do 65 int32_t block_index // block number 66 ); 67 bool try_rows_fixed( // find line stats 68 TO_BLOCK *block, // block to do 69 int32_t block_index, // block number 70 bool testing_on // correct orientation 71 ); 72 void print_block_counts( // find line stats 73 TO_BLOCK *block, // block to do 74 int32_t block_index // block number 75 ); 76 void count_block_votes( // find line stats 77 TO_BLOCK *block, // block to do 78 int32_t &def_fixed, // add to counts 79 int32_t &def_prop, int32_t &maybe_fixed, int32_t &maybe_prop, int32_t &corr_fixed, 80 int32_t &corr_prop, int32_t &dunno); 81 bool row_pitch_stats( // find line stats 82 TO_ROW *row, // current row 83 int32_t maxwidth, // of spaces 84 bool testing_on // correct orientation 85 ); 86 bool find_row_pitch( // find lines 87 TO_ROW *row, // row to do 88 int32_t maxwidth, // max permitted space 89 int32_t dm_gap, // ignorable gaps 90 TO_BLOCK *block, // block of row 91 int32_t block_index, // block_number 92 int32_t row_index, // number of row 93 bool testing_on // correct orientation 94 ); 95 bool fixed_pitch_row( // find lines 96 TO_ROW *row, // row to do 97 BLOCK *block, 98 int32_t block_index // block_number 99 ); 100 bool count_pitch_stats( // find lines 101 TO_ROW *row, // row to do 102 STATS *gap_stats, // blob gaps 103 STATS *pitch_stats, // centre-centre stats 104 float initial_pitch, // guess at pitch 105 float min_space, // estimate space size 106 bool ignore_outsize, // discard big objects 107 bool split_outsize, // split big objects 108 int32_t dm_gap // ignorable gaps 109 ); 110 float tune_row_pitch( // find fp cells 111 TO_ROW *row, // row to do 112 STATS *projection, // vertical projection 113 int16_t projection_left, // edge of projection 114 int16_t projection_right, // edge of projection 115 float space_size, // size of blank 116 float &initial_pitch, // guess at pitch 117 float &best_sp_sd, // space sd 118 int16_t &best_mid_cuts, // no of cheap cuts 119 ICOORDELT_LIST *best_cells, // row cells 120 bool testing_on // inidividual words 121 ); 122 float tune_row_pitch2( // find fp cells 123 TO_ROW *row, // row to do 124 STATS *projection, // vertical projection 125 int16_t projection_left, // edge of projection 126 int16_t projection_right, // edge of projection 127 float space_size, // size of blank 128 float &initial_pitch, // guess at pitch 129 float &best_sp_sd, // space sd 130 int16_t &best_mid_cuts, // no of cheap cuts 131 ICOORDELT_LIST *best_cells, // row cells 132 bool testing_on // inidividual words 133 ); 134 float compute_pitch_sd( // find fp cells 135 TO_ROW *row, // row to do 136 STATS *projection, // vertical projection 137 int16_t projection_left, // edge 138 int16_t projection_right, // edge 139 float space_size, // size of blank 140 float initial_pitch, // guess at pitch 141 float &sp_sd, // space sd 142 int16_t &mid_cuts, // no of free cuts 143 ICOORDELT_LIST *row_cells, // list of chop pts 144 bool testing_on, // inidividual words 145 int16_t start = 0, // start of good range 146 int16_t end = 0 // end of good range 147 ); 148 float compute_pitch_sd2( // find fp cells 149 TO_ROW *row, // row to do 150 STATS *projection, // vertical projection 151 int16_t projection_left, // edge 152 int16_t projection_right, // edge 153 float initial_pitch, // guess at pitch 154 int16_t &occupation, // no of occupied cells 155 int16_t &mid_cuts, // no of free cuts 156 ICOORDELT_LIST *row_cells, // list of chop pts 157 bool testing_on, // inidividual words 158 int16_t start = 0, // start of good range 159 int16_t end = 0 // end of good range 160 ); 161 void print_pitch_sd( // find fp cells 162 TO_ROW *row, // row to do 163 STATS *projection, // vertical projection 164 int16_t projection_left, // edges //size of blank 165 int16_t projection_right, float space_size, 166 float initial_pitch // guess at pitch 167 ); 168 void find_repeated_chars(TO_BLOCK *block, // Block to search. 169 bool testing_on); // Debug mode. 170 void plot_fp_word( // draw block of words 171 TO_BLOCK *block, // block to draw 172 float pitch, // pitch to draw with 173 float nonspace // for space threshold 174 ); 175 176 } // namespace tesseract 177 178 #endif 179