00001
00019 #ifndef MAKEROW_H
00020 #define MAKEROW_H
00021
00022 #include "varable.h"
00023 #include "ocrblock.h"
00024 #include "tessclas.h"
00025 #include "blobbox.h"
00026 #include "statistc.h"
00027 #include "notdll.h"
00028
00033 enum OVERLAP_STATE
00034 {
00036 ASSIGN,
00038 REJECT,
00040 NEW_ROW
00041 };
00042
00229 extern BOOL_VAR_H (textord_show_initial_rows, FALSE,
00230 "Display row accumulation");
00231 extern BOOL_VAR_H (textord_show_parallel_rows, FALSE,
00232 "Display page correlated rows");
00233 extern BOOL_VAR_H (textord_show_expanded_rows, FALSE,
00234 "Display rows after expanding");
00235 extern BOOL_VAR_H (textord_show_final_rows, FALSE,
00236 "Display rows after final fittin");
00237 extern BOOL_VAR_H (textord_show_final_blobs, FALSE,
00238 "Display blob bounds after pre-ass");
00239 extern BOOL_VAR_H (textord_test_landscape, FALSE, "Tests refer to land/port");
00240 extern BOOL_VAR_H (textord_parallel_baselines, TRUE,
00241 "Force parallel baselines");
00242 extern BOOL_VAR_H (textord_straight_baselines, FALSE,
00243 "Force straight baselines");
00244 extern BOOL_VAR_H (textord_quadratic_baselines, FALSE,
00245 "Use quadratic splines");
00246 extern BOOL_VAR_H (textord_old_baselines, TRUE, "Use old baseline algorithm");
00247 extern BOOL_VAR_H (textord_old_xheight, TRUE, "Use old xheight algorithm");
00248 extern BOOL_VAR_H (textord_fix_xheight_bug, TRUE, "Use spline baseline");
00249 extern BOOL_VAR_H (textord_fix_makerow_bug, TRUE,
00250 "Prevent multiple baselines");
00251 extern BOOL_VAR_H (textord_row_xheights, FALSE, "Use row height policy");
00252 extern BOOL_VAR_H (textord_block_xheights, TRUE, "Use block height policy");
00253 extern BOOL_VAR_H (textord_xheight_tweak, FALSE,
00254 "New min condition on height");
00255 extern BOOL_VAR_H (textord_cblob_blockocc, TRUE,
00256 "Use new projection for underlines");
00257 extern BOOL_VAR_H (textord_debug_xheights, FALSE, "Test xheight algorithms");
00258 extern INT_VAR_H (textord_test_x, 0, "coord of test pt");
00259 extern INT_VAR_H (textord_test_y, 0, "coord of test pt");
00260 extern INT_VAR_H (textord_min_blobs_in_row, 4,
00261 "Min blobs before gradient counted");
00262 extern INT_VAR_H (textord_spline_minblobs, 8,
00263 "Min blobs in each spline segment");
00264 extern INT_VAR_H (textord_spline_medianwin, 6,
00265 "Size of window for spline segmentation");
00266 extern INT_VAR_H (textord_min_xheight, 10, "Min credible pixel xheight");
00267 extern double_VAR_H (textord_spline_shift_fraction, 0.02,
00268 "Fraction of line spacing for quad");
00269 extern double_VAR_H (textord_spline_outlier_fraction, 0.1,
00270 "Fraction of line spacing for outlier");
00271 extern double_VAR_H (textord_skew_ile, 0.5, "Ile of gradients for page skew");
00272 extern double_VAR_H (textord_skew_lag, 0.75,
00273 "Lag for skew on row accumulation");
00274 extern double_VAR_H (textord_linespace_iqrlimit, 0.2,
00275 "Max iqr/median for linespace");
00276 extern double_VAR_H (textord_width_limit, 8,
00277 "Max width of blobs to make rows");
00278 extern double_VAR_H (textord_chop_width, 1.5, "Max width before chopping");
00279 extern double_VAR_H (textord_merge_desc, 0.25,
00280 "Fraction of linespace for desc drop");
00281 extern double_VAR_H (textord_merge_x, 0.5,
00282 "Fraction of linespace for x height");
00283 extern double_VAR_H (textord_merge_asc, 0.25,
00284 "Fraction of linespace for asc height");
00285 extern double_VAR_H (textord_minxh, 0.25,
00286 "fraction of linesize for min xheight");
00287 extern double_VAR_H (textord_min_linesize, 1.25,
00288 "* blob height for initial linesize");
00289 extern double_VAR_H (textord_excess_blobsize, 1.3,
00290 "New row made if blob makes row this big");
00291 extern double_VAR_H (textord_occupancy_threshold, 0.4,
00292 "Fraction of neighbourhood");
00293 extern double_VAR_H (textord_underline_width, 2.0,
00294 "Multiple of line_size for underline");
00295 extern double_VAR_H (textord_xheight_mode_fraction, 0.4,
00296 "Min pile height to make xheight");
00297 extern double_VAR_H (textord_ascheight_mode_fraction, 0.15,
00298 "Min pile height to make ascheight");
00299 extern double_VAR_H (textord_ascx_ratio_min, 1.2, "Min cap/xheight");
00300 extern double_VAR_H (textord_ascx_ratio_max, 1.7, "Max cap/xheight");
00301 extern double_VAR_H (textord_descx_ratio_min, 0.15, "Min desc/xheight");
00302 extern double_VAR_H (textord_descx_ratio_max, 0.6, "Max desc/xheight");
00303 extern double_VAR_H (textord_xheight_error_margin, 0.1, "Accepted variation");
00306 float make_rows(
00307 ICOORD page_tr,
00308 BLOCK_LIST *blocks,
00309 TO_BLOCK_LIST *land_blocks,
00310 TO_BLOCK_LIST *port_blocks
00311 );
00312 void make_initial_textrows(
00313 ICOORD page_tr,
00314 TO_BLOCK *block,
00315 FCOORD rotation,
00316 BOOL8 testing_on
00317 );
00318 void fit_lms_line(
00319 TO_ROW *row
00320 );
00321 void compute_page_skew(
00322 TO_BLOCK_LIST *blocks,
00323 float &page_m,
00324 float &page_err
00325 );
00326 void cleanup_rows(
00327 ICOORD page_tr,
00328 TO_BLOCK *block,
00329 float gradient,
00330 FCOORD rotation,
00331 INT32 block_edge,
00332 BOOL8 testing_on
00333 );
00334 void delete_non_dropout_rows(
00335 TO_BLOCK *block,
00336 float gradient,
00337 FCOORD rotation,
00338 INT32 block_edge,
00339 BOOL8 testing_on
00340 );
00341 BOOL8 find_best_dropout_row(
00342 TO_ROW *row,
00343 INT32 distance,
00344 float dist_limit,
00345 INT32 line_index,
00346 TO_ROW_IT *row_it,
00347 BOOL8 testing_on
00348 );
00349 BOX deskew_block_coords(
00350 TO_BLOCK *block,
00351 float gradient
00352 );
00353 void compute_line_occupation(
00354 TO_BLOCK *block,
00355 float gradient,
00356 INT32 min_y,
00357 INT32 max_y,
00358 INT32 *occupation,
00359 INT32 *deltas
00360 );
00361 void compute_occupation_threshold(
00362 INT32 low_window,
00363 INT32 high_window,
00364 INT32 line_count,
00365 INT32 *occupation,
00366 INT32 *thresholds
00367 );
00368 void compute_dropout_distances(
00369 INT32 *occupation,
00370 INT32 *thresholds,
00371 INT32 line_count
00372 );
00373 void expand_rows(
00374 ICOORD page_tr,
00375 TO_BLOCK *block,
00376 float gradient,
00377 FCOORD rotation,
00378 INT32 block_edge,
00379 BOOL8 testing_on
00380 );
00381 void adjust_row_limits(
00382 TO_BLOCK *block
00383 );
00384 void compute_row_stats(
00385 TO_BLOCK *block,
00386 BOOL8 testing_on
00387 );
00388 void compute_block_xheight(
00389 TO_BLOCK *block,
00390 float gradient
00391 );
00392 float median_block_xheight(
00393 TO_BLOCK *block,
00394 float gradient
00395 );
00396 INT32 compute_row_xheight(
00397 TO_ROW *row,
00398 INT32 min_height,
00399 INT32 max_height,
00400 float gradient
00401 );
00402 INT32 compute_row_descdrop(
00403 TO_ROW *row,
00404 float gradient
00405 );
00406 INT32 compute_height_modes(
00407 STATS *heights,
00408 INT32 min_height,
00409 INT32 max_height,
00410 INT32 *modes,
00411 INT32 maxmodes
00412 );
00413 void correct_row_xheight(
00414 TO_ROW *row,
00415 float xheight,
00416 float ascrise,
00417 float descdrop);
00418 void separate_underlines(
00419 TO_BLOCK *block,
00420 float gradient,
00421 FCOORD rotation,
00422 BOOL8 testing_on
00423 );
00424 void pre_associate_blobs(
00425 ICOORD page_tr,
00426 TO_BLOCK *block,
00427 FCOORD rotation,
00428 BOOL8 testing_on
00429 );
00430 void fit_parallel_rows(
00431 TO_BLOCK *block,
00432 float gradient,
00433 FCOORD rotation,
00434 INT32 block_edge,
00435 BOOL8 testing_on
00436 );
00437 void fit_parallel_lms(
00438 float gradient,
00439 TO_ROW *row
00440 );
00441 void make_spline_rows(
00442 TO_BLOCK *block,
00443 float gradient,
00444 FCOORD rotation,
00445 INT32 block_edge,
00446 BOOL8 testing_on
00447 );
00448 void make_baseline_spline(
00449 TO_ROW *row,
00450 TO_BLOCK *block
00451 );
00452 BOOL8 segment_baseline (
00453 TO_ROW * row,
00454 TO_BLOCK * block,
00455 INT32 & segments,
00456 INT32 xstarts[]
00457 );
00458 double *linear_spline_baseline (
00459 TO_ROW * row,
00460 TO_BLOCK * block,
00461 INT32 & segments,
00462 INT32 xstarts[]
00463 );
00464 void assign_blobs_to_rows(
00465 TO_BLOCK *block,
00466 float *gradient,
00467 int pass,
00468 BOOL8 reject_misses,
00469 BOOL8 make_new_rows,
00470 BOOL8 drawing_skew
00471 );
00472
00473 OVERLAP_STATE most_overlapping_row(TO_ROW_IT *row_it,
00474 TO_ROW *&best_row,
00475 float top,
00476 float bottom,
00477 float rowsize,
00478 BOOL8 testing_blob
00479 );
00480 int blob_x_order(
00481 const void *item1,
00482 const void *item2);
00483 int row_y_order(
00484 const void *item1,
00485 const void *item2);
00486 int row_spacing_order(
00487 const void *item1,
00488 const void *item2);
00489 #endif