Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
makerow.h
Go to the documentation of this file.
1 /**********************************************************************
2  * File: makerow.h (Formerly makerows.h)
3  * Description: Code to arrange blobs into rows of text.
4  * Author: Ray Smith
5  * Created: Mon Sep 21 14:34:48 BST 1992
6  *
7  * (C) Copyright 1992, Hewlett-Packard Ltd.
8  ** Licensed under the Apache License, Version 2.0 (the "License");
9  ** you may not use this file except in compliance with the License.
10  ** You may obtain a copy of the License at
11  ** http://www.apache.org/licenses/LICENSE-2.0
12  ** Unless required by applicable law or agreed to in writing, software
13  ** distributed under the License is distributed on an "AS IS" BASIS,
14  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  ** See the License for the specific language governing permissions and
16  ** limitations under the License.
17  *
18  **********************************************************************/
19 
20 #ifndef MAKEROW_H
21 #define MAKEROW_H
22 
23 #include "params.h"
24 #include "ocrblock.h"
25 #include "blobs.h"
26 #include "blobbox.h"
27 #include "statistc.h"
28 #include "notdll.h"
29 
31 {
32  ASSIGN, //assign it to row
33  REJECT, //reject it - dual overlap
35 };
36 
42 };
43 
45 "Display row accumulation");
47 "Display page correlated rows");
49 "Display rows after expanding");
51 "Display rows after final fitting");
53 "Display blob bounds after pre-ass");
54 extern BOOL_VAR_H (textord_test_landscape, FALSE, "Tests refer to land/port");
56 "Force parallel baselines");
58 "Force straight baselines");
60 "Use quadratic splines");
61 extern BOOL_VAR_H (textord_old_baselines, TRUE, "Use old baseline algorithm");
62 extern BOOL_VAR_H (textord_old_xheight, TRUE, "Use old xheight algorithm");
63 extern BOOL_VAR_H (textord_fix_xheight_bug, TRUE, "Use spline baseline");
65 "Prevent multiple baselines");
67 "Use new projection for underlines");
68 extern BOOL_VAR_H (textord_debug_xheights, FALSE, "Test xheight algorithms");
69 extern INT_VAR_H (textord_test_x, 0, "coord of test pt");
70 extern INT_VAR_H (textord_test_y, 0, "coord of test pt");
72 "Min blobs before gradient counted");
74 "Min blobs in each spline segment");
76 "Size of window for spline segmentation");
77 extern INT_VAR_H (textord_min_xheight, 10, "Min credible pixel xheight");
79 "Fraction of line spacing for quad");
81 "Fraction of line spacing for outlier");
82 extern double_VAR_H (textord_skew_ile, 0.5, "Ile of gradients for page skew");
83 extern double_VAR_H (textord_skew_lag, 0.75,
84 "Lag for skew on row accumulation");
86 "Max iqr/median for linespace");
88 "Max width of blobs to make rows");
89 extern double_VAR_H (textord_chop_width, 1.5, "Max width before chopping");
90 extern double_VAR_H (textord_minxh, 0.25,
91 "fraction of linesize for min xheight");
93 "* blob height for initial linesize");
95 "New row made if blob makes row this big");
97 "Fraction of neighbourhood");
99 "Multiple of line_size for underline");
101 "Min blob height/top to include blob top into xheight stats");
103 "Min pile height to make xheight");
105 "Min pile height to make ascheight");
106 extern double_VAR_H (textord_ascx_ratio_min, 1.2, "Min cap/xheight");
107 extern double_VAR_H (textord_ascx_ratio_max, 1.7, "Max cap/xheight");
108 extern double_VAR_H (textord_descx_ratio_min, 0.15, "Min desc/xheight");
109 extern double_VAR_H (textord_descx_ratio_max, 0.6, "Max desc/xheight");
110 extern double_VAR_H (textord_xheight_error_margin, 0.1, "Accepted variation");
111 extern INT_VAR_H (textord_lms_line_trials, 12, "Number of linew fits to do");
113 "Use test xheight mechanism");
114 
115 inline void get_min_max_xheight(int block_linesize,
116  int *min_height, int *max_height) {
117  *min_height = static_cast<inT32>(floor(block_linesize * textord_minxh));
118  if (*min_height < textord_min_xheight) *min_height = textord_min_xheight;
119  *max_height = static_cast<inT32>(ceil(block_linesize * 3.0));
120 }
121 
123  if (row->xheight <= 0) return ROW_INVALID;
124  return (row->ascrise > 0) ? ROW_ASCENDERS_FOUND :
125  (row->descdrop != 0) ? ROW_DESCENDERS_FOUND : ROW_UNKNOWN;
126 }
127 
128 inline bool within_error_margin(float test, float num, float margin) {
129  return (test >= num * (1 - margin) && test <= num * (1 + margin));
130 }
131 
132 void fill_heights(TO_ROW *row, float gradient, int min_height,
133  int max_height, STATS *heights, STATS *floating_heights);
134 
135 float make_single_row(ICOORD page_tr, TO_BLOCK* block,
136  TO_BLOCK_LIST* blocks);
137 float make_rows(ICOORD page_tr, // top right
138  TO_BLOCK_LIST *port_blocks);
139 void make_initial_textrows(ICOORD page_tr,
140  TO_BLOCK *block, // block to do
141  FCOORD rotation, // for drawing
142  BOOL8 testing_on); // correct orientation
143 void fit_lms_line(TO_ROW *row);
144 void compute_page_skew(TO_BLOCK_LIST *blocks, // list of blocks
145  float &page_m, // average gradient
146  float &page_err); // average error
147 void cleanup_rows_making(ICOORD page_tr, // top right
148  TO_BLOCK *block, // block to do
149  float gradient, // gradient to fit
150  FCOORD rotation, // for drawing
151  inT32 block_edge, // edge of block
152  BOOL8 testing_on); // correct orientation
153 void delete_non_dropout_rows( //find lines
154  TO_BLOCK *block, //block to do
155  float gradient, //global skew
156  FCOORD rotation, //deskew vector
157  inT32 block_edge, //left edge
158  BOOL8 testing_on //correct orientation
159  );
160 BOOL8 find_best_dropout_row( //find neighbours
161  TO_ROW *row, //row to test
162  inT32 distance, //dropout dist
163  float dist_limit, //threshold distance
164  inT32 line_index, //index of row
165  TO_ROW_IT *row_it, //current position
166  BOOL8 testing_on //correct orientation
167  );
168 TBOX deskew_block_coords( //block box
169  TO_BLOCK *block, //block to do
170  float gradient //global skew
171  );
172 void compute_line_occupation( //project blobs
173  TO_BLOCK *block, //block to do
174  float gradient, //global skew
175  inT32 min_y, //min coord in block
176  inT32 max_y, //in block
177  inT32 *occupation, //output projection
178  inT32 *deltas //derivative
179  );
180 void compute_occupation_threshold( //project blobs
181  inT32 low_window, //below result point
182  inT32 high_window, //above result point
183  inT32 line_count, //array sizes
184  inT32 *occupation, //input projection
185  inT32 *thresholds //output thresholds
186  );
187 void compute_dropout_distances( //project blobs
188  inT32 *occupation, //input projection
189  inT32 *thresholds, //output thresholds
190  inT32 line_count //array sizes
191  );
192 void expand_rows( //find lines
193  ICOORD page_tr, //top right
194  TO_BLOCK *block, //block to do
195  float gradient, //gradient to fit
196  FCOORD rotation, //for drawing
197  inT32 block_edge, //edge of block
198  BOOL8 testing_on //correct orientation
199  );
200 void adjust_row_limits( //tidy limits
201  TO_BLOCK *block //block to do
202  );
203 void compute_row_stats( //find lines
204  TO_BLOCK *block, //block to do
205  BOOL8 testing_on //correct orientation
206  );
207 float median_block_xheight( //find lines
208  TO_BLOCK *block, //block to do
209  float gradient //global skew
210  );
211 
213  STATS *heights, STATS *floating_heights, bool cap_only, int min_height,
214  int max_height, float *xheight, float *ascrise);
215 
216 inT32 compute_row_descdrop(TO_ROW *row, // row to do
217  float gradient, // global skew
218  int xheight_blob_count,
219  STATS *heights);
220 inT32 compute_height_modes(STATS *heights, // stats to search
221  inT32 min_height, // bottom of range
222  inT32 max_height, // top of range
223  inT32 *modes, // output array
224  inT32 maxmodes); // size of modes
225 void correct_row_xheight(TO_ROW *row, // row to fix
226  float xheight, // average values
227  float ascrise,
228  float descdrop);
229 void separate_underlines(TO_BLOCK *block, // block to do
230  float gradient, // skew angle
231  FCOORD rotation, // inverse landscape
232  BOOL8 testing_on); // correct orientation
233 void pre_associate_blobs( ICOORD page_tr, // top right
234  TO_BLOCK *block, // block to do
235  FCOORD rotation, // inverse landscape
236  BOOL8 testing_on); // correct orientation
237 void fit_parallel_rows(TO_BLOCK *block, // block to do
238  float gradient, // gradient to fit
239  FCOORD rotation, // for drawing
240  inT32 block_edge, // edge of block
241  BOOL8 testing_on); // correct orientation
242 void fit_parallel_lms(float gradient, // forced gradient
243  TO_ROW *row); // row to fit
244 void make_baseline_spline(TO_ROW *row, // row to fit
245  TO_BLOCK *block); // block it came from
246 BOOL8 segment_baseline ( //split baseline
247 TO_ROW * row, //row to fit
248 TO_BLOCK * block, //block it came from
249 inT32 & segments, //no fo segments
250 inT32 xstarts[] //coords of segments
251 );
252 double *linear_spline_baseline ( //split baseline
253 TO_ROW * row, //row to fit
254 TO_BLOCK * block, //block it came from
255 inT32 & segments, //no fo segments
256 inT32 xstarts[] //coords of segments
257 );
258 void assign_blobs_to_rows( //find lines
259  TO_BLOCK *block, //block to do
260  float *gradient, //block skew
261  int pass, //identification
262  BOOL8 reject_misses, //chuck big ones out
263  BOOL8 make_new_rows, //add rows for unmatched
264  BOOL8 drawing_skew //draw smoothed skew
265  );
266  //find best row
267 OVERLAP_STATE most_overlapping_row(TO_ROW_IT *row_it, //iterator
268  TO_ROW *&best_row, //output row
269  float top, //top of blob
270  float bottom, //bottom of blob
271  float rowsize, //max row size
272  BOOL8 testing_blob //test stuff
273  );
274 int blob_x_order( //sort function
275  const void *item1, //items to compare
276  const void *item2);
277 int row_y_order( //sort function
278  const void *item1, //items to compare
279  const void *item2);
280 int row_spacing_order( //sort function
281  const void *item1, //items to compare
282  const void *item2);
283 
284 void mark_repeated_chars(TO_ROW *row);
285 #endif
double textord_min_linesize
Definition: makerow.cpp:84
int textord_spline_minblobs
Definition: makerow.cpp:66
double textord_xheight_mode_fraction
Definition: makerow.cpp:92
double textord_ascx_ratio_min
Definition: makerow.cpp:97
void make_initial_textrows(ICOORD page_tr, TO_BLOCK *block, FCOORD rotation, BOOL8 testing_on)
Definition: makerow.cpp:236
int blob_x_order(const void *item1, const void *item2)
Definition: makerow.cpp:2694
bool textord_fix_xheight_bug
Definition: makerow.cpp:56
int textord_test_y
Definition: makerow.cpp:64
int textord_min_blobs_in_row
Definition: makerow.cpp:65
int row_spacing_order(const void *item1, const void *item2)
Definition: makerow.cpp:2738
int row_y_order(const void *item1, const void *item2)
Definition: makerow.cpp:2716
#define BOOL_VAR_H(name, val, comment)
Definition: params.h:239
TBOX deskew_block_coords(TO_BLOCK *block, float gradient)
Definition: makerow.cpp:835
double textord_ascx_ratio_max
Definition: makerow.cpp:98
void cleanup_rows_making(ICOORD page_tr, TO_BLOCK *block, float gradient, FCOORD rotation, inT32 block_edge, BOOL8 testing_on)
Definition: makerow.cpp:534
void fit_parallel_rows(TO_BLOCK *block, float gradient, FCOORD rotation, inT32 block_edge, BOOL8 testing_on)
Definition: makerow.cpp:2051
bool textord_quadratic_baselines
unsigned char BOOL8
Definition: host.h:113
float make_rows(ICOORD page_tr, TO_BLOCK_LIST *port_blocks)
Definition: makerow.cpp:197
int textord_test_x
Definition: makerow.cpp:63
bool textord_parallel_baselines
Definition: makerow.cpp:52
void compute_occupation_threshold(inT32 low_window, inT32 high_window, inT32 line_count, inT32 *occupation, inT32 *thresholds)
Definition: makerow.cpp:937
float descdrop
Definition: blobbox.h:632
void get_min_max_xheight(int block_linesize, int *min_height, int *max_height)
Definition: makerow.h:115
bool textord_test_landscape
Definition: makerow.cpp:51
bool textord_show_initial_rows
Definition: makerow.cpp:46
bool textord_cblob_blockocc
ROW_CATEGORY
Definition: makerow.h:37
double textord_min_blob_height_fraction
Definition: makerow.cpp:90
bool textord_new_initial_xheight
Definition: makerow.cpp:103
bool textord_debug_xheights
Definition: makerow.cpp:58
int inT32
Definition: host.h:102
Definition: rect.h:29
void fit_parallel_lms(float gradient, TO_ROW *row)
Definition: makerow.cpp:2093
bool textord_show_expanded_rows
Definition: makerow.cpp:48
void assign_blobs_to_rows(TO_BLOCK *block, float *gradient, int pass, BOOL8 reject_misses, BOOL8 make_new_rows, BOOL8 drawing_skew)
Definition: makerow.cpp:2402
int compute_xheight_from_modes(STATS *heights, STATS *floating_heights, bool cap_only, int min_height, int max_height, float *xheight, float *ascrise)
Definition: makerow.cpp:1587
#define FALSE
Definition: capi.h:28
double textord_width_limit
Definition: makerow.cpp:78
void separate_underlines(TO_BLOCK *block, float gradient, FCOORD rotation, BOOL8 testing_on)
Definition: makerow.cpp:1892
OVERLAP_STATE
Definition: makerow.h:30
float make_single_row(ICOORD page_tr, TO_BLOCK *block, TO_BLOCK_LIST *blocks)
Definition: makerow.cpp:167
void fit_lms_line(TO_ROW *row)
Definition: makerow.cpp:276
double textord_underline_width
Definition: makerow.cpp:88
void compute_row_stats(TO_BLOCK *block, BOOL8 testing_on)
Definition: makerow.cpp:1259
#define double_VAR_H(name, val, comment)
Definition: params.h:245
double textord_skew_lag
Definition: makerow.cpp:76
void compute_line_occupation(TO_BLOCK *block, float gradient, inT32 min_y, inT32 max_y, inT32 *occupation, inT32 *deltas)
Definition: makerow.cpp:871
bool textord_straight_baselines
Definition: makerow.cpp:53
BOOL8 segment_baseline(TO_ROW *row, TO_BLOCK *block, inT32 &segments, inT32 xstarts[])
Definition: makerow.cpp:2212
double textord_ascheight_mode_fraction
Definition: makerow.cpp:94
double textord_spline_outlier_fraction
Definition: makerow.cpp:74
bool textord_fix_makerow_bug
Definition: makerow.cpp:57
void make_baseline_spline(TO_ROW *row, TO_BLOCK *block)
Definition: makerow.cpp:2178
bool textord_show_final_rows
Definition: makerow.cpp:49
void mark_repeated_chars(TO_ROW *row)
Definition: makerow.cpp:2760
int textord_lms_line_trials
Definition: makerow.cpp:102
float ascrise
Definition: blobbox.h:631
double textord_minxh
Definition: makerow.cpp:83
void delete_non_dropout_rows(TO_BLOCK *block, float gradient, FCOORD rotation, inT32 block_edge, BOOL8 testing_on)
Definition: makerow.cpp:667
ROW_CATEGORY get_row_category(const TO_ROW *row)
Definition: makerow.h:122
void adjust_row_limits(TO_BLOCK *block)
Definition: makerow.cpp:1223
double textord_spline_shift_fraction
Definition: makerow.cpp:72
float median_block_xheight(TO_BLOCK *block, float gradient)
double textord_skew_ile
Definition: makerow.cpp:75
double textord_occupancy_threshold
Definition: makerow.cpp:87
Definition: makerow.h:33
bool textord_show_parallel_rows
Definition: makerow.cpp:47
Definition: points.h:189
double textord_linespace_iqrlimit
Definition: makerow.cpp:77
bool textord_old_xheight
Definition: makerow.cpp:55
Definition: statistc.h:29
integer coordinate
Definition: points.h:30
void compute_page_skew(TO_BLOCK_LIST *blocks, float &page_m, float &page_err)
Definition: makerow.cpp:296
double textord_excess_blobsize
Definition: makerow.cpp:86
bool textord_show_final_blobs
Definition: makerow.cpp:50
void compute_dropout_distances(inT32 *occupation, inT32 *thresholds, inT32 line_count)
Definition: makerow.cpp:1018
double * linear_spline_baseline(TO_ROW *row, TO_BLOCK *block, inT32 &segments, inT32 xstarts[])
Definition: makerow.cpp:2311
double textord_descx_ratio_min
Definition: makerow.cpp:99
inT32 compute_row_descdrop(TO_ROW *row, float gradient, int xheight_blob_count, STATS *heights)
Definition: makerow.cpp:1683
#define INT_VAR_H(name, val, comment)
Definition: params.h:236
void pre_associate_blobs(ICOORD page_tr, TO_BLOCK *block, FCOORD rotation, BOOL8 testing_on)
Definition: makerow.cpp:1965
double textord_xheight_error_margin
Definition: makerow.cpp:101
int textord_spline_medianwin
Definition: makerow.cpp:67
OVERLAP_STATE most_overlapping_row(TO_ROW_IT *row_it, TO_ROW *&best_row, float top, float bottom, float rowsize, BOOL8 testing_blob)
Definition: makerow.cpp:2598
void fill_heights(TO_ROW *row, float gradient, int min_height, int max_height, STATS *heights, STATS *floating_heights)
Definition: makerow.cpp:1526
float xheight
Definition: blobbox.h:629
BOOL8 find_best_dropout_row(TO_ROW *row, inT32 distance, float dist_limit, inT32 line_index, TO_ROW_IT *row_it, BOOL8 testing_on)
Definition: makerow.cpp:755
void correct_row_xheight(TO_ROW *row, float xheight, float ascrise, float descdrop)
Definition: makerow.cpp:1805
int textord_min_xheight
Definition: makerow.cpp:70
double textord_descx_ratio_max
Definition: makerow.cpp:100
double textord_chop_width
Definition: makerow.cpp:79
Definition: makerow.h:32
bool textord_old_baselines
Definition: makerow.cpp:54
inT32 compute_height_modes(STATS *heights, inT32 min_height, inT32 max_height, inT32 *modes, inT32 maxmodes)
Definition: makerow.cpp:1743
void expand_rows(ICOORD page_tr, TO_BLOCK *block, float gradient, FCOORD rotation, inT32 block_edge, BOOL8 testing_on)
Definition: makerow.cpp:1065
bool within_error_margin(float test, float num, float margin)
Definition: makerow.h:128
#define TRUE
Definition: capi.h:27