All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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  register 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  register int rowindex; /*no of row */
168  register 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  register 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  register 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  register 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  register 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  register 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  register 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 
1023 //partitions and gives all the rest partid 0*/
1024 //
1025 //merge_partitions(partids,partcount,blobcount,bestpart)
1026 //register char *partids; /*partition numbers*/
1027 //int partcount; /*no of partitions*/
1028 //int blobcount; /*no of blobs*/
1029 //int bestpart; /*best partition*/
1030 //{
1031 // register int blobindex; /*no along text line*/
1032 // int runlength; /*run of same partition*/
1033 // int bestrun; /*biggest runlength*/
1034 //
1035 // bestrun=0; /*no runs yet*/
1036 // runlength=1;
1037 // for (blobindex=1;blobindex<blobcount;blobindex++)
1038 // { if (partids[blobindex]!=partids[blobindex-1])
1039 // { if (runlength>bestrun)
1040 // bestrun=runlength; /*find biggest run*/
1041 // runlength=1; /*new run*/
1042 // }
1043 // else
1044 // { runlength++;
1045 // }
1046 // }
1047 // if (runlength>bestrun)
1048 // bestrun=runlength;
1049 //
1050 // for (blobindex=0;blobindex<blobcount;blobindex++)
1051 // { if (blobindex<1
1052 // || partids[blobindex]!=partids[blobindex-1])
1053 // { if ((blobindex+1>=blobcount
1054 // || partids[blobindex]!=partids[blobindex+1])
1055 // /*loner*/
1056 // && (bestrun>2 || partids[blobindex]!=bestpart))
1057 // { partids[blobindex]=partcount; /*discard loner*/
1058 // }
1059 // else if (blobindex+1<blobcount
1060 // && partids[blobindex]==partids[blobindex+1]
1061 // /*pair*/
1062 // && (blobindex+2>=blobcount
1063 // || partids[blobindex]!=partids[blobindex+2])
1064 // && (bestrun>3 || partids[blobindex]!=bestpart))
1065 // { partids[blobindex]=partcount; /*discard both*/
1066 // partids[blobindex+1]=partcount;
1067 // }
1068 // }
1069 // }
1070 // for (blobindex=0;blobindex<blobcount;blobindex++)
1071 // { if (partids[blobindex]<partcount)
1072 // partids[blobindex]=0; /*all others together*/
1073 // }
1074 //}
1075 
1076 /**********************************************************************
1077  * partition_coords
1078  *
1079  * Get the x,y coordinates of all points in the bestpart and put them
1080  * in xcoords,ycoords. Return the number of points found.
1081  **********************************************************************/
1082 
1083 int
1084 partition_coords ( //find relevant coords
1085 TBOX blobcoords[], //bounding boxes
1086 int blobcount, /*no of blobs in row */
1087 char partids[], /*partition no of each blob */
1088 int bestpart, /*best new partition */
1089 int xcoords[], /*points to work on */
1090 int ycoords[] /*points to work on */
1091 ) {
1092  register int blobindex; /*no along text line */
1093  int pointcount; /*no of points */
1094 
1095  pointcount = 0;
1096  for (blobindex = 0; blobindex < blobcount; blobindex++) {
1097  if (partids[blobindex] == bestpart) {
1098  /*centre of blob */
1099  xcoords[pointcount] = (blobcoords[blobindex].left () + blobcoords[blobindex].right ()) >> 1;
1100  ycoords[pointcount++] = blobcoords[blobindex].bottom ();
1101  }
1102  }
1103  return pointcount; /*no of points found */
1104 }
1105 
1106 
1107 /**********************************************************************
1108  * segment_spline
1109  *
1110  * Segment the row at midpoints between maxima and minima of the x,y pairs.
1111  * The xstarts of the segments are returned and the number found.
1112  **********************************************************************/
1113 
1114 int
1115 segment_spline ( //make xstarts
1116 TBOX blobcoords[], //boundign boxes
1117 int blobcount, /*no of blobs in row */
1118 int xcoords[], /*points to work on */
1119 int ycoords[], /*points to work on */
1120 int degree, int pointcount, /*no of points */
1121 int xstarts[] //result
1122 ) {
1123  register int ptindex; /*no along text line */
1124  register int segment; /*partition no */
1125  int lastmin, lastmax; /*possible turn points */
1126  int turnpoints[SPLINESIZE]; /*good turning points */
1127  int turncount; /*no of turning points */
1128  int max_x; //max specified coord
1129 
1130  xstarts[0] = xcoords[0] - 1; //leftmost defined pt
1131  max_x = xcoords[pointcount - 1] + 1;
1132  if (degree < 2)
1133  pointcount = 0;
1134  turncount = 0; /*no turning points yet */
1135  if (pointcount > 3) {
1136  ptindex = 1;
1137  lastmax = lastmin = 0; /*start with first one */
1138  while (ptindex < pointcount - 1 && turncount < SPLINESIZE - 1) {
1139  /*minimum */
1140  if (ycoords[ptindex - 1] > ycoords[ptindex] && ycoords[ptindex] <= ycoords[ptindex + 1]) {
1141  if (ycoords[ptindex] < ycoords[lastmax] - TURNLIMIT) {
1142  if (turncount == 0 || turnpoints[turncount - 1] != lastmax)
1143  /*new max point */
1144  turnpoints[turncount++] = lastmax;
1145  lastmin = ptindex; /*latest minimum */
1146  }
1147  else if (ycoords[ptindex] < ycoords[lastmin]) {
1148  lastmin = ptindex; /*lower minimum */
1149  }
1150  }
1151 
1152  /*maximum */
1153  if (ycoords[ptindex - 1] < ycoords[ptindex] && ycoords[ptindex] >= ycoords[ptindex + 1]) {
1154  if (ycoords[ptindex] > ycoords[lastmin] + TURNLIMIT) {
1155  if (turncount == 0 || turnpoints[turncount - 1] != lastmin)
1156  /*new min point */
1157  turnpoints[turncount++] = lastmin;
1158  lastmax = ptindex; /*latest maximum */
1159  }
1160  else if (ycoords[ptindex] > ycoords[lastmax]) {
1161  lastmax = ptindex; /*higher maximum */
1162  }
1163  }
1164  ptindex++;
1165  }
1166  /*possible global min */
1167  if (ycoords[ptindex] < ycoords[lastmax] - TURNLIMIT
1168  && (turncount == 0 || turnpoints[turncount - 1] != lastmax)) {
1169  if (turncount < SPLINESIZE - 1)
1170  /*2 more turns */
1171  turnpoints[turncount++] = lastmax;
1172  if (turncount < SPLINESIZE - 1)
1173  turnpoints[turncount++] = ptindex;
1174  }
1175  else if (ycoords[ptindex] > ycoords[lastmin] + TURNLIMIT
1176  /*possible global max */
1177  && (turncount == 0 || turnpoints[turncount - 1] != lastmin)) {
1178  if (turncount < SPLINESIZE - 1)
1179  /*2 more turns */
1180  turnpoints[turncount++] = lastmin;
1181  if (turncount < SPLINESIZE - 1)
1182  turnpoints[turncount++] = ptindex;
1183  }
1184  else if (turncount > 0 && turnpoints[turncount - 1] == lastmin
1185  && turncount < SPLINESIZE - 1) {
1186  if (ycoords[ptindex] > ycoords[lastmax])
1187  turnpoints[turncount++] = ptindex;
1188  else
1189  turnpoints[turncount++] = lastmax;
1190  }
1191  else if (turncount > 0 && turnpoints[turncount - 1] == lastmax
1192  && turncount < SPLINESIZE - 1) {
1193  if (ycoords[ptindex] < ycoords[lastmin])
1194  turnpoints[turncount++] = ptindex;
1195  else
1196  turnpoints[turncount++] = lastmin;
1197  }
1198  }
1199 
1200  if (textord_oldbl_debug && turncount > 0)
1201  tprintf ("First turn is %d at (%d,%d)\n",
1202  turnpoints[0], xcoords[turnpoints[0]], ycoords[turnpoints[0]]);
1203  for (segment = 1; segment < turncount; segment++) {
1204  /*centre y coord */
1205  lastmax = (ycoords[turnpoints[segment - 1]] + ycoords[turnpoints[segment]]) / 2;
1206 
1207  /* fix alg so that it works with both rising and falling sections */
1208  if (ycoords[turnpoints[segment - 1]] < ycoords[turnpoints[segment]])
1209  /*find rising y centre */
1210  for (ptindex = turnpoints[segment - 1] + 1; ptindex < turnpoints[segment] && ycoords[ptindex + 1] <= lastmax; ptindex++);
1211  else
1212  /*find falling y centre */
1213  for (ptindex = turnpoints[segment - 1] + 1; ptindex < turnpoints[segment] && ycoords[ptindex + 1] >= lastmax; ptindex++);
1214 
1215  /*centre x */
1216  xstarts[segment] = (xcoords[ptindex - 1] + xcoords[ptindex]
1217  + xcoords[turnpoints[segment - 1]]
1218  + xcoords[turnpoints[segment]] + 2) / 4;
1219  /*halfway between turns */
1220  if (textord_oldbl_debug)
1221  tprintf ("Turn %d is %d at (%d,%d), mid pt is %d@%d, final @%d\n",
1222  segment, turnpoints[segment],
1223  xcoords[turnpoints[segment]], ycoords[turnpoints[segment]],
1224  ptindex - 1, xcoords[ptindex - 1], xstarts[segment]);
1225  }
1226 
1227  xstarts[segment] = max_x;
1228  return segment; /*no of splines */
1229 }
1230 
1231 
1232 /**********************************************************************
1233  * split_stepped_spline
1234  *
1235  * Re-segment the spline in cases where there is a big step function.
1236  * Return TRUE if any were done.
1237  **********************************************************************/
1238 
1239 BOOL8
1240 split_stepped_spline ( //make xstarts
1241 QSPLINE * baseline, //current shot
1242 float jumplimit, //max step fuction
1243 int xcoords[], /*points to work on */
1244 int xstarts[], //result
1245 int &segments //no of segments
1246 ) {
1247  BOOL8 doneany; //return value
1248  register int segment; /*partition no */
1249  int startindex, centreindex, endindex;
1250  float leftcoord, rightcoord;
1251  int leftindex, rightindex;
1252  float step; //spline step
1253 
1254  doneany = FALSE;
1255  startindex = 0;
1256  for (segment = 1; segment < segments - 1; segment++) {
1257  step = baseline->step ((xstarts[segment - 1] + xstarts[segment]) / 2.0,
1258  (xstarts[segment] + xstarts[segment + 1]) / 2.0);
1259  if (step < 0)
1260  step = -step;
1261  if (step > jumplimit) {
1262  while (xcoords[startindex] < xstarts[segment - 1])
1263  startindex++;
1264  centreindex = startindex;
1265  while (xcoords[centreindex] < xstarts[segment])
1266  centreindex++;
1267  endindex = centreindex;
1268  while (xcoords[endindex] < xstarts[segment + 1])
1269  endindex++;
1270  if (segments >= SPLINESIZE) {
1272  tprintf ("Too many segments to resegment spline!!\n");
1273  }
1274  else if (endindex - startindex >= textord_spline_medianwin * 3) {
1275  while (centreindex - startindex <
1276  textord_spline_medianwin * 3 / 2)
1277  centreindex++;
1278  while (endindex - centreindex <
1279  textord_spline_medianwin * 3 / 2)
1280  centreindex--;
1281  leftindex = (startindex + startindex + centreindex) / 3;
1282  rightindex = (centreindex + endindex + endindex) / 3;
1283  leftcoord =
1284  (xcoords[startindex] * 2 + xcoords[centreindex]) / 3.0;
1285  rightcoord =
1286  (xcoords[centreindex] + xcoords[endindex] * 2) / 3.0;
1287  while (xcoords[leftindex] > leftcoord
1288  && leftindex - startindex > textord_spline_medianwin)
1289  leftindex--;
1290  while (xcoords[leftindex] < leftcoord
1291  && centreindex - leftindex >
1293  leftindex++;
1294  if (xcoords[leftindex] - leftcoord >
1295  leftcoord - xcoords[leftindex - 1])
1296  leftindex--;
1297  while (xcoords[rightindex] > rightcoord
1298  && rightindex - centreindex >
1300  rightindex--;
1301  while (xcoords[rightindex] < rightcoord
1302  && endindex - rightindex > textord_spline_medianwin)
1303  rightindex++;
1304  if (xcoords[rightindex] - rightcoord >
1305  rightcoord - xcoords[rightindex - 1])
1306  rightindex--;
1308  tprintf ("Splitting spline at %d with step %g at (%d,%d)\n",
1309  xstarts[segment],
1310  baseline->
1311  step ((xstarts[segment - 1] +
1312  xstarts[segment]) / 2.0,
1313  (xstarts[segment] +
1314  xstarts[segment + 1]) / 2.0),
1315  (xcoords[leftindex - 1] + xcoords[leftindex]) / 2,
1316  (xcoords[rightindex - 1] + xcoords[rightindex]) / 2);
1317  insert_spline_point (xstarts, segment,
1318  (xcoords[leftindex - 1] +
1319  xcoords[leftindex]) / 2,
1320  (xcoords[rightindex - 1] +
1321  xcoords[rightindex]) / 2, segments);
1322  doneany = TRUE;
1323  }
1324  else if (textord_debug_baselines) {
1325  tprintf
1326  ("Resegmenting spline failed - insufficient pts (%d,%d,%d,%d)\n",
1327  startindex, centreindex, endindex,
1329  }
1330  }
1331  // else tprintf("Spline step at %d is %g\n",
1332  // xstarts[segment],
1333  // baseline->step((xstarts[segment-1]+xstarts[segment])/2.0,
1334  // (xstarts[segment]+xstarts[segment+1])/2.0));
1335  }
1336  return doneany;
1337 }
1338 
1339 
1340 /**********************************************************************
1341  * insert_spline_point
1342  *
1343  * Insert a new spline point and shuffle up the others.
1344  **********************************************************************/
1345 
1346 void
1347 insert_spline_point ( //get descenders
1348 int xstarts[], //starts to shuffle
1349 int segment, //insertion pt
1350 int coord1, //coords to add
1351 int coord2, int &segments //total segments
1352 ) {
1353  int index; //for shuffling
1354 
1355  for (index = segments; index > segment; index--)
1356  xstarts[index + 1] = xstarts[index];
1357  segments++;
1358  xstarts[segment] = coord1;
1359  xstarts[segment + 1] = coord2;
1360 }
1361 
1362 
1363 /**********************************************************************
1364  * find_lesser_parts
1365  *
1366  * Average the step from the spline for the other partitions
1367  * and find the commonest partition which has a descender.
1368  **********************************************************************/
1369 
1370 void
1371 find_lesser_parts ( //get descenders
1372 TO_ROW * row, //row to process
1373 TBOX blobcoords[], //bounding boxes
1374 int blobcount, /*no of blobs */
1375 char partids[], /*partition of each blob */
1376 int partsizes[], /*size of each part */
1377 int partcount, /*no of partitions */
1378 int bestpart /*biggest partition */
1379 ) {
1380  register int blobindex; /*index of blob */
1381  register int partition; /*current partition */
1382  int xcentre; /*centre of blob */
1383  int poscount; /*count of best up step */
1384  int negcount; /*count of best down step */
1385  float partsteps[MAXPARTS]; /*average step to part */
1386  float bestneg; /*best down step */
1387  int runlength; /*length of bad run */
1388  int biggestrun; /*biggest bad run */
1389 
1390  biggestrun = 0;
1391  for (partition = 0; partition < partcount; partition++)
1392  partsteps[partition] = 0.0; /*zero accumulators */
1393  for (runlength = 0, blobindex = 0; blobindex < blobcount; blobindex++) {
1394  xcentre = (blobcoords[blobindex].left ()
1395  + blobcoords[blobindex].right ()) >> 1;
1396  /*in other parts */
1397  int part_id =
1398  static_cast<int>(static_cast<unsigned char>(partids[blobindex]));
1399  if (part_id != bestpart) {
1400  runlength++; /*run of non bests */
1401  if (runlength > biggestrun)
1402  biggestrun = runlength;
1403  partsteps[part_id] += blobcoords[blobindex].bottom()
1404  - row->baseline.y(xcentre);
1405  }
1406  else
1407  runlength = 0;
1408  }
1409  if (biggestrun > MAXBADRUN)
1410  row->xheight = -1.0f; /*failed */
1411  else
1412  row->xheight = 1.0f; /*success */
1413  poscount = negcount = 0;
1414  bestneg = 0.0; /*no step yet */
1415  for (partition = 0; partition < partcount; partition++) {
1416  if (partition != bestpart) {
1417 
1418  //by jetsoft divide by zero possible
1419  if (partsizes[partition]==0)
1420  partsteps[partition]=0;
1421  else
1422  partsteps[partition] /= partsizes[partition];
1423  //
1424 
1425 
1426  if (partsteps[partition] >= MINASCRISE
1427  && partsizes[partition] > poscount) {
1428  poscount = partsizes[partition];
1429  }
1430  if (partsteps[partition] <= -MINASCRISE
1431  && partsizes[partition] > negcount) {
1432  /*ascender rise */
1433  bestneg = partsteps[partition];
1434  /*2nd most popular */
1435  negcount = partsizes[partition];
1436  }
1437  }
1438  }
1439  /*average x-height */
1440  partsteps[bestpart] /= blobcount;
1441  row->descdrop = bestneg;
1442 }
1443 
1444 
1445 /**********************************************************************
1446  * old_first_xheight
1447  *
1448  * Makes an x-height spline by copying the baseline and shifting it.
1449  * It estimates the x-height across the line to use as the shift.
1450  * It also finds the ascender height if it can.
1451  **********************************************************************/
1452 
1453 void
1454 old_first_xheight ( //the wiseowl way
1455 TO_ROW * row, /*current row */
1456 TBOX blobcoords[], /*blob bounding boxes */
1457 int initialheight, //initial guess
1458 int blobcount, /*blobs in blobcoords */
1459 QSPLINE * baseline, /*established */
1460 float jumplimit /*min ascender height */
1461 ) {
1462  register int blobindex; /*current blob */
1463  /*height statistics */
1464  STATS heightstat (0, MAXHEIGHT);
1465  int height; /*height of blob */
1466  int xcentre; /*centre of blob */
1467  int lineheight; /*approx xheight */
1468  float ascenders; /*ascender sum */
1469  int asccount; /*no of ascenders */
1470  float xsum; /*xheight sum */
1471  int xcount; /*xheight count */
1472  register float diff; /*height difference */
1473 
1474  if (blobcount > 1) {
1475  for (blobindex = 0; blobindex < blobcount; blobindex++) {
1476  xcentre = (blobcoords[blobindex].left ()
1477  + blobcoords[blobindex].right ()) / 2;
1478  /*height of blob */
1479  height = (int) (blobcoords[blobindex].top () - baseline->y (xcentre) + 0.5);
1480  if (height > initialheight * oldbl_xhfract
1481  && height > textord_min_xheight)
1482  heightstat.add (height, 1);
1483  }
1484  if (heightstat.get_total () > 3) {
1485  lineheight = (int) heightstat.ile (0.25);
1486  if (lineheight <= 0)
1487  lineheight = (int) heightstat.ile (0.5);
1488  }
1489  else
1490  lineheight = initialheight;
1491  }
1492  else {
1493  lineheight = (int) (blobcoords[0].top ()
1494  - baseline->y ((blobcoords[0].left ()
1495  + blobcoords[0].right ()) / 2) +
1496  0.5);
1497  }
1498 
1499  xsum = 0.0f;
1500  xcount = 0;
1501  for (ascenders = 0.0f, asccount = 0, blobindex = 0; blobindex < blobcount;
1502  blobindex++) {
1503  xcentre = (blobcoords[blobindex].left ()
1504  + blobcoords[blobindex].right ()) / 2;
1505  diff = blobcoords[blobindex].top () - baseline->y (xcentre);
1506  /*is it ascender */
1507  if (diff > lineheight + jumplimit) {
1508  ascenders += diff;
1509  asccount++; /*count ascenders */
1510  }
1511  else if (diff > lineheight - jumplimit) {
1512  xsum += diff; /*mean xheight */
1513  xcount++;
1514  }
1515  }
1516  if (xcount > 0)
1517  xsum /= xcount; /*average xheight */
1518  else
1519  xsum = (float) lineheight; /*guess it */
1520  row->xheight *= xsum;
1521  if (asccount > 0)
1522  row->ascrise = ascenders / asccount - xsum;
1523  else
1524  row->ascrise = 0.0f; /*had none */
1525  if (row->xheight == 0)
1526  row->xheight = -1.0f;
1527 }
1528 
1529 
1530 /**********************************************************************
1531  * make_first_xheight
1532  *
1533  * Makes an x-height spline by copying the baseline and shifting it.
1534  * It estimates the x-height across the line to use as the shift.
1535  * It also finds the ascender height if it can.
1536  **********************************************************************/
1537 
1538 void
1539 make_first_xheight ( //find xheight
1540 TO_ROW * row, /*current row */
1541 TBOX blobcoords[], /*blob bounding boxes */
1542 int lineheight, //initial guess
1543 int init_lineheight, //block level guess
1544 int blobcount, /*blobs in blobcoords */
1545 QSPLINE * baseline, /*established */
1546 float jumplimit /*min ascender height */
1547 ) {
1548  STATS heightstat (0, HEIGHTBUCKETS);
1549  int lefts[HEIGHTBUCKETS];
1550  int rights[HEIGHTBUCKETS];
1551  int modelist[MODENUM];
1552  int blobindex;
1553  int mode_count; //blobs to count in thr
1554  int sign_bit;
1555  int mode_threshold;
1556  const int kBaselineTouch = 2; // This really should change with resolution.
1557  const int kGoodStrength = 8; // Strength of baseline-touching heights.
1558  const float kMinHeight = 0.25; // Min fraction of lineheight to use.
1559 
1560  sign_bit = row->xheight > 0 ? 1 : -1;
1561 
1562  memset(lefts, 0, HEIGHTBUCKETS * sizeof(lefts[0]));
1563  memset(rights, 0, HEIGHTBUCKETS * sizeof(rights[0]));
1564  mode_count = 0;
1565  for (blobindex = 0; blobindex < blobcount; blobindex++) {
1566  int xcenter = (blobcoords[blobindex].left () +
1567  blobcoords[blobindex].right ()) / 2;
1568  float base = baseline->y(xcenter);
1569  float bottomdiff = fabs(base - blobcoords[blobindex].bottom());
1570  int strength = textord_ocropus_mode &&
1571  bottomdiff <= kBaselineTouch ? kGoodStrength : 1;
1572  int height = static_cast<int>(blobcoords[blobindex].top () - base + 0.5);
1573  if (blobcoords[blobindex].height () > init_lineheight * kMinHeight) {
1574  if (height > lineheight * oldbl_xhfract
1575  && height > textord_min_xheight) {
1576  heightstat.add (height, strength);
1577  if (height < HEIGHTBUCKETS) {
1578  if (xcenter > rights[height])
1579  rights[height] = xcenter;
1580  if (xcenter > 0 && (lefts[height] == 0 || xcenter < lefts[height]))
1581  lefts[height] = xcenter;
1582  }
1583  }
1584  mode_count += strength;
1585  }
1586  }
1587 
1588  mode_threshold = (int) (blobcount * 0.1);
1589  if (oldbl_dot_error_size > 1 || oldbl_xhfix)
1590  mode_threshold = (int) (mode_count * 0.1);
1591 
1592  if (textord_oldbl_debug) {
1593  tprintf ("blobcount=%d, mode_count=%d, mode_t=%d\n",
1594  blobcount, mode_count, mode_threshold);
1595  }
1596  find_top_modes(&heightstat, HEIGHTBUCKETS, modelist, MODENUM);
1597  if (textord_oldbl_debug) {
1598  for (blobindex = 0; blobindex < MODENUM; blobindex++)
1599  tprintf ("mode[%d]=%d ", blobindex, modelist[blobindex]);
1600  tprintf ("\n");
1601  }
1602  pick_x_height(row, modelist, lefts, rights, &heightstat, mode_threshold);
1603 
1604  if (textord_oldbl_debug)
1605  tprintf ("Output xheight=%g\n", row->xheight);
1606  if (row->xheight < 0 && textord_oldbl_debug)
1607  tprintf ("warning: Row Line height < 0; %4.2f\n", row->xheight);
1608 
1609  if (sign_bit < 0)
1610  row->xheight = -row->xheight;
1611 }
1612 
1613 /**********************************************************************
1614  * find_top_modes
1615  *
1616  * Fill the input array with the indices of the top ten modes of the
1617  * input distribution.
1618  **********************************************************************/
1619 
1620 const int kMinModeFactorOcropus = 32;
1621 const int kMinModeFactor = 12;
1622 
1623 void
1624 find_top_modes ( //get modes
1625 STATS * stats, //stats to hack
1626 int statnum, //no of piles
1627 int modelist[], int modenum //no of modes to get
1628 ) {
1629  int mode_count;
1630  int last_i = 0;
1631  int last_max = MAX_INT32;
1632  int i;
1633  int mode;
1634  int total_max = 0;
1635  int mode_factor = textord_ocropus_mode ?
1637 
1638  for (mode_count = 0; mode_count < modenum; mode_count++) {
1639  mode = 0;
1640  for (i = 0; i < statnum; i++) {
1641  if (stats->pile_count (i) > stats->pile_count (mode)) {
1642  if ((stats->pile_count (i) < last_max) ||
1643  ((stats->pile_count (i) == last_max) && (i > last_i))) {
1644  mode = i;
1645  }
1646  }
1647  }
1648  last_i = mode;
1649  last_max = stats->pile_count (last_i);
1650  total_max += last_max;
1651  if (last_max <= total_max / mode_factor)
1652  mode = 0;
1653  modelist[mode_count] = mode;
1654  }
1655 }
1656 
1657 
1658 /**********************************************************************
1659  * pick_x_height
1660  *
1661  * Choose based on the height modes the best x height value.
1662  **********************************************************************/
1663 
1664 void pick_x_height(TO_ROW * row, //row to do
1665  int modelist[],
1666  int lefts[], int rights[],
1667  STATS * heightstat,
1668  int mode_threshold) {
1669  int x;
1670  int y;
1671  int z;
1672  float ratio;
1673  int found_one_bigger = FALSE;
1674  int best_x_height = 0;
1675  int best_asc = 0;
1676  int num_in_best;
1677 
1678  for (x = 0; x < MODENUM; x++) {
1679  for (y = 0; y < MODENUM; y++) {
1680  /* Check for two modes */
1681  if (modelist[x] && modelist[y] &&
1682  heightstat->pile_count (modelist[x]) > mode_threshold &&
1684  MIN(rights[modelist[x]], rights[modelist[y]]) >
1685  MAX(lefts[modelist[x]], lefts[modelist[y]]))) {
1686  ratio = (float) modelist[y] / (float) modelist[x];
1687  if (1.2 < ratio && ratio < 1.8) {
1688  /* Two modes found */
1689  best_x_height = modelist[x];
1690  num_in_best = heightstat->pile_count (modelist[x]);
1691 
1692  /* Try to get one higher */
1693  do {
1694  found_one_bigger = FALSE;
1695  for (z = 0; z < MODENUM; z++) {
1696  if (modelist[z] == best_x_height + 1 &&
1698  MIN(rights[modelist[x]], rights[modelist[y]]) >
1699  MAX(lefts[modelist[x]], lefts[modelist[y]]))) {
1700  ratio = (float) modelist[y] / (float) modelist[z];
1701  if ((1.2 < ratio && ratio < 1.8) &&
1702  /* Should be half of best */
1703  heightstat->pile_count (modelist[z]) >
1704  num_in_best * 0.5) {
1705  best_x_height++;
1706  found_one_bigger = TRUE;
1707  break;
1708  }
1709  }
1710  }
1711  }
1712  while (found_one_bigger);
1713 
1714  /* try to get a higher ascender */
1715 
1716  best_asc = modelist[y];
1717  num_in_best = heightstat->pile_count (modelist[y]);
1718 
1719  /* Try to get one higher */
1720  do {
1721  found_one_bigger = FALSE;
1722  for (z = 0; z < MODENUM; z++) {
1723  if (modelist[z] > best_asc &&
1725  MIN(rights[modelist[x]], rights[modelist[y]]) >
1726  MAX(lefts[modelist[x]], lefts[modelist[y]]))) {
1727  ratio = (float) modelist[z] / (float) best_x_height;
1728  if ((1.2 < ratio && ratio < 1.8) &&
1729  /* Should be half of best */
1730  heightstat->pile_count (modelist[z]) >
1731  num_in_best * 0.5) {
1732  best_asc = modelist[z];
1733  found_one_bigger = TRUE;
1734  break;
1735  }
1736  }
1737  }
1738  }
1739  while (found_one_bigger);
1740 
1741  row->xheight = (float) best_x_height;
1742  row->ascrise = (float) best_asc - best_x_height;
1743  return;
1744  }
1745  }
1746  }
1747  }
1748 
1749  best_x_height = modelist[0]; /* Single Mode found */
1750  num_in_best = heightstat->pile_count (best_x_height);
1751  do {
1752  /* Try to get one higher */
1753  found_one_bigger = FALSE;
1754  for (z = 1; z < MODENUM; z++) {
1755  /* Should be half of best */
1756  if ((modelist[z] == best_x_height + 1) &&
1757  (heightstat->pile_count (modelist[z]) > num_in_best * 0.5)) {
1758  best_x_height++;
1759  found_one_bigger = TRUE;
1760  break;
1761  }
1762  }
1763  }
1764  while (found_one_bigger);
1765 
1766  row->ascrise = 0.0f;
1767  row->xheight = (float) best_x_height;
1768  if (row->xheight == 0)
1769  row->xheight = -1.0f;
1770 }
void old_first_xheight(TO_ROW *row, TBOX blobcoords[], int initialheight, int blobcount, QSPLINE *baseline, float jumplimit)
Definition: oldbasel.cpp:1454
double step(double x1, double x2)
Definition: quspline.cpp:192
inT32 get_total() const
Definition: statistc.h:86
EXTERN bool textord_oldbl_merge_parts
Definition: oldbasel.cpp:43
EXTERN double textord_oldbl_jumplimit
Definition: oldbasel.cpp:53
#define EXTERN
Definition: oldbasel.cpp:35
void make_first_xheight(TO_ROW *row, TBOX blobcoords[], int lineheight, int init_lineheight, int blobcount, QSPLINE *baseline, float jumplimit)
Definition: oldbasel.cpp:1539
#define MAX(x, y)
Definition: ndminx.h:24
int textord_spline_medianwin
Definition: makerow.cpp:66
#define double_VAR(name, val, comment)
Definition: params.h:286
void free_mem(void *oldchunk)
Definition: memry.cpp:55
float x() const
Definition: points.h:209
#define TURNLIMIT
Definition: oldbasel.cpp:55
#define MINASCRISE
Definition: oldbasel.cpp:60
void compute_block_xheight(TO_BLOCK *block, float gradient)
Definition: makerow.cpp:1285
#define tprintf(...)
Definition: tprintf.h:31
#define MIN(x, y)
Definition: ndminx.h:28
Definition: statistc.h:33
void plot(ScrollView *window, ScrollView::Color colour) const
Definition: quspline.cpp:363
void find_lesser_parts(TO_ROW *row, TBOX blobcoords[], int blobcount, char partids[], int partsizes[], int partcount, int bestpart)
Definition: oldbasel.cpp:1371
void add(inT32 value, inT32 count)
Definition: statistc.cpp:104
EXTERN bool textord_oldbl_debug
Definition: oldbasel.cpp:39
#define BOOL_VAR(name, val, comment)
Definition: params.h:280
unsigned char BOOL8
Definition: host.h:113
void set_cell_over_xheight(float ratio)
Definition: ocrblock.h:116
void set_xheight(inT32 height)
set char size
Definition: ocrblock.h:72
QSPLINE baseline
Definition: blobbox.h:666
const int kMinModeFactor
Definition: oldbasel.cpp:1621
void add(double x, double y)
Definition: quadlsq.cpp:56
EXTERN bool oldbl_xhfix
Definition: oldbasel.cpp:46
int get_ydiffs(TBOX blobcoords[], int blobcount, QSPLINE *spline, float ydiffs[])
Definition: oldbasel.cpp:906
CMD_EVENTS mode
Definition: pgedit.cpp:116
void fit(int degree)
Definition: quadlsq.cpp:100
inT16 right() const
Definition: rect.h:75
BLOBNBOX_LIST * blob_list()
Definition: blobbox.h:595
#define MODENUM
Definition: oldbasel.cpp:69
EXTERN double oldbl_xhfract
Definition: oldbasel.cpp:48
float xheight
Definition: blobbox.h:784
EXTERN double oldbl_dot_error_size
Definition: oldbasel.cpp:51
EXTERN bool textord_oldbl_paradef
Definition: oldbasel.cpp:41
#define MIN_DESC_FRACTION
Definition: oldbasel.cpp:59
float line_m() const
Definition: blobbox.h:566
void merge_oldbl_parts(TBOX blobcoords[], int blobcount, char partids[], int partsizes[], int biggestpart, float jumplimit)
Definition: oldbasel.cpp:793
FCOORD classify_rotation() const
Definition: ocrblock.h:144
EXTERN ScrollView * to_win
Definition: drawtord.cpp:38
void move(ICOORD vec)
Definition: quspline.cpp:259
int segment_spline(TBOX blobcoords[], int blobcount, int xcoords[], int ycoords[], int degree, int pointcount, int xstarts[])
Definition: oldbasel.cpp:1115
double ile(double frac) const
Definition: statistc.cpp:177
BOOL8 split_stepped_spline(QSPLINE *baseline, float jumplimit, int xcoords[], int xstarts[], int &segments)
Definition: oldbasel.cpp:1240
BOOL8 all_caps
Definition: blobbox.h:642
inT16 left() const
Definition: rect.h:68
void insert_spline_point(int xstarts[], int segment, int coord1, int coord2, int &segments)
Definition: oldbasel.cpp:1347
void extrapolate(double gradient, int left, int right)
Definition: quspline.cpp:306
void bounding_box(ICOORD &bottom_left, ICOORD &top_right) const
get box
Definition: pdblock.h:67
#define SPLINESIZE
Definition: oldbasel.cpp:71
#define MAXOVERLAP
Definition: oldbasel.cpp:63
float ascrise
Definition: blobbox.h:655
#define MAXBADRUN
Definition: oldbasel.cpp:64
void make_first_baseline(TBOX blobcoords[], int blobcount, int xcoords[], int ycoords[], QSPLINE *spline, QSPLINE *baseline, float jumplimit)
Definition: oldbasel.cpp:511
#define MAX_INT32
Definition: host.h:120
#define INT_VAR(name, val, comment)
Definition: params.h:277
EXTERN bool textord_ocropus_mode
Definition: oldbasel.cpp:47
#define MAXHEIGHT
Definition: oldbasel.cpp:62
bool textord_old_xheight
Definition: makerow.cpp:54
void pick_x_height(TO_ROW *row, int modelist[], int lefts[], int rights[], STATS *heightstat, int mode_threshold)
Definition: oldbasel.cpp:1664
#define DESCENDER_FRACTION
Definition: oldbasel.cpp:57
int choose_partition(register float diff, float partdiffs[], int lastpart, float jumplimit, float *drift, float *lastdelta, int *partcount)
Definition: oldbasel.cpp:957
#define MIN_ASC_FRACTION
Definition: oldbasel.cpp:58
double y(double x) const
Definition: quspline.cpp:217
integer coordinate
Definition: points.h:30
void compute_row_xheight(TO_ROW *row, const FCOORD &rotation, float gradient, int block_line_size)
Definition: makerow.cpp:1397
inT16 bottom() const
Definition: rect.h:61
int textord_min_xheight
Definition: makerow.cpp:69
inT16 height() const
Definition: rect.h:104
bool textord_show_final_rows
Definition: makerow.cpp:48
int partition_coords(TBOX blobcoords[], int blobcount, char partids[], int bestpart, int xcoords[], int ycoords[])
*merge_partitions(partids,partcount,blobcount,bestpart) discards funny looking
Definition: oldbasel.cpp:1084
TO_ROW_LIST * get_rows()
Definition: blobbox.h:700
inT16 width() const
Definition: rect.h:111
EXTERN bool oldbl_corrfix
Definition: oldbasel.cpp:44
void Add(const ICOORD &pt)
Definition: detlinefit.cpp:52
#define MAXHEIGHTVARIANCE
Definition: oldbasel.cpp:61
TBOX box_next_pre_chopped(BLOBNBOX_IT *it)
Definition: blobbox.cpp:658
EXTERN int oldbl_holed_losscount
Definition: oldbasel.cpp:50
int get_blob_coords(TO_ROW *row, inT32 lineheight, TBOX *blobcoords, BOOL8 &holed_line, int &outcount)
Definition: oldbasel.cpp:441
#define FALSE
Definition: capi.h:29
double get_b()
Definition: quadlsq.h:48
Definition: rect.h:30
BOOL8 overlap(QSPLINE *spline2, double fraction)
Definition: quspline.cpp:280
#define TRUE
Definition: capi.h:28
float y() const
Definition: points.h:212
Definition: quadlsq.h:25
#define ABS(x)
Definition: oldbasel.cpp:73
static const double kXHeightFraction
Definition: ccstruct.h:34
inT32 pile_count(inT32 value) const
Definition: statistc.h:78
const int kMinModeFactorOcropus
Definition: oldbasel.cpp:1620
#define HEIGHTBUCKETS
Definition: oldbasel.cpp:65
void * alloc_mem(inT32 count)
Definition: memry.cpp:47
EXTERN bool textord_really_old_xheight
Definition: oldbasel.cpp:38
#define NULL
Definition: host.h:144
void make_holed_baseline(TBOX blobcoords[], int blobcount, QSPLINE *spline, QSPLINE *baseline, float gradient)
Definition: oldbasel.cpp:654
EXTERN bool textord_oldbl_split_splines
Definition: oldbasel.cpp:42
#define X_HEIGHT_FRACTION
Definition: oldbasel.cpp:56
void find_top_modes(STATS *stats, int statnum, int modelist[], int modenum)
Definition: oldbasel.cpp:1624
#define MAXPARTS
Definition: oldbasel.cpp:70
EXTERN bool textord_debug_baselines
Definition: oldbasel.cpp:40
float xheight
Definition: blobbox.h:653
inT16 top() const
Definition: rect.h:54
double get_c()
Definition: quadlsq.h:51
double ConstrainedFit(const FCOORD &direction, double min_dist, double max_dist, bool debug, ICOORD *line_pt)
Definition: detlinefit.cpp:131
float descdrop
Definition: blobbox.h:656
Definition: points.h:189
void clear()
Definition: quadlsq.cpp:34
BLOCK * block
Definition: blobbox.h:773
float line_size
Definition: blobbox.h:781
int partition_line(TBOX blobcoords[], int blobcount, int *numparts, char partids[], int partsizes[], QSPLINE *spline, float jumplimit, float ydiffs[])
Definition: oldbasel.cpp:712
short inT16
Definition: host.h:100
int inT32
Definition: host.h:102