tesseract  4.0.0-1-g2a2b
tesseract::BaselineDetect Class Reference

#include <baselinedetect.h>

Public Member Functions

 BaselineDetect (int debug_level, const FCOORD &page_skew, TO_BLOCK_LIST *blocks)
 
 ~BaselineDetect ()=default
 
void ComputeStraightBaselines (bool use_box_bottoms)
 
void ComputeBaselineSplinesAndXheights (const ICOORD &page_tr, bool enable_splines, bool remove_noise, bool show_final_rows, Textord *textord)
 

Detailed Description

Definition at line 242 of file baselinedetect.h.

Constructor & Destructor Documentation

◆ BaselineDetect()

tesseract::BaselineDetect::BaselineDetect ( int  debug_level,
const FCOORD page_skew,
TO_BLOCK_LIST *  blocks 
)

Definition at line 793 of file baselinedetect.cpp.

795  : page_skew_(page_skew), debug_level_(debug_level) {
796  TO_BLOCK_IT it(blocks);
797  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
798  TO_BLOCK* to_block = it.data();
799  BLOCK* block = to_block->block;
800  POLY_BLOCK* pb = block->pdblk.poly_block();
801  // A note about non-text blocks.
802  // On output, non-text blocks are supposed to contain a single empty word
803  // in each incoming text line. These mark out the polygonal bounds of the
804  // block. Ideally no baselines should be required, but currently
805  // make_words crashes if a baseline and xheight are not provided, so we
806  // include non-text blocks here, but flag them for special treatment.
807  bool non_text = pb != nullptr && !pb->IsText();
808  blocks_.push_back(new BaselineBlock(debug_level_, non_text, to_block));
809  }
810 }
POLY_BLOCK * poly_block() const
Definition: pdblock.h:56
bool IsText() const
Definition: polyblk.h:49
Definition: ocrblock.h:30
BLOCK * block
Definition: blobbox.h:790
PDBLK pdblk
Definition: ocrblock.h:192

◆ ~BaselineDetect()

tesseract::BaselineDetect::~BaselineDetect ( )
default

Member Function Documentation

◆ ComputeBaselineSplinesAndXheights()

void tesseract::BaselineDetect::ComputeBaselineSplinesAndXheights ( const ICOORD page_tr,
bool  enable_splines,
bool  remove_noise,
bool  show_final_rows,
Textord textord 
)

Definition at line 847 of file baselinedetect.cpp.

851  {
852  for (int i = 0; i < blocks_.size(); ++i) {
853  BaselineBlock* bl_block = blocks_[i];
854  if (enable_splines)
855  bl_block->PrepareForSplineFitting(page_tr, remove_noise);
856  bl_block->FitBaselineSplines(enable_splines, show_final_rows, textord);
857  if (show_final_rows) {
858  bl_block->DrawFinalRows(page_tr);
859  }
860  }
861 }

◆ ComputeStraightBaselines()

void tesseract::BaselineDetect::ComputeStraightBaselines ( bool  use_box_bottoms)

Definition at line 815 of file baselinedetect.cpp.

815  {
816  GenericVector<double> block_skew_angles;
817  for (int i = 0; i < blocks_.size(); ++i) {
818  BaselineBlock* bl_block = blocks_[i];
819  if (debug_level_ > 0)
820  tprintf("Fitting initial baselines...\n");
821  if (bl_block->FitBaselinesAndFindSkew(use_box_bottoms)) {
822  block_skew_angles.push_back(bl_block->skew_angle());
823  }
824  }
825  // Compute a page-wide default skew for blocks with too little information.
826  double default_block_skew = page_skew_.angle();
827  if (!block_skew_angles.empty()) {
828  default_block_skew = MedianOfCircularValues(M_PI, &block_skew_angles);
829  }
830  if (debug_level_ > 0) {
831  tprintf("Page skew angle = %g\n", default_block_skew);
832  }
833  // Set bad lines in each block to the default block skew and then force fit
834  // a linespacing model where it makes sense to do so.
835  for (int i = 0; i < blocks_.size(); ++i) {
836  BaselineBlock* bl_block = blocks_[i];
837  bl_block->ParallelizeBaselines(default_block_skew);
838  bl_block->SetupBlockParameters(); // This replaced compute_row_stats.
839  }
840 }
float angle() const
find angle
Definition: points.h:248
bool empty() const
Definition: genericvector.h:90
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:37
int push_back(T object)
T MedianOfCircularValues(T modulus, GenericVector< T > *v)
Definition: linlsq.h:113

The documentation for this class was generated from the following files: