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()) {
74 if (bblob->
cblob() != NULL) {
75 C_OUTLINE_IT cout_it(cblob_it.data()->out_list());
76 cout_it.move_to_last();
78 delete bblob->
cblob();
81 if (bblob->
cblob() != NULL)
82 cblob_it.add_after_then_move(bblob->
cblob());
90 WERD* word =
new WERD(&cblobs, 0, NULL);
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 198 STATS gap_stats (0, maxwidth);
199 STATS cluster_stats[4];
209 for (blob_it.mark_cycle_pt (); !blob_it.cycled_list (); blob_it.forward ()) {
210 blob = blob_it.data ();
214 gap_stats.
add (blob_box.
width (), 1);
217 for (blob_it.mark_cycle_pt (); !blob_it.cycled_list (); blob_it.forward ()) {
218 blob = blob_it.data ();
221 if (prev_valid && blob_box.
left () - prev_x < maxwidth) {
222 gap_stats.
add (blob_box.
left () - prev_x, 1);
225 prev_x = blob_box.
right ();
233 gap_stats.
smooth (smooth_factor);
236 cluster_count = gap_stats.
cluster (lower, upper,
239 while (cluster_count < 2 && ceil (lower) < floor (upper)) {
241 upper = (upper * 3 + lower) / 4;
242 lower = (lower * 3 + upper) / 4;
243 cluster_count = gap_stats.
cluster (lower, upper,
247 if (cluster_count < 2) {
252 for (gap_index = 0; gap_index < cluster_count; gap_index++)
253 gaps[gap_index] = cluster_stats[gap_index + 1].ile (0.5);
255 if (cluster_count > 2) {
257 tprintf (
"Row at %g has 3 sizes of gap:%g,%g,%g\n",
259 cluster_stats[1].
ile (0.5),
260 cluster_stats[2].
ile (0.5), cluster_stats[3].
ile (0.5));
263 if (gaps[1] > lower) {
266 && gaps[2] > gaps[1]) {
270 else if (gaps[2] > lower
277 tprintf (
"Had to switch most common from lower to upper!!\n");
288 if (gaps[1] < gaps[0]) {
290 tprintf (
"Had to switch most common from lower to upper!!\n");
309 tprintf (
"Disagreement between block and row at %g!!\n",
311 tprintf (
"Lower=%g, upper=%g, Stats:\n", lower, upper);
331 tprintf (
"Row at %g has minspace=%d(%g), max_non=%d(%g)\n",
369 STATS gap_stats (0, maxwidth);
386 for (blob_it.mark_cycle_pt (); !blob_it.cycled_list (); blob_it.forward ()) {
387 blob = blob_it.data ();
390 this_valid = blob_box.
width () >= min_width;
391 if (this_valid && prev_valid
392 && blob_box.
left () - prev_x < maxwidth) {
393 gap_stats.
add (blob_box.
left () - prev_x, 1);
396 prev_x = blob_box.
right ();
397 prev_valid = this_valid;
404 for (blob_it.mark_cycle_pt (); !blob_it.cycled_list ();
405 blob_it.forward ()) {
406 blob = blob_it.data ();
409 if (blob_box.
left () - prev_x < maxwidth) {
410 gap_stats.
add (blob_box.
left () - prev_x, 1);
412 prev_x = blob_box.
right ();
425 gap_stats.
smooth (smooth_factor);
427 prev_count = cluster_count;
428 cluster_count = gap_stats.
cluster (lower, upper,
433 if (cluster_count < 1) {
438 for (gap_index = 0; gap_index < cluster_count; gap_index++)
439 gaps[gap_index] = cluster_stats[gap_index + 1].ile (0.5);
442 tprintf (
"cluster_count=%d:", cluster_count);
443 for (gap_index = 0; gap_index < cluster_count; gap_index++)
444 tprintf (
" %g(%d)", gaps[gap_index],
445 cluster_stats[gap_index + 1].get_total ());
450 for (gap_index = 0; gap_index < cluster_count
452 if (gap_index < cluster_count)
453 lower = gaps[gap_index];
456 tprintf (
"No cluster below block threshold!, using default=%g\n",
460 for (gap_index = 0; gap_index < cluster_count
461 && gaps[gap_index] <= block->
max_nonspace; gap_index++);
462 if (gap_index < cluster_count)
463 upper = gaps[gap_index];
466 tprintf (
"No cluster above block threshold!, using default=%g\n",
486 tprintf (
"Row at %g has minspace=%d(%g), max_non=%d(%g)\n",
506 TO_ROW_IT row_it = block->
get_rows ();
507 ROW *real_row = NULL;
512 for (row_it.mark_cycle_pt (); !row_it.cycled_list (); row_it.forward ()) {
513 row = row_it.data ();
526 (pb != NULL && !pb->
IsText()) ||
537 if (real_row != NULL) {
539 real_row_it.add_after_then_move (real_row);
565 if (word_it.empty ())
567 word_box = word_it.data ()->bounding_box ();
568 for (word_it.mark_cycle_pt (); !word_it.cycled_list (); word_it.forward ())
569 word_box += word_it.data ()->bounding_box ();
571 real_row =
new ROW(row,
573 word_it.set_to_list (real_row->
word_list ());
575 word_it.add_list_after (&row->
rep_words);
593 C_OUTLINE_IT cout_it;
595 C_BLOB_IT cblob_it = &cblobs;
600 for (blobindex = 0; blobindex < blobcount; blobindex++) {
601 bblob = box_it->extract();
603 if (bblob->
cblob() != NULL) {
604 cout_it.set_to_list(cblob_it.data()->out_list());
605 cout_it.move_to_last();
607 delete bblob->
cblob();
611 if (bblob->
cblob() != NULL)
612 cblob_it.add_after_then_move(bblob->
cblob());
621 word =
new WERD(&cblobs, blanks, NULL);
625 if (box_it->at_first())
void add(inT32 value, inT32 count)
void make_single_word(bool one_blob, TO_ROW_LIST *rows, ROW_LIST *real_rows)
bool use_cjk_fp_model() const
ROW * make_blob_words(TO_ROW *row, FCOORD rotation)
PITCH_TYPE pitch_decision
EXTERN bool textord_chopper_test
BLOBNBOX_LIST * blob_list()
void plot_word_decisions(ScrollView *win, inT16 pitch, TO_ROW *row)
EXTERN double textord_words_minlarge
ROW_LIST * row_list()
get rows
EXTERN double textord_words_definite_spread
void recalc_bounding_box()
void set_row_spaces(TO_BLOCK *block, FCOORD rotation, BOOL8 testing_on)
bool textord_test_landscape
C_OUTLINE_LIST * out_list()
void set_stats(BOOL8 prop, inT16 kern, inT16 space, inT16 ch_pitch)
EXTERN ScrollView * to_win
EXTERN bool textord_show_initial_words
void smooth(inT32 factor)
void set_flag(WERD_FLAGS mask, BOOL8 value)
const TBOX & bounding_box() const
ROW * fixed_pitch_words(TO_ROW *row, FCOORD rotation)
inT32 cluster(float lower, float upper, float multiple, inT32 max_clusters, STATS *clusters)
WERD * make_real_word(BLOBNBOX_IT *box_it, inT32 blobcount, BOOL8 bol, uinT8 blanks)
void check_pitch()
check proportional
EXTERN double textord_words_initial_lower
EXTERN bool textord_fp_chopping
EXTERN double words_initial_upper
bool joined_to_prev() const
bool contains(const FCOORD pt) const
#define BOOL_VAR(name, val, comment)
EXTERN double textord_spacesize_ratioprop
EXTERN double textord_words_min_minspace
void compute_fixed_pitch_cjk(ICOORD page_tr, TO_BLOCK_LIST *port_blocks)
void compute_fixed_pitch(ICOORD page_tr, TO_BLOCK_LIST *port_blocks, float gradient, FCOORD rotation, BOOL8 testing_on)
ROW * make_rep_words(TO_ROW *row, TO_BLOCK *block)
inT32 row_words2(TO_BLOCK *block, TO_ROW *row, inT32 maxwidth, FCOORD rotation, BOOL8 testing_on)
void make_real_words(tesseract::Textord *textord, TO_BLOCK *block, FCOORD rotation)
POLY_BLOCK * poly_block() const
void make_words(tesseract::Textord *textord, ICOORD page_tr, float gradient, BLOCK_LIST *blocks, TO_BLOCK_LIST *port_blocks)
EXTERN double words_initial_lower
EXTERN bool textord_force_make_prop_words
void print_summary() const
inT32 row_words(TO_BLOCK *block, TO_ROW *row, inT32 maxwidth, FCOORD rotation, BOOL8 testing_on)
double ile(double frac) const
#define BLOCK_STATS_CLUSTERS
ROW * make_prop_words(TO_ROW *row, FCOORD rotation)
EXTERN double textord_wordstats_smooth_factor
EXTERN double textord_words_initial_upper
void to_spacing(ICOORD page_tr, TO_BLOCK_LIST *blocks)