tesseract  4.00.00dev
tordmain.h File Reference
#include <time.h>
#include "params.h"
#include "ocrblock.h"
#include "blobs.h"
#include "blobbox.h"

Go to the source code of this file.

Namespaces

 tesseract
 

Functions

void tesseract::SetBlobStrokeWidth (Pix *pix, BLOBNBOX *blob)
 
void tesseract::assign_blobs_to_blocks2 (Pix *pix, BLOCK_LIST *blocks, TO_BLOCK_LIST *port_blocks)
 
void tweak_row_baseline (ROW *row, double blshift_maxshift, double blshift_xfraction)
 

Function Documentation

◆ tweak_row_baseline()

void tweak_row_baseline ( ROW row,
double  blshift_maxshift,
double  blshift_xfraction 
)

Definition at line 885 of file tordmain.cpp.

887  {
888  TBOX blob_box; //bounding box
889  C_BLOB *blob; //current blob
890  WERD *word; //current word
891  inT32 blob_count; //no of blobs
892  inT32 src_index; //source segment
893  inT32 dest_index; //destination segment
894  inT32 *xstarts; //spline segments
895  double *coeffs; //spline coeffs
896  float ydiff; //baseline error
897  float x_centre; //centre of blob
898  //words of row
899  WERD_IT word_it = row->word_list ();
900  C_BLOB_IT blob_it; //blob iterator
901 
902  blob_count = 0;
903  for (word_it.mark_cycle_pt (); !word_it.cycled_list (); word_it.forward ()) {
904  word = word_it.data (); //current word
905  //get total blobs
906  blob_count += word->cblob_list ()->length ();
907  }
908  if (blob_count == 0)
909  return;
910  xstarts =
911  (inT32 *) alloc_mem ((blob_count + row->baseline.segments + 1) *
912  sizeof (inT32));
913  coeffs =
914  (double *) alloc_mem ((blob_count + row->baseline.segments) * 3 *
915  sizeof (double));
916 
917  src_index = 0;
918  dest_index = 0;
919  xstarts[0] = row->baseline.xcoords[0];
920  for (word_it.mark_cycle_pt (); !word_it.cycled_list (); word_it.forward ()) {
921  word = word_it.data (); //current word
922  //blobs in word
923  blob_it.set_to_list (word->cblob_list ());
924  for (blob_it.mark_cycle_pt (); !blob_it.cycled_list ();
925  blob_it.forward ()) {
926  blob = blob_it.data ();
927  blob_box = blob->bounding_box ();
928  x_centre = (blob_box.left () + blob_box.right ()) / 2.0;
929  ydiff = blob_box.bottom () - row->base_line (x_centre);
930  if (ydiff < 0)
931  ydiff = -ydiff / row->x_height ();
932  else
933  ydiff = ydiff / row->x_height ();
934  if (ydiff < blshift_maxshift
935  && blob_box.height () / row->x_height () > blshift_xfraction) {
936  if (xstarts[dest_index] >= x_centre)
937  xstarts[dest_index] = blob_box.left ();
938  coeffs[dest_index * 3] = 0;
939  coeffs[dest_index * 3 + 1] = 0;
940  coeffs[dest_index * 3 + 2] = blob_box.bottom ();
941  //shift it
942  dest_index++;
943  xstarts[dest_index] = blob_box.right () + 1;
944  }
945  else {
946  if (xstarts[dest_index] <= x_centre) {
947  while (row->baseline.xcoords[src_index + 1] <= x_centre
948  && src_index < row->baseline.segments - 1) {
949  if (row->baseline.xcoords[src_index + 1] >
950  xstarts[dest_index]) {
951  coeffs[dest_index * 3] =
952  row->baseline.quadratics[src_index].a;
953  coeffs[dest_index * 3 + 1] =
954  row->baseline.quadratics[src_index].b;
955  coeffs[dest_index * 3 + 2] =
956  row->baseline.quadratics[src_index].c;
957  dest_index++;
958  xstarts[dest_index] =
959  row->baseline.xcoords[src_index + 1];
960  }
961  src_index++;
962  }
963  coeffs[dest_index * 3] =
964  row->baseline.quadratics[src_index].a;
965  coeffs[dest_index * 3 + 1] =
966  row->baseline.quadratics[src_index].b;
967  coeffs[dest_index * 3 + 2] =
968  row->baseline.quadratics[src_index].c;
969  dest_index++;
970  xstarts[dest_index] = row->baseline.xcoords[src_index + 1];
971  }
972  }
973  }
974  }
975  while (src_index < row->baseline.segments
976  && row->baseline.xcoords[src_index + 1] <= xstarts[dest_index])
977  src_index++;
978  while (src_index < row->baseline.segments) {
979  coeffs[dest_index * 3] = row->baseline.quadratics[src_index].a;
980  coeffs[dest_index * 3 + 1] = row->baseline.quadratics[src_index].b;
981  coeffs[dest_index * 3 + 2] = row->baseline.quadratics[src_index].c;
982  dest_index++;
983  src_index++;
984  xstarts[dest_index] = row->baseline.xcoords[src_index];
985  }
986  //turn to spline
987  row->baseline = QSPLINE (dest_index, xstarts, coeffs);
988  free_mem(xstarts);
989  free_mem(coeffs);
990 }
void free_mem(void *oldchunk)
Definition: memry.cpp:47
int32_t inT32
Definition: host.h:38
WERD_LIST * word_list()
Definition: ocrrow.h:52
float x_height() const
Definition: ocrrow.h:61
inT16 left() const
Definition: rect.h:68
void * alloc_mem(inT32 count)
Definition: memry.cpp:39
double a
Definition: quadratc.h:58
Definition: rect.h:30
TBOX bounding_box() const
Definition: stepblob.cpp:250
C_BLOB_LIST * cblob_list()
Definition: werd.h:100
inT16 height() const
Definition: rect.h:104
float c
Definition: quadratc.h:60
inT16 right() const
Definition: rect.h:75
inT16 bottom() const
Definition: rect.h:61
float base_line(float xpos) const
Definition: ocrrow.h:56
Definition: werd.h:60
float b
Definition: quadratc.h:59