tesseract  4.00.00dev
tesseract::BaselineDetect Class Reference

#include <baselinedetect.h>

Public Member Functions

 BaselineDetect (int debug_level, const FCOORD &page_skew, TO_BLOCK_LIST *blocks)
 
 ~BaselineDetect ()
 
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 785 of file baselinedetect.cpp.

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

◆ ~BaselineDetect()

tesseract::BaselineDetect::~BaselineDetect ( )

Definition at line 804 of file baselinedetect.cpp.

804  {
805 }

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 842 of file baselinedetect.cpp.

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

◆ ComputeStraightBaselines()

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

Definition at line 810 of file baselinedetect.cpp.

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

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