tesseract  5.0.0-alpha-619-ge9db
tordmain.cpp File Reference
#include "tordmain.h"
#include <cfloat>
#include <cmath>
#include <cstdint>
#include "allheaders.h"
#include "arrayaccess.h"
#include "blobbox.h"
#include "ccstruct.h"
#include "clst.h"
#include "coutln.h"
#include "drawtord.h"
#include "edgblob.h"
#include "errcode.h"
#include <tesseract/genericvector.h>
#include "makerow.h"
#include "morph.h"
#include "ocrblock.h"
#include "ocrrow.h"
#include "params.h"
#include "pdblock.h"
#include "points.h"
#include "polyblk.h"
#include "quadratc.h"
#include "quspline.h"
#include "rect.h"
#include "scrollview.h"
#include "statistc.h"
#include "stepblob.h"
#include "textord.h"
#include "tprintf.h"
#include "werd.h"

Go to the source code of this file.

Classes

struct  tesseract::BlockGroup
 

Namespaces

 tesseract
 

Macros

#define _USE_MATH_DEFINES
 
#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)
 

Macro Definition Documentation

◆ _USE_MATH_DEFINES

#define _USE_MATH_DEFINES

Definition at line 18 of file tordmain.cpp.

◆ MAX_NEAREST_DIST

#define MAX_NEAREST_DIST   600

Definition at line 57 of file tordmain.cpp.

Function Documentation

◆ tweak_row_baseline()

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

Definition at line 893 of file tordmain.cpp.

897  {
898  TBOX blob_box; //bounding box
899  C_BLOB *blob; //current blob
900  WERD *word; //current word
901  int32_t blob_count; //no of blobs
902  int32_t src_index; //source segment
903  int32_t dest_index; //destination segment
904  float ydiff; //baseline error
905  float x_centre; //centre of blob
906  //words of row
907  WERD_IT word_it = row->word_list ();
908  C_BLOB_IT blob_it; //blob iterator
909 
910  blob_count = 0;
911  for (word_it.mark_cycle_pt (); !word_it.cycled_list (); word_it.forward ()) {
912  word = word_it.data (); //current word
913  //get total blobs
914  blob_count += word->cblob_list ()->length ();
915  }
916  if (blob_count == 0)
917  return;
918  // spline segments
919  std::vector<int32_t> xstarts(blob_count + row->baseline.segments + 1);
920  // spline coeffs
921  std::vector<double> coeffs((blob_count + row->baseline.segments) * 3);
922 
923  src_index = 0;
924  dest_index = 0;
925  xstarts[0] = row->baseline.xcoords[0];
926  for (word_it.mark_cycle_pt (); !word_it.cycled_list (); word_it.forward ()) {
927  word = word_it.data (); //current word
928  //blobs in word
929  blob_it.set_to_list (word->cblob_list ());
930  for (blob_it.mark_cycle_pt (); !blob_it.cycled_list ();
931  blob_it.forward ()) {
932  blob = blob_it.data ();
933  blob_box = blob->bounding_box ();
934  x_centre = (blob_box.left () + blob_box.right ()) / 2.0;
935  ydiff = blob_box.bottom () - row->base_line (x_centre);
936  if (ydiff < 0)
937  ydiff = -ydiff / row->x_height ();
938  else
939  ydiff = ydiff / row->x_height ();
940  if (ydiff < blshift_maxshift
941  && blob_box.height () / row->x_height () > blshift_xfraction) {
942  if (xstarts[dest_index] >= x_centre)
943  xstarts[dest_index] = blob_box.left ();
944  coeffs[dest_index * 3] = 0;
945  coeffs[dest_index * 3 + 1] = 0;
946  coeffs[dest_index * 3 + 2] = blob_box.bottom ();
947  //shift it
948  dest_index++;
949  xstarts[dest_index] = blob_box.right () + 1;
950  }
951  else {
952  if (xstarts[dest_index] <= x_centre) {
953  while (row->baseline.xcoords[src_index + 1] <= x_centre
954  && src_index < row->baseline.segments - 1) {
955  if (row->baseline.xcoords[src_index + 1] >
956  xstarts[dest_index]) {
957  coeffs[dest_index * 3] =
958  row->baseline.quadratics[src_index].a;
959  coeffs[dest_index * 3 + 1] =
960  row->baseline.quadratics[src_index].b;
961  coeffs[dest_index * 3 + 2] =
962  row->baseline.quadratics[src_index].c;
963  dest_index++;
964  xstarts[dest_index] =
965  row->baseline.xcoords[src_index + 1];
966  }
967  src_index++;
968  }
969  coeffs[dest_index * 3] =
970  row->baseline.quadratics[src_index].a;
971  coeffs[dest_index * 3 + 1] =
972  row->baseline.quadratics[src_index].b;
973  coeffs[dest_index * 3 + 2] =
974  row->baseline.quadratics[src_index].c;
975  dest_index++;
976  xstarts[dest_index] = row->baseline.xcoords[src_index + 1];
977  }
978  }
979  }
980  }
981  while (src_index < row->baseline.segments
982  && row->baseline.xcoords[src_index + 1] <= xstarts[dest_index])
983  src_index++;
984  while (src_index < row->baseline.segments) {
985  coeffs[dest_index * 3] = row->baseline.quadratics[src_index].a;
986  coeffs[dest_index * 3 + 1] = row->baseline.quadratics[src_index].b;
987  coeffs[dest_index * 3 + 2] = row->baseline.quadratics[src_index].c;
988  dest_index++;
989  src_index++;
990  xstarts[dest_index] = row->baseline.xcoords[src_index];
991  }
992  //turn to spline
C_BLOB::bounding_box
TBOX bounding_box() const
Definition: stepblob.cpp:247
ROW::base_line
float base_line(float xpos) const
Definition: ocrrow.h:58
QUAD_COEFFS::a
double a
Definition: quadratc.h:71
baseline
Definition: mfoutline.h:62
C_BLOB
Definition: stepblob.h:36
TBOX::height
int16_t height() const
Definition: rect.h:107
WERD::cblob_list
C_BLOB_LIST * cblob_list()
Definition: werd.h:94
ROW::x_height
float x_height() const
Definition: ocrrow.h:63
TBOX::bottom
int16_t bottom() const
Definition: rect.h:64
WERD
Definition: werd.h:55
TBOX::left
int16_t left() const
Definition: rect.h:71
TBOX::right
int16_t right() const
Definition: rect.h:78
QUAD_COEFFS::c
float c
Definition: quadratc.h:73
QUAD_COEFFS::b
float b
Definition: quadratc.h:72
ROW::word_list
WERD_LIST * word_list()
Definition: ocrrow.h:54
TBOX
Definition: rect.h:33