tesseract  4.00.00dev
oldbasel.cpp
Go to the documentation of this file.
1 /**********************************************************************
2  * File: oldbasel.cpp (Formerly oldbl.c)
3  * Description: A re-implementation of the old baseline algorithm.
4  * Author: Ray Smith
5  * Created: Wed Oct 6 09:41:48 BST 1993
6  *
7  * (C) Copyright 1993, Hewlett-Packard Ltd.
8  ** Licensed under the Apache License, Version 2.0 (the "License");
9  ** you may not use this file except in compliance with the License.
10  ** You may obtain a copy of the License at
11  ** http://www.apache.org/licenses/LICENSE-2.0
12  ** Unless required by applicable law or agreed to in writing, software
13  ** distributed under the License is distributed on an "AS IS" BASIS,
14  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  ** See the License for the specific language governing permissions and
16  ** limitations under the License.
17  *
18  **********************************************************************/
19 
20 #include "ccstruct.h"
21 #include "statistc.h"
22 #include "quadlsq.h"
23 #include "detlinefit.h"
24 #include "makerow.h"
25 #include "drawtord.h"
26 #include "oldbasel.h"
27 #include "textord.h"
28 #include "tprintf.h"
29 
30 // Include automatically generated configuration file if running autoconf.
31 #ifdef HAVE_CONFIG_H
32 #include "config_auto.h"
33 #endif
34 
35 #define EXTERN
36 
38 "Use original wiseowl xheight");
39 EXTERN BOOL_VAR (textord_oldbl_debug, FALSE, "Debug old baseline generation");
40 EXTERN BOOL_VAR (textord_debug_baselines, FALSE, "Debug baseline generation");
41 EXTERN BOOL_VAR (textord_oldbl_paradef, TRUE, "Use para default mechanism");
42 EXTERN BOOL_VAR (textord_oldbl_split_splines, TRUE, "Split stepped splines");
43 EXTERN BOOL_VAR (textord_oldbl_merge_parts, TRUE, "Merge suspect partitions");
44 EXTERN BOOL_VAR (oldbl_corrfix, TRUE, "Improve correlation of heights");
46 "Fix bug in modes threshold for xheights");
47 EXTERN BOOL_VAR(textord_ocropus_mode, FALSE, "Make baselines for ocropus");
48 EXTERN double_VAR (oldbl_xhfract, 0.4, "Fraction of est allowed in calc");
50 "Max lost before fallback line used");
51 EXTERN double_VAR (oldbl_dot_error_size, 1.26, "Max aspect ratio of a dot");
53 "X fraction for new partition");
54 
55 #define TURNLIMIT 1 /*min size for turning point */
56 #define X_HEIGHT_FRACTION 0.7 /*x-height/caps height */
57 #define DESCENDER_FRACTION 0.5 /*descender/x-height */
58 #define MIN_ASC_FRACTION 0.20 /*min size of ascenders */
59 #define MIN_DESC_FRACTION 0.25 /*min size of descenders */
60 #define MINASCRISE 2.0 /*min ascender/desc step */
61 #define MAXHEIGHTVARIANCE 0.15 /*accepted variation in x-height */
62 #define MAXHEIGHT 300 /*max blob height */
63 #define MAXOVERLAP 0.1 /*max 10% missed overlap */
64 #define MAXBADRUN 2 /*max non best for failed */
65 #define HEIGHTBUCKETS 200 /* Num of buckets */
66 #define DELTAHEIGHT 5.0 /* Small amount of diff */
67 #define GOODHEIGHT 5
68 #define MAXLOOPS 10
69 #define MODENUM 10
70 #define MAXPARTS 6
71 #define SPLINESIZE 23
72 
73 #define ABS(x) ((x)<0 ? (-(x)) : (x))
74 
75 namespace tesseract {
76 
77 /**********************************************************************
78  * make_old_baselines
79  *
80  * Top level function to make baselines the old way.
81  **********************************************************************/
82 
83 void Textord::make_old_baselines(TO_BLOCK *block, // block to do
84  BOOL8 testing_on, // correct orientation
85  float gradient) {
86  QSPLINE *prev_baseline; // baseline of previous row
87  TO_ROW *row; // current row
88  TO_ROW_IT row_it = block->get_rows();
89  BLOBNBOX_IT blob_it;
90 
91  prev_baseline = NULL; // nothing yet
92  for (row_it.mark_cycle_pt(); !row_it.cycled_list(); row_it.forward()) {
93  row = row_it.data();
94  find_textlines(block, row, 2, NULL);
95  if (row->xheight <= 0 && prev_baseline != NULL)
96  find_textlines(block, row, 2, prev_baseline);
97  if (row->xheight > 0) { // was a good one
98  prev_baseline = &row->baseline;
99  } else {
100  prev_baseline = NULL;
101  blob_it.set_to_list(row->blob_list());
103  tprintf("Row baseline generation failed on row at (%d,%d)\n",
104  blob_it.data()->bounding_box().left(),
105  blob_it.data()->bounding_box().bottom());
106  }
107  }
108  correlate_lines(block, gradient);
109  block->block->set_xheight(block->xheight);
110 }
111 
112 
113 /**********************************************************************
114  * correlate_lines
115  *
116  * Correlate the x-heights and ascender heights of a block to fill-in
117  * the ascender height and descender height for rows without one.
118  * Also fix baselines of rows without a decent fit.
119  **********************************************************************/
120 
121 void Textord::correlate_lines(TO_BLOCK *block, float gradient) {
122  TO_ROW **rows; //array of ptrs
123  int rowcount; /*no of rows to do */
124  int rowindex; /*no of row */
125  // iterator
126  TO_ROW_IT row_it = block->get_rows ();
127 
128  rowcount = row_it.length ();
129  if (rowcount == 0) {
130  //default value
131  block->xheight = block->line_size;
132  return; /*none to do */
133  }
134  rows = (TO_ROW **) alloc_mem (rowcount * sizeof (TO_ROW *));
135  rowindex = 0;
136  for (row_it.mark_cycle_pt (); !row_it.cycled_list (); row_it.forward ())
137  //make array
138  rows[rowindex++] = row_it.data ();
139 
140  /*try to fix bad lines */
141  correlate_neighbours(block, rows, rowcount);
142 
144  block->xheight = (float) correlate_with_stats(rows, rowcount, block);
145  if (block->xheight <= 0)
147  if (block->xheight < textord_min_xheight)
148  block->xheight = (float) textord_min_xheight;
149  } else {
150  compute_block_xheight(block, gradient);
151  }
152 
153  free_mem(rows);
154 }
155 
156 
157 /**********************************************************************
158  * correlate_neighbours
159  *
160  * Try to fix rows that had a bad spline fit by using neighbours.
161  **********************************************************************/
162 
163 void Textord::correlate_neighbours(TO_BLOCK *block, // block rows are in.
164  TO_ROW **rows, // rows of block.
165  int rowcount) { // no of rows to do.
166  TO_ROW *row; /*current row */
167  int rowindex; /*no of row */
168  int otherrow; /*second row */
169  int upperrow; /*row above to use */
170  int lowerrow; /*row below to use */
171  float biggest;
172 
173  for (rowindex = 0; rowindex < rowcount; rowindex++) {
174  row = rows[rowindex]; /*current row */
175  if (row->xheight < 0) {
176  /*quadratic failed */
177  for (otherrow = rowindex - 2;
178  otherrow >= 0
179  && (rows[otherrow]->xheight < 0.0
180  || !row->baseline.overlap (&rows[otherrow]->baseline,
181  MAXOVERLAP)); otherrow--);
182  upperrow = otherrow; /*decent row above */
183  for (otherrow = rowindex + 1;
184  otherrow < rowcount
185  && (rows[otherrow]->xheight < 0.0
186  || !row->baseline.overlap (&rows[otherrow]->baseline,
187  MAXOVERLAP)); otherrow++);
188  lowerrow = otherrow; /*decent row below */
189  if (upperrow >= 0)
190  find_textlines(block, row, 2, &rows[upperrow]->baseline);
191  if (row->xheight < 0 && lowerrow < rowcount)
192  find_textlines(block, row, 2, &rows[lowerrow]->baseline);
193  if (row->xheight < 0) {
194  if (upperrow >= 0)
195  find_textlines(block, row, 1, &rows[upperrow]->baseline);
196  else if (lowerrow < rowcount)
197  find_textlines(block, row, 1, &rows[lowerrow]->baseline);
198  }
199  }
200  }
201 
202  for (biggest = 0.0f, rowindex = 0; rowindex < rowcount; rowindex++) {
203  row = rows[rowindex]; /*current row */
204  if (row->xheight < 0) /*linear failed */
205  /*make do */
206  row->xheight = -row->xheight;
207  biggest = MAX (biggest, row->xheight);
208  }
209 }
210 
211 
212 /**********************************************************************
213  * correlate_with_stats
214  *
215  * correlate the x-heights and ascender heights of a block to fill-in
216  * the ascender height and descender height for rows without one.
217  **********************************************************************/
218 
219 int Textord::correlate_with_stats(TO_ROW **rows, // rows of block.
220  int rowcount, // no of rows to do.
221  TO_BLOCK* block) {
222  TO_ROW *row; /*current row */
223  int rowindex; /*no of row */
224  float lineheight; /*mean x-height */
225  float ascheight; /*average ascenders */
226  float minascheight; /*min allowed ascheight */
227  int xcount; /*no of samples for xheight */
228  float fullheight; /*mean top height */
229  int fullcount; /*no of samples */
230  float descheight; /*mean descender drop */
231  float mindescheight; /*min allowed descheight */
232  int desccount; /*no of samples */
233 
234  /*no samples */
235  xcount = fullcount = desccount = 0;
236  lineheight = ascheight = fullheight = descheight = 0.0;
237  for (rowindex = 0; rowindex < rowcount; rowindex++) {
238  row = rows[rowindex]; /*current row */
239  if (row->ascrise > 0.0) { /*got ascenders? */
240  lineheight += row->xheight;/*average x-heights */
241  ascheight += row->ascrise; /*average ascenders */
242  xcount++;
243  }
244  else {
245  fullheight += row->xheight;/*assume full height */
246  fullcount++;
247  }
248  if (row->descdrop < 0.0) { /*got descenders? */
249  /*average descenders */
250  descheight += row->descdrop;
251  desccount++;
252  }
253  }
254 
255  if (xcount > 0 && (!oldbl_corrfix || xcount >= fullcount)) {
256  lineheight /= xcount; /*average x-height */
257  /*average caps height */
258  fullheight = lineheight + ascheight / xcount;
259  /*must be decent size */
260  if (fullheight < lineheight * (1 + MIN_ASC_FRACTION))
261  fullheight = lineheight * (1 + MIN_ASC_FRACTION);
262  }
263  else {
264  fullheight /= fullcount; /*average max height */
265  /*guess x-height */
266  lineheight = fullheight * X_HEIGHT_FRACTION;
267  }
268  if (desccount > 0 && (!oldbl_corrfix || desccount >= rowcount / 2))
269  descheight /= desccount; /*average descenders */
270  else
271  /*guess descenders */
272  descheight = -lineheight * DESCENDER_FRACTION;
273 
274  if (lineheight > 0.0f)
275  block->block->set_cell_over_xheight((fullheight - descheight) / lineheight);
276 
277  minascheight = lineheight * MIN_ASC_FRACTION;
278  mindescheight = -lineheight * MIN_DESC_FRACTION;
279  for (rowindex = 0; rowindex < rowcount; rowindex++) {
280  row = rows[rowindex]; /*do each row */
281  row->all_caps = FALSE;
282  if (row->ascrise / row->xheight < MIN_ASC_FRACTION) {
283  /*no ascenders */
284  if (row->xheight >= lineheight * (1 - MAXHEIGHTVARIANCE)
285  && row->xheight <= lineheight * (1 + MAXHEIGHTVARIANCE)) {
286  row->ascrise = fullheight - lineheight;
287  /*set to average */
288  row->xheight = lineheight;
289 
290  }
291  else if (row->xheight >= fullheight * (1 - MAXHEIGHTVARIANCE)
292  && row->xheight <= fullheight * (1 + MAXHEIGHTVARIANCE)) {
293  row->ascrise = row->xheight - lineheight;
294  /*set to average */
295  row->xheight = lineheight;
296  row->all_caps = TRUE;
297  }
298  else {
299  row->ascrise = (fullheight - lineheight) * row->xheight
300  / fullheight;
301  /*scale it */
302  row->xheight -= row->ascrise;
303  row->all_caps = TRUE;
304  }
305  if (row->ascrise < minascheight)
306  row->ascrise =
307  row->xheight * ((1.0 - X_HEIGHT_FRACTION) / X_HEIGHT_FRACTION);
308  }
309  if (row->descdrop > mindescheight) {
310  if (row->xheight >= lineheight * (1 - MAXHEIGHTVARIANCE)
311  && row->xheight <= lineheight * (1 + MAXHEIGHTVARIANCE))
312  /*set to average */
313  row->descdrop = descheight;
314  else
315  row->descdrop = -row->xheight * DESCENDER_FRACTION;
316  }
317  }
318  return (int) lineheight; //block xheight
319 }
320 
321 
322 /**********************************************************************
323  * find_textlines
324  *
325  * Compute the baseline for the given row.
326  **********************************************************************/
327 
328 void Textord::find_textlines(TO_BLOCK *block, // block row is in
329  TO_ROW *row, // row to do
330  int degree, // required approximation
331  QSPLINE *spline) { // starting spline
332  int partcount; /*no of partitions of */
333  BOOL8 holed_line = FALSE; //lost too many blobs
334  int bestpart; /*biggest partition */
335  char *partids; /*partition no of each blob */
336  int partsizes[MAXPARTS]; /*no in each partition */
337  int lineheight; /*guessed x-height */
338  float jumplimit; /*allowed delta change */
339  int *xcoords; /*useful sample points */
340  int *ycoords; /*useful sample points */
341  TBOX *blobcoords; /*edges of blob rectangles */
342  int blobcount; /*no of blobs on line */
343  float *ydiffs; /*diffs from 1st approx */
344  int pointcount; /*no of coords */
345  int xstarts[SPLINESIZE + 1]; //segment boundaries
346  int segments; //no of segments
347 
348  //no of blobs in row
349  blobcount = row->blob_list ()->length ();
350  partids = (char *) alloc_mem (blobcount * sizeof (char));
351  xcoords = (int *) alloc_mem (blobcount * sizeof (int));
352  ycoords = (int *) alloc_mem (blobcount * sizeof (int));
353  blobcoords = (TBOX *) alloc_mem (blobcount * sizeof (TBOX));
354  ydiffs = (float *) alloc_mem (blobcount * sizeof (float));
355 
356  lineheight = get_blob_coords (row, (int) block->line_size, blobcoords,
357  holed_line, blobcount);
358  /*limit for line change */
359  jumplimit = lineheight * textord_oldbl_jumplimit;
360  if (jumplimit < MINASCRISE)
361  jumplimit = MINASCRISE;
362 
363  if (textord_oldbl_debug) {
364  tprintf
365  ("\nInput height=%g, Estimate x-height=%d pixels, jumplimit=%.2f\n",
366  block->line_size, lineheight, jumplimit);
367  }
368  if (holed_line)
369  make_holed_baseline (blobcoords, blobcount, spline, &row->baseline,
370  row->line_m ());
371  else
372  make_first_baseline (blobcoords, blobcount,
373  xcoords, ycoords, spline, &row->baseline, jumplimit);
374 #ifndef GRAPHICS_DISABLED
377 #endif
378  if (blobcount > 1) {
379  bestpart = partition_line (blobcoords, blobcount,
380  &partcount, partids, partsizes,
381  &row->baseline, jumplimit, ydiffs);
382  pointcount = partition_coords (blobcoords, blobcount,
383  partids, bestpart, xcoords, ycoords);
384  segments = segment_spline (blobcoords, blobcount,
385  xcoords, ycoords,
386  degree, pointcount, xstarts);
387  if (!holed_line) {
388  do {
389  row->baseline = QSPLINE (xstarts, segments,
390  xcoords, ycoords, pointcount, degree);
391  }
393  && split_stepped_spline (&row->baseline, jumplimit / 2,
394  xcoords, xstarts, segments));
395  }
396  find_lesser_parts(row,
397  blobcoords,
398  blobcount,
399  partids,
400  partsizes,
401  partcount,
402  bestpart);
403 
404  }
405  else {
406  row->xheight = -1.0f; /*failed */
407  row->descdrop = 0.0f;
408  row->ascrise = 0.0f;
409  }
410  row->baseline.extrapolate (row->line_m (),
411  block->block->bounding_box ().left (),
412  block->block->bounding_box ().right ());
413 
415  old_first_xheight (row, blobcoords, lineheight,
416  blobcount, &row->baseline, jumplimit);
417  } else if (textord_old_xheight) {
418  make_first_xheight (row, blobcoords, lineheight, (int) block->line_size,
419  blobcount, &row->baseline, jumplimit);
420  } else {
422  row->line_m(), block->line_size);
423  }
424  free_mem(partids);
425  free_mem(xcoords);
426  free_mem(ycoords);
427  free_mem(blobcoords);
428  free_mem(ydiffs);
429 }
430 
431 } // namespace tesseract.
432 
433 
434 /**********************************************************************
435  * get_blob_coords
436  *
437  * Fill the blobcoords array with the coordinates of the blobs
438  * in the row. The return value is the first guess at the line height.
439  **********************************************************************/
440 
441 int get_blob_coords( //get boxes
442  TO_ROW *row, //row to use
443  inT32 lineheight, //block level
444  TBOX *blobcoords, //ouput boxes
445  BOOL8 &holed_line, //lost a lot of blobs
446  int &outcount //no of real blobs
447  ) {
448  //blobs
449  BLOBNBOX_IT blob_it = row->blob_list ();
450  int blobindex; /*no along text line */
451  int losscount; //lost blobs
452  int maxlosscount; //greatest lost blobs
453  /*height stat collection */
454  STATS heightstat (0, MAXHEIGHT);
455 
456  if (blob_it.empty ())
457  return 0; //none
458  maxlosscount = 0;
459  losscount = 0;
460  blob_it.mark_cycle_pt ();
461  blobindex = 0;
462  do {
463  blobcoords[blobindex] = box_next_pre_chopped (&blob_it);
464  if (blobcoords[blobindex].height () > lineheight * 0.25)
465  heightstat.add (blobcoords[blobindex].height (), 1);
466  if (blobindex == 0
467  || blobcoords[blobindex].height () > lineheight * 0.25
468  || blob_it.cycled_list ()) {
469  blobindex++; /*no of merged blobs */
470  losscount = 0;
471  }
472  else {
473  if (blobcoords[blobindex].height ()
474  < blobcoords[blobindex].width () * oldbl_dot_error_size
475  && blobcoords[blobindex].width ()
476  < blobcoords[blobindex].height () * oldbl_dot_error_size) {
477  //counts as dot
478  blobindex++;
479  losscount = 0;
480  }
481  else {
482  losscount++; //lost it
483  if (losscount > maxlosscount)
484  //remember max
485  maxlosscount = losscount;
486  }
487  }
488  }
489  while (!blob_it.cycled_list ());
490 
491  holed_line = maxlosscount > oldbl_holed_losscount;
492  outcount = blobindex; /*total blobs */
493 
494  if (heightstat.get_total () > 1)
495  /*guess x-height */
496  return (int) heightstat.ile (0.25);
497  else
498  return blobcoords[0].height ();
499 }
500 
501 
502 /**********************************************************************
503  * make_first_baseline
504  *
505  * Make the first estimate at a baseline, either by shifting
506  * a supplied previous spline, or by doing a piecewise linear
507  * approximation using all the blobs.
508  **********************************************************************/
509 
510 void
511 make_first_baseline ( //initial approximation
512 TBOX blobcoords[], /*blob bounding boxes */
513 int blobcount, /*no of blobcoords */
514 int xcoords[], /*coords for spline */
515 int ycoords[], /*approximator */
516 QSPLINE * spline, /*initial spline */
517 QSPLINE * baseline, /*output spline */
518 float jumplimit /*guess half descenders */
519 ) {
520  int leftedge; /*left edge of line */
521  int rightedge; /*right edge of line */
522  int blobindex; /*current blob */
523  int segment; /*current segment */
524  float prevy, thisy, nexty; /*3 y coords */
525  float y1, y2, y3; /*3 smooth blobs */
526  float maxmax, minmin; /*absolute limits */
527  int x2 = 0; /*right edge of old y3 */
528  int ycount; /*no of ycoords in use */
529  float yturns[SPLINESIZE]; /*y coords of turn pts */
530  int xturns[SPLINESIZE]; /*xcoords of turn pts */
531  int xstarts[SPLINESIZE + 1];
532  int segments; //no of segments
533  ICOORD shift; //shift of spline
534 
535  prevy = 0;
536  /*left edge of row */
537  leftedge = blobcoords[0].left ();
538  /*right edge of line */
539  rightedge = blobcoords[blobcount - 1].right ();
540  if (spline == NULL /*no given spline */
541  || spline->segments < 3 /*or trivial */
542  /*or too non-overlap */
543  || spline->xcoords[1] > leftedge + MAXOVERLAP * (rightedge - leftedge)
544  || spline->xcoords[spline->segments - 1] < rightedge
545  - MAXOVERLAP * (rightedge - leftedge)) {
547  return; //use default
548  xstarts[0] = blobcoords[0].left () - 1;
549  for (blobindex = 0; blobindex < blobcount; blobindex++) {
550  xcoords[blobindex] = (blobcoords[blobindex].left ()
551  + blobcoords[blobindex].right ()) / 2;
552  ycoords[blobindex] = blobcoords[blobindex].bottom ();
553  }
554  xstarts[1] = blobcoords[blobcount - 1].right () + 1;
555  segments = 1; /*no of segments */
556 
557  /*linear */
558  *baseline = QSPLINE (xstarts, segments, xcoords, ycoords, blobcount, 1);
559 
560  if (blobcount >= 3) {
561  y1 = y2 = y3 = 0.0f;
562  ycount = 0;
563  segment = 0; /*no of segments */
564  maxmax = minmin = 0.0f;
565  thisy = ycoords[0] - baseline->y (xcoords[0]);
566  nexty = ycoords[1] - baseline->y (xcoords[1]);
567  for (blobindex = 2; blobindex < blobcount; blobindex++) {
568  prevy = thisy; /*shift ycoords */
569  thisy = nexty;
570  nexty = ycoords[blobindex] - baseline->y (xcoords[blobindex]);
571  /*middle of smooth y */
572  if (ABS (thisy - prevy) < jumplimit && ABS (thisy - nexty) < jumplimit) {
573  y1 = y2; /*shift window */
574  y2 = y3;
575  y3 = thisy; /*middle point */
576  ycount++;
577  /*local max */
578  if (ycount >= 3 && ((y1 < y2 && y2 >= y3)
579  /*local min */
580  || (y1 > y2 && y2 <= y3))) {
581  if (segment < SPLINESIZE - 2) {
582  /*turning pt */
583  xturns[segment] = x2;
584  yturns[segment] = y2;
585  segment++; /*no of spline segs */
586  }
587  }
588  if (ycount == 1) {
589  maxmax = minmin = y3;/*initialise limits */
590  }
591  else {
592  if (y3 > maxmax)
593  maxmax = y3; /*biggest max */
594  if (y3 < minmin)
595  minmin = y3; /*smallest min */
596  }
597  /*possible turning pt */
598  x2 = blobcoords[blobindex - 1].right ();
599  }
600  }
601 
602  jumplimit *= 1.2;
603  /*must be wavy */
604  if (maxmax - minmin > jumplimit) {
605  ycount = segment; /*no of segments */
606  for (blobindex = 0, segment = 1; blobindex < ycount;
607  blobindex++) {
608  if (yturns[blobindex] > minmin + jumplimit
609  || yturns[blobindex] < maxmax - jumplimit) {
610  /*significant peak */
611  if (segment == 1
612  || yturns[blobindex] > prevy + jumplimit
613  || yturns[blobindex] < prevy - jumplimit) {
614  /*different to previous */
615  xstarts[segment] = xturns[blobindex];
616  segment++;
617  prevy = yturns[blobindex];
618  }
619  /*bigger max */
620  else if ((prevy > minmin + jumplimit && yturns[blobindex] > prevy)
621  /*smaller min */
622  || (prevy < maxmax - jumplimit && yturns[blobindex] < prevy)) {
623  xstarts[segment - 1] = xturns[blobindex];
624  /*improved previous */
625  prevy = yturns[blobindex];
626  }
627  }
628  }
629  xstarts[segment] = blobcoords[blobcount - 1].right () + 1;
630  segments = segment; /*no of segments */
631  /*linear */
632  *baseline = QSPLINE (xstarts, segments, xcoords, ycoords, blobcount, 1);
633  }
634  }
635  }
636  else {
637  *baseline = *spline; /*copy it */
638  shift = ICOORD (0, (inT16) (blobcoords[0].bottom ()
639  - spline->y (blobcoords[0].right ())));
640  baseline->move (shift);
641  }
642 }
643 
644 
645 /**********************************************************************
646  * make_holed_baseline
647  *
648  * Make the first estimate at a baseline, either by shifting
649  * a supplied previous spline, or by doing a piecewise linear
650  * approximation using all the blobs.
651  **********************************************************************/
652 
653 void
654 make_holed_baseline ( //initial approximation
655 TBOX blobcoords[], /*blob bounding boxes */
656 int blobcount, /*no of blobcoords */
657 QSPLINE * spline, /*initial spline */
658 QSPLINE * baseline, /*output spline */
659 float gradient //of line
660 ) {
661  int leftedge; /*left edge of line */
662  int rightedge; /*right edge of line */
663  int blobindex; /*current blob */
664  float x; //centre of row
665  ICOORD shift; //shift of spline
666 
667  tesseract::DetLineFit lms; // straight baseline
668  inT32 xstarts[2]; //straight line
669  double coeffs[3];
670  float c; //line parameter
671 
672  /*left edge of row */
673  leftedge = blobcoords[0].left ();
674  /*right edge of line */
675  rightedge = blobcoords[blobcount - 1].right();
676  for (blobindex = 0; blobindex < blobcount; blobindex++) {
677  lms.Add(ICOORD((blobcoords[blobindex].left() +
678  blobcoords[blobindex].right()) / 2,
679  blobcoords[blobindex].bottom()));
680  }
681  lms.ConstrainedFit(gradient, &c);
682  xstarts[0] = leftedge;
683  xstarts[1] = rightedge;
684  coeffs[0] = 0;
685  coeffs[1] = gradient;
686  coeffs[2] = c;
687  *baseline = QSPLINE (1, xstarts, coeffs);
688  if (spline != NULL /*no given spline */
689  && spline->segments >= 3 /*or trivial */
690  /*or too non-overlap */
691  && spline->xcoords[1] <= leftedge + MAXOVERLAP * (rightedge - leftedge)
692  && spline->xcoords[spline->segments - 1] >= rightedge
693  - MAXOVERLAP * (rightedge - leftedge)) {
694  *baseline = *spline; /*copy it */
695  x = (leftedge + rightedge) / 2.0;
696  shift = ICOORD (0, (inT16) (gradient * x + c - spline->y (x)));
697  baseline->move (shift);
698  }
699 }
700 
701 
702 /**********************************************************************
703  * partition_line
704  *
705  * Partition a row of blobs into different groups of continuous
706  * y position. jumplimit specifies the max allowable limit on a jump
707  * before a new partition is started.
708  * The return value is the biggest partition
709  **********************************************************************/
710 
711 int
712 partition_line ( //partition blobs
713 TBOX blobcoords[], //bounding boxes
714 int blobcount, /*no of blobs on row */
715 int *numparts, /*number of partitions */
716 char partids[], /*partition no of each blob */
717 int partsizes[], /*no in each partition */
718 QSPLINE * spline, /*curve to fit to */
719 float jumplimit, /*allowed delta change */
720 float ydiffs[] /*diff from spline */
721 ) {
722  int blobindex; /*no along text line */
723  int bestpart; /*best new partition */
724  int biggestpart; /*part with most members */
725  float diff; /*difference from line */
726  int startx; /*index of start blob */
727  float partdiffs[MAXPARTS]; /*step between parts */
728 
729  for (bestpart = 0; bestpart < MAXPARTS; bestpart++)
730  partsizes[bestpart] = 0; /*zero them all */
731 
732  startx = get_ydiffs (blobcoords, blobcount, spline, ydiffs);
733  *numparts = 1; /*1 partition */
734  bestpart = -1; /*first point */
735  float drift = 0.0f;
736  float last_delta = 0.0f;
737  for (blobindex = startx; blobindex < blobcount; blobindex++) {
738  /*do each blob in row */
739  diff = ydiffs[blobindex]; /*diff from line */
740  if (textord_oldbl_debug) {
741  tprintf ("%d(%d,%d), ", blobindex,
742  blobcoords[blobindex].left (),
743  blobcoords[blobindex].bottom ());
744  }
745  bestpart = choose_partition(diff, partdiffs, bestpart, jumplimit,
746  &drift, &last_delta, numparts);
747  /*record partition */
748  partids[blobindex] = bestpart;
749  partsizes[bestpart]++; /*another in it */
750  }
751 
752  bestpart = -1; /*first point */
753  drift = 0.0f;
754  last_delta = 0.0f;
755  partsizes[0]--; /*doing 1st pt again */
756  /*do each blob in row */
757  for (blobindex = startx; blobindex >= 0; blobindex--) {
758  diff = ydiffs[blobindex]; /*diff from line */
759  if (textord_oldbl_debug) {
760  tprintf ("%d(%d,%d), ", blobindex,
761  blobcoords[blobindex].left (),
762  blobcoords[blobindex].bottom ());
763  }
764  bestpart = choose_partition(diff, partdiffs, bestpart, jumplimit,
765  &drift, &last_delta, numparts);
766  /*record partition */
767  partids[blobindex] = bestpart;
768  partsizes[bestpart]++; /*another in it */
769  }
770 
771  for (biggestpart = 0, bestpart = 1; bestpart < *numparts; bestpart++)
772  if (partsizes[bestpart] >= partsizes[biggestpart])
773  biggestpart = bestpart; /*new biggest */
775  merge_oldbl_parts(blobcoords,
776  blobcount,
777  partids,
778  partsizes,
779  biggestpart,
780  jumplimit);
781  return biggestpart; /*biggest partition */
782 }
783 
784 
785 /**********************************************************************
786  * merge_oldbl_parts
787  *
788  * For any adjacent group of blobs in a different part, put them in the
789  * main part if they fit closely to neighbours in the main part.
790  **********************************************************************/
791 
792 void
793 merge_oldbl_parts ( //partition blobs
794 TBOX blobcoords[], //bounding boxes
795 int blobcount, /*no of blobs on row */
796 char partids[], /*partition no of each blob */
797 int partsizes[], /*no in each partition */
798 int biggestpart, //major partition
799 float jumplimit /*allowed delta change */
800 ) {
801  BOOL8 found_one; //found a bestpart blob
802  BOOL8 close_one; //found was close enough
803  int blobindex; /*no along text line */
804  int prevpart; //previous iteration
805  int runlength; //no in this part
806  float diff; /*difference from line */
807  int startx; /*index of start blob */
808  int test_blob; //another index
809  FCOORD coord; //blob coordinate
810  float m, c; //fitted line
811  QLSQ stats; //line stuff
812 
813  prevpart = biggestpart;
814  runlength = 0;
815  startx = 0;
816  for (blobindex = 0; blobindex < blobcount; blobindex++) {
817  if (partids[blobindex] != prevpart) {
818  // tprintf("Partition change at (%d,%d) from %d to %d after run of %d\n",
819  // blobcoords[blobindex].left(),blobcoords[blobindex].bottom(),
820  // prevpart,partids[blobindex],runlength);
821  if (prevpart != biggestpart && runlength > MAXBADRUN) {
822  stats.clear ();
823  for (test_blob = startx; test_blob < blobindex; test_blob++) {
824  coord = FCOORD ((blobcoords[test_blob].left ()
825  + blobcoords[test_blob].right ()) / 2.0,
826  blobcoords[test_blob].bottom ());
827  stats.add (coord.x (), coord.y ());
828  }
829  stats.fit (1);
830  m = stats.get_b ();
831  c = stats.get_c ();
833  tprintf ("Fitted line y=%g x + %g\n", m, c);
834  found_one = FALSE;
835  close_one = FALSE;
836  for (test_blob = 1; !found_one
837  && (startx - test_blob >= 0
838  || blobindex + test_blob <= blobcount); test_blob++) {
839  if (startx - test_blob >= 0
840  && partids[startx - test_blob] == biggestpart) {
841  found_one = TRUE;
842  coord = FCOORD ((blobcoords[startx - test_blob].left ()
843  + blobcoords[startx -
844  test_blob].right ()) /
845  2.0,
846  blobcoords[startx -
847  test_blob].bottom ());
848  diff = m * coord.x () + c - coord.y ();
850  tprintf
851  ("Diff of common blob to suspect part=%g at (%g,%g)\n",
852  diff, coord.x (), coord.y ());
853  if (diff < jumplimit && -diff < jumplimit)
854  close_one = TRUE;
855  }
856  if (blobindex + test_blob <= blobcount
857  && partids[blobindex + test_blob - 1] == biggestpart) {
858  found_one = TRUE;
859  coord =
860  FCOORD ((blobcoords[blobindex + test_blob - 1].
861  left () + blobcoords[blobindex + test_blob -
862  1].right ()) / 2.0,
863  blobcoords[blobindex + test_blob -
864  1].bottom ());
865  diff = m * coord.x () + c - coord.y ();
867  tprintf
868  ("Diff of common blob to suspect part=%g at (%g,%g)\n",
869  diff, coord.x (), coord.y ());
870  if (diff < jumplimit && -diff < jumplimit)
871  close_one = TRUE;
872  }
873  }
874  if (close_one) {
876  tprintf
877  ("Merged %d blobs back into part %d from %d starting at (%d,%d)\n",
878  runlength, biggestpart, prevpart,
879  blobcoords[startx].left (),
880  blobcoords[startx].bottom ());
881  //switch sides
882  partsizes[prevpart] -= runlength;
883  for (test_blob = startx; test_blob < blobindex; test_blob++)
884  partids[test_blob] = biggestpart;
885  }
886  }
887  prevpart = partids[blobindex];
888  runlength = 1;
889  startx = blobindex;
890  }
891  else
892  runlength++;
893  }
894 }
895 
896 
897 /**********************************************************************
898  * get_ydiffs
899  *
900  * Get the differences between the blobs and the spline,
901  * putting them in ydiffs. The return value is the index
902  * of the blob in the middle of the "best behaved" region
903  **********************************************************************/
904 
905 int
906 get_ydiffs ( //evaluate differences
907 TBOX blobcoords[], //bounding boxes
908 int blobcount, /*no of blobs */
909 QSPLINE * spline, /*approximating spline */
910 float ydiffs[] /*output */
911 ) {
912  int blobindex; /*current blob */
913  int xcentre; /*xcoord */
914  int lastx; /*last xcentre */
915  float diffsum; /*sum of diffs */
916  float diff; /*current difference */
917  float drift; /*sum of spline steps */
918  float bestsum; /*smallest diffsum */
919  int bestindex; /*index of bestsum */
920 
921  diffsum = 0.0f;
922  bestindex = 0;
923  bestsum = (float) MAX_INT32;
924  drift = 0.0f;
925  lastx = blobcoords[0].left ();
926  /*do each blob in row */
927  for (blobindex = 0; blobindex < blobcount; blobindex++) {
928  /*centre of blob */
929  xcentre = (blobcoords[blobindex].left () + blobcoords[blobindex].right ()) >> 1;
930  //step functions in spline
931  drift += spline->step (lastx, xcentre);
932  lastx = xcentre;
933  diff = blobcoords[blobindex].bottom ();
934  diff -= spline->y (xcentre);
935  diff += drift;
936  ydiffs[blobindex] = diff; /*store difference */
937  if (blobindex > 2)
938  /*remove old one */
939  diffsum -= ABS (ydiffs[blobindex - 3]);
940  diffsum += ABS (diff); /*add new one */
941  if (blobindex >= 2 && diffsum < bestsum) {
942  bestsum = diffsum; /*find min sum */
943  bestindex = blobindex - 1; /*middle of set */
944  }
945  }
946  return bestindex;
947 }
948 
949 
950 /**********************************************************************
951  * choose_partition
952  *
953  * Choose a partition for the point and return the index.
954  **********************************************************************/
955 
956 int
957 choose_partition ( //select partition
958 register float diff, /*diff from spline */
959 float partdiffs[], /*diff on all parts */
960 int lastpart, /*last assigned partition */
961 float jumplimit, /*new part threshold */
962 float* drift,
963 float* lastdelta,
964 int *partcount /*no of partitions */
965 ) {
966  int partition; /*partition no */
967  int bestpart; /*best new partition */
968  float bestdelta; /*best gap from a part */
969  float delta; /*diff from part */
970 
971  if (lastpart < 0) {
972  partdiffs[0] = diff;
973  lastpart = 0; /*first point */
974  *drift = 0.0f;
975  *lastdelta = 0.0f;
976  }
977  /*adjusted diff from part */
978  delta = diff - partdiffs[lastpart] - *drift;
979  if (textord_oldbl_debug) {
980  tprintf ("Diff=%.2f, Delta=%.3f, Drift=%.3f, ", diff, delta, *drift);
981  }
982  if (ABS (delta) > jumplimit / 2) {
983  /*delta on part 0 */
984  bestdelta = diff - partdiffs[0] - *drift;
985  bestpart = 0; /*0 best so far */
986  for (partition = 1; partition < *partcount; partition++) {
987  delta = diff - partdiffs[partition] - *drift;
988  if (ABS (delta) < ABS (bestdelta)) {
989  bestdelta = delta;
990  bestpart = partition; /*part with nearest jump */
991  }
992  }
993  delta = bestdelta;
994  /*too far away */
995  if (ABS (bestdelta) > jumplimit
996  && *partcount < MAXPARTS) { /*and spare part left */
997  bestpart = (*partcount)++; /*best was new one */
998  /*start new one */
999  partdiffs[bestpart] = diff - *drift;
1000  delta = 0.0f;
1001  }
1002  }
1003  else {
1004  bestpart = lastpart; /*best was last one */
1005  }
1006 
1007  if (bestpart == lastpart
1008  && (ABS (delta - *lastdelta) < jumplimit / 2
1009  || ABS (delta) < jumplimit / 2))
1010  /*smooth the drift */
1011  *drift = (3 * *drift + delta) / 3;
1012  *lastdelta = delta;
1013 
1014  if (textord_oldbl_debug) {
1015  tprintf ("P=%d\n", bestpart);
1016  }
1017 
1018  return bestpart;
1019 }
1020 
1021 /**********************************************************************
1022  * partition_coords
1023  *
1024  * Get the x,y coordinates of all points in the bestpart and put them
1025  * in xcoords,ycoords. Return the number of points found.
1026  **********************************************************************/
1027 
1028 int
1029 partition_coords ( //find relevant coords
1030 TBOX blobcoords[], //bounding boxes
1031 int blobcount, /*no of blobs in row */
1032 char partids[], /*partition no of each blob */
1033 int bestpart, /*best new partition */
1034 int xcoords[], /*points to work on */
1035 int ycoords[] /*points to work on */
1036 ) {
1037  int blobindex; /*no along text line */
1038  int pointcount; /*no of points */
1039 
1040  pointcount = 0;
1041  for (blobindex = 0; blobindex < blobcount; blobindex++) {
1042  if (partids[blobindex] == bestpart) {
1043  /*centre of blob */
1044  xcoords[pointcount] = (blobcoords[blobindex].left () + blobcoords[blobindex].right ()) >> 1;
1045  ycoords[pointcount++] = blobcoords[blobindex].bottom ();
1046  }
1047  }
1048  return pointcount; /*no of points found */
1049 }
1050 
1051 
1052 /**********************************************************************
1053  * segment_spline
1054  *
1055  * Segment the row at midpoints between maxima and minima of the x,y pairs.
1056  * The xstarts of the segments are returned and the number found.
1057  **********************************************************************/
1058 
1059 int
1060 segment_spline ( //make xstarts
1061 TBOX blobcoords[], //boundign boxes
1062 int blobcount, /*no of blobs in row */
1063 int xcoords[], /*points to work on */
1064 int ycoords[], /*points to work on */
1065 int degree, int pointcount, /*no of points */
1066 int xstarts[] //result
1067 ) {
1068  int ptindex; /*no along text line */
1069  int segment; /*partition no */
1070  int lastmin, lastmax; /*possible turn points */
1071  int turnpoints[SPLINESIZE]; /*good turning points */
1072  int turncount; /*no of turning points */
1073  int max_x; //max specified coord
1074 
1075  xstarts[0] = xcoords[0] - 1; //leftmost defined pt
1076  max_x = xcoords[pointcount - 1] + 1;
1077  if (degree < 2)
1078  pointcount = 0;
1079  turncount = 0; /*no turning points yet */
1080  if (pointcount > 3) {
1081  ptindex = 1;
1082  lastmax = lastmin = 0; /*start with first one */
1083  while (ptindex < pointcount - 1 && turncount < SPLINESIZE - 1) {
1084  /*minimum */
1085  if (ycoords[ptindex - 1] > ycoords[ptindex] && ycoords[ptindex] <= ycoords[ptindex + 1]) {
1086  if (ycoords[ptindex] < ycoords[lastmax] - TURNLIMIT) {
1087  if (turncount == 0 || turnpoints[turncount - 1] != lastmax)
1088  /*new max point */
1089  turnpoints[turncount++] = lastmax;
1090  lastmin = ptindex; /*latest minimum */
1091  }
1092  else if (ycoords[ptindex] < ycoords[lastmin]) {
1093  lastmin = ptindex; /*lower minimum */
1094  }
1095  }
1096 
1097  /*maximum */
1098  if (ycoords[ptindex - 1] < ycoords[ptindex] && ycoords[ptindex] >= ycoords[ptindex + 1]) {
1099  if (ycoords[ptindex] > ycoords[lastmin] + TURNLIMIT) {
1100  if (turncount == 0 || turnpoints[turncount - 1] != lastmin)
1101  /*new min point */
1102  turnpoints[turncount++] = lastmin;
1103  lastmax = ptindex; /*latest maximum */
1104  }
1105  else if (ycoords[ptindex] > ycoords[lastmax]) {
1106  lastmax = ptindex; /*higher maximum */
1107  }
1108  }
1109  ptindex++;
1110  }
1111  /*possible global min */
1112  if (ycoords[ptindex] < ycoords[lastmax] - TURNLIMIT
1113  && (turncount == 0 || turnpoints[turncount - 1] != lastmax)) {
1114  if (turncount < SPLINESIZE - 1)
1115  /*2 more turns */
1116  turnpoints[turncount++] = lastmax;
1117  if (turncount < SPLINESIZE - 1)
1118  turnpoints[turncount++] = ptindex;
1119  }
1120  else if (ycoords[ptindex] > ycoords[lastmin] + TURNLIMIT
1121  /*possible global max */
1122  && (turncount == 0 || turnpoints[turncount - 1] != lastmin)) {
1123  if (turncount < SPLINESIZE - 1)
1124  /*2 more turns */
1125  turnpoints[turncount++] = lastmin;
1126  if (turncount < SPLINESIZE - 1)
1127  turnpoints[turncount++] = ptindex;
1128  }
1129  else if (turncount > 0 && turnpoints[turncount - 1] == lastmin
1130  && turncount < SPLINESIZE - 1) {
1131  if (ycoords[ptindex] > ycoords[lastmax])
1132  turnpoints[turncount++] = ptindex;
1133  else
1134  turnpoints[turncount++] = lastmax;
1135  }
1136  else if (turncount > 0 && turnpoints[turncount - 1] == lastmax
1137  && turncount < SPLINESIZE - 1) {
1138  if (ycoords[ptindex] < ycoords[lastmin])
1139  turnpoints[turncount++] = ptindex;
1140  else
1141  turnpoints[turncount++] = lastmin;
1142  }
1143  }
1144 
1145  if (textord_oldbl_debug && turncount > 0)
1146  tprintf ("First turn is %d at (%d,%d)\n",
1147  turnpoints[0], xcoords[turnpoints[0]], ycoords[turnpoints[0]]);
1148  for (segment = 1; segment < turncount; segment++) {
1149  /*centre y coord */
1150  lastmax = (ycoords[turnpoints[segment - 1]] + ycoords[turnpoints[segment]]) / 2;
1151 
1152  /* fix alg so that it works with both rising and falling sections */
1153  if (ycoords[turnpoints[segment - 1]] < ycoords[turnpoints[segment]])
1154  /*find rising y centre */
1155  for (ptindex = turnpoints[segment - 1] + 1; ptindex < turnpoints[segment] && ycoords[ptindex + 1] <= lastmax; ptindex++);
1156  else
1157  /*find falling y centre */
1158  for (ptindex = turnpoints[segment - 1] + 1; ptindex < turnpoints[segment] && ycoords[ptindex + 1] >= lastmax; ptindex++);
1159 
1160  /*centre x */
1161  xstarts[segment] = (xcoords[ptindex - 1] + xcoords[ptindex]
1162  + xcoords[turnpoints[segment - 1]]
1163  + xcoords[turnpoints[segment]] + 2) / 4;
1164  /*halfway between turns */
1165  if (textord_oldbl_debug)
1166  tprintf ("Turn %d is %d at (%d,%d), mid pt is %d@%d, final @%d\n",
1167  segment, turnpoints[segment],
1168  xcoords[turnpoints[segment]], ycoords[turnpoints[segment]],
1169  ptindex - 1, xcoords[ptindex - 1], xstarts[segment]);
1170  }
1171 
1172  xstarts[segment] = max_x;
1173  return segment; /*no of splines */
1174 }
1175 
1176 
1177 /**********************************************************************
1178  * split_stepped_spline
1179  *
1180  * Re-segment the spline in cases where there is a big step function.
1181  * Return TRUE if any were done.
1182  **********************************************************************/
1183 
1184 BOOL8
1185 split_stepped_spline ( //make xstarts
1186 QSPLINE * baseline, //current shot
1187 float jumplimit, //max step fuction
1188 int xcoords[], /*points to work on */
1189 int xstarts[], //result
1190 int &segments //no of segments
1191 ) {
1192  BOOL8 doneany; //return value
1193  int segment; /*partition no */
1194  int startindex, centreindex, endindex;
1195  float leftcoord, rightcoord;
1196  int leftindex, rightindex;
1197  float step; //spline step
1198 
1199  doneany = FALSE;
1200  startindex = 0;
1201  for (segment = 1; segment < segments - 1; segment++) {
1202  step = baseline->step ((xstarts[segment - 1] + xstarts[segment]) / 2.0,
1203  (xstarts[segment] + xstarts[segment + 1]) / 2.0);
1204  if (step < 0)
1205  step = -step;
1206  if (step > jumplimit) {
1207  while (xcoords[startindex] < xstarts[segment - 1])
1208  startindex++;
1209  centreindex = startindex;
1210  while (xcoords[centreindex] < xstarts[segment])
1211  centreindex++;
1212  endindex = centreindex;
1213  while (xcoords[endindex] < xstarts[segment + 1])
1214  endindex++;
1215  if (segments >= SPLINESIZE) {
1217  tprintf ("Too many segments to resegment spline!!\n");
1218  }
1219  else if (endindex - startindex >= textord_spline_medianwin * 3) {
1220  while (centreindex - startindex <
1221  textord_spline_medianwin * 3 / 2)
1222  centreindex++;
1223  while (endindex - centreindex <
1224  textord_spline_medianwin * 3 / 2)
1225  centreindex--;
1226  leftindex = (startindex + startindex + centreindex) / 3;
1227  rightindex = (centreindex + endindex + endindex) / 3;
1228  leftcoord =
1229  (xcoords[startindex] * 2 + xcoords[centreindex]) / 3.0;
1230  rightcoord =
1231  (xcoords[centreindex] + xcoords[endindex] * 2) / 3.0;
1232  while (xcoords[leftindex] > leftcoord
1233  && leftindex - startindex > textord_spline_medianwin)
1234  leftindex--;
1235  while (xcoords[leftindex] < leftcoord
1236  && centreindex - leftindex >
1238  leftindex++;
1239  if (xcoords[leftindex] - leftcoord >
1240  leftcoord - xcoords[leftindex - 1])
1241  leftindex--;
1242  while (xcoords[rightindex] > rightcoord
1243  && rightindex - centreindex >
1245  rightindex--;
1246  while (xcoords[rightindex] < rightcoord
1247  && endindex - rightindex > textord_spline_medianwin)
1248  rightindex++;
1249  if (xcoords[rightindex] - rightcoord >
1250  rightcoord - xcoords[rightindex - 1])
1251  rightindex--;
1253  tprintf ("Splitting spline at %d with step %g at (%d,%d)\n",
1254  xstarts[segment],
1255  baseline->
1256  step ((xstarts[segment - 1] +
1257  xstarts[segment]) / 2.0,
1258  (xstarts[segment] +
1259  xstarts[segment + 1]) / 2.0),
1260  (xcoords[leftindex - 1] + xcoords[leftindex]) / 2,
1261  (xcoords[rightindex - 1] + xcoords[rightindex]) / 2);
1262  insert_spline_point (xstarts, segment,
1263  (xcoords[leftindex - 1] +
1264  xcoords[leftindex]) / 2,
1265  (xcoords[rightindex - 1] +
1266  xcoords[rightindex]) / 2, segments);
1267  doneany = TRUE;
1268  }
1269  else if (textord_debug_baselines) {
1270  tprintf
1271  ("Resegmenting spline failed - insufficient pts (%d,%d,%d,%d)\n",
1272  startindex, centreindex, endindex,
1274  }
1275  }
1276  // else tprintf("Spline step at %d is %g\n",
1277  // xstarts[segment],
1278  // baseline->step((xstarts[segment-1]+xstarts[segment])/2.0,
1279  // (xstarts[segment]+xstarts[segment+1])/2.0));
1280  }
1281  return doneany;
1282 }
1283 
1284 
1285 /**********************************************************************
1286  * insert_spline_point
1287  *
1288  * Insert a new spline point and shuffle up the others.
1289  **********************************************************************/
1290 
1291 void
1292 insert_spline_point ( //get descenders
1293 int xstarts[], //starts to shuffle
1294 int segment, //insertion pt
1295 int coord1, //coords to add
1296 int coord2, int &segments //total segments
1297 ) {
1298  int index; //for shuffling
1299 
1300  for (index = segments; index > segment; index--)
1301  xstarts[index + 1] = xstarts[index];
1302  segments++;
1303  xstarts[segment] = coord1;
1304  xstarts[segment + 1] = coord2;
1305 }
1306 
1307 
1308 /**********************************************************************
1309  * find_lesser_parts
1310  *
1311  * Average the step from the spline for the other partitions
1312  * and find the commonest partition which has a descender.
1313  **********************************************************************/
1314 
1315 void
1316 find_lesser_parts ( //get descenders
1317 TO_ROW * row, //row to process
1318 TBOX blobcoords[], //bounding boxes
1319 int blobcount, /*no of blobs */
1320 char partids[], /*partition of each blob */
1321 int partsizes[], /*size of each part */
1322 int partcount, /*no of partitions */
1323 int bestpart /*biggest partition */
1324 ) {
1325  int blobindex; /*index of blob */
1326  int partition; /*current partition */
1327  int xcentre; /*centre of blob */
1328  int poscount; /*count of best up step */
1329  int negcount; /*count of best down step */
1330  float partsteps[MAXPARTS]; /*average step to part */
1331  float bestneg; /*best down step */
1332  int runlength; /*length of bad run */
1333  int biggestrun; /*biggest bad run */
1334 
1335  biggestrun = 0;
1336  for (partition = 0; partition < partcount; partition++)
1337  partsteps[partition] = 0.0; /*zero accumulators */
1338  for (runlength = 0, blobindex = 0; blobindex < blobcount; blobindex++) {
1339  xcentre = (blobcoords[blobindex].left ()
1340  + blobcoords[blobindex].right ()) >> 1;
1341  /*in other parts */
1342  int part_id =
1343  static_cast<int>(static_cast<unsigned char>(partids[blobindex]));
1344  if (part_id != bestpart) {
1345  runlength++; /*run of non bests */
1346  if (runlength > biggestrun)
1347  biggestrun = runlength;
1348  partsteps[part_id] += blobcoords[blobindex].bottom()
1349  - row->baseline.y(xcentre);
1350  }
1351  else
1352  runlength = 0;
1353  }
1354  if (biggestrun > MAXBADRUN)
1355  row->xheight = -1.0f; /*failed */
1356  else
1357  row->xheight = 1.0f; /*success */
1358  poscount = negcount = 0;
1359  bestneg = 0.0; /*no step yet */
1360  for (partition = 0; partition < partcount; partition++) {
1361  if (partition != bestpart) {
1362  // by jetsoft divide by zero possible
1363  if (partsizes[partition] == 0)
1364  partsteps[partition] = 0;
1365  else
1366  partsteps[partition] /= partsizes[partition];
1367  //
1368 
1369  if (partsteps[partition] >= MINASCRISE
1370  && partsizes[partition] > poscount) {
1371  poscount = partsizes[partition];
1372  }
1373  if (partsteps[partition] <= -MINASCRISE
1374  && partsizes[partition] > negcount) {
1375  /*ascender rise */
1376  bestneg = partsteps[partition];
1377  /*2nd most popular */
1378  negcount = partsizes[partition];
1379  }
1380  }
1381  }
1382  /*average x-height */
1383  partsteps[bestpart] /= blobcount;
1384  row->descdrop = bestneg;
1385 }
1386 
1387 
1388 /**********************************************************************
1389  * old_first_xheight
1390  *
1391  * Makes an x-height spline by copying the baseline and shifting it.
1392  * It estimates the x-height across the line to use as the shift.
1393  * It also finds the ascender height if it can.
1394  **********************************************************************/
1395 
1396 void
1397 old_first_xheight ( //the wiseowl way
1398 TO_ROW * row, /*current row */
1399 TBOX blobcoords[], /*blob bounding boxes */
1400 int initialheight, //initial guess
1401 int blobcount, /*blobs in blobcoords */
1402 QSPLINE * baseline, /*established */
1403 float jumplimit /*min ascender height */
1404 ) {
1405  int blobindex; /*current blob */
1406  /*height statistics */
1407  STATS heightstat (0, MAXHEIGHT);
1408  int height; /*height of blob */
1409  int xcentre; /*centre of blob */
1410  int lineheight; /*approx xheight */
1411  float ascenders; /*ascender sum */
1412  int asccount; /*no of ascenders */
1413  float xsum; /*xheight sum */
1414  int xcount; /*xheight count */
1415  float diff; /*height difference */
1416 
1417  if (blobcount > 1) {
1418  for (blobindex = 0; blobindex < blobcount; blobindex++) {
1419  xcentre = (blobcoords[blobindex].left ()
1420  + blobcoords[blobindex].right ()) / 2;
1421  /*height of blob */
1422  height = (int) (blobcoords[blobindex].top () - baseline->y (xcentre) + 0.5);
1423  if (height > initialheight * oldbl_xhfract
1424  && height > textord_min_xheight)
1425  heightstat.add (height, 1);
1426  }
1427  if (heightstat.get_total () > 3) {
1428  lineheight = (int) heightstat.ile (0.25);
1429  if (lineheight <= 0)
1430  lineheight = (int) heightstat.ile (0.5);
1431  }
1432  else
1433  lineheight = initialheight;
1434  }
1435  else {
1436  lineheight = (int) (blobcoords[0].top ()
1437  - baseline->y ((blobcoords[0].left ()
1438  + blobcoords[0].right ()) / 2) +
1439  0.5);
1440  }
1441 
1442  xsum = 0.0f;
1443  xcount = 0;
1444  for (ascenders = 0.0f, asccount = 0, blobindex = 0; blobindex < blobcount;
1445  blobindex++) {
1446  xcentre = (blobcoords[blobindex].left ()
1447  + blobcoords[blobindex].right ()) / 2;
1448  diff = blobcoords[blobindex].top () - baseline->y (xcentre);
1449  /*is it ascender */
1450  if (diff > lineheight + jumplimit) {
1451  ascenders += diff;
1452  asccount++; /*count ascenders */
1453  }
1454  else if (diff > lineheight - jumplimit) {
1455  xsum += diff; /*mean xheight */
1456  xcount++;
1457  }
1458  }
1459  if (xcount > 0)
1460  xsum /= xcount; /*average xheight */
1461  else
1462  xsum = (float) lineheight; /*guess it */
1463  row->xheight *= xsum;
1464  if (asccount > 0)
1465  row->ascrise = ascenders / asccount - xsum;
1466  else
1467  row->ascrise = 0.0f; /*had none */
1468  if (row->xheight == 0)
1469  row->xheight = -1.0f;
1470 }
1471 
1472 
1473 /**********************************************************************
1474  * make_first_xheight
1475  *
1476  * Makes an x-height spline by copying the baseline and shifting it.
1477  * It estimates the x-height across the line to use as the shift.
1478  * It also finds the ascender height if it can.
1479  **********************************************************************/
1480 
1481 void
1482 make_first_xheight ( //find xheight
1483 TO_ROW * row, /*current row */
1484 TBOX blobcoords[], /*blob bounding boxes */
1485 int lineheight, //initial guess
1486 int init_lineheight, //block level guess
1487 int blobcount, /*blobs in blobcoords */
1488 QSPLINE * baseline, /*established */
1489 float jumplimit /*min ascender height */
1490 ) {
1491  STATS heightstat (0, HEIGHTBUCKETS);
1492  int lefts[HEIGHTBUCKETS];
1493  int rights[HEIGHTBUCKETS];
1494  int modelist[MODENUM];
1495  int blobindex;
1496  int mode_count; //blobs to count in thr
1497  int sign_bit;
1498  int mode_threshold;
1499  const int kBaselineTouch = 2; // This really should change with resolution.
1500  const int kGoodStrength = 8; // Strength of baseline-touching heights.
1501  const float kMinHeight = 0.25; // Min fraction of lineheight to use.
1502 
1503  sign_bit = row->xheight > 0 ? 1 : -1;
1504 
1505  memset(lefts, 0, HEIGHTBUCKETS * sizeof(lefts[0]));
1506  memset(rights, 0, HEIGHTBUCKETS * sizeof(rights[0]));
1507  mode_count = 0;
1508  for (blobindex = 0; blobindex < blobcount; blobindex++) {
1509  int xcenter = (blobcoords[blobindex].left () +
1510  blobcoords[blobindex].right ()) / 2;
1511  float base = baseline->y(xcenter);
1512  float bottomdiff = fabs(base - blobcoords[blobindex].bottom());
1513  int strength = textord_ocropus_mode &&
1514  bottomdiff <= kBaselineTouch ? kGoodStrength : 1;
1515  int height = static_cast<int>(blobcoords[blobindex].top () - base + 0.5);
1516  if (blobcoords[blobindex].height () > init_lineheight * kMinHeight) {
1517  if (height > lineheight * oldbl_xhfract
1518  && height > textord_min_xheight) {
1519  heightstat.add (height, strength);
1520  if (height < HEIGHTBUCKETS) {
1521  if (xcenter > rights[height])
1522  rights[height] = xcenter;
1523  if (xcenter > 0 && (lefts[height] == 0 || xcenter < lefts[height]))
1524  lefts[height] = xcenter;
1525  }
1526  }
1527  mode_count += strength;
1528  }
1529  }
1530 
1531  mode_threshold = (int) (blobcount * 0.1);
1532  if (oldbl_dot_error_size > 1 || oldbl_xhfix)
1533  mode_threshold = (int) (mode_count * 0.1);
1534 
1535  if (textord_oldbl_debug) {
1536  tprintf ("blobcount=%d, mode_count=%d, mode_t=%d\n",
1537  blobcount, mode_count, mode_threshold);
1538  }
1539  find_top_modes(&heightstat, HEIGHTBUCKETS, modelist, MODENUM);
1540  if (textord_oldbl_debug) {
1541  for (blobindex = 0; blobindex < MODENUM; blobindex++)
1542  tprintf ("mode[%d]=%d ", blobindex, modelist[blobindex]);
1543  tprintf ("\n");
1544  }
1545  pick_x_height(row, modelist, lefts, rights, &heightstat, mode_threshold);
1546 
1547  if (textord_oldbl_debug)
1548  tprintf ("Output xheight=%g\n", row->xheight);
1549  if (row->xheight < 0 && textord_oldbl_debug)
1550  tprintf ("warning: Row Line height < 0; %4.2f\n", row->xheight);
1551 
1552  if (sign_bit < 0)
1553  row->xheight = -row->xheight;
1554 }
1555 
1556 /**********************************************************************
1557  * find_top_modes
1558  *
1559  * Fill the input array with the indices of the top ten modes of the
1560  * input distribution.
1561  **********************************************************************/
1562 
1563 const int kMinModeFactorOcropus = 32;
1564 const int kMinModeFactor = 12;
1565 
1566 void
1567 find_top_modes ( //get modes
1568 STATS * stats, //stats to hack
1569 int statnum, //no of piles
1570 int modelist[], int modenum //no of modes to get
1571 ) {
1572  int mode_count;
1573  int last_i = 0;
1574  int last_max = MAX_INT32;
1575  int i;
1576  int mode;
1577  int total_max = 0;
1578  int mode_factor = textord_ocropus_mode ?
1580 
1581  for (mode_count = 0; mode_count < modenum; mode_count++) {
1582  mode = 0;
1583  for (i = 0; i < statnum; i++) {
1584  if (stats->pile_count (i) > stats->pile_count (mode)) {
1585  if ((stats->pile_count (i) < last_max) ||
1586  ((stats->pile_count (i) == last_max) && (i > last_i))) {
1587  mode = i;
1588  }
1589  }
1590  }
1591  last_i = mode;
1592  last_max = stats->pile_count (last_i);
1593  total_max += last_max;
1594  if (last_max <= total_max / mode_factor)
1595  mode = 0;
1596  modelist[mode_count] = mode;
1597  }
1598 }
1599 
1600 
1601 /**********************************************************************
1602  * pick_x_height
1603  *
1604  * Choose based on the height modes the best x height value.
1605  **********************************************************************/
1606 
1607 void pick_x_height(TO_ROW * row, //row to do
1608  int modelist[],
1609  int lefts[], int rights[],
1610  STATS * heightstat,
1611  int mode_threshold) {
1612  int x;
1613  int y;
1614  int z;
1615  float ratio;
1616  int found_one_bigger = FALSE;
1617  int best_x_height = 0;
1618  int best_asc = 0;
1619  int num_in_best;
1620 
1621  for (x = 0; x < MODENUM; x++) {
1622  for (y = 0; y < MODENUM; y++) {
1623  /* Check for two modes */
1624  if (modelist[x] && modelist[y] &&
1625  heightstat->pile_count (modelist[x]) > mode_threshold &&
1627  MIN(rights[modelist[x]], rights[modelist[y]]) >
1628  MAX(lefts[modelist[x]], lefts[modelist[y]]))) {
1629  ratio = (float) modelist[y] / (float) modelist[x];
1630  if (1.2 < ratio && ratio < 1.8) {
1631  /* Two modes found */
1632  best_x_height = modelist[x];
1633  num_in_best = heightstat->pile_count (modelist[x]);
1634 
1635  /* Try to get one higher */
1636  do {
1637  found_one_bigger = FALSE;
1638  for (z = 0; z < MODENUM; z++) {
1639  if (modelist[z] == best_x_height + 1 &&
1641  MIN(rights[modelist[x]], rights[modelist[y]]) >
1642  MAX(lefts[modelist[x]], lefts[modelist[y]]))) {
1643  ratio = (float) modelist[y] / (float) modelist[z];
1644  if ((1.2 < ratio && ratio < 1.8) &&
1645  /* Should be half of best */
1646  heightstat->pile_count (modelist[z]) >
1647  num_in_best * 0.5) {
1648  best_x_height++;
1649  found_one_bigger = TRUE;
1650  break;
1651  }
1652  }
1653  }
1654  }
1655  while (found_one_bigger);
1656 
1657  /* try to get a higher ascender */
1658 
1659  best_asc = modelist[y];
1660  num_in_best = heightstat->pile_count (modelist[y]);
1661 
1662  /* Try to get one higher */
1663  do {
1664  found_one_bigger = FALSE;
1665  for (z = 0; z < MODENUM; z++) {
1666  if (modelist[z] > best_asc &&
1668  MIN(rights[modelist[x]], rights[modelist[y]]) >
1669  MAX(lefts[modelist[x]], lefts[modelist[y]]))) {
1670  ratio = (float) modelist[z] / (float) best_x_height;
1671  if ((1.2 < ratio && ratio < 1.8) &&
1672  /* Should be half of best */
1673  heightstat->pile_count (modelist[z]) >
1674  num_in_best * 0.5) {
1675  best_asc = modelist[z];
1676  found_one_bigger = TRUE;
1677  break;
1678  }
1679  }
1680  }
1681  }
1682  while (found_one_bigger);
1683 
1684  row->xheight = (float) best_x_height;
1685  row->ascrise = (float) best_asc - best_x_height;
1686  return;
1687  }
1688  }
1689  }
1690  }
1691 
1692  best_x_height = modelist[0]; /* Single Mode found */
1693  num_in_best = heightstat->pile_count (best_x_height);
1694  do {
1695  /* Try to get one higher */
1696  found_one_bigger = FALSE;
1697  for (z = 1; z < MODENUM; z++) {
1698  /* Should be half of best */
1699  if ((modelist[z] == best_x_height + 1) &&
1700  (heightstat->pile_count (modelist[z]) > num_in_best * 0.5)) {
1701  best_x_height++;
1702  found_one_bigger = TRUE;
1703  break;
1704  }
1705  }
1706  }
1707  while (found_one_bigger);
1708 
1709  row->ascrise = 0.0f;
1710  row->xheight = (float) best_x_height;
1711  if (row->xheight == 0)
1712  row->xheight = -1.0f;
1713 }
#define MODENUM
Definition: oldbasel.cpp:69
void set_xheight(inT32 height)
set char size
Definition: ocrblock.h:72
#define MAXHEIGHT
Definition: oldbasel.cpp:62
double get_c()
Definition: quadlsq.h:51
void free_mem(void *oldchunk)
Definition: memry.cpp:47
TBOX box_next_pre_chopped(BLOBNBOX_IT *it)
Definition: blobbox.cpp:660
EXTERN bool oldbl_xhfix
Definition: oldbasel.cpp:46
void move(ICOORD vec)
Definition: quspline.cpp:259
double get_b()
Definition: quadlsq.h:48
#define TRUE
Definition: capi.h:45
void make_first_baseline(TBOX blobcoords[], int blobcount, int xcoords[], int ycoords[], QSPLINE *spline, QSPLINE *baseline, float jumplimit)
Definition: oldbasel.cpp:511
Definition: points.h:189
#define EXTERN
Definition: oldbasel.cpp:35
inT32 get_total() const
Definition: statistc.h:86
int32_t inT32
Definition: host.h:38
float xheight
Definition: blobbox.h:653
void make_holed_baseline(TBOX blobcoords[], int blobcount, QSPLINE *spline, QSPLINE *baseline, float gradient)
Definition: oldbasel.cpp:654
void bounding_box(ICOORD &bottom_left, ICOORD &top_right) const
get box
Definition: pdblock.h:59
int partition_coords(TBOX blobcoords[], int blobcount, char partids[], int bestpart, int xcoords[], int ycoords[])
Definition: oldbasel.cpp:1029
const int kMinModeFactor
Definition: oldbasel.cpp:1564
#define MAX_INT32
Definition: host.h:62
EXTERN bool textord_ocropus_mode
Definition: oldbasel.cpp:47
float descdrop
Definition: blobbox.h:656
int get_blob_coords(TO_ROW *row, inT32 lineheight, TBOX *blobcoords, BOOL8 &holed_line, int &outcount)
Definition: oldbasel.cpp:441
void merge_oldbl_parts(TBOX blobcoords[], int blobcount, char partids[], int partsizes[], int biggestpart, float jumplimit)
Definition: oldbasel.cpp:793
EXTERN bool textord_oldbl_debug
Definition: oldbasel.cpp:39
static const double kXHeightFraction
Definition: ccstruct.h:34
#define tprintf(...)
Definition: tprintf.h:31
void insert_spline_point(int xstarts[], int segment, int coord1, int coord2, int &segments)
Definition: oldbasel.cpp:1292
EXTERN double textord_oldbl_jumplimit
Definition: oldbasel.cpp:53
#define X_HEIGHT_FRACTION
Definition: oldbasel.cpp:56
void plot(ScrollView *window, ScrollView::Color colour) const
Definition: quspline.cpp:363
#define BOOL_VAR(name, val, comment)
Definition: params.h:279
#define TURNLIMIT
Definition: oldbasel.cpp:55
inT32 pile_count(inT32 value) const
Definition: statistc.h:78
float line_m() const
Definition: blobbox.h:566
int segment_spline(TBOX blobcoords[], int blobcount, int xcoords[], int ycoords[], int degree, int pointcount, int xstarts[])
Definition: oldbasel.cpp:1060
#define MAXPARTS
Definition: oldbasel.cpp:70
EXTERN bool textord_debug_baselines
Definition: oldbasel.cpp:40
int16_t inT16
Definition: host.h:36
inT16 left() const
Definition: rect.h:68
void find_top_modes(STATS *stats, int statnum, int modelist[], int modenum)
Definition: oldbasel.cpp:1567
EXTERN bool oldbl_corrfix
Definition: oldbasel.cpp:44
float line_size
Definition: blobbox.h:781
QSPLINE baseline
Definition: blobbox.h:666
#define double_VAR(name, val, comment)
Definition: params.h:285
void set_cell_over_xheight(float ratio)
Definition: ocrblock.h:116
#define MIN_ASC_FRACTION
Definition: oldbasel.cpp:58
unsigned char BOOL8
Definition: host.h:44
#define FALSE
Definition: capi.h:46
const char int mode
Definition: ioapi.h:38
bool textord_show_final_rows
Definition: makerow.cpp:48
void add(double x, double y)
Definition: quadlsq.cpp:56
#define MAXOVERLAP
Definition: oldbasel.cpp:63
double y(double x) const
Definition: quspline.cpp:217
void old_first_xheight(TO_ROW *row, TBOX blobcoords[], int initialheight, int blobcount, QSPLINE *baseline, float jumplimit)
Definition: oldbasel.cpp:1397
void make_first_xheight(TO_ROW *row, TBOX blobcoords[], int lineheight, int init_lineheight, int blobcount, QSPLINE *baseline, float jumplimit)
Definition: oldbasel.cpp:1482
EXTERN ScrollView * to_win
Definition: drawtord.cpp:38
#define INT_VAR(name, val, comment)
Definition: params.h:276
BOOL8 overlap(QSPLINE *spline2, double fraction)
Definition: quspline.cpp:280
double step(double x1, double x2)
Definition: quspline.cpp:192
Definition: quadlsq.h:25
void compute_row_xheight(TO_ROW *row, const FCOORD &rotation, float gradient, int block_line_size)
Definition: makerow.cpp:1383
EXTERN bool textord_really_old_xheight
Definition: oldbasel.cpp:38
#define ABS(x)
Definition: oldbasel.cpp:73
void add(inT32 value, inT32 count)
Definition: statistc.cpp:101
void fit(int degree)
Definition: quadlsq.cpp:100
inT16 top() const
Definition: rect.h:54
int textord_min_xheight
Definition: makerow.cpp:69
#define MAX(x, y)
Definition: ndminx.h:24
void * alloc_mem(inT32 count)
Definition: memry.cpp:39
int choose_partition(register float diff, float partdiffs[], int lastpart, float jumplimit, float *drift, float *lastdelta, int *partcount)
Definition: oldbasel.cpp:957
#define MAXBADRUN
Definition: oldbasel.cpp:64
BOOL8 split_stepped_spline(QSPLINE *baseline, float jumplimit, int xcoords[], int xstarts[], int &segments)
Definition: oldbasel.cpp:1185
Definition: rect.h:30
#define MIN(x, y)
Definition: ndminx.h:28
int partition_line(TBOX blobcoords[], int blobcount, int *numparts, char partids[], int partsizes[], QSPLINE *spline, float jumplimit, float ydiffs[])
Definition: oldbasel.cpp:712
float xheight
Definition: blobbox.h:784
#define SPLINESIZE
Definition: oldbasel.cpp:71
inT16 height() const
Definition: rect.h:104
int get_ydiffs(TBOX blobcoords[], int blobcount, QSPLINE *spline, float ydiffs[])
Definition: oldbasel.cpp:906
void Add(const ICOORD &pt)
Definition: detlinefit.cpp:52
float y() const
Definition: points.h:212
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
inT16 right() const
Definition: rect.h:75
EXTERN double oldbl_dot_error_size
Definition: oldbasel.cpp:51
inT16 width() const
Definition: rect.h:111
#define DESCENDER_FRACTION
Definition: oldbasel.cpp:57
Definition: statistc.h:33
void compute_block_xheight(TO_BLOCK *block, float gradient)
Definition: makerow.cpp:1271
void find_lesser_parts(TO_ROW *row, TBOX blobcoords[], int blobcount, char partids[], int partsizes[], int partcount, int bestpart)
Definition: oldbasel.cpp:1316
EXTERN bool textord_oldbl_split_splines
Definition: oldbasel.cpp:42
double ile(double frac) const
Definition: statistc.cpp:174
inT16 bottom() const
Definition: rect.h:61
BLOCK * block
Definition: blobbox.h:773
const int kMinModeFactorOcropus
Definition: oldbasel.cpp:1563
EXTERN bool textord_oldbl_merge_parts
Definition: oldbasel.cpp:43
#define MINASCRISE
Definition: oldbasel.cpp:60
BLOBNBOX_LIST * blob_list()
Definition: blobbox.h:595
TO_ROW_LIST * get_rows()
Definition: blobbox.h:700
#define MAXHEIGHTVARIANCE
Definition: oldbasel.cpp:61
float x() const
Definition: points.h:209
EXTERN int oldbl_holed_losscount
Definition: oldbasel.cpp:50
void pick_x_height(TO_ROW *row, int modelist[], int lefts[], int rights[], STATS *heightstat, int mode_threshold)
Definition: oldbasel.cpp:1607
void extrapolate(double gradient, int left, int right)
Definition: quspline.cpp:306
EXTERN double oldbl_xhfract
Definition: oldbasel.cpp:48
FCOORD classify_rotation() const
Definition: ocrblock.h:144
void clear()
Definition: quadlsq.cpp:34
EXTERN bool textord_oldbl_paradef
Definition: oldbasel.cpp:41
bool textord_old_xheight
Definition: makerow.cpp:54
#define MIN_DESC_FRACTION
Definition: oldbasel.cpp:59
float ascrise
Definition: blobbox.h:655
BOOL8 all_caps
Definition: blobbox.h:642
#define HEIGHTBUCKETS
Definition: oldbasel.cpp:65
double ConstrainedFit(const FCOORD &direction, double min_dist, double max_dist, bool debug, ICOORD *line_pt)
Definition: detlinefit.cpp:131
integer coordinate
Definition: points.h:30
int textord_spline_medianwin
Definition: makerow.cpp:66