All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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)
 
void SetDebugImage (Pix *pixIn, const STRING &output_path)
 

Detailed Description

Definition at line 242 of file baselinedetect.h.

Constructor & Destructor Documentation

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

Definition at line 786 of file baselinedetect.cpp.

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

Definition at line 806 of file baselinedetect.cpp.

806  {
807  pixDestroy(&pix_debug_);
808 }

Member Function Documentation

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

Definition at line 845 of file baselinedetect.cpp.

849  {
850  Pix* pix_spline = pix_debug_ ? pixConvertTo32(pix_debug_) : NULL;
851  for (int i = 0; i < blocks_.size(); ++i) {
852  BaselineBlock* bl_block = blocks_[i];
853  bl_block->PrepareForSplineFitting(page_tr, remove_noise);
854  bl_block->FitBaselineSplines(enable_splines, show_final_rows, textord);
855  if (pix_spline) {
856  bl_block->DrawPixSpline(pix_spline);
857  }
858  if (show_final_rows) {
859  bl_block->DrawFinalRows(page_tr);
860  }
861  }
862 
863  if (pix_spline) {
864  STRING outfile_name = debug_file_prefix_ + "_spline.png";
865  pixWrite(outfile_name.string(), pix_spline, IFF_PNG);
866  pixDestroy(&pix_spline);
867  }
868 }
Definition: strngs.h:44
#define NULL
Definition: host.h:144
const char * string() const
Definition: strngs.cpp:193
void tesseract::BaselineDetect::ComputeStraightBaselines ( bool  use_box_bottoms)

Definition at line 813 of file baselinedetect.cpp.

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

Definition at line 870 of file baselinedetect.cpp.

870  {
871  pixDestroy(&pix_debug_);
872  pix_debug_ = pixClone(pixIn);
873  debug_file_prefix_ = output_path;
874 }

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