tesseract v5.3.3.20231005
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 239 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 846 of file baselinedetect.cpp.

848 : page_skew_(page_skew), debug_level_(debug_level) {
849 TO_BLOCK_IT it(blocks);
850 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
851 TO_BLOCK *to_block = it.data();
852 BLOCK *block = to_block->block;
853 POLY_BLOCK *pb = block->pdblk.poly_block();
854 // A note about non-text blocks.
855 // On output, non-text blocks are supposed to contain a single empty word
856 // in each incoming text line. These mark out the polygonal bounds of the
857 // block. Ideally no baselines should be required, but currently
858 // make_words crashes if a baseline and xheight are not provided, so we
859 // include non-text blocks here, but flag them for special treatment.
860 bool non_text = pb != nullptr && !pb->IsText();
861 blocks_.push_back(new BaselineBlock(debug_level_, non_text, to_block));
862 }
863}

◆ ~BaselineDetect()

tesseract::BaselineDetect::~BaselineDetect ( )
inline

Definition at line 243 of file baselinedetect.h.

243 {
244 for (auto block : blocks_) {
245 delete block;
246 }
247 }

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

903 {
904 for (auto bl_block : blocks_) {
905 if (enable_splines) {
906 bl_block->PrepareForSplineFitting(page_tr, remove_noise);
907 }
908 bl_block->FitBaselineSplines(enable_splines, show_final_rows, textord);
909#ifndef GRAPHICS_DISABLED
910 if (show_final_rows) {
911 bl_block->DrawFinalRows(page_tr);
912 }
913#endif
914 }
915}

◆ ComputeStraightBaselines()

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

Definition at line 868 of file baselinedetect.cpp.

868 {
869 std::vector<double> block_skew_angles;
870 for (auto bl_block : blocks_) {
871 if (debug_level_ > 0) {
872 tprintf("Fitting initial baselines...\n");
873 }
874 if (bl_block->FitBaselinesAndFindSkew(use_box_bottoms)) {
875 block_skew_angles.push_back(bl_block->skew_angle());
876 }
877 }
878 // Compute a page-wide default skew for blocks with too little information.
879 double default_block_skew = page_skew_.angle();
880 if (!block_skew_angles.empty()) {
881 default_block_skew = MedianOfCircularValues(M_PI, block_skew_angles);
882 }
883 if (debug_level_ > 0) {
884 tprintf("Page skew angle = %g\n", default_block_skew);
885 }
886 // Set bad lines in each block to the default block skew and then force fit
887 // a linespacing model where it makes sense to do so.
888 for (auto bl_block : blocks_) {
889 bl_block->ParallelizeBaselines(default_block_skew);
890 bl_block->SetupBlockParameters(); // This replaced compute_row_stats.
891 }
892}
void tprintf(const char *format,...)
Definition: tprintf.cpp:41
T MedianOfCircularValues(T modulus, std::vector< T > &v)
Definition: linlsq.h:117
float angle() const
find angle
Definition: points.h:246

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