52 tprintf(
"AssociateUtils::ComputeStats() for col=%d, row=%d%s\n",
53 col, row, fixed_pitch ?
" (fixed pitch)" :
"");
58 if (fixed_pitch && blob_row != NULL) {
69 tprintf(
"normalizing height = %g (scale %g xheight %g ascenders %g)\n",
74 float wh_ratio = word_res->
GetBlobsWidth(col, row) / normalizing_height;
75 if (wh_ratio > max_char_wh_ratio) stats->bad_shape =
true;
80 int negative_gap_sum = 0;
81 for (
int c = col; c < row; ++c) {
83 (gap > 0) ? stats->gap_sum += gap : negative_gap_sum += gap;
85 if (stats->gap_sum == 0) stats->gap_sum = negative_gap_sum;
87 tprintf(
"wh_ratio=%g (max_char_wh_ratio=%g) gap_sum=%d %s\n",
88 wh_ratio, max_char_wh_ratio, stats->gap_sum,
89 stats->bad_shape ?
"bad_shape" :
"");
99 float left_gap = word_res->
GetBlobsGap(col - 1) / normalizing_height;
101 if ((!end_row && left_gap <
kMinGap) || left_seam->
priority() > 0.0f) {
102 stats->bad_shape =
true;
105 tprintf(
"left_gap %g, left_seam %g %s\n", left_gap,
106 left_seam->
priority(), stats->bad_shape ?
"bad_shape" :
"");
109 float right_gap = 0.0f;
111 right_gap = word_res->
GetBlobsGap(row) / normalizing_height;
113 if (right_gap < kMinGap || right_seam->priority() > 0.0f) {
114 stats->bad_shape =
true;
115 if (right_gap <
kMinGap) stats->bad_fixed_pitch_right_gap =
true;
118 tprintf(
"right_gap %g right_seam %g %s\n", right_gap,
119 right_seam->
priority(), stats->bad_shape ?
"bad_shape" :
"");
128 stats->full_wh_ratio = wh_ratio + right_gap;
129 if (parent_stats != NULL) {
130 stats->full_wh_ratio_total =
131 (parent_stats->full_wh_ratio_total + stats->full_wh_ratio);
133 stats->full_wh_ratio_total /
static_cast<float>(parent_path_length+1);
134 stats->full_wh_ratio_var =
135 parent_stats->full_wh_ratio_var + pow(mean-stats->full_wh_ratio, 2);
137 stats->full_wh_ratio_total = stats->full_wh_ratio;
140 tprintf(
"full_wh_ratio %g full_wh_ratio_total %g full_wh_ratio_var %g\n",
141 stats->full_wh_ratio, stats->full_wh_ratio_total,
142 stats->full_wh_ratio_var);
151 if (col == 0 && end_row && wh_ratio > max_char_wh_ratio) {
152 stats->shape_cost += 10;
154 stats->shape_cost += stats->full_wh_ratio_var;
155 if (debug)
tprintf(
"shape_cost %g\n", stats->shape_cost);
int GetBlobsWidth(int start_blob, int last_blob)
GenericVector< SEAM * > seam_array
static const float kMinGap
static float FixedPitchWidthCost(float norm_width, float right_gap, bool end_pos, float max_char_wh_ratio)
int GetBlobsGap(int blob_index)
GenericVector< int > blob_widths