38 #include "config_auto.h"
45 "Force proportional word segmentation on all rows");
47 "Chopper is being tested.");
49 #define FIXED_WIDTH_MULTIPLE 5
50 #define BLOCK_STATS_CLUSTERS 10
61 TO_ROW_IT to_row_it(rows);
62 ROW_IT row_it(real_rows);
63 for (to_row_it.mark_cycle_pt(); !to_row_it.cycled_list();
64 to_row_it.forward()) {
65 TO_ROW* row = to_row_it.data();
69 C_BLOB_IT cblob_it(&cblobs);
71 for (;!box_it.empty(); box_it.forward()) {
75 C_OUTLINE_IT cout_it(cblob_it.data()->out_list());
76 cout_it.move_to_last();
78 delete bblob->
cblob();
82 cblob_it.add_after_then_move(bblob->
cblob());
94 word_it.add_after_then_move(word);
95 row_it.add_after_then_move(real_row);
108 TO_BLOCK_LIST *port_blocks) {
109 TO_BLOCK_IT block_it;
119 block_it.set_to_list(port_blocks);
120 for (block_it.mark_cycle_pt(); !block_it.cycled_list(); block_it.forward()) {
121 block = block_it.data();
140 TO_ROW_IT row_it = block->
get_rows ();
144 for (row_it.mark_cycle_pt (); !row_it.cycled_list (); row_it.forward ()) {
145 row = row_it.data ();
156 tprintf (
"Assigning defaults %d non, %d space to row at %g\n",
163 #ifndef GRAPHICS_DISABLED
200 STATS gap_stats (0, maxwidth);
201 STATS cluster_stats[4];
211 for (blob_it.mark_cycle_pt (); !blob_it.cycled_list (); blob_it.forward ()) {
212 blob = blob_it.data ();
216 gap_stats.
add (blob_box.
width (), 1);
220 for (blob_it.mark_cycle_pt (); !blob_it.cycled_list (); blob_it.forward ()) {
221 blob = blob_it.data ();
226 if (this_valid && prev_valid
227 && blob_box.
left () - prev_x < maxwidth) {
228 gap_stats.
add (blob_box.
left () - prev_x, 1);
230 prev_x = blob_box.
right ();
231 prev_valid = this_valid;
239 gap_stats.
smooth (smooth_factor);
242 cluster_count = gap_stats.
cluster (lower, upper,
245 while (cluster_count < 2 && ceil (lower) < floor (upper)) {
247 upper = (upper * 3 + lower) / 4;
248 lower = (lower * 3 + upper) / 4;
249 cluster_count = gap_stats.
cluster (lower, upper,
253 if (cluster_count < 2) {
258 for (gap_index = 0; gap_index < cluster_count; gap_index++)
259 gaps[gap_index] = cluster_stats[gap_index + 1].ile (0.5);
261 if (cluster_count > 2) {
263 tprintf (
"Row at %g has 3 sizes of gap:%g,%g,%g\n",
265 cluster_stats[1].
ile (0.5),
266 cluster_stats[2].
ile (0.5), cluster_stats[3].
ile (0.5));
269 if (gaps[1] > lower) {
272 && gaps[2] > gaps[1]) {
276 else if (gaps[2] > lower
283 tprintf (
"Had to switch most common from lower to upper!!\n");
294 if (gaps[1] < gaps[0]) {
296 tprintf (
"Had to switch most common from lower to upper!!\n");
315 tprintf (
"Disagreement between block and row at %g!!\n",
317 tprintf (
"Lower=%g, upper=%g, Stats:\n", lower, upper);
337 tprintf (
"Row at %g has minspace=%d(%g), max_non=%d(%g)\n",
375 STATS gap_stats (0, maxwidth);
392 for (blob_it.mark_cycle_pt (); !blob_it.cycled_list (); blob_it.forward ()) {
393 blob = blob_it.data ();
396 this_valid = blob_box.
width () >= min_width;
397 if (this_valid && prev_valid
398 && blob_box.
left () - prev_x < maxwidth) {
399 gap_stats.
add (blob_box.
left () - prev_x, 1);
402 prev_x = blob_box.
right ();
403 prev_valid = this_valid;
410 for (blob_it.mark_cycle_pt (); !blob_it.cycled_list ();
411 blob_it.forward ()) {
412 blob = blob_it.data ();
415 if (blob_box.
left () - prev_x < maxwidth) {
416 gap_stats.
add (blob_box.
left () - prev_x, 1);
418 prev_x = blob_box.
right ();
431 gap_stats.
smooth (smooth_factor);
433 prev_count = cluster_count;
434 cluster_count = gap_stats.
cluster (lower, upper,
439 if (cluster_count < 1) {
444 for (gap_index = 0; gap_index < cluster_count; gap_index++)
445 gaps[gap_index] = cluster_stats[gap_index + 1].ile (0.5);
448 tprintf (
"cluster_count=%d:", cluster_count);
449 for (gap_index = 0; gap_index < cluster_count; gap_index++)
450 tprintf (
" %g(%d)", gaps[gap_index],
451 cluster_stats[gap_index + 1].get_total ());
456 for (gap_index = 0; gap_index < cluster_count
458 if (gap_index < cluster_count)
459 lower = gaps[gap_index];
462 tprintf (
"No cluster below block threshold!, using default=%g\n",
466 for (gap_index = 0; gap_index < cluster_count
467 && gaps[gap_index] <= block->
max_nonspace; gap_index++);
468 if (gap_index < cluster_count)
469 upper = gaps[gap_index];
472 tprintf (
"No cluster above block threshold!, using default=%g\n",
492 tprintf (
"Row at %g has minspace=%d(%g), max_non=%d(%g)\n",
512 TO_ROW_IT row_it = block->
get_rows ();
518 for (row_it.mark_cycle_pt (); !row_it.cycled_list (); row_it.forward ()) {
519 row = row_it.data ();
543 if (real_row !=
NULL) {
545 real_row_it.add_after_then_move (real_row);
571 if (word_it.empty ())
573 word_box = word_it.data ()->bounding_box ();
574 for (word_it.mark_cycle_pt (); !word_it.cycled_list (); word_it.forward ())
575 word_box += word_it.data ()->bounding_box ();
577 real_row =
new ROW(row,
579 word_it.set_to_list (real_row->
word_list ());
581 word_it.add_list_after (&row->
rep_words);
599 C_OUTLINE_IT cout_it;
601 C_BLOB_IT cblob_it = &cblobs;
606 for (blobindex = 0; blobindex < blobcount; blobindex++) {
607 bblob = box_it->extract();
610 cout_it.set_to_list(cblob_it.data()->out_list());
611 cout_it.move_to_last();
613 delete bblob->
cblob();
618 cblob_it.add_after_then_move(bblob->
cblob());
627 word =
new WERD(&cblobs, blanks,
NULL);
631 if (box_it->at_first())
EXTERN double textord_words_definite_spread
inT32 cluster(float lower, float upper, float multiple, inT32 max_clusters, STATS *clusters)
EXTERN double words_initial_upper
ROW * make_blob_words(TO_ROW *row, FCOORD rotation)
EXTERN double textord_wordstats_smooth_factor
WERD * make_real_word(BLOBNBOX_IT *box_it, inT32 blobcount, BOOL8 bol, uinT8 blanks)
void print_summary() const
void make_single_word(bool one_blob, TO_ROW_LIST *rows, ROW_LIST *real_rows)
void compute_fixed_pitch_cjk(ICOORD page_tr, TO_BLOCK_LIST *port_blocks)
bool joined_to_prev() const
void set_row_spaces(TO_BLOCK *block, FCOORD rotation, BOOL8 testing_on)
void make_real_words(tesseract::Textord *textord, TO_BLOCK *block, FCOORD rotation)
void add(inT32 value, inT32 count)
#define BOOL_VAR(name, val, comment)
EXTERN bool textord_chopper_test
void set_stats(BOOL8 prop, inT16 kern, inT16 space, inT16 ch_pitch)
inT32 row_words(TO_BLOCK *block, TO_ROW *row, inT32 maxwidth, FCOORD rotation, BOOL8 testing_on)
BLOBNBOX_LIST * blob_list()
EXTERN bool textord_fp_chopping
ROW * make_rep_words(TO_ROW *row, TO_BLOCK *block)
C_OUTLINE_LIST * out_list()
bool use_cjk_fp_model() const
inT32 row_words2(TO_BLOCK *block, TO_ROW *row, inT32 maxwidth, FCOORD rotation, BOOL8 testing_on)
EXTERN ScrollView * to_win
double ile(double frac) const
EXTERN double textord_spacesize_ratioprop
bool textord_test_landscape
EXTERN double textord_words_initial_upper
#define BLOCK_STATS_CLUSTERS
EXTERN double textord_words_min_minspace
void smooth(inT32 factor)
EXTERN double textord_words_minlarge
void check_pitch()
check proportional
EXTERN bool textord_show_initial_words
void compute_fixed_pitch(ICOORD page_tr, TO_BLOCK_LIST *port_blocks, float gradient, FCOORD rotation, BOOL8 testing_on)
void plot_word_decisions(ScrollView *win, inT16 pitch, TO_ROW *row)
PITCH_TYPE pitch_decision
void to_spacing(ICOORD page_tr, TO_BLOCK_LIST *blocks)
ROW * make_prop_words(TO_ROW *row, FCOORD rotation)
bool contains(const FCOORD pt) const
const TBOX & bounding_box() const
EXTERN double words_initial_lower
ROW_LIST * row_list()
get rows
EXTERN bool textord_force_make_prop_words
POLY_BLOCK * poly_block() const
void set_flag(WERD_FLAGS mask, BOOL8 value)
ROW * fixed_pitch_words(TO_ROW *row, FCOORD rotation)
EXTERN double textord_words_width_ile
EXTERN double textord_words_initial_lower
void recalc_bounding_box()
void make_words(tesseract::Textord *textord, ICOORD page_tr, float gradient, BLOCK_LIST *blocks, TO_BLOCK_LIST *port_blocks)