72 for (
int blob_id = 0; blob_id < num_blobs; ++blob_id) {
79 int min_bottom, max_bottom, min_top, max_top;
89 tprintf(
"Class %s is %s with top %d vs limits of %d->%d, +/-%d\n",
91 bad ?
"Misfit" :
"OK", top, min_top, max_top,
102 float* baseline_shift) {
105 int bottom_shift = 0;
110 for (
int blob_id = 0; blob_id < num_blobs; ++blob_id) {
120 int min_bottom, max_bottom, min_top, max_top;
130 tprintf(
"Class %s: height=%d, bottom=%d,%d top=%d,%d, actual=%d,%d: ",
132 height, min_bottom, max_bottom, min_top, max_top,
149 tprintf(
" xht range min=%d, max=%d\n", min_xht, max_xht);
153 for (
int y = min_xht; y <= max_xht; ++y)
154 top_stats.
add(y, misfit_dist);
159 int min_shift = min_bottom - bottom;
160 int max_shift = max_bottom - bottom;
162 tprintf(
" bottom shift min=%d, max=%d\n", min_shift, max_shift);
167 int misfit_weight = abs(min_shift);
168 if (max_shift > min_shift)
169 misfit_weight /= max_shift - min_shift;
170 for (
int y = min_shift; y <= max_shift; ++y)
171 shift_stats.
add(y, misfit_weight);
173 if (bottom_shift == 0) {
187 tprintf(
"Applying bottom shift=%d\n", bottom_shift);
190 }
while (bottom_shift != 0 &&
193 *baseline_shift = -bottom_shift / word_res->
denorm.
y_scale();
195 tprintf(
"baseline shift=%g\n", *baseline_shift);
198 return bottom_shift != 0 ? word_res->
x_height : 0.0f;
201 float new_xht = top_stats.
median();
203 tprintf(
"Median xht=%f\n", new_xht);
204 tprintf(
"Mode20:A: New x-height = %f (norm), %f (orig)\n",
211 return bottom_shift != 0 ? word_res->
x_height : 0.0f;
const int kBlnBaselineOffset
bool get_isalpha(UNICHAR_ID unichar_id) const
int IntCastRounded(double x)
GenericVector< TBLOB * > blobs
int x_ht_acceptance_tolerance
UNICHAR_ID unichar_id(int index) const
void get_top_bottom(UNICHAR_ID unichar_id, int *min_bottom, int *max_bottom, int *min_top, int *max_top) const
void add(inT32 value, inT32 count)
WERD_CHOICE * best_choice
TBOX bounding_box() const
const int kMaxCharTopRange
int CountMisfitTops(WERD_RES *word_res)
int DivRounded(int a, int b)
bool get_isdigit(UNICHAR_ID unichar_id) const
float ComputeCompatibleXheight(WERD_RES *word_res, float *baseline_shift)
const char * id_to_unichar(UNICHAR_ID id) const