tesseract  4.0.0-1-g2a2b
oldbasel.h File Reference
#include "params.h"
#include "blobbox.h"

Go to the source code of this file.

Functions

int get_blob_coords (TO_ROW *row, int32_t lineheight, TBOX *blobcoords, bool &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 (float diff, float partdiffs[], int lastpart, float jumplimit, float *drift, float *last_delta, int *partcount)
 
int partition_coords (TBOX blobcoords[], int blobcount, char partids[], int bestpart, int xcoords[], int ycoords[])
 
int segment_spline (TBOX blobcoords[], int blobcount, int xcoords[], int ycoords[], int degree, int pointcount, int xstarts[])
 
bool 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)
 
int * make_height_array (TBOX blobcoords[], int blobcount, QSPLINE *baseline)
 
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

bool textord_really_old_xheight = FALSE
 
bool textord_oldbl_debug = FALSE
 
bool textord_debug_baselines = FALSE
 
bool textord_oldbl_paradef = TRUE
 
bool textord_oldbl_split_splines = TRUE
 
bool textord_oldbl_merge_parts = TRUE
 
bool oldbl_xhfix = FALSE
 
int oldbl_holed_losscount = 10
 
double oldbl_dot_error_size = 1.26
 
double textord_oldbl_jumplimit = 0.15
 

Function Documentation

◆ choose_partition()

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

Definition at line 947 of file oldbasel.cpp.

955  {
956  int partition; /*partition no */
957  int bestpart; /*best new partition */
958  float bestdelta; /*best gap from a part */
959  float delta; /*diff from part */
960 
961  if (lastpart < 0) {
962  partdiffs[0] = diff;
963  lastpart = 0; /*first point */
964  *drift = 0.0f;
965  *lastdelta = 0.0f;
966  }
967  /*adjusted diff from part */
968  delta = diff - partdiffs[lastpart] - *drift;
969  if (textord_oldbl_debug) {
970  tprintf ("Diff=%.2f, Delta=%.3f, Drift=%.3f, ", diff, delta, *drift);
971  }
972  if (ABS (delta) > jumplimit / 2) {
973  /*delta on part 0 */
974  bestdelta = diff - partdiffs[0] - *drift;
975  bestpart = 0; /*0 best so far */
976  for (partition = 1; partition < *partcount; partition++) {
977  delta = diff - partdiffs[partition] - *drift;
978  if (ABS (delta) < ABS (bestdelta)) {
979  bestdelta = delta;
980  bestpart = partition; /*part with nearest jump */
981  }
982  }
983  delta = bestdelta;
984  /*too far away */
985  if (ABS (bestdelta) > jumplimit
986  && *partcount < MAXPARTS) { /*and spare part left */
987  bestpart = (*partcount)++; /*best was new one */
988  /*start new one */
989  partdiffs[bestpart] = diff - *drift;
990  delta = 0.0f;
991  }
992  }
993  else {
994  bestpart = lastpart; /*best was last one */
995  }
996 
997  if (bestpart == lastpart
998  && (ABS (delta - *lastdelta) < jumplimit / 2
999  || ABS (delta) < jumplimit / 2))
1000  /*smooth the drift */
1001  *drift = (3 * *drift + delta) / 3;
1002  *lastdelta = delta;
1003 
1004  if (textord_oldbl_debug) {
1005  tprintf ("P=%d\n", bestpart);
1006  }
1007 
1008  return bestpart;
1009 }
#define MAXPARTS
Definition: oldbasel.cpp:73
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:37
EXTERN bool textord_oldbl_debug
Definition: oldbasel.cpp:42
#define ABS(x)
Definition: oldbasel.cpp:76

◆ find_lesser_parts()

void find_lesser_parts ( TO_ROW row,
TBOX  blobcoords[],
int  blobcount,
char  partids[],
int  partsizes[],
int  partcount,
int  bestpart 
)

Definition at line 1306 of file oldbasel.cpp.

1314  {
1315  int blobindex; /*index of blob */
1316  int partition; /*current partition */
1317  int xcentre; /*centre of blob */
1318  int poscount; /*count of best up step */
1319  int negcount; /*count of best down step */
1320  float partsteps[MAXPARTS]; /*average step to part */
1321  float bestneg; /*best down step */
1322  int runlength; /*length of bad run */
1323  int biggestrun; /*biggest bad run */
1324 
1325  biggestrun = 0;
1326  for (partition = 0; partition < partcount; partition++)
1327  partsteps[partition] = 0.0; /*zero accumulators */
1328  for (runlength = 0, blobindex = 0; blobindex < blobcount; blobindex++) {
1329  xcentre = (blobcoords[blobindex].left ()
1330  + blobcoords[blobindex].right ()) >> 1;
1331  /*in other parts */
1332  int part_id =
1333  static_cast<int>(static_cast<unsigned char>(partids[blobindex]));
1334  if (part_id != bestpart) {
1335  runlength++; /*run of non bests */
1336  if (runlength > biggestrun)
1337  biggestrun = runlength;
1338  partsteps[part_id] += blobcoords[blobindex].bottom()
1339  - row->baseline.y(xcentre);
1340  }
1341  else
1342  runlength = 0;
1343  }
1344  if (biggestrun > MAXBADRUN)
1345  row->xheight = -1.0f; /*failed */
1346  else
1347  row->xheight = 1.0f; /*success */
1348  poscount = negcount = 0;
1349  bestneg = 0.0; /*no step yet */
1350  for (partition = 0; partition < partcount; partition++) {
1351  if (partition != bestpart) {
1352  // by jetsoft divide by zero possible
1353  if (partsizes[partition] == 0)
1354  partsteps[partition] = 0;
1355  else
1356  partsteps[partition] /= partsizes[partition];
1357  //
1358 
1359  if (partsteps[partition] >= MINASCRISE
1360  && partsizes[partition] > poscount) {
1361  poscount = partsizes[partition];
1362  }
1363  if (partsteps[partition] <= -MINASCRISE
1364  && partsizes[partition] > negcount) {
1365  /*ascender rise */
1366  bestneg = partsteps[partition];
1367  /*2nd most popular */
1368  negcount = partsizes[partition];
1369  }
1370  }
1371  }
1372  /*average x-height */
1373  partsteps[bestpart] /= blobcount;
1374  row->descdrop = bestneg;
1375 }
QSPLINE baseline
Definition: blobbox.h:683
float descdrop
Definition: blobbox.h:673
#define MAXPARTS
Definition: oldbasel.cpp:73
#define MAXBADRUN
Definition: oldbasel.cpp:67
double y(double x) const
Definition: quspline.cpp:209
float xheight
Definition: blobbox.h:670
#define MINASCRISE
Definition: oldbasel.cpp:63
int16_t left() const
Definition: rect.h:72
int16_t right() const
Definition: rect.h:79
int16_t bottom() const
Definition: rect.h:65

◆ find_top_modes()

void find_top_modes ( STATS stats,
int  statnum,
int  modelist[],
int  modenum 
)

Definition at line 1557 of file oldbasel.cpp.

1561  {
1562  int mode_count;
1563  int last_i = 0;
1564  int last_max = INT32_MAX;
1565  int i;
1566  int mode;
1567  int total_max = 0;
1568  int mode_factor = textord_ocropus_mode ?
1570 
1571  for (mode_count = 0; mode_count < modenum; mode_count++) {
1572  mode = 0;
1573  for (i = 0; i < statnum; i++) {
1574  if (stats->pile_count (i) > stats->pile_count (mode)) {
1575  if ((stats->pile_count (i) < last_max) ||
1576  ((stats->pile_count (i) == last_max) && (i > last_i))) {
1577  mode = i;
1578  }
1579  }
1580  }
1581  last_i = mode;
1582  last_max = stats->pile_count (last_i);
1583  total_max += last_max;
1584  if (last_max <= total_max / mode_factor)
1585  mode = 0;
1586  modelist[mode_count] = mode;
1587  }
1588 }
int32_t pile_count(int32_t value) const
Definition: statistc.h:78
const int kMinModeFactorOcropus
Definition: oldbasel.cpp:1553
const int kMinModeFactor
Definition: oldbasel.cpp:1554
EXTERN bool textord_ocropus_mode
Definition: oldbasel.cpp:50

◆ get_blob_coords()

int get_blob_coords ( TO_ROW row,
int32_t  lineheight,
TBOX blobcoords,
bool &  holed_line,
int &  outcount 
)

Definition at line 431 of file oldbasel.cpp.

437  {
438  //blobs
439  BLOBNBOX_IT blob_it = row->blob_list ();
440  int blobindex; /*no along text line */
441  int losscount; //lost blobs
442  int maxlosscount; //greatest lost blobs
443  /*height stat collection */
444  STATS heightstat (0, MAXHEIGHT);
445 
446  if (blob_it.empty ())
447  return 0; //none
448  maxlosscount = 0;
449  losscount = 0;
450  blob_it.mark_cycle_pt ();
451  blobindex = 0;
452  do {
453  blobcoords[blobindex] = box_next_pre_chopped (&blob_it);
454  if (blobcoords[blobindex].height () > lineheight * 0.25)
455  heightstat.add (blobcoords[blobindex].height (), 1);
456  if (blobindex == 0
457  || blobcoords[blobindex].height () > lineheight * 0.25
458  || blob_it.cycled_list ()) {
459  blobindex++; /*no of merged blobs */
460  losscount = 0;
461  }
462  else {
463  if (blobcoords[blobindex].height ()
464  < blobcoords[blobindex].width () * oldbl_dot_error_size
465  && blobcoords[blobindex].width ()
466  < blobcoords[blobindex].height () * oldbl_dot_error_size) {
467  //counts as dot
468  blobindex++;
469  losscount = 0;
470  }
471  else {
472  losscount++; //lost it
473  if (losscount > maxlosscount)
474  //remember max
475  maxlosscount = losscount;
476  }
477  }
478  }
479  while (!blob_it.cycled_list ());
480 
481  holed_line = maxlosscount > oldbl_holed_losscount;
482  outcount = blobindex; /*total blobs */
483 
484  if (heightstat.get_total () > 1)
485  /*guess x-height */
486  return (int) heightstat.ile (0.25);
487  else
488  return blobcoords[0].height ();
489 }
TBOX box_next_pre_chopped(BLOBNBOX_IT *it)
Definition: blobbox.cpp:666
EXTERN double oldbl_dot_error_size
Definition: oldbasel.cpp:54
Definition: statistc.h:33
#define MAXHEIGHT
Definition: oldbasel.cpp:65
int16_t width() const
Definition: rect.h:115
EXTERN int oldbl_holed_losscount
Definition: oldbasel.cpp:53
int16_t height() const
Definition: rect.h:108
BLOBNBOX_LIST * blob_list()
Definition: blobbox.h:612

◆ get_ydiffs()

int get_ydiffs ( TBOX  blobcoords[],
int  blobcount,
QSPLINE spline,
float  ydiffs[] 
)

Definition at line 896 of file oldbasel.cpp.

901  {
902  int blobindex; /*current blob */
903  int xcentre; /*xcoord */
904  int lastx; /*last xcentre */
905  float diffsum; /*sum of diffs */
906  float diff; /*current difference */
907  float drift; /*sum of spline steps */
908  float bestsum; /*smallest diffsum */
909  int bestindex; /*index of bestsum */
910 
911  diffsum = 0.0f;
912  bestindex = 0;
913  bestsum = (float) INT32_MAX;
914  drift = 0.0f;
915  lastx = blobcoords[0].left ();
916  /*do each blob in row */
917  for (blobindex = 0; blobindex < blobcount; blobindex++) {
918  /*centre of blob */
919  xcentre = (blobcoords[blobindex].left () + blobcoords[blobindex].right ()) >> 1;
920  //step functions in spline
921  drift += spline->step (lastx, xcentre);
922  lastx = xcentre;
923  diff = blobcoords[blobindex].bottom ();
924  diff -= spline->y (xcentre);
925  diff += drift;
926  ydiffs[blobindex] = diff; /*store difference */
927  if (blobindex > 2)
928  /*remove old one */
929  diffsum -= ABS (ydiffs[blobindex - 3]);
930  diffsum += ABS (diff); /*add new one */
931  if (blobindex >= 2 && diffsum < bestsum) {
932  bestsum = diffsum; /*find min sum */
933  bestindex = blobindex - 1; /*middle of set */
934  }
935  }
936  return bestindex;
937 }
double y(double x) const
Definition: quspline.cpp:209
int16_t left() const
Definition: rect.h:72
double step(double x1, double x2)
Definition: quspline.cpp:184
int16_t right() const
Definition: rect.h:79
int16_t bottom() const
Definition: rect.h:65
#define ABS(x)
Definition: oldbasel.cpp:76

◆ insert_spline_point()

void insert_spline_point ( int  xstarts[],
int  segment,
int  coord1,
int  coord2,
int &  segments 
)

Definition at line 1282 of file oldbasel.cpp.

1287  {
1288  int index; //for shuffling
1289 
1290  for (index = segments; index > segment; index--)
1291  xstarts[index + 1] = xstarts[index];
1292  segments++;
1293  xstarts[segment] = coord1;
1294  xstarts[segment + 1] = coord2;
1295 }

◆ make_first_baseline()

void make_first_baseline ( TBOX  blobcoords[],
int  blobcount,
int  xcoords[],
int  ycoords[],
QSPLINE spline,
QSPLINE baseline,
float  jumplimit 
)

Definition at line 501 of file oldbasel.cpp.

509  {
510  int leftedge; /*left edge of line */
511  int rightedge; /*right edge of line */
512  int blobindex; /*current blob */
513  int segment; /*current segment */
514  float prevy, thisy, nexty; /*3 y coords */
515  float y1, y2, y3; /*3 smooth blobs */
516  float maxmax, minmin; /*absolute limits */
517  int x2 = 0; /*right edge of old y3 */
518  int ycount; /*no of ycoords in use */
519  float yturns[SPLINESIZE]; /*y coords of turn pts */
520  int xturns[SPLINESIZE]; /*xcoords of turn pts */
521  int xstarts[SPLINESIZE + 1];
522  int segments; //no of segments
523  ICOORD shift; //shift of spline
524 
525  prevy = 0;
526  /*left edge of row */
527  leftedge = blobcoords[0].left ();
528  /*right edge of line */
529  rightedge = blobcoords[blobcount - 1].right ();
530  if (spline == nullptr /*no given spline */
531  || spline->segments < 3 /*or trivial */
532  /*or too non-overlap */
533  || spline->xcoords[1] > leftedge + MAXOVERLAP * (rightedge - leftedge)
534  || spline->xcoords[spline->segments - 1] < rightedge
535  - MAXOVERLAP * (rightedge - leftedge)) {
537  return; //use default
538  xstarts[0] = blobcoords[0].left () - 1;
539  for (blobindex = 0; blobindex < blobcount; blobindex++) {
540  xcoords[blobindex] = (blobcoords[blobindex].left ()
541  + blobcoords[blobindex].right ()) / 2;
542  ycoords[blobindex] = blobcoords[blobindex].bottom ();
543  }
544  xstarts[1] = blobcoords[blobcount - 1].right () + 1;
545  segments = 1; /*no of segments */
546 
547  /*linear */
548  *baseline = QSPLINE (xstarts, segments, xcoords, ycoords, blobcount, 1);
549 
550  if (blobcount >= 3) {
551  y1 = y2 = y3 = 0.0f;
552  ycount = 0;
553  segment = 0; /*no of segments */
554  maxmax = minmin = 0.0f;
555  thisy = ycoords[0] - baseline->y (xcoords[0]);
556  nexty = ycoords[1] - baseline->y (xcoords[1]);
557  for (blobindex = 2; blobindex < blobcount; blobindex++) {
558  prevy = thisy; /*shift ycoords */
559  thisy = nexty;
560  nexty = ycoords[blobindex] - baseline->y (xcoords[blobindex]);
561  /*middle of smooth y */
562  if (ABS (thisy - prevy) < jumplimit && ABS (thisy - nexty) < jumplimit) {
563  y1 = y2; /*shift window */
564  y2 = y3;
565  y3 = thisy; /*middle point */
566  ycount++;
567  /*local max */
568  if (ycount >= 3 && ((y1 < y2 && y2 >= y3)
569  /*local min */
570  || (y1 > y2 && y2 <= y3))) {
571  if (segment < SPLINESIZE - 2) {
572  /*turning pt */
573  xturns[segment] = x2;
574  yturns[segment] = y2;
575  segment++; /*no of spline segs */
576  }
577  }
578  if (ycount == 1) {
579  maxmax = minmin = y3;/*initialise limits */
580  }
581  else {
582  if (y3 > maxmax)
583  maxmax = y3; /*biggest max */
584  if (y3 < minmin)
585  minmin = y3; /*smallest min */
586  }
587  /*possible turning pt */
588  x2 = blobcoords[blobindex - 1].right ();
589  }
590  }
591 
592  jumplimit *= 1.2;
593  /*must be wavy */
594  if (maxmax - minmin > jumplimit) {
595  ycount = segment; /*no of segments */
596  for (blobindex = 0, segment = 1; blobindex < ycount;
597  blobindex++) {
598  if (yturns[blobindex] > minmin + jumplimit
599  || yturns[blobindex] < maxmax - jumplimit) {
600  /*significant peak */
601  if (segment == 1
602  || yturns[blobindex] > prevy + jumplimit
603  || yturns[blobindex] < prevy - jumplimit) {
604  /*different to previous */
605  xstarts[segment] = xturns[blobindex];
606  segment++;
607  prevy = yturns[blobindex];
608  }
609  /*bigger max */
610  else if ((prevy > minmin + jumplimit && yturns[blobindex] > prevy)
611  /*smaller min */
612  || (prevy < maxmax - jumplimit && yturns[blobindex] < prevy)) {
613  xstarts[segment - 1] = xturns[blobindex];
614  /*improved previous */
615  prevy = yturns[blobindex];
616  }
617  }
618  }
619  xstarts[segment] = blobcoords[blobcount - 1].right () + 1;
620  segments = segment; /*no of segments */
621  /*linear */
622  *baseline = QSPLINE (xstarts, segments, xcoords, ycoords, blobcount, 1);
623  }
624  }
625  }
626  else {
627  *baseline = *spline; /*copy it */
628  shift = ICOORD (0, (int16_t) (blobcoords[0].bottom ()
629  - spline->y (blobcoords[0].right ())));
630  baseline->move (shift);
631  }
632 }
double y(double x) const
Definition: quspline.cpp:209
EXTERN bool textord_oldbl_paradef
Definition: oldbasel.cpp:44
int16_t left() const
Definition: rect.h:72
integer coordinate
Definition: points.h:32
#define SPLINESIZE
Definition: oldbasel.cpp:74
int16_t right() const
Definition: rect.h:79
#define MAXOVERLAP
Definition: oldbasel.cpp:66
int16_t bottom() const
Definition: rect.h:65
#define ABS(x)
Definition: oldbasel.cpp:76

◆ make_first_xheight()

void make_first_xheight ( TO_ROW row,
TBOX  blobcoords[],
int  lineheight,
int  init_lineheight,
int  blobcount,
QSPLINE baseline,
float  jumplimit 
)

Definition at line 1472 of file oldbasel.cpp.

1480  {
1481  STATS heightstat (0, HEIGHTBUCKETS);
1482  int lefts[HEIGHTBUCKETS];
1483  int rights[HEIGHTBUCKETS];
1484  int modelist[MODENUM];
1485  int blobindex;
1486  int mode_count; //blobs to count in thr
1487  int sign_bit;
1488  int mode_threshold;
1489  const int kBaselineTouch = 2; // This really should change with resolution.
1490  const int kGoodStrength = 8; // Strength of baseline-touching heights.
1491  const float kMinHeight = 0.25; // Min fraction of lineheight to use.
1492 
1493  sign_bit = row->xheight > 0 ? 1 : -1;
1494 
1495  memset(lefts, 0, HEIGHTBUCKETS * sizeof(lefts[0]));
1496  memset(rights, 0, HEIGHTBUCKETS * sizeof(rights[0]));
1497  mode_count = 0;
1498  for (blobindex = 0; blobindex < blobcount; blobindex++) {
1499  int xcenter = (blobcoords[blobindex].left () +
1500  blobcoords[blobindex].right ()) / 2;
1501  float base = baseline->y(xcenter);
1502  float bottomdiff = fabs(base - blobcoords[blobindex].bottom());
1503  int strength = textord_ocropus_mode &&
1504  bottomdiff <= kBaselineTouch ? kGoodStrength : 1;
1505  int height = static_cast<int>(blobcoords[blobindex].top () - base + 0.5);
1506  if (blobcoords[blobindex].height () > init_lineheight * kMinHeight) {
1507  if (height > lineheight * oldbl_xhfract
1508  && height > textord_min_xheight) {
1509  heightstat.add (height, strength);
1510  if (height < HEIGHTBUCKETS) {
1511  if (xcenter > rights[height])
1512  rights[height] = xcenter;
1513  if (xcenter > 0 && (lefts[height] == 0 || xcenter < lefts[height]))
1514  lefts[height] = xcenter;
1515  }
1516  }
1517  mode_count += strength;
1518  }
1519  }
1520 
1521  mode_threshold = (int) (blobcount * 0.1);
1522  if (oldbl_dot_error_size > 1 || oldbl_xhfix)
1523  mode_threshold = (int) (mode_count * 0.1);
1524 
1525  if (textord_oldbl_debug) {
1526  tprintf ("blobcount=%d, mode_count=%d, mode_t=%d\n",
1527  blobcount, mode_count, mode_threshold);
1528  }
1529  find_top_modes(&heightstat, HEIGHTBUCKETS, modelist, MODENUM);
1530  if (textord_oldbl_debug) {
1531  for (blobindex = 0; blobindex < MODENUM; blobindex++)
1532  tprintf ("mode[%d]=%d ", blobindex, modelist[blobindex]);
1533  tprintf ("\n");
1534  }
1535  pick_x_height(row, modelist, lefts, rights, &heightstat, mode_threshold);
1536 
1537  if (textord_oldbl_debug)
1538  tprintf ("Output xheight=%g\n", row->xheight);
1539  if (row->xheight < 0 && textord_oldbl_debug)
1540  tprintf ("warning: Row Line height < 0; %4.2f\n", row->xheight);
1541 
1542  if (sign_bit < 0)
1543  row->xheight = -row->xheight;
1544 }
void find_top_modes(STATS *stats, int statnum, int modelist[], int modenum)
Definition: oldbasel.cpp:1557
EXTERN double oldbl_dot_error_size
Definition: oldbasel.cpp:54
int textord_min_xheight
Definition: makerow.cpp:68
Definition: statistc.h:33
EXTERN double oldbl_xhfract
Definition: oldbasel.cpp:51
float xheight
Definition: blobbox.h:670
int16_t left() const
Definition: rect.h:72
EXTERN bool oldbl_xhfix
Definition: oldbasel.cpp:49
int16_t top() const
Definition: rect.h:58
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:37
EXTERN bool textord_ocropus_mode
Definition: oldbasel.cpp:50
int16_t right() const
Definition: rect.h:79
#define HEIGHTBUCKETS
Definition: oldbasel.cpp:68
#define MODENUM
Definition: oldbasel.cpp:72
void pick_x_height(TO_ROW *row, int modelist[], int lefts[], int rights[], STATS *heightstat, int mode_threshold)
Definition: oldbasel.cpp:1597
EXTERN bool textord_oldbl_debug
Definition: oldbasel.cpp:42

◆ make_height_array()

int* make_height_array ( TBOX  blobcoords[],
int  blobcount,
QSPLINE baseline 
)

◆ make_holed_baseline()

void make_holed_baseline ( TBOX  blobcoords[],
int  blobcount,
QSPLINE spline,
QSPLINE baseline,
float  gradient 
)

Definition at line 644 of file oldbasel.cpp.

650  {
651  int leftedge; /*left edge of line */
652  int rightedge; /*right edge of line */
653  int blobindex; /*current blob */
654  float x; //centre of row
655  ICOORD shift; //shift of spline
656 
657  tesseract::DetLineFit lms; // straight baseline
658  int32_t xstarts[2]; //straight line
659  double coeffs[3];
660  float c; //line parameter
661 
662  /*left edge of row */
663  leftedge = blobcoords[0].left ();
664  /*right edge of line */
665  rightedge = blobcoords[blobcount - 1].right();
666  for (blobindex = 0; blobindex < blobcount; blobindex++) {
667  lms.Add(ICOORD((blobcoords[blobindex].left() +
668  blobcoords[blobindex].right()) / 2,
669  blobcoords[blobindex].bottom()));
670  }
671  lms.ConstrainedFit(gradient, &c);
672  xstarts[0] = leftedge;
673  xstarts[1] = rightedge;
674  coeffs[0] = 0;
675  coeffs[1] = gradient;
676  coeffs[2] = c;
677  *baseline = QSPLINE (1, xstarts, coeffs);
678  if (spline != nullptr /*no given spline */
679  && spline->segments >= 3 /*or trivial */
680  /*or too non-overlap */
681  && spline->xcoords[1] <= leftedge + MAXOVERLAP * (rightedge - leftedge)
682  && spline->xcoords[spline->segments - 1] >= rightedge
683  - MAXOVERLAP * (rightedge - leftedge)) {
684  *baseline = *spline; /*copy it */
685  x = (leftedge + rightedge) / 2.0;
686  shift = ICOORD (0, (int16_t) (gradient * x + c - spline->y (x)));
687  baseline->move (shift);
688  }
689 }
double y(double x) const
Definition: quspline.cpp:209
int16_t left() const
Definition: rect.h:72
void Add(const ICOORD &pt)
Definition: detlinefit.cpp:51
integer coordinate
Definition: points.h:32
int16_t right() const
Definition: rect.h:79
#define MAXOVERLAP
Definition: oldbasel.cpp:66
double ConstrainedFit(const FCOORD &direction, double min_dist, double max_dist, bool debug, ICOORD *line_pt)
Definition: detlinefit.cpp:130

◆ merge_oldbl_parts()

void merge_oldbl_parts ( TBOX  blobcoords[],
int  blobcount,
char  partids[],
int  partsizes[],
int  biggestpart,
float  jumplimit 
)

Definition at line 783 of file oldbasel.cpp.

790  {
791  bool found_one; //found a bestpart blob
792  bool close_one; //found was close enough
793  int blobindex; /*no along text line */
794  int prevpart; //previous iteration
795  int runlength; //no in this part
796  float diff; /*difference from line */
797  int startx; /*index of start blob */
798  int test_blob; //another index
799  FCOORD coord; //blob coordinate
800  float m, c; //fitted line
801  QLSQ stats; //line stuff
802 
803  prevpart = biggestpart;
804  runlength = 0;
805  startx = 0;
806  for (blobindex = 0; blobindex < blobcount; blobindex++) {
807  if (partids[blobindex] != prevpart) {
808  // tprintf("Partition change at (%d,%d) from %d to %d after run of %d\n",
809  // blobcoords[blobindex].left(),blobcoords[blobindex].bottom(),
810  // prevpart,partids[blobindex],runlength);
811  if (prevpart != biggestpart && runlength > MAXBADRUN) {
812  stats.clear ();
813  for (test_blob = startx; test_blob < blobindex; test_blob++) {
814  coord = FCOORD ((blobcoords[test_blob].left ()
815  + blobcoords[test_blob].right ()) / 2.0,
816  blobcoords[test_blob].bottom ());
817  stats.add (coord.x (), coord.y ());
818  }
819  stats.fit (1);
820  m = stats.get_b ();
821  c = stats.get_c ();
823  tprintf ("Fitted line y=%g x + %g\n", m, c);
824  found_one = false;
825  close_one = false;
826  for (test_blob = 1; !found_one
827  && (startx - test_blob >= 0
828  || blobindex + test_blob <= blobcount); test_blob++) {
829  if (startx - test_blob >= 0
830  && partids[startx - test_blob] == biggestpart) {
831  found_one = true;
832  coord = FCOORD ((blobcoords[startx - test_blob].left ()
833  + blobcoords[startx -
834  test_blob].right ()) /
835  2.0,
836  blobcoords[startx -
837  test_blob].bottom ());
838  diff = m * coord.x () + c - coord.y ();
840  tprintf
841  ("Diff of common blob to suspect part=%g at (%g,%g)\n",
842  diff, coord.x (), coord.y ());
843  if (diff < jumplimit && -diff < jumplimit)
844  close_one = true;
845  }
846  if (blobindex + test_blob <= blobcount
847  && partids[blobindex + test_blob - 1] == biggestpart) {
848  found_one = true;
849  coord =
850  FCOORD ((blobcoords[blobindex + test_blob - 1].
851  left () + blobcoords[blobindex + test_blob -
852  1].right ()) / 2.0,
853  blobcoords[blobindex + test_blob -
854  1].bottom ());
855  diff = m * coord.x () + c - coord.y ();
857  tprintf
858  ("Diff of common blob to suspect part=%g at (%g,%g)\n",
859  diff, coord.x (), coord.y ());
860  if (diff < jumplimit && -diff < jumplimit)
861  close_one = true;
862  }
863  }
864  if (close_one) {
866  tprintf
867  ("Merged %d blobs back into part %d from %d starting at (%d,%d)\n",
868  runlength, biggestpart, prevpart,
869  blobcoords[startx].left (),
870  blobcoords[startx].bottom ());
871  //switch sides
872  partsizes[prevpart] -= runlength;
873  for (test_blob = startx; test_blob < blobindex; test_blob++)
874  partids[test_blob] = biggestpart;
875  }
876  }
877  prevpart = partids[blobindex];
878  runlength = 1;
879  startx = blobindex;
880  }
881  else
882  runlength++;
883  }
884 }
#define MAXBADRUN
Definition: oldbasel.cpp:67
void fit(int degree)
Definition: quadlsq.cpp:100
double get_c()
Definition: quadlsq.h:51
void add(double x, double y)
Definition: quadlsq.cpp:56
void clear()
Definition: quadlsq.cpp:34
Definition: quadlsq.h:25
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:37
Definition: points.h:189
float x() const
Definition: points.h:208
double get_b()
Definition: quadlsq.h:48
EXTERN bool textord_oldbl_debug
Definition: oldbasel.cpp:42
float y() const
Definition: points.h:211

◆ old_first_xheight()

void old_first_xheight ( TO_ROW row,
TBOX  blobcoords[],
int  initialheight,
int  blobcount,
QSPLINE baseline,
float  jumplimit 
)

Definition at line 1387 of file oldbasel.cpp.

1394  {
1395  int blobindex; /*current blob */
1396  /*height statistics */
1397  STATS heightstat (0, MAXHEIGHT);
1398  int height; /*height of blob */
1399  int xcentre; /*centre of blob */
1400  int lineheight; /*approx xheight */
1401  float ascenders; /*ascender sum */
1402  int asccount; /*no of ascenders */
1403  float xsum; /*xheight sum */
1404  int xcount; /*xheight count */
1405  float diff; /*height difference */
1406 
1407  if (blobcount > 1) {
1408  for (blobindex = 0; blobindex < blobcount; blobindex++) {
1409  xcentre = (blobcoords[blobindex].left ()
1410  + blobcoords[blobindex].right ()) / 2;
1411  /*height of blob */
1412  height = (int) (blobcoords[blobindex].top () - baseline->y (xcentre) + 0.5);
1413  if (height > initialheight * oldbl_xhfract
1414  && height > textord_min_xheight)
1415  heightstat.add (height, 1);
1416  }
1417  if (heightstat.get_total () > 3) {
1418  lineheight = (int) heightstat.ile (0.25);
1419  if (lineheight <= 0)
1420  lineheight = (int) heightstat.ile (0.5);
1421  }
1422  else
1423  lineheight = initialheight;
1424  }
1425  else {
1426  lineheight = (int) (blobcoords[0].top ()
1427  - baseline->y ((blobcoords[0].left ()
1428  + blobcoords[0].right ()) / 2) +
1429  0.5);
1430  }
1431 
1432  xsum = 0.0f;
1433  xcount = 0;
1434  for (ascenders = 0.0f, asccount = 0, blobindex = 0; blobindex < blobcount;
1435  blobindex++) {
1436  xcentre = (blobcoords[blobindex].left ()
1437  + blobcoords[blobindex].right ()) / 2;
1438  diff = blobcoords[blobindex].top () - baseline->y (xcentre);
1439  /*is it ascender */
1440  if (diff > lineheight + jumplimit) {
1441  ascenders += diff;
1442  asccount++; /*count ascenders */
1443  }
1444  else if (diff > lineheight - jumplimit) {
1445  xsum += diff; /*mean xheight */
1446  xcount++;
1447  }
1448  }
1449  if (xcount > 0)
1450  xsum /= xcount; /*average xheight */
1451  else
1452  xsum = (float) lineheight; /*guess it */
1453  row->xheight *= xsum;
1454  if (asccount > 0)
1455  row->ascrise = ascenders / asccount - xsum;
1456  else
1457  row->ascrise = 0.0f; /*had none */
1458  if (row->xheight == 0)
1459  row->xheight = -1.0f;
1460 }
int textord_min_xheight
Definition: makerow.cpp:68
Definition: statistc.h:33
EXTERN double oldbl_xhfract
Definition: oldbasel.cpp:51
#define MAXHEIGHT
Definition: oldbasel.cpp:65
float xheight
Definition: blobbox.h:670
int16_t left() const
Definition: rect.h:72
int16_t top() const
Definition: rect.h:58
float ascrise
Definition: blobbox.h:672
int16_t right() const
Definition: rect.h:79

◆ partition_coords()

int partition_coords ( TBOX  blobcoords[],
int  blobcount,
char  partids[],
int  bestpart,
int  xcoords[],
int  ycoords[] 
)

Definition at line 1019 of file oldbasel.cpp.

1026  {
1027  int blobindex; /*no along text line */
1028  int pointcount; /*no of points */
1029 
1030  pointcount = 0;
1031  for (blobindex = 0; blobindex < blobcount; blobindex++) {
1032  if (partids[blobindex] == bestpart) {
1033  /*centre of blob */
1034  xcoords[pointcount] = (blobcoords[blobindex].left () + blobcoords[blobindex].right ()) >> 1;
1035  ycoords[pointcount++] = blobcoords[blobindex].bottom ();
1036  }
1037  }
1038  return pointcount; /*no of points found */
1039 }
int16_t left() const
Definition: rect.h:72
int16_t right() const
Definition: rect.h:79
int16_t bottom() const
Definition: rect.h:65

◆ partition_line()

int partition_line ( TBOX  blobcoords[],
int  blobcount,
int *  numparts,
char  partids[],
int  partsizes[],
QSPLINE spline,
float  jumplimit,
float  ydiffs[] 
)

Definition at line 702 of file oldbasel.cpp.

711  {
712  int blobindex; /*no along text line */
713  int bestpart; /*best new partition */
714  int biggestpart; /*part with most members */
715  float diff; /*difference from line */
716  int startx; /*index of start blob */
717  float partdiffs[MAXPARTS]; /*step between parts */
718 
719  for (bestpart = 0; bestpart < MAXPARTS; bestpart++)
720  partsizes[bestpart] = 0; /*zero them all */
721 
722  startx = get_ydiffs (blobcoords, blobcount, spline, ydiffs);
723  *numparts = 1; /*1 partition */
724  bestpart = -1; /*first point */
725  float drift = 0.0f;
726  float last_delta = 0.0f;
727  for (blobindex = startx; blobindex < blobcount; blobindex++) {
728  /*do each blob in row */
729  diff = ydiffs[blobindex]; /*diff from line */
730  if (textord_oldbl_debug) {
731  tprintf ("%d(%d,%d), ", blobindex,
732  blobcoords[blobindex].left (),
733  blobcoords[blobindex].bottom ());
734  }
735  bestpart = choose_partition(diff, partdiffs, bestpart, jumplimit,
736  &drift, &last_delta, numparts);
737  /*record partition */
738  partids[blobindex] = bestpart;
739  partsizes[bestpart]++; /*another in it */
740  }
741 
742  bestpart = -1; /*first point */
743  drift = 0.0f;
744  last_delta = 0.0f;
745  partsizes[0]--; /*doing 1st pt again */
746  /*do each blob in row */
747  for (blobindex = startx; blobindex >= 0; blobindex--) {
748  diff = ydiffs[blobindex]; /*diff from line */
749  if (textord_oldbl_debug) {
750  tprintf ("%d(%d,%d), ", blobindex,
751  blobcoords[blobindex].left (),
752  blobcoords[blobindex].bottom ());
753  }
754  bestpart = choose_partition(diff, partdiffs, bestpart, jumplimit,
755  &drift, &last_delta, numparts);
756  /*record partition */
757  partids[blobindex] = bestpart;
758  partsizes[bestpart]++; /*another in it */
759  }
760 
761  for (biggestpart = 0, bestpart = 1; bestpart < *numparts; bestpart++)
762  if (partsizes[bestpart] >= partsizes[biggestpart])
763  biggestpart = bestpart; /*new biggest */
765  merge_oldbl_parts(blobcoords,
766  blobcount,
767  partids,
768  partsizes,
769  biggestpart,
770  jumplimit);
771  return biggestpart; /*biggest partition */
772 }
#define MAXPARTS
Definition: oldbasel.cpp:73
int choose_partition(float diff, float partdiffs[], int lastpart, float jumplimit, float *drift, float *lastdelta, int *partcount)
Definition: oldbasel.cpp:947
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:37
void merge_oldbl_parts(TBOX blobcoords[], int blobcount, char partids[], int partsizes[], int biggestpart, float jumplimit)
Definition: oldbasel.cpp:783
int get_ydiffs(TBOX blobcoords[], int blobcount, QSPLINE *spline, float ydiffs[])
Definition: oldbasel.cpp:896
EXTERN bool textord_oldbl_merge_parts
Definition: oldbasel.cpp:46
EXTERN bool textord_oldbl_debug
Definition: oldbasel.cpp:42

◆ pick_x_height()

void pick_x_height ( TO_ROW row,
int  modelist[],
int  lefts[],
int  rights[],
STATS heightstat,
int  mode_threshold 
)

Definition at line 1597 of file oldbasel.cpp.

1601  {
1602  int x;
1603  int y;
1604  int z;
1605  float ratio;
1606  int found_one_bigger = FALSE;
1607  int best_x_height = 0;
1608  int best_asc = 0;
1609  int num_in_best;
1610 
1611  for (x = 0; x < MODENUM; x++) {
1612  for (y = 0; y < MODENUM; y++) {
1613  /* Check for two modes */
1614  if (modelist[x] && modelist[y] &&
1615  heightstat->pile_count (modelist[x]) > mode_threshold &&
1617  std::min(rights[modelist[x]], rights[modelist[y]]) >
1618  std::max(lefts[modelist[x]], lefts[modelist[y]]))) {
1619  ratio = (float) modelist[y] / (float) modelist[x];
1620  if (1.2 < ratio && ratio < 1.8) {
1621  /* Two modes found */
1622  best_x_height = modelist[x];
1623  num_in_best = heightstat->pile_count (modelist[x]);
1624 
1625  /* Try to get one higher */
1626  do {
1627  found_one_bigger = FALSE;
1628  for (z = 0; z < MODENUM; z++) {
1629  if (modelist[z] == best_x_height + 1 &&
1631  std::min(rights[modelist[x]], rights[modelist[y]]) >
1632  std::max(lefts[modelist[x]], lefts[modelist[y]]))) {
1633  ratio = (float) modelist[y] / (float) modelist[z];
1634  if ((1.2 < ratio && ratio < 1.8) &&
1635  /* Should be half of best */
1636  heightstat->pile_count (modelist[z]) >
1637  num_in_best * 0.5) {
1638  best_x_height++;
1639  found_one_bigger = TRUE;
1640  break;
1641  }
1642  }
1643  }
1644  }
1645  while (found_one_bigger);
1646 
1647  /* try to get a higher ascender */
1648 
1649  best_asc = modelist[y];
1650  num_in_best = heightstat->pile_count (modelist[y]);
1651 
1652  /* Try to get one higher */
1653  do {
1654  found_one_bigger = FALSE;
1655  for (z = 0; z < MODENUM; z++) {
1656  if (modelist[z] > best_asc &&
1658  std::min(rights[modelist[x]], rights[modelist[y]]) >
1659  std::max(lefts[modelist[x]], lefts[modelist[y]]))) {
1660  ratio = (float) modelist[z] / (float) best_x_height;
1661  if ((1.2 < ratio && ratio < 1.8) &&
1662  /* Should be half of best */
1663  heightstat->pile_count (modelist[z]) >
1664  num_in_best * 0.5) {
1665  best_asc = modelist[z];
1666  found_one_bigger = TRUE;
1667  break;
1668  }
1669  }
1670  }
1671  }
1672  while (found_one_bigger);
1673 
1674  row->xheight = (float) best_x_height;
1675  row->ascrise = (float) best_asc - best_x_height;
1676  return;
1677  }
1678  }
1679  }
1680  }
1681 
1682  best_x_height = modelist[0]; /* Single Mode found */
1683  num_in_best = heightstat->pile_count (best_x_height);
1684  do {
1685  /* Try to get one higher */
1686  found_one_bigger = FALSE;
1687  for (z = 1; z < MODENUM; z++) {
1688  /* Should be half of best */
1689  if ((modelist[z] == best_x_height + 1) &&
1690  (heightstat->pile_count (modelist[z]) > num_in_best * 0.5)) {
1691  best_x_height++;
1692  found_one_bigger = TRUE;
1693  break;
1694  }
1695  }
1696  }
1697  while (found_one_bigger);
1698 
1699  row->ascrise = 0.0f;
1700  row->xheight = (float) best_x_height;
1701  if (row->xheight == 0)
1702  row->xheight = -1.0f;
1703 }
int32_t pile_count(int32_t value) const
Definition: statistc.h:78
#define TRUE
Definition: capi.h:51
float xheight
Definition: blobbox.h:670
#define FALSE
Definition: capi.h:52
float ascrise
Definition: blobbox.h:672
EXTERN bool textord_ocropus_mode
Definition: oldbasel.cpp:50
#define MODENUM
Definition: oldbasel.cpp:72

◆ segment_spline()

int segment_spline ( TBOX  blobcoords[],
int  blobcount,
int  xcoords[],
int  ycoords[],
int  degree,
int  pointcount,
int  xstarts[] 
)

Definition at line 1050 of file oldbasel.cpp.

1057  {
1058  int ptindex; /*no along text line */
1059  int segment; /*partition no */
1060  int lastmin, lastmax; /*possible turn points */
1061  int turnpoints[SPLINESIZE]; /*good turning points */
1062  int turncount; /*no of turning points */
1063  int max_x; //max specified coord
1064 
1065  xstarts[0] = xcoords[0] - 1; //leftmost defined pt
1066  max_x = xcoords[pointcount - 1] + 1;
1067  if (degree < 2)
1068  pointcount = 0;
1069  turncount = 0; /*no turning points yet */
1070  if (pointcount > 3) {
1071  ptindex = 1;
1072  lastmax = lastmin = 0; /*start with first one */
1073  while (ptindex < pointcount - 1 && turncount < SPLINESIZE - 1) {
1074  /*minimum */
1075  if (ycoords[ptindex - 1] > ycoords[ptindex] && ycoords[ptindex] <= ycoords[ptindex + 1]) {
1076  if (ycoords[ptindex] < ycoords[lastmax] - TURNLIMIT) {
1077  if (turncount == 0 || turnpoints[turncount - 1] != lastmax)
1078  /*new max point */
1079  turnpoints[turncount++] = lastmax;
1080  lastmin = ptindex; /*latest minimum */
1081  }
1082  else if (ycoords[ptindex] < ycoords[lastmin]) {
1083  lastmin = ptindex; /*lower minimum */
1084  }
1085  }
1086 
1087  /*maximum */
1088  if (ycoords[ptindex - 1] < ycoords[ptindex] && ycoords[ptindex] >= ycoords[ptindex + 1]) {
1089  if (ycoords[ptindex] > ycoords[lastmin] + TURNLIMIT) {
1090  if (turncount == 0 || turnpoints[turncount - 1] != lastmin)
1091  /*new min point */
1092  turnpoints[turncount++] = lastmin;
1093  lastmax = ptindex; /*latest maximum */
1094  }
1095  else if (ycoords[ptindex] > ycoords[lastmax]) {
1096  lastmax = ptindex; /*higher maximum */
1097  }
1098  }
1099  ptindex++;
1100  }
1101  /*possible global min */
1102  if (ycoords[ptindex] < ycoords[lastmax] - TURNLIMIT
1103  && (turncount == 0 || turnpoints[turncount - 1] != lastmax)) {
1104  if (turncount < SPLINESIZE - 1)
1105  /*2 more turns */
1106  turnpoints[turncount++] = lastmax;
1107  if (turncount < SPLINESIZE - 1)
1108  turnpoints[turncount++] = ptindex;
1109  }
1110  else if (ycoords[ptindex] > ycoords[lastmin] + TURNLIMIT
1111  /*possible global max */
1112  && (turncount == 0 || turnpoints[turncount - 1] != lastmin)) {
1113  if (turncount < SPLINESIZE - 1)
1114  /*2 more turns */
1115  turnpoints[turncount++] = lastmin;
1116  if (turncount < SPLINESIZE - 1)
1117  turnpoints[turncount++] = ptindex;
1118  }
1119  else if (turncount > 0 && turnpoints[turncount - 1] == lastmin
1120  && turncount < SPLINESIZE - 1) {
1121  if (ycoords[ptindex] > ycoords[lastmax])
1122  turnpoints[turncount++] = ptindex;
1123  else
1124  turnpoints[turncount++] = lastmax;
1125  }
1126  else if (turncount > 0 && turnpoints[turncount - 1] == lastmax
1127  && turncount < SPLINESIZE - 1) {
1128  if (ycoords[ptindex] < ycoords[lastmin])
1129  turnpoints[turncount++] = ptindex;
1130  else
1131  turnpoints[turncount++] = lastmin;
1132  }
1133  }
1134 
1135  if (textord_oldbl_debug && turncount > 0)
1136  tprintf ("First turn is %d at (%d,%d)\n",
1137  turnpoints[0], xcoords[turnpoints[0]], ycoords[turnpoints[0]]);
1138  for (segment = 1; segment < turncount; segment++) {
1139  /*centre y coord */
1140  lastmax = (ycoords[turnpoints[segment - 1]] + ycoords[turnpoints[segment]]) / 2;
1141 
1142  /* fix alg so that it works with both rising and falling sections */
1143  if (ycoords[turnpoints[segment - 1]] < ycoords[turnpoints[segment]])
1144  /*find rising y centre */
1145  for (ptindex = turnpoints[segment - 1] + 1; ptindex < turnpoints[segment] && ycoords[ptindex + 1] <= lastmax; ptindex++);
1146  else
1147  /*find falling y centre */
1148  for (ptindex = turnpoints[segment - 1] + 1; ptindex < turnpoints[segment] && ycoords[ptindex + 1] >= lastmax; ptindex++);
1149 
1150  /*centre x */
1151  xstarts[segment] = (xcoords[ptindex - 1] + xcoords[ptindex]
1152  + xcoords[turnpoints[segment - 1]]
1153  + xcoords[turnpoints[segment]] + 2) / 4;
1154  /*halfway between turns */
1155  if (textord_oldbl_debug)
1156  tprintf ("Turn %d is %d at (%d,%d), mid pt is %d@%d, final @%d\n",
1157  segment, turnpoints[segment],
1158  xcoords[turnpoints[segment]], ycoords[turnpoints[segment]],
1159  ptindex - 1, xcoords[ptindex - 1], xstarts[segment]);
1160  }
1161 
1162  xstarts[segment] = max_x;
1163  return segment; /*no of splines */
1164 }
#define TURNLIMIT
Definition: oldbasel.cpp:58
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:37
#define SPLINESIZE
Definition: oldbasel.cpp:74
EXTERN bool textord_oldbl_debug
Definition: oldbasel.cpp:42

◆ split_stepped_spline()

bool split_stepped_spline ( QSPLINE baseline,
float  jumplimit,
int *  xcoords,
int *  xstarts,
int &  segments 
)

Definition at line 1175 of file oldbasel.cpp.

1181  {
1182  bool doneany; //return value
1183  int segment; /*partition no */
1184  int startindex, centreindex, endindex;
1185  float leftcoord, rightcoord;
1186  int leftindex, rightindex;
1187  float step; //spline step
1188 
1189  doneany = false;
1190  startindex = 0;
1191  for (segment = 1; segment < segments - 1; segment++) {
1192  step = baseline->step ((xstarts[segment - 1] + xstarts[segment]) / 2.0,
1193  (xstarts[segment] + xstarts[segment + 1]) / 2.0);
1194  if (step < 0)
1195  step = -step;
1196  if (step > jumplimit) {
1197  while (xcoords[startindex] < xstarts[segment - 1])
1198  startindex++;
1199  centreindex = startindex;
1200  while (xcoords[centreindex] < xstarts[segment])
1201  centreindex++;
1202  endindex = centreindex;
1203  while (xcoords[endindex] < xstarts[segment + 1])
1204  endindex++;
1205  if (segments >= SPLINESIZE) {
1207  tprintf ("Too many segments to resegment spline!!\n");
1208  }
1209  else if (endindex - startindex >= textord_spline_medianwin * 3) {
1210  while (centreindex - startindex <
1211  textord_spline_medianwin * 3 / 2)
1212  centreindex++;
1213  while (endindex - centreindex <
1214  textord_spline_medianwin * 3 / 2)
1215  centreindex--;
1216  leftindex = (startindex + startindex + centreindex) / 3;
1217  rightindex = (centreindex + endindex + endindex) / 3;
1218  leftcoord =
1219  (xcoords[startindex] * 2 + xcoords[centreindex]) / 3.0;
1220  rightcoord =
1221  (xcoords[centreindex] + xcoords[endindex] * 2) / 3.0;
1222  while (xcoords[leftindex] > leftcoord
1223  && leftindex - startindex > textord_spline_medianwin)
1224  leftindex--;
1225  while (xcoords[leftindex] < leftcoord
1226  && centreindex - leftindex >
1228  leftindex++;
1229  if (xcoords[leftindex] - leftcoord >
1230  leftcoord - xcoords[leftindex - 1])
1231  leftindex--;
1232  while (xcoords[rightindex] > rightcoord
1233  && rightindex - centreindex >
1235  rightindex--;
1236  while (xcoords[rightindex] < rightcoord
1237  && endindex - rightindex > textord_spline_medianwin)
1238  rightindex++;
1239  if (xcoords[rightindex] - rightcoord >
1240  rightcoord - xcoords[rightindex - 1])
1241  rightindex--;
1243  tprintf ("Splitting spline at %d with step %g at (%d,%d)\n",
1244  xstarts[segment],
1245  baseline->
1246  step ((xstarts[segment - 1] +
1247  xstarts[segment]) / 2.0,
1248  (xstarts[segment] +
1249  xstarts[segment + 1]) / 2.0),
1250  (xcoords[leftindex - 1] + xcoords[leftindex]) / 2,
1251  (xcoords[rightindex - 1] + xcoords[rightindex]) / 2);
1252  insert_spline_point (xstarts, segment,
1253  (xcoords[leftindex - 1] +
1254  xcoords[leftindex]) / 2,
1255  (xcoords[rightindex - 1] +
1256  xcoords[rightindex]) / 2, segments);
1257  doneany = true;
1258  }
1259  else if (textord_debug_baselines) {
1260  tprintf
1261  ("Resegmenting spline failed - insufficient pts (%d,%d,%d,%d)\n",
1262  startindex, centreindex, endindex,
1263  (int32_t) textord_spline_medianwin);
1264  }
1265  }
1266  // else tprintf("Spline step at %d is %g\n",
1267  // xstarts[segment],
1268  // baseline->step((xstarts[segment-1]+xstarts[segment])/2.0,
1269  // (xstarts[segment]+xstarts[segment+1])/2.0));
1270  }
1271  return doneany;
1272 }
int textord_spline_medianwin
Definition: makerow.cpp:65
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:37
EXTERN bool textord_debug_baselines
Definition: oldbasel.cpp:43
#define SPLINESIZE
Definition: oldbasel.cpp:74
void insert_spline_point(int xstarts[], int segment, int coord1, int coord2, int &segments)
Definition: oldbasel.cpp:1282

Variable Documentation

◆ oldbl_dot_error_size

double oldbl_dot_error_size = 1.26

"Max aspect ratio of a dot"

Definition at line 54 of file oldbasel.cpp.

◆ oldbl_holed_losscount

int oldbl_holed_losscount = 10

"Max lost before fallback line used"

Definition at line 53 of file oldbasel.cpp.

◆ oldbl_xhfix

bool oldbl_xhfix = FALSE

"Fix bug in modes threshold for xheights"

Definition at line 49 of file oldbasel.cpp.

◆ textord_debug_baselines

bool textord_debug_baselines = FALSE

"Debug baseline generation"

Definition at line 43 of file oldbasel.cpp.

◆ textord_oldbl_debug

bool textord_oldbl_debug = FALSE

"Debug old baseline generation"

Definition at line 42 of file oldbasel.cpp.

◆ textord_oldbl_jumplimit

double textord_oldbl_jumplimit = 0.15

"X fraction for new partition"

Definition at line 56 of file oldbasel.cpp.

◆ textord_oldbl_merge_parts

bool textord_oldbl_merge_parts = TRUE

"Merge suspect partitions"

Definition at line 46 of file oldbasel.cpp.

◆ textord_oldbl_paradef

bool textord_oldbl_paradef = TRUE

"Use para default mechanism"

Definition at line 44 of file oldbasel.cpp.

◆ textord_oldbl_split_splines

bool textord_oldbl_split_splines = TRUE

"Split stepped splines"

Definition at line 45 of file oldbasel.cpp.

◆ textord_really_old_xheight

bool textord_really_old_xheight = FALSE

"Use original wiseowl xheight"

Definition at line 41 of file oldbasel.cpp.