Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
oldbasel.cpp File Reference
#include "mfcpch.h"
#include "ccstruct.h"
#include "statistc.h"
#include "quadlsq.h"
#include "detlinefit.h"
#include "makerow.h"
#include "drawtord.h"
#include "oldbasel.h"
#include "textord.h"
#include "tprintf.h"

Go to the source code of this file.

Namespaces

 tesseract
 

Macros

#define EXTERN
 
#define TURNLIMIT   1 /*min size for turning point */
 
#define X_HEIGHT_FRACTION   0.7 /*x-height/caps height */
 
#define DESCENDER_FRACTION   0.5 /*descender/x-height */
 
#define MIN_ASC_FRACTION   0.20 /*min size of ascenders */
 
#define MIN_DESC_FRACTION   0.25 /*min size of descenders */
 
#define MINASCRISE   2.0 /*min ascender/desc step */
 
#define MAXHEIGHTVARIANCE   0.15 /*accepted variation in x-height */
 
#define MAXHEIGHT   300 /*max blob height */
 
#define MAXOVERLAP   0.1 /*max 10% missed overlap */
 
#define MAXBADRUN   2 /*max non best for failed */
 
#define HEIGHTBUCKETS   200 /* Num of buckets */
 
#define DELTAHEIGHT   5.0 /* Small amount of diff */
 
#define GOODHEIGHT   5
 
#define MAXLOOPS   10
 
#define MODENUM   10
 
#define MAXPARTS   6
 
#define SPLINESIZE   23
 
#define ABS(x)   ((x)<0 ? (-(x)) : (x))
 

Functions

int get_blob_coords (TO_ROW *row, inT32 lineheight, TBOX *blobcoords, BOOL8 &holed_line, int &outcount)
 
void make_first_baseline (TBOX blobcoords[], int blobcount, int xcoords[], int ycoords[], QSPLINE *spline, QSPLINE *baseline, float jumplimit)
 
void make_holed_baseline (TBOX blobcoords[], int blobcount, QSPLINE *spline, QSPLINE *baseline, float gradient)
 
int partition_line (TBOX blobcoords[], int blobcount, int *numparts, char partids[], int partsizes[], QSPLINE *spline, float jumplimit, float ydiffs[])
 
void merge_oldbl_parts (TBOX blobcoords[], int blobcount, char partids[], int partsizes[], int biggestpart, float jumplimit)
 
int get_ydiffs (TBOX blobcoords[], int blobcount, QSPLINE *spline, float ydiffs[])
 
int choose_partition (register float diff, float partdiffs[], int lastpart, float jumplimit, float *drift, float *lastdelta, int *partcount)
 
int partition_coords (TBOX blobcoords[], int blobcount, char partids[], int bestpart, int xcoords[], int ycoords[])
 *merge_partitions(partids,partcount,blobcount,bestpart) discards funny looking More...
 
int segment_spline (TBOX blobcoords[], int blobcount, int xcoords[], int ycoords[], int degree, int pointcount, int xstarts[])
 
BOOL8 split_stepped_spline (QSPLINE *baseline, float jumplimit, int xcoords[], int xstarts[], int &segments)
 
void insert_spline_point (int xstarts[], int segment, int coord1, int coord2, int &segments)
 
void find_lesser_parts (TO_ROW *row, TBOX blobcoords[], int blobcount, char partids[], int partsizes[], int partcount, int bestpart)
 
void old_first_xheight (TO_ROW *row, TBOX blobcoords[], int initialheight, int blobcount, QSPLINE *baseline, float jumplimit)
 
void make_first_xheight (TO_ROW *row, TBOX blobcoords[], int lineheight, int init_lineheight, int blobcount, QSPLINE *baseline, float jumplimit)
 
void find_top_modes (STATS *stats, int statnum, int modelist[], int modenum)
 
void pick_x_height (TO_ROW *row, int modelist[], int lefts[], int rights[], STATS *heightstat, int mode_threshold)
 

Variables

EXTERN bool textord_really_old_xheight = FALSE
 
EXTERN bool textord_oldbl_debug = FALSE
 
EXTERN bool textord_debug_baselines = FALSE
 
EXTERN bool textord_oldbl_paradef = TRUE
 
EXTERN bool textord_oldbl_split_splines = TRUE
 
EXTERN bool textord_oldbl_merge_parts = TRUE
 
EXTERN bool oldbl_corrfix = TRUE
 
EXTERN bool oldbl_xhfix = FALSE
 
EXTERN bool textord_ocropus_mode = FALSE
 
EXTERN double oldbl_xhfract = 0.4
 
EXTERN int oldbl_holed_losscount = 10
 
EXTERN double oldbl_dot_error_size = 1.26
 
EXTERN double textord_oldbl_jumplimit = 0.15
 
const int kMinModeFactorOcropus = 32
 
const int kMinModeFactor = 12
 

Macro Definition Documentation

#define ABS (   x)    ((x)<0 ? (-(x)) : (x))

Definition at line 74 of file oldbasel.cpp.

#define DELTAHEIGHT   5.0 /* Small amount of diff */

Definition at line 67 of file oldbasel.cpp.

#define DESCENDER_FRACTION   0.5 /*descender/x-height */

Definition at line 58 of file oldbasel.cpp.

#define EXTERN

Definition at line 36 of file oldbasel.cpp.

#define GOODHEIGHT   5

Definition at line 68 of file oldbasel.cpp.

#define HEIGHTBUCKETS   200 /* Num of buckets */

Definition at line 66 of file oldbasel.cpp.

#define MAXBADRUN   2 /*max non best for failed */

Definition at line 65 of file oldbasel.cpp.

#define MAXHEIGHT   300 /*max blob height */

Definition at line 63 of file oldbasel.cpp.

#define MAXHEIGHTVARIANCE   0.15 /*accepted variation in x-height */

Definition at line 62 of file oldbasel.cpp.

#define MAXLOOPS   10

Definition at line 69 of file oldbasel.cpp.

#define MAXOVERLAP   0.1 /*max 10% missed overlap */

Definition at line 64 of file oldbasel.cpp.

#define MAXPARTS   6

Definition at line 71 of file oldbasel.cpp.

#define MIN_ASC_FRACTION   0.20 /*min size of ascenders */

Definition at line 59 of file oldbasel.cpp.

#define MIN_DESC_FRACTION   0.25 /*min size of descenders */

Definition at line 60 of file oldbasel.cpp.

#define MINASCRISE   2.0 /*min ascender/desc step */

Definition at line 61 of file oldbasel.cpp.

#define MODENUM   10

Definition at line 70 of file oldbasel.cpp.

#define SPLINESIZE   23

Definition at line 72 of file oldbasel.cpp.

#define TURNLIMIT   1 /*min size for turning point */

Definition at line 56 of file oldbasel.cpp.

#define X_HEIGHT_FRACTION   0.7 /*x-height/caps height */

Definition at line 57 of file oldbasel.cpp.

Function Documentation

int choose_partition ( register float  diff,
float  partdiffs[],
int  lastpart,
float  jumplimit,
float *  drift,
float *  lastdelta,
int *  partcount 
)

Definition at line 963 of file oldbasel.cpp.

971  {
972  register int partition; /*partition no */
973  int bestpart; /*best new partition */
974  float bestdelta; /*best gap from a part */
975  float delta; /*diff from part */
976 
977  if (lastpart < 0) {
978  partdiffs[0] = diff;
979  lastpart = 0; /*first point */
980  *drift = 0.0f;
981  *lastdelta = 0.0f;
982  }
983  /*adjusted diff from part */
984  delta = diff - partdiffs[lastpart] - *drift;
985  if (textord_oldbl_debug) {
986  tprintf ("Diff=%.2f, Delta=%.3f, Drift=%.3f, ", diff, delta, *drift);
987  }
988  if (ABS (delta) > jumplimit / 2) {
989  /*delta on part 0 */
990  bestdelta = diff - partdiffs[0] - *drift;
991  bestpart = 0; /*0 best so far */
992  for (partition = 1; partition < *partcount; partition++) {
993  delta = diff - partdiffs[partition] - *drift;
994  if (ABS (delta) < ABS (bestdelta)) {
995  bestdelta = delta;
996  bestpart = partition; /*part with nearest jump */
997  }
998  }
999  delta = bestdelta;
1000  /*too far away */
1001  if (ABS (bestdelta) > jumplimit
1002  && *partcount < MAXPARTS) { /*and spare part left */
1003  bestpart = (*partcount)++; /*best was new one */
1004  /*start new one */
1005  partdiffs[bestpart] = diff - *drift;
1006  delta = 0.0f;
1007  }
1008  }
1009  else {
1010  bestpart = lastpart; /*best was last one */
1011  }
1012 
1013  if (bestpart == lastpart
1014  && (ABS (delta - *lastdelta) < jumplimit / 2
1015  || ABS (delta) < jumplimit / 2))
1016  /*smooth the drift */
1017  *drift = (3 * *drift + delta) / 3;
1018  *lastdelta = delta;
1019 
1020  if (textord_oldbl_debug) {
1021  tprintf ("P=%d\n", bestpart);
1022  }
1023 
1024  return bestpart;
1025 }
EXTERN bool textord_oldbl_debug
Definition: oldbasel.cpp:40
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:41
#define MAXPARTS
Definition: oldbasel.cpp:71
#define ABS(x)
Definition: oldbasel.cpp:74
void find_lesser_parts ( TO_ROW row,
TBOX  blobcoords[],
int  blobcount,
char  partids[],
int  partsizes[],
int  partcount,
int  bestpart 
)

Definition at line 1377 of file oldbasel.cpp.

1385  {
1386  register int blobindex; /*index of blob */
1387  register int partition; /*current partition */
1388  int xcentre; /*centre of blob */
1389  int poscount; /*count of best up step */
1390  int negcount; /*count of best down step */
1391  float partsteps[MAXPARTS]; /*average step to part */
1392  float bestpos; /*best up step */
1393  float bestneg; /*best down step */
1394  int runlength; /*length of bad run */
1395  int biggestrun; /*biggest bad run */
1396 
1397  biggestrun = 0;
1398  for (partition = 0; partition < partcount; partition++)
1399  partsteps[partition] = 0.0; /*zero accumulators */
1400  for (runlength = 0, blobindex = 0; blobindex < blobcount; blobindex++) {
1401  xcentre = (blobcoords[blobindex].left ()
1402  + blobcoords[blobindex].right ()) >> 1;
1403  /*in other parts */
1404  if (partids[blobindex] != bestpart) {
1405  runlength++; /*run of non bests */
1406  if (runlength > biggestrun)
1407  biggestrun = runlength;
1408  partsteps[partids[blobindex]] += blobcoords[blobindex].bottom ()
1409  - row->baseline.y (xcentre);
1410  }
1411  else
1412  runlength = 0;
1413  }
1414  if (biggestrun > MAXBADRUN)
1415  row->xheight = -1.0f; /*failed */
1416  else
1417  row->xheight = 1.0f; /*success */
1418  poscount = negcount = 0;
1419  bestpos = bestneg = 0.0; /*no step yet */
1420  for (partition = 0; partition < partcount; partition++) {
1421  if (partition != bestpart) {
1422 
1423  //by jetsoft divide by zero possible
1424  if (partsizes[partition]==0)
1425  partsteps[partition]=0;
1426  else
1427  partsteps[partition] /= partsizes[partition];
1428  //
1429 
1430 
1431  if (partsteps[partition] >= MINASCRISE
1432  && partsizes[partition] > poscount) {
1433  /*ascender rise */
1434  bestpos = partsteps[partition];
1435  /*2nd most popular */
1436  poscount = partsizes[partition];
1437  }
1438  if (partsteps[partition] <= -MINASCRISE
1439  && partsizes[partition] > negcount) {
1440  /*ascender rise */
1441  bestneg = partsteps[partition];
1442  /*2nd most popular */
1443  negcount = partsizes[partition];
1444  }
1445  }
1446  }
1447  /*average x-height */
1448  partsteps[bestpart] /= blobcount;
1449  row->descdrop = bestneg;
1450 }
QSPLINE baseline
Definition: blobbox.h:642
float descdrop
Definition: blobbox.h:632
inT16 left() const
Definition: rect.h:67
inT16 right() const
Definition: rect.h:74
#define MAXBADRUN
Definition: oldbasel.cpp:65
#define MAXPARTS
Definition: oldbasel.cpp:71
double y(double x) const
Definition: quspline.cpp:217
float xheight
Definition: blobbox.h:629
#define MINASCRISE
Definition: oldbasel.cpp:61
inT16 bottom() const
Definition: rect.h:60
void find_top_modes ( STATS stats,
int  statnum,
int  modelist[],
int  modenum 
)

Definition at line 1632 of file oldbasel.cpp.

1636  {
1637  int mode_count;
1638  int last_i = 0;
1639  int last_max = MAX_INT32;
1640  int i;
1641  int mode;
1642  int total_max = 0;
1643  int mode_factor = textord_ocropus_mode ?
1645 
1646  for (mode_count = 0; mode_count < modenum; mode_count++) {
1647  mode = 0;
1648  for (i = 0; i < statnum; i++) {
1649  if (stats->pile_count (i) > stats->pile_count (mode)) {
1650  if ((stats->pile_count (i) < last_max) ||
1651  ((stats->pile_count (i) == last_max) && (i > last_i))) {
1652  mode = i;
1653  }
1654  }
1655  }
1656  last_i = mode;
1657  last_max = stats->pile_count (last_i);
1658  total_max += last_max;
1659  if (last_max <= total_max / mode_factor)
1660  mode = 0;
1661  modelist[mode_count] = mode;
1662  }
1663 }
EXTERN bool textord_ocropus_mode
Definition: oldbasel.cpp:48
const int kMinModeFactorOcropus
Definition: oldbasel.cpp:1628
inT32 pile_count(inT32 value) const
Definition: statistc.h:74
#define MAX_INT32
Definition: host.h:120
CMD_EVENTS mode
Definition: pgedit.cpp:115
const int kMinModeFactor
Definition: oldbasel.cpp:1629
int get_blob_coords ( TO_ROW row,
inT32  lineheight,
TBOX blobcoords,
BOOL8 holed_line,
int &  outcount 
)

Definition at line 447 of file oldbasel.cpp.

453  {
454  //blobs
455  BLOBNBOX_IT blob_it = row->blob_list ();
456  register int blobindex; /*no along text line */
457  int losscount; //lost blobs
458  int maxlosscount; //greatest lost blobs
459  /*height stat collection */
460  STATS heightstat (0, MAXHEIGHT);
461 
462  if (blob_it.empty ())
463  return 0; //none
464  maxlosscount = 0;
465  losscount = 0;
466  blob_it.mark_cycle_pt ();
467  blobindex = 0;
468  do {
469  blobcoords[blobindex] = box_next_pre_chopped (&blob_it);
470  if (blobcoords[blobindex].height () > lineheight * 0.25)
471  heightstat.add (blobcoords[blobindex].height (), 1);
472  if (blobindex == 0
473  || blobcoords[blobindex].height () > lineheight * 0.25
474  || blob_it.cycled_list ()) {
475  blobindex++; /*no of merged blobs */
476  losscount = 0;
477  }
478  else {
479  if (blobcoords[blobindex].height ()
480  < blobcoords[blobindex].width () * oldbl_dot_error_size
481  && blobcoords[blobindex].width ()
482  < blobcoords[blobindex].height () * oldbl_dot_error_size) {
483  //counts as dot
484  blobindex++;
485  losscount = 0;
486  }
487  else {
488  losscount++; //lost it
489  if (losscount > maxlosscount)
490  //remember max
491  maxlosscount = losscount;
492  }
493  }
494  }
495  while (!blob_it.cycled_list ());
496 
497  holed_line = maxlosscount > oldbl_holed_losscount;
498  outcount = blobindex; /*total blobs */
499 
500  if (heightstat.get_total () > 1)
501  /*guess x-height */
502  return (int) heightstat.ile (0.25);
503  else
504  return blobcoords[0].height ();
505 }
TBOX box_next_pre_chopped(BLOBNBOX_IT *it)
Definition: blobbox.cpp:614
EXTERN int oldbl_holed_losscount
Definition: oldbasel.cpp:51
inT16 width() const
Definition: rect.h:104
EXTERN double oldbl_dot_error_size
Definition: oldbasel.cpp:52
Definition: statistc.h:29
#define MAXHEIGHT
Definition: oldbasel.cpp:63
BLOBNBOX_LIST * blob_list()
Definition: blobbox.h:571
inT16 height() const
Definition: rect.h:97
int get_ydiffs ( TBOX  blobcoords[],
int  blobcount,
QSPLINE spline,
float  ydiffs[] 
)

Definition at line 912 of file oldbasel.cpp.

917  {
918  register int blobindex; /*current blob */
919  int xcentre; /*xcoord */
920  int lastx; /*last xcentre */
921  float diffsum; /*sum of diffs */
922  float diff; /*current difference */
923  float drift; /*sum of spline steps */
924  float bestsum; /*smallest diffsum */
925  int bestindex; /*index of bestsum */
926 
927  diffsum = 0.0f;
928  bestindex = 0;
929  bestsum = (float) MAX_INT32;
930  drift = 0.0f;
931  lastx = blobcoords[0].left ();
932  /*do each blob in row */
933  for (blobindex = 0; blobindex < blobcount; blobindex++) {
934  /*centre of blob */
935  xcentre = (blobcoords[blobindex].left () + blobcoords[blobindex].right ()) >> 1;
936  //step functions in spline
937  drift += spline->step (lastx, xcentre);
938  lastx = xcentre;
939  diff = blobcoords[blobindex].bottom ();
940  diff -= spline->y (xcentre);
941  diff += drift;
942  ydiffs[blobindex] = diff; /*store difference */
943  if (blobindex > 2)
944  /*remove old one */
945  diffsum -= ABS (ydiffs[blobindex - 3]);
946  diffsum += ABS (diff); /*add new one */
947  if (blobindex >= 2 && diffsum < bestsum) {
948  bestsum = diffsum; /*find min sum */
949  bestindex = blobindex - 1; /*middle of set */
950  }
951  }
952  return bestindex;
953 }
double step(double x1, double x2)
Definition: quspline.cpp:192
inT16 left() const
Definition: rect.h:67
inT16 right() const
Definition: rect.h:74
#define MAX_INT32
Definition: host.h:120
double y(double x) const
Definition: quspline.cpp:217
#define ABS(x)
Definition: oldbasel.cpp:74
inT16 bottom() const
Definition: rect.h:60
void insert_spline_point ( int  xstarts[],
int  segment,
int  coord1,
int  coord2,
int &  segments 
)

Definition at line 1353 of file oldbasel.cpp.

1358  {
1359  int index; //for shuffling
1360 
1361  for (index = segments; index > segment; index--)
1362  xstarts[index + 1] = xstarts[index];
1363  segments++;
1364  xstarts[segment] = coord1;
1365  xstarts[segment + 1] = coord2;
1366 }
void make_first_baseline ( TBOX  blobcoords[],
int  blobcount,
int  xcoords[],
int  ycoords[],
QSPLINE spline,
QSPLINE baseline,
float  jumplimit 
)

Definition at line 517 of file oldbasel.cpp.

525  {
526  int leftedge; /*left edge of line */
527  int rightedge; /*right edge of line */
528  int blobindex; /*current blob */
529  int segment; /*current segment */
530  float prevy, thisy, nexty; /*3 y coords */
531  float y1, y2, y3; /*3 smooth blobs */
532  float maxmax, minmin; /*absolute limits */
533  int x2 = 0; /*right edge of old y3 */
534  int ycount; /*no of ycoords in use */
535  float yturns[SPLINESIZE]; /*y coords of turn pts */
536  int xturns[SPLINESIZE]; /*xcoords of turn pts */
537  int xstarts[SPLINESIZE + 1];
538  int segments; //no of segments
539  ICOORD shift; //shift of spline
540 
541  prevy = 0;
542  /*left edge of row */
543  leftedge = blobcoords[0].left ();
544  /*right edge of line */
545  rightedge = blobcoords[blobcount - 1].right ();
546  if (spline == NULL /*no given spline */
547  || spline->segments < 3 /*or trivial */
548  /*or too non-overlap */
549  || spline->xcoords[1] > leftedge + MAXOVERLAP * (rightedge - leftedge)
550  || spline->xcoords[spline->segments - 1] < rightedge
551  - MAXOVERLAP * (rightedge - leftedge)) {
553  return; //use default
554  xstarts[0] = blobcoords[0].left () - 1;
555  for (blobindex = 0; blobindex < blobcount; blobindex++) {
556  xcoords[blobindex] = (blobcoords[blobindex].left ()
557  + blobcoords[blobindex].right ()) / 2;
558  ycoords[blobindex] = blobcoords[blobindex].bottom ();
559  }
560  xstarts[1] = blobcoords[blobcount - 1].right () + 1;
561  segments = 1; /*no of segments */
562 
563  /*linear */
564  *baseline = QSPLINE (xstarts, segments, xcoords, ycoords, blobcount, 1);
565 
566  if (blobcount >= 3) {
567  y1 = y2 = y3 = 0.0f;
568  ycount = 0;
569  segment = 0; /*no of segments */
570  maxmax = minmin = 0.0f;
571  thisy = ycoords[0] - baseline->y (xcoords[0]);
572  nexty = ycoords[1] - baseline->y (xcoords[1]);
573  for (blobindex = 2; blobindex < blobcount; blobindex++) {
574  prevy = thisy; /*shift ycoords */
575  thisy = nexty;
576  nexty = ycoords[blobindex] - baseline->y (xcoords[blobindex]);
577  /*middle of smooth y */
578  if (ABS (thisy - prevy) < jumplimit && ABS (thisy - nexty) < jumplimit) {
579  y1 = y2; /*shift window */
580  y2 = y3;
581  y3 = thisy; /*middle point */
582  ycount++;
583  /*local max */
584  if (ycount >= 3 && ((y1 < y2 && y2 >= y3)
585  /*local min */
586  || (y1 > y2 && y2 <= y3))) {
587  if (segment < SPLINESIZE - 2) {
588  /*turning pt */
589  xturns[segment] = x2;
590  yturns[segment] = y2;
591  segment++; /*no of spline segs */
592  }
593  }
594  if (ycount == 1) {
595  maxmax = minmin = y3;/*initialise limits */
596  }
597  else {
598  if (y3 > maxmax)
599  maxmax = y3; /*biggest max */
600  if (y3 < minmin)
601  minmin = y3; /*smallest min */
602  }
603  /*possible turning pt */
604  x2 = blobcoords[blobindex - 1].right ();
605  }
606  }
607 
608  jumplimit *= 1.2;
609  /*must be wavy */
610  if (maxmax - minmin > jumplimit) {
611  ycount = segment; /*no of segments */
612  for (blobindex = 0, segment = 1; blobindex < ycount;
613  blobindex++) {
614  if (yturns[blobindex] > minmin + jumplimit
615  || yturns[blobindex] < maxmax - jumplimit) {
616  /*significant peak */
617  if (segment == 1
618  || yturns[blobindex] > prevy + jumplimit
619  || yturns[blobindex] < prevy - jumplimit) {
620  /*different to previous */
621  xstarts[segment] = xturns[blobindex];
622  segment++;
623  prevy = yturns[blobindex];
624  }
625  /*bigger max */
626  else if ((prevy > minmin + jumplimit && yturns[blobindex] > prevy)
627  /*smaller min */
628  || (prevy < maxmax - jumplimit && yturns[blobindex] < prevy)) {
629  xstarts[segment - 1] = xturns[blobindex];
630  /*improved previous */
631  prevy = yturns[blobindex];
632  }
633  }
634  }
635  xstarts[segment] = blobcoords[blobcount - 1].right () + 1;
636  segments = segment; /*no of segments */
637  /*linear */
638  *baseline = QSPLINE (xstarts, segments, xcoords, ycoords, blobcount, 1);
639  }
640  }
641  }
642  else {
643  *baseline = *spline; /*copy it */
644  shift = ICOORD (0, (inT16) (blobcoords[0].bottom ()
645  - spline->y (blobcoords[0].right ())));
646  baseline->move (shift);
647  }
648 }
#define NULL
Definition: host.h:144
inT16 left() const
Definition: rect.h:67
inT16 right() const
Definition: rect.h:74
#define SPLINESIZE
Definition: oldbasel.cpp:72
#define MAXOVERLAP
Definition: oldbasel.cpp:64
void move(ICOORD vec)
Definition: quspline.cpp:259
short inT16
Definition: host.h:100
integer coordinate
Definition: points.h:30
double y(double x) const
Definition: quspline.cpp:217
#define ABS(x)
Definition: oldbasel.cpp:74
EXTERN bool textord_oldbl_paradef
Definition: oldbasel.cpp:42
inT16 bottom() const
Definition: rect.h:60
void make_first_xheight ( TO_ROW row,
TBOX  blobcoords[],
int  lineheight,
int  init_lineheight,
int  blobcount,
QSPLINE baseline,
float  jumplimit 
)

Definition at line 1547 of file oldbasel.cpp.

1555  {
1556  STATS heightstat (0, HEIGHTBUCKETS);
1557  int lefts[HEIGHTBUCKETS];
1558  int rights[HEIGHTBUCKETS];
1559  int modelist[MODENUM];
1560  int blobindex;
1561  int mode_count; //blobs to count in thr
1562  int sign_bit;
1563  int mode_threshold;
1564  const int kBaselineTouch = 2; // This really should change with resolution.
1565  const int kGoodStrength = 8; // Strength of baseline-touching heights.
1566  const float kMinHeight = 0.25; // Min fraction of lineheight to use.
1567 
1568  sign_bit = row->xheight > 0 ? 1 : -1;
1569 
1570  memset(lefts, 0, HEIGHTBUCKETS * sizeof(lefts[0]));
1571  memset(rights, 0, HEIGHTBUCKETS * sizeof(rights[0]));
1572  mode_count = 0;
1573  for (blobindex = 0; blobindex < blobcount; blobindex++) {
1574  int xcenter = (blobcoords[blobindex].left () +
1575  blobcoords[blobindex].right ()) / 2;
1576  float base = baseline->y(xcenter);
1577  float bottomdiff = fabs(base - blobcoords[blobindex].bottom());
1578  int strength = textord_ocropus_mode &&
1579  bottomdiff <= kBaselineTouch ? kGoodStrength : 1;
1580  int height = static_cast<int>(blobcoords[blobindex].top () - base + 0.5);
1581  if (blobcoords[blobindex].height () > init_lineheight * kMinHeight) {
1582  if (height > lineheight * oldbl_xhfract
1583  && height > textord_min_xheight) {
1584  heightstat.add (height, strength);
1585  if (height < HEIGHTBUCKETS) {
1586  if (xcenter > rights[height])
1587  rights[height] = xcenter;
1588  if (xcenter > 0 && (lefts[height] == 0 || xcenter < lefts[height]))
1589  lefts[height] = xcenter;
1590  }
1591  }
1592  mode_count += strength;
1593  }
1594  }
1595 
1596  mode_threshold = (int) (blobcount * 0.1);
1597  if (oldbl_dot_error_size > 1 || oldbl_xhfix)
1598  mode_threshold = (int) (mode_count * 0.1);
1599 
1600  if (textord_oldbl_debug) {
1601  tprintf ("blobcount=%d, mode_count=%d, mode_t=%d\n",
1602  blobcount, mode_count, mode_threshold);
1603  }
1604  find_top_modes(&heightstat, HEIGHTBUCKETS, modelist, MODENUM);
1605  if (textord_oldbl_debug) {
1606  for (blobindex = 0; blobindex < MODENUM; blobindex++)
1607  tprintf ("mode[%d]=%d ", blobindex, modelist[blobindex]);
1608  tprintf ("\n");
1609  }
1610  pick_x_height(row, modelist, lefts, rights, &heightstat, mode_threshold);
1611 
1612  if (textord_oldbl_debug)
1613  tprintf ("Output xheight=%g\n", row->xheight);
1614  if (row->xheight < 0 && textord_oldbl_debug)
1615  tprintf ("warning: Row Line height < 0; %4.2f\n", row->xheight);
1616 
1617  if (sign_bit < 0)
1618  row->xheight = -row->xheight;
1619 }
void * base[2]
Definition: tessarray.h:53
EXTERN bool textord_ocropus_mode
Definition: oldbasel.cpp:48
void find_top_modes(STATS *stats, int statnum, int modelist[], int modenum)
Definition: oldbasel.cpp:1632
EXTERN bool textord_oldbl_debug
Definition: oldbasel.cpp:40
inT16 left() const
Definition: rect.h:67
inT16 right() const
Definition: rect.h:74
EXTERN double oldbl_xhfract
Definition: oldbasel.cpp:49
EXTERN double oldbl_dot_error_size
Definition: oldbasel.cpp:52
inT16 top() const
Definition: rect.h:53
void pick_x_height(TO_ROW *row, int modelist[], int lefts[], int rights[], STATS *heightstat, int mode_threshold)
Definition: oldbasel.cpp:1672
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:41
int textord_min_xheight
Definition: makerow.cpp:70
EXTERN bool oldbl_xhfix
Definition: oldbasel.cpp:47
Definition: statistc.h:29
double y(double x) const
Definition: quspline.cpp:217
float xheight
Definition: blobbox.h:629
#define HEIGHTBUCKETS
Definition: oldbasel.cpp:66
#define MODENUM
Definition: oldbasel.cpp:70
void make_holed_baseline ( TBOX  blobcoords[],
int  blobcount,
QSPLINE spline,
QSPLINE baseline,
float  gradient 
)

Definition at line 660 of file oldbasel.cpp.

666  {
667  int leftedge; /*left edge of line */
668  int rightedge; /*right edge of line */
669  int blobindex; /*current blob */
670  float x; //centre of row
671  ICOORD shift; //shift of spline
672 
673  tesseract::DetLineFit lms; // straight baseline
674  inT32 xstarts[2]; //straight line
675  double coeffs[3];
676  float c; //line parameter
677 
678  /*left edge of row */
679  leftedge = blobcoords[0].left ();
680  /*right edge of line */
681  rightedge = blobcoords[blobcount - 1].right();
682  for (blobindex = 0; blobindex < blobcount; blobindex++) {
683  lms.Add(ICOORD((blobcoords[blobindex].left() +
684  blobcoords[blobindex].right()) / 2,
685  blobcoords[blobindex].bottom()));
686  }
687  lms.ConstrainedFit(gradient, &c);
688  xstarts[0] = leftedge;
689  xstarts[1] = rightedge;
690  coeffs[0] = 0;
691  coeffs[1] = gradient;
692  coeffs[2] = c;
693  *baseline = QSPLINE (1, xstarts, coeffs);
694  if (spline != NULL /*no given spline */
695  && spline->segments >= 3 /*or trivial */
696  /*or too non-overlap */
697  && spline->xcoords[1] <= leftedge + MAXOVERLAP * (rightedge - leftedge)
698  && spline->xcoords[spline->segments - 1] >= rightedge
699  - MAXOVERLAP * (rightedge - leftedge)) {
700  *baseline = *spline; /*copy it */
701  x = (leftedge + rightedge) / 2.0;
702  shift = ICOORD (0, (inT16) (gradient * x + c - spline->y (x)));
703  baseline->move (shift);
704  }
705 }
void Add(const ICOORD &pt)
Definition: detlinefit.cpp:41
#define NULL
Definition: host.h:144
inT16 left() const
Definition: rect.h:67
int inT32
Definition: host.h:102
inT16 right() const
Definition: rect.h:74
#define MAXOVERLAP
Definition: oldbasel.cpp:64
double ConstrainedFit(double m, float *c)
Definition: detlinefit.cpp:159
void move(ICOORD vec)
Definition: quspline.cpp:259
short inT16
Definition: host.h:100
integer coordinate
Definition: points.h:30
double y(double x) const
Definition: quspline.cpp:217
void merge_oldbl_parts ( TBOX  blobcoords[],
int  blobcount,
char  partids[],
int  partsizes[],
int  biggestpart,
float  jumplimit 
)

Definition at line 799 of file oldbasel.cpp.

806  {
807  BOOL8 found_one; //found a bestpart blob
808  BOOL8 close_one; //found was close enough
809  register int blobindex; /*no along text line */
810  int prevpart; //previous iteration
811  int runlength; //no in this part
812  float diff; /*difference from line */
813  int startx; /*index of start blob */
814  int test_blob; //another index
815  FCOORD coord; //blob coordinate
816  float m, c; //fitted line
817  QLSQ stats; //line stuff
818 
819  prevpart = biggestpart;
820  runlength = 0;
821  startx = 0;
822  for (blobindex = 0; blobindex < blobcount; blobindex++) {
823  if (partids[blobindex] != prevpart) {
824  // tprintf("Partition change at (%d,%d) from %d to %d after run of %d\n",
825  // blobcoords[blobindex].left(),blobcoords[blobindex].bottom(),
826  // prevpart,partids[blobindex],runlength);
827  if (prevpart != biggestpart && runlength > MAXBADRUN) {
828  stats.clear ();
829  for (test_blob = startx; test_blob < blobindex; test_blob++) {
830  coord = FCOORD ((blobcoords[test_blob].left ()
831  + blobcoords[test_blob].right ()) / 2.0,
832  blobcoords[test_blob].bottom ());
833  stats.add (coord.x (), coord.y ());
834  }
835  stats.fit (1);
836  m = stats.get_b ();
837  c = stats.get_c ();
839  tprintf ("Fitted line y=%g x + %g\n", m, c);
840  found_one = FALSE;
841  close_one = FALSE;
842  for (test_blob = 1; !found_one
843  && (startx - test_blob >= 0
844  || blobindex + test_blob <= blobcount); test_blob++) {
845  if (startx - test_blob >= 0
846  && partids[startx - test_blob] == biggestpart) {
847  found_one = TRUE;
848  coord = FCOORD ((blobcoords[startx - test_blob].left ()
849  + blobcoords[startx -
850  test_blob].right ()) /
851  2.0,
852  blobcoords[startx -
853  test_blob].bottom ());
854  diff = m * coord.x () + c - coord.y ();
856  tprintf
857  ("Diff of common blob to suspect part=%g at (%g,%g)\n",
858  diff, coord.x (), coord.y ());
859  if (diff < jumplimit && -diff < jumplimit)
860  close_one = TRUE;
861  }
862  if (blobindex + test_blob <= blobcount
863  && partids[blobindex + test_blob - 1] == biggestpart) {
864  found_one = TRUE;
865  coord =
866  FCOORD ((blobcoords[blobindex + test_blob - 1].
867  left () + blobcoords[blobindex + test_blob -
868  1].right ()) / 2.0,
869  blobcoords[blobindex + test_blob -
870  1].bottom ());
871  diff = m * coord.x () + c - coord.y ();
873  tprintf
874  ("Diff of common blob to suspect part=%g at (%g,%g)\n",
875  diff, coord.x (), coord.y ());
876  if (diff < jumplimit && -diff < jumplimit)
877  close_one = TRUE;
878  }
879  }
880  if (close_one) {
882  tprintf
883  ("Merged %d blobs back into part %d from %d starting at (%d,%d)\n",
884  runlength, biggestpart, prevpart,
885  blobcoords[startx].left (),
886  blobcoords[startx].bottom ());
887  //switch sides
888  partsizes[prevpart] -= runlength;
889  for (test_blob = startx; test_blob < blobindex; test_blob++)
890  partids[test_blob] = biggestpart;
891  }
892  }
893  prevpart = partids[blobindex];
894  runlength = 1;
895  startx = blobindex;
896  }
897  else
898  runlength++;
899  }
900 }
void fit(int degree)
Definition: quadlsq.cpp:105
Definition: quadlsq.h:25
double get_b()
Definition: quadlsq.h:48
unsigned char BOOL8
Definition: host.h:113
EXTERN bool textord_oldbl_debug
Definition: oldbasel.cpp:40
double get_c()
Definition: quadlsq.h:51
#define FALSE
Definition: capi.h:28
void clear()
Definition: quadlsq.cpp:36
void add(double x, double y)
Definition: quadlsq.cpp:58
#define MAXBADRUN
Definition: oldbasel.cpp:65
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:41
Definition: points.h:189
float y() const
Definition: points.h:212
float x() const
Definition: points.h:209
#define TRUE
Definition: capi.h:27
void old_first_xheight ( TO_ROW row,
TBOX  blobcoords[],
int  initialheight,
int  blobcount,
QSPLINE baseline,
float  jumplimit 
)

Definition at line 1462 of file oldbasel.cpp.

1469  {
1470  register int blobindex; /*current blob */
1471  /*height statistics */
1472  STATS heightstat (0, MAXHEIGHT);
1473  int height; /*height of blob */
1474  int xcentre; /*centre of blob */
1475  int lineheight; /*approx xheight */
1476  float ascenders; /*ascender sum */
1477  int asccount; /*no of ascenders */
1478  float xsum; /*xheight sum */
1479  int xcount; /*xheight count */
1480  register float diff; /*height difference */
1481 
1482  if (blobcount > 1) {
1483  for (blobindex = 0; blobindex < blobcount; blobindex++) {
1484  xcentre = (blobcoords[blobindex].left ()
1485  + blobcoords[blobindex].right ()) / 2;
1486  /*height of blob */
1487  height = (int) (blobcoords[blobindex].top () - baseline->y (xcentre) + 0.5);
1488  if (height > initialheight * oldbl_xhfract
1489  && height > textord_min_xheight)
1490  heightstat.add (height, 1);
1491  }
1492  if (heightstat.get_total () > 3) {
1493  lineheight = (int) heightstat.ile (0.25);
1494  if (lineheight <= 0)
1495  lineheight = (int) heightstat.ile (0.5);
1496  }
1497  else
1498  lineheight = initialheight;
1499  }
1500  else {
1501  lineheight = (int) (blobcoords[0].top ()
1502  - baseline->y ((blobcoords[0].left ()
1503  + blobcoords[0].right ()) / 2) +
1504  0.5);
1505  }
1506 
1507  xsum = 0.0f;
1508  xcount = 0;
1509  for (ascenders = 0.0f, asccount = 0, blobindex = 0; blobindex < blobcount;
1510  blobindex++) {
1511  xcentre = (blobcoords[blobindex].left ()
1512  + blobcoords[blobindex].right ()) / 2;
1513  diff = blobcoords[blobindex].top () - baseline->y (xcentre);
1514  /*is it ascender */
1515  if (diff > lineheight + jumplimit) {
1516  ascenders += diff;
1517  asccount++; /*count ascenders */
1518  }
1519  else if (diff > lineheight - jumplimit) {
1520  xsum += diff; /*mean xheight */
1521  xcount++;
1522  }
1523  }
1524  if (xcount > 0)
1525  xsum /= xcount; /*average xheight */
1526  else
1527  xsum = (float) lineheight; /*guess it */
1528  row->xheight *= xsum;
1529  if (asccount > 0)
1530  row->ascrise = ascenders / asccount - xsum;
1531  else
1532  row->ascrise = 0.0f; /*had none */
1533  if (row->xheight == 0)
1534  row->xheight = -1.0f;
1535 }
inT16 left() const
Definition: rect.h:67
#define f(xc, yc)
Definition: imgscale.cpp:39
inT16 right() const
Definition: rect.h:74
EXTERN double oldbl_xhfract
Definition: oldbasel.cpp:49
float ascrise
Definition: blobbox.h:631
inT16 top() const
Definition: rect.h:53
int textord_min_xheight
Definition: makerow.cpp:70
Definition: statistc.h:29
#define MAXHEIGHT
Definition: oldbasel.cpp:63
double y(double x) const
Definition: quspline.cpp:217
size_t top
Definition: tessarray.h:52
float xheight
Definition: blobbox.h:629
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 at line 1090 of file oldbasel.cpp.

1097  {
1098  register int blobindex; /*no along text line */
1099  int pointcount; /*no of points */
1100 
1101  pointcount = 0;
1102  for (blobindex = 0; blobindex < blobcount; blobindex++) {
1103  if (partids[blobindex] == bestpart) {
1104  /*centre of blob */
1105  xcoords[pointcount] = (blobcoords[blobindex].left () + blobcoords[blobindex].right ()) >> 1;
1106  ycoords[pointcount++] = blobcoords[blobindex].bottom ();
1107  }
1108  }
1109  return pointcount; /*no of points found */
1110 }
inT16 left() const
Definition: rect.h:67
inT16 right() const
Definition: rect.h:74
inT16 bottom() const
Definition: rect.h:60
int partition_line ( TBOX  blobcoords[],
int  blobcount,
int *  numparts,
char  partids[],
int  partsizes[],
QSPLINE spline,
float  jumplimit,
float  ydiffs[] 
)

Definition at line 718 of file oldbasel.cpp.

727  {
728  register int blobindex; /*no along text line */
729  int bestpart; /*best new partition */
730  int biggestpart; /*part with most members */
731  float diff; /*difference from line */
732  int startx; /*index of start blob */
733  float partdiffs[MAXPARTS]; /*step between parts */
734 
735  for (bestpart = 0; bestpart < MAXPARTS; bestpart++)
736  partsizes[bestpart] = 0; /*zero them all */
737 
738  startx = get_ydiffs (blobcoords, blobcount, spline, ydiffs);
739  *numparts = 1; /*1 partition */
740  bestpart = -1; /*first point */
741  float drift = 0.0f;
742  float last_delta = 0.0f;
743  for (blobindex = startx; blobindex < blobcount; blobindex++) {
744  /*do each blob in row */
745  diff = ydiffs[blobindex]; /*diff from line */
746  if (textord_oldbl_debug) {
747  tprintf ("%d(%d,%d), ", blobindex,
748  blobcoords[blobindex].left (),
749  blobcoords[blobindex].bottom ());
750  }
751  bestpart = choose_partition(diff, partdiffs, bestpart, jumplimit,
752  &drift, &last_delta, numparts);
753  /*record partition */
754  partids[blobindex] = bestpart;
755  partsizes[bestpart]++; /*another in it */
756  }
757 
758  bestpart = -1; /*first point */
759  drift = 0.0f;
760  last_delta = 0.0f;
761  partsizes[0]--; /*doing 1st pt again */
762  /*do each blob in row */
763  for (blobindex = startx; blobindex >= 0; blobindex--) {
764  diff = ydiffs[blobindex]; /*diff from line */
765  if (textord_oldbl_debug) {
766  tprintf ("%d(%d,%d), ", blobindex,
767  blobcoords[blobindex].left (),
768  blobcoords[blobindex].bottom ());
769  }
770  bestpart = choose_partition(diff, partdiffs, bestpart, jumplimit,
771  &drift, &last_delta, numparts);
772  /*record partition */
773  partids[blobindex] = bestpart;
774  partsizes[bestpart]++; /*another in it */
775  }
776 
777  for (biggestpart = 0, bestpart = 1; bestpart < *numparts; bestpart++)
778  if (partsizes[bestpart] >= partsizes[biggestpart])
779  biggestpart = bestpart; /*new biggest */
781  merge_oldbl_parts(blobcoords,
782  blobcount,
783  partids,
784  partsizes,
785  biggestpart,
786  jumplimit);
787  return biggestpart; /*biggest partition */
788 }
EXTERN bool textord_oldbl_debug
Definition: oldbasel.cpp:40
int choose_partition(register float diff, float partdiffs[], int lastpart, float jumplimit, float *drift, float *lastdelta, int *partcount)
Definition: oldbasel.cpp:963
EXTERN bool textord_oldbl_merge_parts
Definition: oldbasel.cpp:44
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:41
int get_ydiffs(TBOX blobcoords[], int blobcount, QSPLINE *spline, float ydiffs[])
Definition: oldbasel.cpp:912
#define MAXPARTS
Definition: oldbasel.cpp:71
void merge_oldbl_parts(TBOX blobcoords[], int blobcount, char partids[], int partsizes[], int biggestpart, float jumplimit)
Definition: oldbasel.cpp:799
void pick_x_height ( TO_ROW row,
int  modelist[],
int  lefts[],
int  rights[],
STATS heightstat,
int  mode_threshold 
)

Definition at line 1672 of file oldbasel.cpp.

1676  {
1677  int x;
1678  int y;
1679  int z;
1680  float ratio;
1681  int found_one_bigger = FALSE;
1682  int best_x_height = 0;
1683  int best_asc = 0;
1684  int num_in_best;
1685 
1686  for (x = 0; x < MODENUM; x++) {
1687  for (y = 0; y < MODENUM; y++) {
1688  /* Check for two modes */
1689  if (modelist[x] && modelist[y] &&
1690  heightstat->pile_count (modelist[x]) > mode_threshold &&
1692  MIN(rights[modelist[x]], rights[modelist[y]]) >
1693  MAX(lefts[modelist[x]], lefts[modelist[y]]))) {
1694  ratio = (float) modelist[y] / (float) modelist[x];
1695  if (1.2 < ratio && ratio < 1.8) {
1696  /* Two modes found */
1697  best_x_height = modelist[x];
1698  num_in_best = heightstat->pile_count (modelist[x]);
1699 
1700  /* Try to get one higher */
1701  do {
1702  found_one_bigger = FALSE;
1703  for (z = 0; z < MODENUM; z++) {
1704  if (modelist[z] == best_x_height + 1 &&
1706  MIN(rights[modelist[x]], rights[modelist[y]]) >
1707  MAX(lefts[modelist[x]], lefts[modelist[y]]))) {
1708  ratio = (float) modelist[y] / (float) modelist[z];
1709  if ((1.2 < ratio && ratio < 1.8) &&
1710  /* Should be half of best */
1711  heightstat->pile_count (modelist[z]) >
1712  num_in_best * 0.5) {
1713  best_x_height++;
1714  found_one_bigger = TRUE;
1715  break;
1716  }
1717  }
1718  }
1719  }
1720  while (found_one_bigger);
1721 
1722  /* try to get a higher ascender */
1723 
1724  best_asc = modelist[y];
1725  num_in_best = heightstat->pile_count (modelist[y]);
1726 
1727  /* Try to get one higher */
1728  do {
1729  found_one_bigger = FALSE;
1730  for (z = 0; z < MODENUM; z++) {
1731  if (modelist[z] > best_asc &&
1733  MIN(rights[modelist[x]], rights[modelist[y]]) >
1734  MAX(lefts[modelist[x]], lefts[modelist[y]]))) {
1735  ratio = (float) modelist[z] / (float) best_x_height;
1736  if ((1.2 < ratio && ratio < 1.8) &&
1737  /* Should be half of best */
1738  heightstat->pile_count (modelist[z]) >
1739  num_in_best * 0.5) {
1740  best_asc = modelist[z];
1741  found_one_bigger = TRUE;
1742  break;
1743  }
1744  }
1745  }
1746  }
1747  while (found_one_bigger);
1748 
1749  row->xheight = (float) best_x_height;
1750  row->ascrise = (float) best_asc - best_x_height;
1751  return;
1752  }
1753  }
1754  }
1755  }
1756 
1757  best_x_height = modelist[0]; /* Single Mode found */
1758  num_in_best = heightstat->pile_count (best_x_height);
1759  do {
1760  /* Try to get one higher */
1761  found_one_bigger = FALSE;
1762  for (z = 1; z < MODENUM; z++) {
1763  /* Should be half of best */
1764  if ((modelist[z] == best_x_height + 1) &&
1765  (heightstat->pile_count (modelist[z]) > num_in_best * 0.5)) {
1766  best_x_height++;
1767  found_one_bigger = TRUE;
1768  break;
1769  }
1770  }
1771  }
1772  while (found_one_bigger);
1773 
1774  row->ascrise = 0.0f;
1775  row->xheight = (float) best_x_height;
1776  if (row->xheight == 0)
1777  row->xheight = -1.0f;
1778 }
EXTERN bool textord_ocropus_mode
Definition: oldbasel.cpp:48
#define FALSE
Definition: capi.h:28
inT32 pile_count(inT32 value) const
Definition: statistc.h:74
float ascrise
Definition: blobbox.h:631
#define MIN(x, y)
Definition: ndminx.h:28
float xheight
Definition: blobbox.h:629
#define MAX(x, y)
Definition: ndminx.h:24
#define MODENUM
Definition: oldbasel.cpp:70
#define TRUE
Definition: capi.h:27
int segment_spline ( TBOX  blobcoords[],
int  blobcount,
int  xcoords[],
int  ycoords[],
int  degree,
int  pointcount,
int  xstarts[] 
)

Definition at line 1121 of file oldbasel.cpp.

1128  {
1129  register int ptindex; /*no along text line */
1130  register int segment; /*partition no */
1131  int lastmin, lastmax; /*possible turn points */
1132  int turnpoints[SPLINESIZE]; /*good turning points */
1133  int turncount; /*no of turning points */
1134  int max_x; //max specified coord
1135 
1136  xstarts[0] = xcoords[0] - 1; //leftmost defined pt
1137  max_x = xcoords[pointcount - 1] + 1;
1138  if (degree < 2)
1139  pointcount = 0;
1140  turncount = 0; /*no turning points yet */
1141  if (pointcount > 3) {
1142  ptindex = 1;
1143  lastmax = lastmin = 0; /*start with first one */
1144  while (ptindex < pointcount - 1 && turncount < SPLINESIZE - 1) {
1145  /*minimum */
1146  if (ycoords[ptindex - 1] > ycoords[ptindex] && ycoords[ptindex] <= ycoords[ptindex + 1]) {
1147  if (ycoords[ptindex] < ycoords[lastmax] - TURNLIMIT) {
1148  if (turncount == 0 || turnpoints[turncount - 1] != lastmax)
1149  /*new max point */
1150  turnpoints[turncount++] = lastmax;
1151  lastmin = ptindex; /*latest minimum */
1152  }
1153  else if (ycoords[ptindex] < ycoords[lastmin]) {
1154  lastmin = ptindex; /*lower minimum */
1155  }
1156  }
1157 
1158  /*maximum */
1159  if (ycoords[ptindex - 1] < ycoords[ptindex] && ycoords[ptindex] >= ycoords[ptindex + 1]) {
1160  if (ycoords[ptindex] > ycoords[lastmin] + TURNLIMIT) {
1161  if (turncount == 0 || turnpoints[turncount - 1] != lastmin)
1162  /*new min point */
1163  turnpoints[turncount++] = lastmin;
1164  lastmax = ptindex; /*latest maximum */
1165  }
1166  else if (ycoords[ptindex] > ycoords[lastmax]) {
1167  lastmax = ptindex; /*higher maximum */
1168  }
1169  }
1170  ptindex++;
1171  }
1172  /*possible global min */
1173  if (ycoords[ptindex] < ycoords[lastmax] - TURNLIMIT
1174  && (turncount == 0 || turnpoints[turncount - 1] != lastmax)) {
1175  if (turncount < SPLINESIZE - 1)
1176  /*2 more turns */
1177  turnpoints[turncount++] = lastmax;
1178  if (turncount < SPLINESIZE - 1)
1179  turnpoints[turncount++] = ptindex;
1180  }
1181  else if (ycoords[ptindex] > ycoords[lastmin] + TURNLIMIT
1182  /*possible global max */
1183  && (turncount == 0 || turnpoints[turncount - 1] != lastmin)) {
1184  if (turncount < SPLINESIZE - 1)
1185  /*2 more turns */
1186  turnpoints[turncount++] = lastmin;
1187  if (turncount < SPLINESIZE - 1)
1188  turnpoints[turncount++] = ptindex;
1189  }
1190  else if (turncount > 0 && turnpoints[turncount - 1] == lastmin
1191  && turncount < SPLINESIZE - 1) {
1192  if (ycoords[ptindex] > ycoords[lastmax])
1193  turnpoints[turncount++] = ptindex;
1194  else
1195  turnpoints[turncount++] = lastmax;
1196  }
1197  else if (turncount > 0 && turnpoints[turncount - 1] == lastmax
1198  && turncount < SPLINESIZE - 1) {
1199  if (ycoords[ptindex] < ycoords[lastmin])
1200  turnpoints[turncount++] = ptindex;
1201  else
1202  turnpoints[turncount++] = lastmin;
1203  }
1204  }
1205 
1206  if (textord_oldbl_debug && turncount > 0)
1207  tprintf ("First turn is %d at (%d,%d)\n",
1208  turnpoints[0], xcoords[turnpoints[0]], ycoords[turnpoints[0]]);
1209  for (segment = 1; segment < turncount; segment++) {
1210  /*centre y coord */
1211  lastmax = (ycoords[turnpoints[segment - 1]] + ycoords[turnpoints[segment]]) / 2;
1212 
1213  /* fix alg so that it works with both rising and falling sections */
1214  if (ycoords[turnpoints[segment - 1]] < ycoords[turnpoints[segment]])
1215  /*find rising y centre */
1216  for (ptindex = turnpoints[segment - 1] + 1; ptindex < turnpoints[segment] && ycoords[ptindex + 1] <= lastmax; ptindex++);
1217  else
1218  /*find falling y centre */
1219  for (ptindex = turnpoints[segment - 1] + 1; ptindex < turnpoints[segment] && ycoords[ptindex + 1] >= lastmax; ptindex++);
1220 
1221  /*centre x */
1222  xstarts[segment] = (xcoords[ptindex - 1] + xcoords[ptindex]
1223  + xcoords[turnpoints[segment - 1]]
1224  + xcoords[turnpoints[segment]] + 2) / 4;
1225  /*halfway between turns */
1226  if (textord_oldbl_debug)
1227  tprintf ("Turn %d is %d at (%d,%d), mid pt is %d@%d, final @%d\n",
1228  segment, turnpoints[segment],
1229  xcoords[turnpoints[segment]], ycoords[turnpoints[segment]],
1230  ptindex - 1, xcoords[ptindex - 1], xstarts[segment]);
1231  }
1232 
1233  xstarts[segment] = max_x;
1234  return segment; /*no of splines */
1235 }
EXTERN bool textord_oldbl_debug
Definition: oldbasel.cpp:40
#define SPLINESIZE
Definition: oldbasel.cpp:72
#define TURNLIMIT
Definition: oldbasel.cpp:56
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:41
BOOL8 split_stepped_spline ( QSPLINE baseline,
float  jumplimit,
int  xcoords[],
int  xstarts[],
int &  segments 
)

Definition at line 1246 of file oldbasel.cpp.

1252  {
1253  BOOL8 doneany; //return value
1254  register int segment; /*partition no */
1255  int startindex, centreindex, endindex;
1256  float leftcoord, rightcoord;
1257  int leftindex, rightindex;
1258  float step; //spline step
1259 
1260  doneany = FALSE;
1261  startindex = 0;
1262  for (segment = 1; segment < segments - 1; segment++) {
1263  step = baseline->step ((xstarts[segment - 1] + xstarts[segment]) / 2.0,
1264  (xstarts[segment] + xstarts[segment + 1]) / 2.0);
1265  if (step < 0)
1266  step = -step;
1267  if (step > jumplimit) {
1268  while (xcoords[startindex] < xstarts[segment - 1])
1269  startindex++;
1270  centreindex = startindex;
1271  while (xcoords[centreindex] < xstarts[segment])
1272  centreindex++;
1273  endindex = centreindex;
1274  while (xcoords[endindex] < xstarts[segment + 1])
1275  endindex++;
1276  if (segments >= SPLINESIZE) {
1278  tprintf ("Too many segments to resegment spline!!\n");
1279  }
1280  else if (endindex - startindex >= textord_spline_medianwin * 3) {
1281  while (centreindex - startindex <
1282  textord_spline_medianwin * 3 / 2)
1283  centreindex++;
1284  while (endindex - centreindex <
1285  textord_spline_medianwin * 3 / 2)
1286  centreindex--;
1287  leftindex = (startindex + startindex + centreindex) / 3;
1288  rightindex = (centreindex + endindex + endindex) / 3;
1289  leftcoord =
1290  (xcoords[startindex] * 2 + xcoords[centreindex]) / 3.0;
1291  rightcoord =
1292  (xcoords[centreindex] + xcoords[endindex] * 2) / 3.0;
1293  while (xcoords[leftindex] > leftcoord
1294  && leftindex - startindex > textord_spline_medianwin)
1295  leftindex--;
1296  while (xcoords[leftindex] < leftcoord
1297  && centreindex - leftindex >
1299  leftindex++;
1300  if (xcoords[leftindex] - leftcoord >
1301  leftcoord - xcoords[leftindex - 1])
1302  leftindex--;
1303  while (xcoords[rightindex] > rightcoord
1304  && rightindex - centreindex >
1306  rightindex--;
1307  while (xcoords[rightindex] < rightcoord
1308  && endindex - rightindex > textord_spline_medianwin)
1309  rightindex++;
1310  if (xcoords[rightindex] - rightcoord >
1311  rightcoord - xcoords[rightindex - 1])
1312  rightindex--;
1314  tprintf ("Splitting spline at %d with step %g at (%d,%d)\n",
1315  xstarts[segment],
1316  baseline->
1317  step ((xstarts[segment - 1] +
1318  xstarts[segment]) / 2.0,
1319  (xstarts[segment] +
1320  xstarts[segment + 1]) / 2.0),
1321  (xcoords[leftindex - 1] + xcoords[leftindex]) / 2,
1322  (xcoords[rightindex - 1] + xcoords[rightindex]) / 2);
1323  insert_spline_point (xstarts, segment,
1324  (xcoords[leftindex - 1] +
1325  xcoords[leftindex]) / 2,
1326  (xcoords[rightindex - 1] +
1327  xcoords[rightindex]) / 2, segments);
1328  doneany = TRUE;
1329  }
1330  else if (textord_debug_baselines) {
1331  tprintf
1332  ("Resegmenting spline failed - insufficient pts (%d,%d,%d,%d)\n",
1333  startindex, centreindex, endindex,
1335  }
1336  }
1337  // else tprintf("Spline step at %d is %g\n",
1338  // xstarts[segment],
1339  // baseline->step((xstarts[segment-1]+xstarts[segment])/2.0,
1340  // (xstarts[segment]+xstarts[segment+1])/2.0));
1341  }
1342  return doneany;
1343 }
void insert_spline_point(int xstarts[], int segment, int coord1, int coord2, int &segments)
Definition: oldbasel.cpp:1353
double step(double x1, double x2)
Definition: quspline.cpp:192
unsigned char BOOL8
Definition: host.h:113
EXTERN bool textord_debug_baselines
Definition: oldbasel.cpp:41
int inT32
Definition: host.h:102
#define FALSE
Definition: capi.h:28
int textord_spline_medianwin
Definition: makerow.cpp:67
#define SPLINESIZE
Definition: oldbasel.cpp:72
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:41
#define TRUE
Definition: capi.h:27

Variable Documentation

const int kMinModeFactor = 12

Definition at line 1629 of file oldbasel.cpp.

const int kMinModeFactorOcropus = 32

Definition at line 1628 of file oldbasel.cpp.

EXTERN bool oldbl_corrfix = TRUE

"Improve correlation of heights"

Definition at line 45 of file oldbasel.cpp.

EXTERN double oldbl_dot_error_size = 1.26

"Max aspect ratio of a dot"

Definition at line 52 of file oldbasel.cpp.

EXTERN int oldbl_holed_losscount = 10

"Max lost before fallback line used"

Definition at line 51 of file oldbasel.cpp.

EXTERN bool oldbl_xhfix = FALSE

"Fix bug in modes threshold for xheights"

Definition at line 47 of file oldbasel.cpp.

EXTERN double oldbl_xhfract = 0.4

"Fraction of est allowed in calc"

Definition at line 49 of file oldbasel.cpp.

EXTERN bool textord_debug_baselines = FALSE

"Debug baseline generation"

Definition at line 41 of file oldbasel.cpp.

EXTERN bool textord_ocropus_mode = FALSE

"Make baselines for ocropus"

Definition at line 48 of file oldbasel.cpp.

EXTERN bool textord_oldbl_debug = FALSE

"Debug old baseline generation"

Definition at line 40 of file oldbasel.cpp.

EXTERN double textord_oldbl_jumplimit = 0.15

"X fraction for new partition"

Definition at line 54 of file oldbasel.cpp.

EXTERN bool textord_oldbl_merge_parts = TRUE

"Merge suspect partitions"

Definition at line 44 of file oldbasel.cpp.

EXTERN bool textord_oldbl_paradef = TRUE

"Use para default mechanism"

Definition at line 42 of file oldbasel.cpp.

EXTERN bool textord_oldbl_split_splines = TRUE

"Split stepped splines"

Definition at line 43 of file oldbasel.cpp.

EXTERN bool textord_really_old_xheight = FALSE

"Use original wiseowl xheight"

Definition at line 39 of file oldbasel.cpp.