Tesseract 3.02

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
textord.h
Go to the documentation of this file.
1
2 // File: textord.h
3 // Description: The Textord class definition gathers text line and word
4 // finding functionality.
5 // Author: Ray Smith
6 // Created: Fri Mar 13 14:29:01 PDT 2009
7 //
8 // (C) Copyright 2009, Google Inc.
9 // Licensed under the Apache License, Version 2.0 (the "License");
10 // you may not use this file except in compliance with the License.
11 // You may obtain a copy of the License at
12 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
20
21 #ifndef TESSERACT_TEXTORD_TEXTORD_H__
22 #define TESSERACT_TEXTORD_TEXTORD_H__
23
24 #include "ccstruct.h"
25 #include "blobbox.h"
26 #include "gap_map.h"
27 #include "notdll.h"
28 #include "publictypes.h" // For PageSegMode.
29
30 class FCOORD;
31 class BLOCK_LIST;
32 class PAGE_RES;
33 class TO_BLOCK;
34 class TO_BLOCK_LIST;
35 class ScrollView;
36
37 namespace tesseract {
38
39 class Textord {
40 public:
41 explicit Textord(CCStruct* ccstruct);
42 ~Textord();
43
44 // Make the textlines and words inside each block.
45 void TextordPage(PageSegMode pageseg_mode,
46 int width, int height, Pix* pix,
47 BLOCK_LIST* blocks, TO_BLOCK_LIST* to_blocks);
48
49 // If we were supposed to return only a single textline, and there is more
50 // than one, clean up and leave only the best.
51 void CleanupSingleRowResult(PageSegMode pageseg_mode, PAGE_RES* page_res);
52
53 bool use_cjk_fp_model() const {
54 return use_cjk_fp_model_;
55 }
56 void set_use_cjk_fp_model(bool flag) {
57 use_cjk_fp_model_ = flag;
58 }
59
60 // tospace.cpp ///////////////////////////////////////////
61 void to_spacing(
62 ICOORD page_tr, //topright of page
63 TO_BLOCK_LIST *blocks //blocks on page
64 );
65 ROW *make_prop_words(TO_ROW *row, // row to make
66 FCOORD rotation // for drawing
67 );
68 ROW *make_blob_words(TO_ROW *row, // row to make
69 FCOORD rotation // for drawing
70 );
71 // tordmain.cpp ///////////////////////////////////////////
72 void find_components(Pix* pix, BLOCK_LIST *blocks, TO_BLOCK_LIST *to_blocks);
73 void filter_blobs(ICOORD page_tr, TO_BLOCK_LIST *blocks, BOOL8 testing_on);
74
75 private:
76 // For underlying memory management and other utilities.
77 CCStruct* ccstruct_;
78
79 // The size of the input image.
80 ICOORD page_tr_;
81
82 bool use_cjk_fp_model_;
83
84 // makerow.cpp ///////////////////////////////////////////
85 // Make the textlines inside each block.
86 void MakeRows(PageSegMode pageseg_mode, const FCOORD& skew,
87 int width, int height, TO_BLOCK_LIST* to_blocks);
88 // Make the textlines inside a single block.
89 void MakeBlockRows(int min_spacing, int max_spacing,
90 const FCOORD& skew, TO_BLOCK* block,
91 ScrollView* win);
92
93 void fit_rows(float gradient, ICOORD page_tr, TO_BLOCK_LIST *blocks);
94 void cleanup_rows_fitting(ICOORD page_tr, // top right
95 TO_BLOCK *block, // block to do
96 float gradient, // gradient to fit
97 FCOORD rotation, // for drawing
98 inT32 block_edge, // edge of block
99 BOOL8 testing_on); // correct orientation
100 void compute_block_xheight(TO_BLOCK *block, float gradient);
101 void compute_row_xheight(TO_ROW *row, // row to do
102 const FCOORD& rotation,
103 float gradient, // global skew
104 int block_line_size);
105 void make_spline_rows(TO_BLOCK *block, // block to do
106 float gradient, // gradient to fit
107 FCOORD rotation, // for drawing
108 inT32 block_edge, // edge of block
109 BOOL8 testing_on);
110
112 void make_old_baselines(TO_BLOCK *block, // block to do
113 BOOL8 testing_on, // correct orientation
114 float gradient);
115 void correlate_lines(TO_BLOCK *block, float gradient);
116 void correlate_neighbours(TO_BLOCK *block, // block rows are in.
117 TO_ROW **rows, // rows of block.
118 int rowcount); // no of rows to do.
119 int correlate_with_stats(TO_ROW **rows, // rows of block.
120 int rowcount, // no of rows to do.
121 TO_BLOCK* block);
122 void find_textlines(TO_BLOCK *block, // block row is in
123 TO_ROW *row, // row to do
124 int degree, // required approximation
125 QSPLINE *spline); // starting spline
126 // tospace.cpp ///////////////////////////////////////////
127 //DEBUG USE ONLY
128 void block_spacing_stats(TO_BLOCK *block,
129 GAPMAP *gapmap,
130 BOOL8 &old_text_ord_proportional,
131 //resulting estimate
132 inT16 &block_space_gap_width,
133 //resulting estimate
134 inT16 &block_non_space_gap_width
135 );
136 void row_spacing_stats(TO_ROW *row,
137 GAPMAP *gapmap,
138 inT16 block_idx,
139 inT16 row_idx,
140 //estimate for block
141 inT16 block_space_gap_width,
142 //estimate for block
143 inT16 block_non_space_gap_width
144 );
145 void old_to_method(TO_ROW *row,
146 STATS *all_gap_stats,
147 STATS *space_gap_stats,
148 STATS *small_gap_stats,
149 inT16 block_space_gap_width,
150 //estimate for block
151 inT16 block_non_space_gap_width
152 );
153 BOOL8 isolated_row_stats(TO_ROW *row,
154 GAPMAP *gapmap,
155 STATS *all_gap_stats,
156 BOOL8 suspected_table,
157 inT16 block_idx,
158 inT16 row_idx);
159 inT16 stats_count_under(STATS *stats, inT16 threshold);
160 void improve_row_threshold(TO_ROW *row, STATS *all_gap_stats);
161 BOOL8 make_a_word_break(TO_ROW *row, // row being made
162 TBOX blob_box, // for next_blob // how many blanks?
163 inT16 prev_gap,
164 TBOX prev_blob_box,
165 inT16 real_current_gap,
166 inT16 within_xht_current_gap,
167 TBOX next_blob_box,
168 inT16 next_gap,
169 uinT8 &blanks,
170 BOOL8 &fuzzy_sp,
171 BOOL8 &fuzzy_non,
172 BOOL8& prev_gap_was_a_space,
173 BOOL8& break_at_next_gap);
174 BOOL8 narrow_blob(TO_ROW *row, TBOX blob_box);
175 BOOL8 wide_blob(TO_ROW *row, TBOX blob_box);
176 BOOL8 suspected_punct_blob(TO_ROW *row, TBOX box);
177 void peek_at_next_gap(TO_ROW *row,
178 BLOBNBOX_IT box_it,
179 TBOX &next_blob_box,
180 inT16 &next_gap,
181 inT16 &next_within_xht_gap);
182 void mark_gap(TBOX blob, //blob following gap
183 inT16 rule, // heuristic id
184 inT16 prev_gap,
185 inT16 prev_blob_width,
186 inT16 current_gap,
187 inT16 next_blob_width,
188 inT16 next_gap);
189 float find_mean_blob_spacing(WERD *word);
190 BOOL8 ignore_big_gap(TO_ROW *row,
191 inT32 row_length,
192 GAPMAP *gapmap,
193 inT16 left,
194 inT16 right);
195 //get bounding box
196 TBOX reduced_box_next(TO_ROW *row, //current row
197 BLOBNBOX_IT *it //iterator to blobds
198 );
199 TBOX reduced_box_for_blob(BLOBNBOX *blob, TO_ROW *row, inT16 *left_above_xht);
200 // tordmain.cpp ///////////////////////////////////////////
201 float filter_noise_blobs(BLOBNBOX_LIST *src_list,
202 BLOBNBOX_LIST *noise_list,
203 BLOBNBOX_LIST *small_list,
204 BLOBNBOX_LIST *large_list);
205 void cleanup_blocks(BLOCK_LIST *blocks);
206 BOOL8 clean_noise_from_row(ROW *row);
207 void clean_noise_from_words(ROW *row);
208 // Remove outlines that are a tiny fraction in either width or height
209 // of the word height.
210 void clean_small_noise_from_words(ROW *row);
211 public:
212 // makerow.cpp ///////////////////////////////////////////
213 BOOL_VAR_H(textord_single_height_mode, false,
214 "Script has no xheight, so use a single mode for horizontal text");
215 // tospace.cpp ///////////////////////////////////////////
216 BOOL_VAR_H(tosp_old_to_method, false, "Space stats use prechopping?");
217 BOOL_VAR_H(tosp_old_to_constrain_sp_kn, false,
218 "Constrain relative values of inter and intra-word gaps for "
219 "old_to_method.");
220 BOOL_VAR_H(tosp_only_use_prop_rows, true,
221 "Block stats to use fixed pitch rows?");
222 BOOL_VAR_H(tosp_force_wordbreak_on_punct, false,
223 "Force word breaks on punct to break long lines in non-space "
224 "delimited langs");
225 BOOL_VAR_H(tosp_use_pre_chopping, false,
226 "Space stats use prechopping?");
227 BOOL_VAR_H(tosp_old_to_bug_fix, false,
228 "Fix suspected bug in old code");
229 BOOL_VAR_H(tosp_block_use_cert_spaces, true,
230 "Only stat OBVIOUS spaces");
231 BOOL_VAR_H(tosp_row_use_cert_spaces, true,
232 "Only stat OBVIOUS spaces");
233 BOOL_VAR_H(tosp_narrow_blobs_not_cert, true,
234 "Only stat OBVIOUS spaces");
235 BOOL_VAR_H(tosp_row_use_cert_spaces1, true,
236 "Only stat OBVIOUS spaces");
237 BOOL_VAR_H(tosp_recovery_isolated_row_stats, true,
238 "Use row alone when inadequate cert spaces");
239 BOOL_VAR_H(tosp_only_small_gaps_for_kern, false, "Better guess");
240 BOOL_VAR_H(tosp_all_flips_fuzzy, false, "Pass ANY flip to context?");
241 BOOL_VAR_H(tosp_fuzzy_limit_all, true,
242 "Dont restrict kn->sp fuzzy limit to tables");
243 BOOL_VAR_H(tosp_stats_use_xht_gaps, true,
244 "Use within xht gap for wd breaks");
245 BOOL_VAR_H(tosp_use_xht_gaps, true,
246 "Use within xht gap for wd breaks");
247 BOOL_VAR_H(tosp_only_use_xht_gaps, false,
248 "Only use within xht gap for wd breaks");
249 BOOL_VAR_H(tosp_rule_9_test_punct, false,
250 "Dont chng kn to space next to punct");
251 BOOL_VAR_H(tosp_flip_fuzz_kn_to_sp, true, "Default flip");
252 BOOL_VAR_H(tosp_flip_fuzz_sp_to_kn, true, "Default flip");
253 BOOL_VAR_H(tosp_improve_thresh, false,
254 "Enable improvement heuristic");
255 INT_VAR_H(tosp_debug_level, 0, "Debug data");
256 INT_VAR_H(tosp_enough_space_samples_for_median, 3,
257 "or should we use mean");
258 INT_VAR_H(tosp_redo_kern_limit, 10,
259 "No.samples reqd to reestimate for row");
260 INT_VAR_H(tosp_few_samples, 40,
261 "No.gaps reqd with 1 large gap to treat as a table");
262 INT_VAR_H(tosp_short_row, 20,
263 "No.gaps reqd with few cert spaces to use certs");
264 INT_VAR_H(tosp_sanity_method, 1, "How to avoid being silly");
265 double_VAR_H(tosp_old_sp_kn_th_factor, 2.0,
266 "Factor for defining space threshold in terms of space and "
267 "kern sizes");
268 double_VAR_H(tosp_threshold_bias1, 0,
269 "how far between kern and space?");
270 double_VAR_H(tosp_threshold_bias2, 0,
271 "how far between kern and space?");
272 double_VAR_H(tosp_narrow_fraction, 0.3,
273 "Fract of xheight for narrow");
274 double_VAR_H(tosp_narrow_aspect_ratio, 0.48,
275 "narrow if w/h less than this");
276 double_VAR_H(tosp_wide_fraction, 0.52, "Fract of xheight for wide");
277 double_VAR_H(tosp_wide_aspect_ratio, 0.0,
278 "wide if w/h less than this");
279 double_VAR_H(tosp_fuzzy_space_factor, 0.6,
280 "Fract of xheight for fuzz sp");
281 double_VAR_H(tosp_fuzzy_space_factor1, 0.5,
282 "Fract of xheight for fuzz sp");
283 double_VAR_H(tosp_fuzzy_space_factor2, 0.72,
284 "Fract of xheight for fuzz sp");
285 double_VAR_H(tosp_gap_factor, 0.83, "gap ratio to flip sp->kern");
286 double_VAR_H(tosp_kern_gap_factor1, 2.0,
287 "gap ratio to flip kern->sp");
288 double_VAR_H(tosp_kern_gap_factor2, 1.3,
289 "gap ratio to flip kern->sp");
290 double_VAR_H(tosp_kern_gap_factor3, 2.5,
291 "gap ratio to flip kern->sp");
292 double_VAR_H(tosp_ignore_big_gaps, -1, "xht multiplier");
293 double_VAR_H(tosp_ignore_very_big_gaps, 3.5, "xht multiplier");
294 double_VAR_H(tosp_rep_space, 1.6, "rep gap multiplier for space");
295 double_VAR_H(tosp_enough_small_gaps, 0.65,
296 "Fract of kerns reqd for isolated row stats");
297 double_VAR_H(tosp_table_kn_sp_ratio, 2.25,
298 "Min difference of kn & sp in table");
299 double_VAR_H(tosp_table_xht_sp_ratio, 0.33,
300 "Expect spaces bigger than this");
301 double_VAR_H(tosp_table_fuzzy_kn_sp_ratio, 3.0,
302 "Fuzzy if less than this");
303 double_VAR_H(tosp_fuzzy_kn_fraction, 0.5, "New fuzzy kn alg");
304 double_VAR_H(tosp_fuzzy_sp_fraction, 0.5, "New fuzzy sp alg");
305 double_VAR_H(tosp_min_sane_kn_sp, 1.5,
306 "Dont trust spaces less than this time kn");
307 double_VAR_H(tosp_init_guess_kn_mult, 2.2,
308 "Thresh guess - mult kn by this");
309 double_VAR_H(tosp_init_guess_xht_mult, 0.28,
310 "Thresh guess - mult xht by this");
311 double_VAR_H(tosp_max_sane_kn_thresh, 5.0,
312 "Multiplier on kn to limit thresh");
313 double_VAR_H(tosp_flip_caution, 0.0,
314 "Dont autoflip kn to sp when large separation");
315 double_VAR_H(tosp_large_kerning, 0.19,
316 "Limit use of xht gap with large kns");
317 double_VAR_H(tosp_dont_fool_with_small_kerns, -1,
318 "Limit use of xht gap with odd small kns");
319 double_VAR_H(tosp_near_lh_edge, 0,
320 "Dont reduce box if the top left is non blank");
321 double_VAR_H(tosp_silly_kn_sp_gap, 0.2,
322 "Dont let sp minus kn get too small");
323 double_VAR_H(tosp_pass_wide_fuzz_sp_to_context, 0.75,
324 "How wide fuzzies need context");
325 // tordmain.cpp ///////////////////////////////////////////
326 BOOL_VAR_H(textord_no_rejects, false, "Don't remove noise blobs");
327 BOOL_VAR_H(textord_show_blobs, false, "Display unsorted blobs");
328 BOOL_VAR_H(textord_show_boxes, false, "Display boxes");
329 INT_VAR_H(textord_max_noise_size, 7, "Pixel size of noise");
330 double_VAR_H(textord_blob_size_bigile, 95, "Percentile for large blobs");
331 double_VAR_H(textord_noise_area_ratio, 0.7,
332 "Fraction of bounding box for noise");
333 double_VAR_H(textord_blob_size_smallile, 20, "Percentile for small blobs");
334 double_VAR_H(textord_initialx_ile, 0.75, "Ile of sizes for xheight guess");
335 double_VAR_H(textord_initialasc_ile, 0.90, "Ile of sizes for xheight guess");
336 INT_VAR_H(textord_noise_sizefraction, 10, "Fraction of size for maxima");
337 double_VAR_H(textord_noise_sizelimit, 0.5, "Fraction of x for big t count");
338 INT_VAR_H(textord_noise_translimit, 16, "Transitions for normal blob");
339 double_VAR_H(textord_noise_normratio, 2.0, "Dot to norm ratio for deletion");
340 BOOL_VAR_H(textord_noise_rejwords, true, "Reject noise-like words");
341 BOOL_VAR_H(textord_noise_rejrows, true, "Reject noise-like rows");
342 double_VAR_H(textord_noise_syfract, 0.2, "xh fract error for norm blobs");
343 double_VAR_H(textord_noise_sxfract, 0.4,
344 "xh fract width error for norm blobs");
345 double_VAR_H(textord_noise_hfract, 1.0/64,
346 "Height fraction to discard outlines as speckle noise");
347 INT_VAR_H(textord_noise_sncount, 1, "super norm blobs to save row");
348 double_VAR_H(textord_noise_rowratio, 6.0, "Dot to norm ratio for deletion");
349 BOOL_VAR_H(textord_noise_debug, FALSE, "Debug row garbage detector");
350 double_VAR_H(textord_blshift_maxshift, 0.00, "Max baseline shift");
351 double_VAR_H(textord_blshift_xfraction, 9.99, "Min size of baseline shift");
352 };
353 } // namespace tesseract.
354
355 #endif // TESSERACT_TEXTORD_TEXTORD_H__