All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
tordmain.cpp File Reference
#include "stderr.h"
#include "globaloc.h"
#include "blread.h"
#include "blobbox.h"
#include "ccstruct.h"
#include "edgblob.h"
#include "drawtord.h"
#include "makerow.h"
#include "wordseg.h"
#include "textord.h"
#include "tordmain.h"
#include "allheaders.h"

Go to the source code of this file.

Classes

struct  tesseract::BlockGroup
 

Namespaces

 tesseract
 

Macros

#define EXTERN
 
#define MAX_NEAREST_DIST   600
 

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)
 

Variables

const int kWordGridSize = 50
 

Macro Definition Documentation

#define EXTERN

Definition at line 45 of file tordmain.cpp.

#define MAX_NEAREST_DIST   600

Definition at line 47 of file tordmain.cpp.

Function Documentation

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

Definition at line 886 of file tordmain.cpp.

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

Variable Documentation

const int kWordGridSize = 50

Definition at line 42 of file tordmain.cpp.