tesseract  4.0.0-1-g2a2b
oldbasel.cpp
Go to the documentation of this file.
1 /**********************************************************************
2  * File: oldbasel.cpp (Formerly oldbl.c)
3  * Description: A re-implementation of the old baseline algorithm.
4  * Author: Ray Smith
5  * Created: Wed Oct 6 09:41:48 BST 1993
6  *
7  * (C) Copyright 1993, Hewlett-Packard Ltd.
8  ** Licensed under the Apache License, Version 2.0 (the "License");
9  ** you may not use this file except in compliance with the License.
10  ** You may obtain a copy of the License at
11  ** http://www.apache.org/licenses/LICENSE-2.0
12  ** Unless required by applicable law or agreed to in writing, software
13  ** distributed under the License is distributed on an "AS IS" BASIS,
14  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  ** See the License for the specific language governing permissions and
16  ** limitations under the License.
17  *
18  **********************************************************************/
19 
20 #include <vector> // for std::vector
21 #include "ccstruct.h"
22 #include "statistc.h"
23 #include "quadlsq.h"
24 #include "detlinefit.h"
25 #include "makerow.h"
26 #include "drawtord.h"
27 #include "oldbasel.h"
28 #include "textord.h"
29 #include "tprintf.h"
30 
31 // Include automatically generated configuration file if running autoconf.
32 #ifdef HAVE_CONFIG_H
33 #include "config_auto.h"
34 #endif
35 
36 #include <algorithm>
37 
38 #define EXTERN
39 
41 "Use original wiseowl xheight");
42 EXTERN BOOL_VAR (textord_oldbl_debug, FALSE, "Debug old baseline generation");
43 EXTERN BOOL_VAR (textord_debug_baselines, FALSE, "Debug baseline generation");
44 EXTERN BOOL_VAR (textord_oldbl_paradef, TRUE, "Use para default mechanism");
45 EXTERN BOOL_VAR (textord_oldbl_split_splines, TRUE, "Split stepped splines");
46 EXTERN BOOL_VAR (textord_oldbl_merge_parts, TRUE, "Merge suspect partitions");
47 EXTERN BOOL_VAR (oldbl_corrfix, TRUE, "Improve correlation of heights");
49 "Fix bug in modes threshold for xheights");
50 EXTERN BOOL_VAR(textord_ocropus_mode, FALSE, "Make baselines for ocropus");
51 EXTERN double_VAR (oldbl_xhfract, 0.4, "Fraction of est allowed in calc");
53 "Max lost before fallback line used");
54 EXTERN double_VAR (oldbl_dot_error_size, 1.26, "Max aspect ratio of a dot");
56 "X fraction for new partition");
57 
58 #define TURNLIMIT 1 /*min size for turning point */
59 #define X_HEIGHT_FRACTION 0.7 /*x-height/caps height */
60 #define DESCENDER_FRACTION 0.5 /*descender/x-height */
61 #define MIN_ASC_FRACTION 0.20 /*min size of ascenders */
62 #define MIN_DESC_FRACTION 0.25 /*min size of descenders */
63 #define MINASCRISE 2.0 /*min ascender/desc step */
64 #define MAXHEIGHTVARIANCE 0.15 /*accepted variation in x-height */
65 #define MAXHEIGHT 300 /*max blob height */
66 #define MAXOVERLAP 0.1 /*max 10% missed overlap */
67 #define MAXBADRUN 2 /*max non best for failed */
68 #define HEIGHTBUCKETS 200 /* Num of buckets */
69 #define DELTAHEIGHT 5.0 /* Small amount of diff */
70 #define GOODHEIGHT 5
71 #define MAXLOOPS 10
72 #define MODENUM 10
73 #define MAXPARTS 6
74 #define SPLINESIZE 23
75 
76 #define ABS(x) ((x)<0 ? (-(x)) : (x))
77 
78 namespace tesseract {
79 
80 /**********************************************************************
81  * make_old_baselines
82  *
83  * Top level function to make baselines the old way.
84  **********************************************************************/
85 
86 void Textord::make_old_baselines(TO_BLOCK* block, // block to do
87  bool testing_on, // correct orientation
88  float gradient) {
89  QSPLINE *prev_baseline; // baseline of previous row
90  TO_ROW *row; // current row
91  TO_ROW_IT row_it = block->get_rows();
92  BLOBNBOX_IT blob_it;
93 
94  prev_baseline = nullptr; // nothing yet
95  for (row_it.mark_cycle_pt(); !row_it.cycled_list(); row_it.forward()) {
96  row = row_it.data();
97  find_textlines(block, row, 2, nullptr);
98  if (row->xheight <= 0 && prev_baseline != nullptr)
99  find_textlines(block, row, 2, prev_baseline);
100  if (row->xheight > 0) { // was a good one
101  prev_baseline = &row->baseline;
102  } else {
103  prev_baseline = nullptr;
104  blob_it.set_to_list(row->blob_list());
106  tprintf("Row baseline generation failed on row at (%d,%d)\n",
107  blob_it.data()->bounding_box().left(),
108  blob_it.data()->bounding_box().bottom());
109  }
110  }
111  correlate_lines(block, gradient);
112  block->block->set_xheight(block->xheight);
113 }
114 
115 
116 /**********************************************************************
117  * correlate_lines
118  *
119  * Correlate the x-heights and ascender heights of a block to fill-in
120  * the ascender height and descender height for rows without one.
121  * Also fix baselines of rows without a decent fit.
122  **********************************************************************/
123 
124 void Textord::correlate_lines(TO_BLOCK *block, float gradient) {
125  int rowcount; /*no of rows to do */
126  int rowindex; /*no of row */
127  // iterator
128  TO_ROW_IT row_it = block->get_rows ();
129 
130  rowcount = row_it.length ();
131  if (rowcount == 0) {
132  //default value
133  block->xheight = block->line_size;
134  return; /*none to do */
135  }
136  // array of ptrs
137  std::vector <TO_ROW *> rows(rowcount);
138  rowindex = 0;
139  for (row_it.mark_cycle_pt (); !row_it.cycled_list (); row_it.forward ())
140  //make array
141  rows[rowindex++] = row_it.data ();
142 
143  /*try to fix bad lines */
144  correlate_neighbours(block, &rows[0], rowcount);
145 
147  block->xheight = (float) correlate_with_stats(&rows[0], rowcount, block);
148  if (block->xheight <= 0)
150  if (block->xheight < textord_min_xheight)
151  block->xheight = (float) textord_min_xheight;
152  } else {
153  compute_block_xheight(block, gradient);
154  }
155 }
156 
157 
158 /**********************************************************************
159  * correlate_neighbours
160  *
161  * Try to fix rows that had a bad spline fit by using neighbours.
162  **********************************************************************/
163 
164 void Textord::correlate_neighbours(TO_BLOCK *block, // block rows are in.
165  TO_ROW **rows, // rows of block.
166  int rowcount) { // no of rows to do.
167  TO_ROW *row; /*current row */
168  int rowindex; /*no of row */
169  int otherrow; /*second row */
170  int upperrow; /*row above to use */
171  int lowerrow; /*row below to use */
172  float biggest;
173 
174  for (rowindex = 0; rowindex < rowcount; rowindex++) {
175  row = rows[rowindex]; /*current row */
176  if (row->xheight < 0) {
177  /*quadratic failed */
178  for (otherrow = rowindex - 2;
179  otherrow >= 0
180  && (rows[otherrow]->xheight < 0.0
181  || !row->baseline.overlap (&rows[otherrow]->baseline,
182  MAXOVERLAP)); otherrow--);
183  upperrow = otherrow; /*decent row above */
184  for (otherrow = rowindex + 1;
185  otherrow < rowcount
186  && (rows[otherrow]->xheight < 0.0
187  || !row->baseline.overlap (&rows[otherrow]->baseline,
188  MAXOVERLAP)); otherrow++);
189  lowerrow = otherrow; /*decent row below */
190  if (upperrow >= 0)
191  find_textlines(block, row, 2, &rows[upperrow]->baseline);
192  if (row->xheight < 0 && lowerrow < rowcount)
193  find_textlines(block, row, 2, &rows[lowerrow]->baseline);
194  if (row->xheight < 0) {
195  if (upperrow >= 0)
196  find_textlines(block, row, 1, &rows[upperrow]->baseline);
197  else if (lowerrow < rowcount)
198  find_textlines(block, row, 1, &rows[lowerrow]->baseline);
199  }
200  }
201  }
202 
203  for (biggest = 0.0f, rowindex = 0; rowindex < rowcount; rowindex++) {
204  row = rows[rowindex]; /*current row */
205  if (row->xheight < 0) /*linear failed */
206  /*make do */
207  row->xheight = -row->xheight;
208  biggest = std::max(biggest, row->xheight);
209  }
210 }
211 
212 
213 /**********************************************************************
214  * correlate_with_stats
215  *
216  * correlate the x-heights and ascender heights of a block to fill-in
217  * the ascender height and descender height for rows without one.
218  **********************************************************************/
219 
220 int Textord::correlate_with_stats(TO_ROW **rows, // rows of block.
221  int rowcount, // no of rows to do.
222  TO_BLOCK* block) {
223  TO_ROW *row; /*current row */
224  int rowindex; /*no of row */
225  float lineheight; /*mean x-height */
226  float ascheight; /*average ascenders */
227  float minascheight; /*min allowed ascheight */
228  int xcount; /*no of samples for xheight */
229  float fullheight; /*mean top height */
230  int fullcount; /*no of samples */
231  float descheight; /*mean descender drop */
232  float mindescheight; /*min allowed descheight */
233  int desccount; /*no of samples */
234 
235  /*no samples */
236  xcount = fullcount = desccount = 0;
237  lineheight = ascheight = fullheight = descheight = 0.0;
238  for (rowindex = 0; rowindex < rowcount; rowindex++) {
239  row = rows[rowindex]; /*current row */
240  if (row->ascrise > 0.0) { /*got ascenders? */
241  lineheight += row->xheight;/*average x-heights */
242  ascheight += row->ascrise; /*average ascenders */
243  xcount++;
244  }
245  else {
246  fullheight += row->xheight;/*assume full height */
247  fullcount++;
248  }
249  if (row->descdrop < 0.0) { /*got descenders? */
250  /*average descenders */
251  descheight += row->descdrop;
252  desccount++;
253  }
254  }
255 
256  if (xcount > 0 && (!oldbl_corrfix || xcount >= fullcount)) {
257  lineheight /= xcount; /*average x-height */
258  /*average caps height */
259  fullheight = lineheight + ascheight / xcount;
260  /*must be decent size */
261  if (fullheight < lineheight * (1 + MIN_ASC_FRACTION))
262  fullheight = lineheight * (1 + MIN_ASC_FRACTION);
263  }
264  else {
265  fullheight /= fullcount; /*average max height */
266  /*guess x-height */
267  lineheight = fullheight * X_HEIGHT_FRACTION;
268  }
269  if (desccount > 0 && (!oldbl_corrfix || desccount >= rowcount / 2))
270  descheight /= desccount; /*average descenders */
271  else
272  /*guess descenders */
273  descheight = -lineheight * DESCENDER_FRACTION;
274 
275  if (lineheight > 0.0f)
276  block->block->set_cell_over_xheight((fullheight - descheight) / lineheight);
277 
278  minascheight = lineheight * MIN_ASC_FRACTION;
279  mindescheight = -lineheight * MIN_DESC_FRACTION;
280  for (rowindex = 0; rowindex < rowcount; rowindex++) {
281  row = rows[rowindex]; /*do each row */
282  row->all_caps = false;
283  if (row->ascrise / row->xheight < MIN_ASC_FRACTION) {
284  /*no ascenders */
285  if (row->xheight >= lineheight * (1 - MAXHEIGHTVARIANCE)
286  && row->xheight <= lineheight * (1 + MAXHEIGHTVARIANCE)) {
287  row->ascrise = fullheight - lineheight;
288  /*set to average */
289  row->xheight = lineheight;
290 
291  }
292  else if (row->xheight >= fullheight * (1 - MAXHEIGHTVARIANCE)
293  && row->xheight <= fullheight * (1 + MAXHEIGHTVARIANCE)) {
294  row->ascrise = row->xheight - lineheight;
295  /*set to average */
296  row->xheight = lineheight;
297  row->all_caps = true;
298  }
299  else {
300  row->ascrise = (fullheight - lineheight) * row->xheight
301  / fullheight;
302  /*scale it */
303  row->xheight -= row->ascrise;
304  row->all_caps = true;
305  }
306  if (row->ascrise < minascheight)
307  row->ascrise =
308  row->xheight * ((1.0 - X_HEIGHT_FRACTION) / X_HEIGHT_FRACTION);
309  }
310  if (row->descdrop > mindescheight) {
311  if (row->xheight >= lineheight * (1 - MAXHEIGHTVARIANCE)
312  && row->xheight <= lineheight * (1 + MAXHEIGHTVARIANCE))
313  /*set to average */
314  row->descdrop = descheight;
315  else
316  row->descdrop = -row->xheight * DESCENDER_FRACTION;
317  }
318  }
319  return (int) lineheight; //block xheight
320 }
321 
322 
323 /**********************************************************************
324  * find_textlines
325  *
326  * Compute the baseline for the given row.
327  **********************************************************************/
328 
329 void Textord::find_textlines(TO_BLOCK *block, // block row is in
330  TO_ROW *row, // row to do
331  int degree, // required approximation
332  QSPLINE *spline) { // starting spline
333  int partcount; /*no of partitions of */
334  bool holed_line = false; //lost too many blobs
335  int bestpart; /*biggest partition */
336  int partsizes[MAXPARTS]; /*no in each partition */
337  int lineheight; /*guessed x-height */
338  float jumplimit; /*allowed delta change */
339  int blobcount; /*no of blobs on line */
340  int pointcount; /*no of coords */
341  int xstarts[SPLINESIZE + 1]; //segment boundaries
342  int segments; //no of segments
343 
344  //no of blobs in row
345  blobcount = row->blob_list ()->length ();
346  // partition no of each blob
347  std::vector<char> partids(blobcount);
348  // useful sample points
349  std::vector<int> xcoords(blobcount);
350  // useful sample points
351  std::vector<int> ycoords(blobcount);
352  // edges of blob rectangles
353  std::vector<TBOX> blobcoords(blobcount);
354  // diffs from 1st approx
355  std::vector<float> ydiffs(blobcount);
356 
357  lineheight = get_blob_coords(row, (int)block->line_size, &blobcoords[0],
358  holed_line, blobcount);
359  /*limit for line change */
360  jumplimit = lineheight * textord_oldbl_jumplimit;
361  if (jumplimit < MINASCRISE)
362  jumplimit = MINASCRISE;
363 
364  if (textord_oldbl_debug) {
365  tprintf
366  ("\nInput height=%g, Estimate x-height=%d pixels, jumplimit=%.2f\n",
367  block->line_size, lineheight, jumplimit);
368  }
369  if (holed_line)
370  make_holed_baseline(&blobcoords[0], blobcount, spline, &row->baseline,
371  row->line_m ());
372  else
373  make_first_baseline(&blobcoords[0], blobcount,
374  &xcoords[0], &ycoords[0], spline, &row->baseline, jumplimit);
375 #ifndef GRAPHICS_DISABLED
378 #endif
379  if (blobcount > 1) {
380  bestpart = partition_line(&blobcoords[0], blobcount,
381  &partcount, &partids[0], partsizes,
382  &row->baseline, jumplimit, &ydiffs[0]);
383  pointcount = partition_coords(&blobcoords[0], blobcount,
384  &partids[0], bestpart, &xcoords[0], &ycoords[0]);
385  segments = segment_spline(&blobcoords[0], blobcount,
386  &xcoords[0], &ycoords[0], degree, pointcount, xstarts);
387  if (!holed_line) {
388  do {
389  row->baseline = QSPLINE(xstarts, segments,
390  &xcoords[0], &ycoords[0], pointcount, degree);
391  }
393  && split_stepped_spline (&row->baseline, jumplimit / 2,
394  &xcoords[0], xstarts, segments));
395  }
396  find_lesser_parts(row, &blobcoords[0], blobcount,
397  &partids[0], partsizes, partcount, bestpart);
398 
399  }
400  else {
401  row->xheight = -1.0f; /*failed */
402  row->descdrop = 0.0f;
403  row->ascrise = 0.0f;
404  }
405  row->baseline.extrapolate (row->line_m (),
406  block->block->pdblk.bounding_box ().left (),
407  block->block->pdblk.bounding_box ().right ());
408 
410  old_first_xheight (row, &blobcoords[0], lineheight,
411  blobcount, &row->baseline, jumplimit);
412  } else if (textord_old_xheight) {
413  make_first_xheight (row, &blobcoords[0], lineheight, (int)block->line_size,
414  blobcount, &row->baseline, jumplimit);
415  } else {
417  row->line_m(), block->line_size);
418  }
419 }
420 
421 } // namespace tesseract.
422 
423 
424 /**********************************************************************
425  * get_blob_coords
426  *
427  * Fill the blobcoords array with the coordinates of the blobs
428  * in the row. The return value is the first guess at the line height.
429  **********************************************************************/
430 
431 int get_blob_coords( //get boxes
432  TO_ROW* row, //row to use
433  int32_t lineheight, //block level
434  TBOX* blobcoords, //output boxes
435  bool& holed_line, //lost a lot of blobs
436  int& outcount //no of real blobs
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 }
490 
491 
492 /**********************************************************************
493  * make_first_baseline
494  *
495  * Make the first estimate at a baseline, either by shifting
496  * a supplied previous spline, or by doing a piecewise linear
497  * approximation using all the blobs.
498  **********************************************************************/
499 
500 void
501 make_first_baseline ( //initial approximation
502 TBOX blobcoords[], /*blob bounding boxes */
503 int blobcount, /*no of blobcoords */
504 int xcoords[], /*coords for spline */
505 int ycoords[], /*approximator */
506 QSPLINE * spline, /*initial spline */
507 QSPLINE * baseline, /*output spline */
508 float jumplimit /*guess half descenders */
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 }
633 
634 
635 /**********************************************************************
636  * make_holed_baseline
637  *
638  * Make the first estimate at a baseline, either by shifting
639  * a supplied previous spline, or by doing a piecewise linear
640  * approximation using all the blobs.
641  **********************************************************************/
642 
643 void
644 make_holed_baseline ( //initial approximation
645 TBOX blobcoords[], /*blob bounding boxes */
646 int blobcount, /*no of blobcoords */
647 QSPLINE * spline, /*initial spline */
648 QSPLINE * baseline, /*output spline */
649 float gradient //of line
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 }
690 
691 
692 /**********************************************************************
693  * partition_line
694  *
695  * Partition a row of blobs into different groups of continuous
696  * y position. jumplimit specifies the max allowable limit on a jump
697  * before a new partition is started.
698  * The return value is the biggest partition
699  **********************************************************************/
700 
701 int
702 partition_line ( //partition blobs
703 TBOX blobcoords[], //bounding boxes
704 int blobcount, /*no of blobs on row */
705 int *numparts, /*number of partitions */
706 char partids[], /*partition no of each blob */
707 int partsizes[], /*no in each partition */
708 QSPLINE * spline, /*curve to fit to */
709 float jumplimit, /*allowed delta change */
710 float ydiffs[] /*diff from spline */
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 }
773 
774 
775 /**********************************************************************
776  * merge_oldbl_parts
777  *
778  * For any adjacent group of blobs in a different part, put them in the
779  * main part if they fit closely to neighbours in the main part.
780  **********************************************************************/
781 
782 void
783 merge_oldbl_parts ( //partition blobs
784 TBOX blobcoords[], //bounding boxes
785 int blobcount, /*no of blobs on row */
786 char partids[], /*partition no of each blob */
787 int partsizes[], /*no in each partition */
788 int biggestpart, //major partition
789 float jumplimit /*allowed delta change */
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 }
885 
886 
887 /**********************************************************************
888  * get_ydiffs
889  *
890  * Get the differences between the blobs and the spline,
891  * putting them in ydiffs. The return value is the index
892  * of the blob in the middle of the "best behaved" region
893  **********************************************************************/
894 
895 int
896 get_ydiffs ( //evaluate differences
897 TBOX blobcoords[], //bounding boxes
898 int blobcount, /*no of blobs */
899 QSPLINE * spline, /*approximating spline */
900 float ydiffs[] /*output */
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 }
938 
939 
940 /**********************************************************************
941  * choose_partition
942  *
943  * Choose a partition for the point and return the index.
944  **********************************************************************/
945 
946 int
947 choose_partition ( //select partition
948 float diff, /*diff from spline */
949 float partdiffs[], /*diff on all parts */
950 int lastpart, /*last assigned partition */
951 float jumplimit, /*new part threshold */
952 float* drift,
953 float* lastdelta,
954 int *partcount /*no of partitions */
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 }
1010 
1011 /**********************************************************************
1012  * partition_coords
1013  *
1014  * Get the x,y coordinates of all points in the bestpart and put them
1015  * in xcoords,ycoords. Return the number of points found.
1016  **********************************************************************/
1017 
1018 int
1019 partition_coords ( //find relevant coords
1020 TBOX blobcoords[], //bounding boxes
1021 int blobcount, /*no of blobs in row */
1022 char partids[], /*partition no of each blob */
1023 int bestpart, /*best new partition */
1024 int xcoords[], /*points to work on */
1025 int ycoords[] /*points to work on */
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 }
1040 
1041 
1042 /**********************************************************************
1043  * segment_spline
1044  *
1045  * Segment the row at midpoints between maxima and minima of the x,y pairs.
1046  * The xstarts of the segments are returned and the number found.
1047  **********************************************************************/
1048 
1049 int
1050 segment_spline ( //make xstarts
1051 TBOX blobcoords[], //boundign boxes
1052 int blobcount, /*no of blobs in row */
1053 int xcoords[], /*points to work on */
1054 int ycoords[], /*points to work on */
1055 int degree, int pointcount, /*no of points */
1056 int xstarts[] //result
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 }
1165 
1166 
1167 /**********************************************************************
1168  * split_stepped_spline
1169  *
1170  * Re-segment the spline in cases where there is a big step function.
1171  * Return TRUE if any were done.
1172  **********************************************************************/
1173 
1174 bool
1175 split_stepped_spline( //make xstarts
1176  QSPLINE* baseline, //current shot
1177  float jumplimit, //max step function
1178  int* xcoords, /*points to work on */
1179  int* xstarts, //result
1180  int& segments //no of segments
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 }
1273 
1274 
1275 /**********************************************************************
1276  * insert_spline_point
1277  *
1278  * Insert a new spline point and shuffle up the others.
1279  **********************************************************************/
1280 
1281 void
1282 insert_spline_point ( //get descenders
1283 int xstarts[], //starts to shuffle
1284 int segment, //insertion pt
1285 int coord1, //coords to add
1286 int coord2, int &segments //total segments
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 }
1296 
1297 
1298 /**********************************************************************
1299  * find_lesser_parts
1300  *
1301  * Average the step from the spline for the other partitions
1302  * and find the commonest partition which has a descender.
1303  **********************************************************************/
1304 
1305 void
1306 find_lesser_parts ( //get descenders
1307 TO_ROW * row, //row to process
1308 TBOX blobcoords[], //bounding boxes
1309 int blobcount, /*no of blobs */
1310 char partids[], /*partition of each blob */
1311 int partsizes[], /*size of each part */
1312 int partcount, /*no of partitions */
1313 int bestpart /*biggest partition */
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 }
1376 
1377 
1378 /**********************************************************************
1379  * old_first_xheight
1380  *
1381  * Makes an x-height spline by copying the baseline and shifting it.
1382  * It estimates the x-height across the line to use as the shift.
1383  * It also finds the ascender height if it can.
1384  **********************************************************************/
1385 
1386 void
1387 old_first_xheight ( //the wiseowl way
1388 TO_ROW * row, /*current row */
1389 TBOX blobcoords[], /*blob bounding boxes */
1390 int initialheight, //initial guess
1391 int blobcount, /*blobs in blobcoords */
1392 QSPLINE * baseline, /*established */
1393 float jumplimit /*min ascender height */
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 }
1461 
1462 
1463 /**********************************************************************
1464  * make_first_xheight
1465  *
1466  * Makes an x-height spline by copying the baseline and shifting it.
1467  * It estimates the x-height across the line to use as the shift.
1468  * It also finds the ascender height if it can.
1469  **********************************************************************/
1470 
1471 void
1472 make_first_xheight ( //find xheight
1473 TO_ROW * row, /*current row */
1474 TBOX blobcoords[], /*blob bounding boxes */
1475 int lineheight, //initial guess
1476 int init_lineheight, //block level guess
1477 int blobcount, /*blobs in blobcoords */
1478 QSPLINE * baseline, /*established */
1479 float jumplimit /*min ascender height */
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 }
1545 
1546 /**********************************************************************
1547  * find_top_modes
1548  *
1549  * Fill the input array with the indices of the top ten modes of the
1550  * input distribution.
1551  **********************************************************************/
1552 
1553 const int kMinModeFactorOcropus = 32;
1554 const int kMinModeFactor = 12;
1555 
1556 void
1557 find_top_modes ( //get modes
1558 STATS * stats, //stats to hack
1559 int statnum, //no of piles
1560 int modelist[], int modenum //no of modes to get
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 }
1589 
1590 
1591 /**********************************************************************
1592  * pick_x_height
1593  *
1594  * Choose based on the height modes the best x height value.
1595  **********************************************************************/
1596 
1597 void pick_x_height(TO_ROW * row, //row to do
1598  int modelist[],
1599  int lefts[], int rights[],
1600  STATS * heightstat,
1601  int mode_threshold) {
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 }
QSPLINE baseline
Definition: blobbox.h:683
EXTERN bool textord_oldbl_split_splines
Definition: oldbasel.cpp:45
int get_blob_coords(TO_ROW *row, int32_t lineheight, TBOX *blobcoords, bool &holed_line, int &outcount)
Definition: oldbasel.cpp:431
TBOX box_next_pre_chopped(BLOBNBOX_IT *it)
Definition: blobbox.cpp:666
void find_top_modes(STATS *stats, int statnum, int modelist[], int modenum)
Definition: oldbasel.cpp:1557
void plot(ScrollView *window, ScrollView::Color colour) const
Definition: quspline.cpp:347
float descdrop
Definition: blobbox.h:673
EXTERN double textord_oldbl_jumplimit
Definition: oldbasel.cpp:56
#define MAXPARTS
Definition: oldbasel.cpp:73
int segment_spline(TBOX blobcoords[], int blobcount, int xcoords[], int ycoords[], int degree, int pointcount, int xstarts[])
Definition: oldbasel.cpp:1050
int32_t pile_count(int32_t value) const
Definition: statistc.h:78
#define MAXBADRUN
Definition: oldbasel.cpp:67
#define DESCENDER_FRACTION
Definition: oldbasel.cpp:60
void fit(int degree)
Definition: quadlsq.cpp:100
#define TRUE
Definition: capi.h:51
#define BOOL_VAR(name, val, comment)
Definition: params.h:279
void make_first_xheight(TO_ROW *row, TBOX blobcoords[], int lineheight, int init_lineheight, int blobcount, QSPLINE *baseline, float jumplimit)
Definition: oldbasel.cpp:1472
#define MAXHEIGHTVARIANCE
Definition: oldbasel.cpp:64
int choose_partition(float diff, float partdiffs[], int lastpart, float jumplimit, float *drift, float *lastdelta, int *partcount)
Definition: oldbasel.cpp:947
float line_m() const
Definition: blobbox.h:583
double get_c()
Definition: quadlsq.h:51
EXTERN double oldbl_dot_error_size
Definition: oldbasel.cpp:54
#define double_VAR(name, val, comment)
Definition: params.h:285
int textord_min_xheight
Definition: makerow.cpp:68
bool textord_old_xheight
Definition: makerow.cpp:53
void old_first_xheight(TO_ROW *row, TBOX blobcoords[], int initialheight, int blobcount, QSPLINE *baseline, float jumplimit)
Definition: oldbasel.cpp:1387
#define MIN_ASC_FRACTION
Definition: oldbasel.cpp:61
Definition: rect.h:34
void compute_row_xheight(TO_ROW *row, const FCOORD &rotation, float gradient, int block_line_size)
Definition: makerow.cpp:1368
const int kMinModeFactorOcropus
Definition: oldbasel.cpp:1553
int textord_spline_medianwin
Definition: makerow.cpp:65
Definition: statistc.h:33
double y(double x) const
Definition: quspline.cpp:209
void extrapolate(double gradient, int left, int right)
Definition: quspline.cpp:291
#define X_HEIGHT_FRACTION
Definition: oldbasel.cpp:59
bool overlap(QSPLINE *spline2, double fraction)
Definition: quspline.cpp:272
TO_ROW_LIST * get_rows()
Definition: blobbox.h:717
EXTERN double oldbl_xhfract
Definition: oldbasel.cpp:51
#define MAXHEIGHT
Definition: oldbasel.cpp:65
void compute_block_xheight(TO_BLOCK *block, float gradient)
Definition: makerow.cpp:1256
int16_t width() const
Definition: rect.h:115
EXTERN bool textord_oldbl_paradef
Definition: oldbasel.cpp:44
static const double kXHeightFraction
Definition: ccstruct.h:34
float xheight
Definition: blobbox.h:670
void add(double x, double y)
Definition: quadlsq.cpp:56
#define MINASCRISE
Definition: oldbasel.cpp:63
int16_t left() const
Definition: rect.h:72
EXTERN bool oldbl_xhfix
Definition: oldbasel.cpp:49
int16_t top() const
Definition: rect.h:58
EXTERN bool oldbl_corrfix
Definition: oldbasel.cpp:47
double step(double x1, double x2)
Definition: quspline.cpp:184
void Add(const ICOORD &pt)
Definition: detlinefit.cpp:51
void find_lesser_parts(TO_ROW *row, TBOX blobcoords[], int blobcount, char partids[], int partsizes[], int partcount, int bestpart)
Definition: oldbasel.cpp:1306
void clear()
Definition: quadlsq.cpp:34
bool textord_show_final_rows
Definition: makerow.cpp:47
integer coordinate
Definition: points.h:32
#define FALSE
Definition: capi.h:52
const int kMinModeFactor
Definition: oldbasel.cpp:1554
double ile(double frac) const
Definition: statistc.cpp:173
bool split_stepped_spline(QSPLINE *baseline, float jumplimit, int *xcoords, int *xstarts, int &segments)
Definition: oldbasel.cpp:1175
FCOORD classify_rotation() const
Definition: ocrblock.h:142
float xheight
Definition: blobbox.h:801
Definition: quadlsq.h:25
#define TURNLIMIT
Definition: oldbasel.cpp:58
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:37
float ascrise
Definition: blobbox.h:672
#define EXTERN
Definition: oldbasel.cpp:38
void make_first_baseline(TBOX blobcoords[], int blobcount, int xcoords[], int ycoords[], QSPLINE *spline, QSPLINE *baseline, float jumplimit)
Definition: oldbasel.cpp:501
void add(int32_t value, int32_t count)
Definition: statistc.cpp:100
EXTERN ScrollView * to_win
Definition: drawtord.cpp:37
BLOCK * block
Definition: blobbox.h:790
void set_cell_over_xheight(float ratio)
Definition: ocrblock.h:114
void merge_oldbl_parts(TBOX blobcoords[], int blobcount, char partids[], int partsizes[], int biggestpart, float jumplimit)
Definition: oldbasel.cpp:783
EXTERN bool textord_debug_baselines
Definition: oldbasel.cpp:43
#define SPLINESIZE
Definition: oldbasel.cpp:74
int partition_line(TBOX blobcoords[], int blobcount, int *numparts, char partids[], int partsizes[], QSPLINE *spline, float jumplimit, float ydiffs[])
Definition: oldbasel.cpp:702
void set_xheight(int32_t height)
set char size
Definition: ocrblock.h:70
EXTERN bool textord_ocropus_mode
Definition: oldbasel.cpp:50
void bounding_box(ICOORD &bottom_left, ICOORD &top_right) const
get box
Definition: pdblock.h:60
Definition: points.h:189
int16_t right() const
Definition: rect.h:79
float x() const
Definition: points.h:208
#define HEIGHTBUCKETS
Definition: oldbasel.cpp:68
int get_ydiffs(TBOX blobcoords[], int blobcount, QSPLINE *spline, float ydiffs[])
Definition: oldbasel.cpp:896
bool all_caps
Definition: blobbox.h:659
EXTERN int oldbl_holed_losscount
Definition: oldbasel.cpp:53
#define MAXOVERLAP
Definition: oldbasel.cpp:66
#define MIN_DESC_FRACTION
Definition: oldbasel.cpp:62
EXTERN bool textord_oldbl_merge_parts
Definition: oldbasel.cpp:46
double ConstrainedFit(const FCOORD &direction, double min_dist, double max_dist, bool debug, ICOORD *line_pt)
Definition: detlinefit.cpp:130
#define MODENUM
Definition: oldbasel.cpp:72
int16_t bottom() const
Definition: rect.h:65
double get_b()
Definition: quadlsq.h:48
PDBLK pdblk
Definition: ocrblock.h:192
void pick_x_height(TO_ROW *row, int modelist[], int lefts[], int rights[], STATS *heightstat, int mode_threshold)
Definition: oldbasel.cpp:1597
int16_t height() const
Definition: rect.h:108
EXTERN bool textord_oldbl_debug
Definition: oldbasel.cpp:42
void insert_spline_point(int xstarts[], int segment, int coord1, int coord2, int &segments)
Definition: oldbasel.cpp:1282
BLOBNBOX_LIST * blob_list()
Definition: blobbox.h:612
int32_t get_total() const
Definition: statistc.h:86
#define ABS(x)
Definition: oldbasel.cpp:76
void make_holed_baseline(TBOX blobcoords[], int blobcount, QSPLINE *spline, QSPLINE *baseline, float gradient)
Definition: oldbasel.cpp:644
#define INT_VAR(name, val, comment)
Definition: params.h:276
float y() const
Definition: points.h:211
EXTERN bool textord_really_old_xheight
Definition: oldbasel.cpp:41
float line_size
Definition: blobbox.h:798
int partition_coords(TBOX blobcoords[], int blobcount, char partids[], int bestpart, int xcoords[], int ycoords[])
Definition: oldbasel.cpp:1019