tesseract  5.0.0-alpha-619-ge9db
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 790 of file baselinedetect.cpp.

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

◆ ~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 844 of file baselinedetect.cpp.

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

◆ ComputeStraightBaselines()

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

Definition at line 812 of file baselinedetect.cpp.

812  {
813  GenericVector<double> block_skew_angles;
814  for (int i = 0; i < blocks_.size(); ++i) {
815  BaselineBlock* bl_block = blocks_[i];
816  if (debug_level_ > 0)
817  tprintf("Fitting initial baselines...\n");
818  if (bl_block->FitBaselinesAndFindSkew(use_box_bottoms)) {
819  block_skew_angles.push_back(bl_block->skew_angle());
820  }
821  }
822  // Compute a page-wide default skew for blocks with too little information.
823  double default_block_skew = page_skew_.angle();
824  if (!block_skew_angles.empty()) {
825  default_block_skew = MedianOfCircularValues(M_PI, &block_skew_angles);
826  }
827  if (debug_level_ > 0) {
828  tprintf("Page skew angle = %g\n", default_block_skew);
829  }
830  // Set bad lines in each block to the default block skew and then force fit
831  // a linespacing model where it makes sense to do so.
832  for (int i = 0; i < blocks_.size(); ++i) {
833  BaselineBlock* bl_block = blocks_[i];
834  bl_block->ParallelizeBaselines(default_block_skew);
835  bl_block->SetupBlockParameters(); // This replaced compute_row_stats.
836  }
837 }

The documentation for this class was generated from the following files:
FCOORD::angle
float angle() const
find angle
Definition: points.h:246
POLY_BLOCK::IsText
bool IsText() const
Definition: polyblk.h:62
TO_BLOCK
Definition: blobbox.h:691
GenericVector::push_back
int push_back(T object)
Definition: genericvector.h:799
BLOCK
Definition: ocrblock.h:28
BLOCK::pdblk
PDBLK pdblk
Page Description Block.
Definition: ocrblock.h:189
PDBLK::poly_block
POLY_BLOCK * poly_block() const
Definition: pdblock.h:54
TO_BLOCK::block
BLOCK * block
Definition: blobbox.h:776
GenericVector::empty
bool empty() const
Definition: genericvector.h:86
GenericVector< double >
tprintf
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:34
POLY_BLOCK
Definition: polyblk.h:26
MedianOfCircularValues
T MedianOfCircularValues(T modulus, GenericVector< T > *v)
Definition: linlsq.h:112