#include <baselinedetect.h>
Definition at line 40 of file baselinedetect.h.
◆ BaselineRow()
tesseract::BaselineRow::BaselineRow |
( |
double |
line_size, |
|
|
TO_ROW * |
to_row |
|
) |
| |
Definition at line 65 of file baselinedetect.cpp.
67 baseline_pt1_(0.0f, 0.0f), baseline_pt2_(0.0f, 0.0f),
68 baseline_error_(0.0), good_baseline_(
false) {
const double kMaxBaselineError
BLOBNBOX_LIST * blob_list()
const double kFitHalfrangeFactor
const double kOffsetQuantizationFactor
◆ AdjustBaselineToGrid()
double tesseract::BaselineRow::AdjustBaselineToGrid |
( |
int |
debug, |
|
|
const FCOORD & |
direction, |
|
|
double |
line_spacing, |
|
|
double |
line_offset |
|
) |
| |
Definition at line 229 of file baselinedetect.cpp.
233 if (blobs_->empty()) {
236 bounding_box_.
print();
241 double best_error = 0.0;
243 for (
int i = 0; i < displacement_modes_.
size(); ++i) {
244 double blob_y = displacement_modes_[i];
248 tprintf(
"Mode at %g has error %g from model \n", blob_y, error);
250 if (best_index < 0 || error < best_error) {
257 double model_margin = max_baseline_error_ - best_error;
258 if (best_index >= 0 && model_margin > 0.0) {
262 double shift = displacement_modes_[best_index] - perp_disp;
263 if (fabs(shift) > max_baseline_error_) {
265 tprintf(
"Attempting linespacing model fit with mode %g to row at:",
266 displacement_modes_[best_index]);
267 bounding_box_.
print();
269 FitConstrainedIfBetter(debug,
direction, model_margin,
270 displacement_modes_[best_index]);
271 }
else if (debug > 1) {
272 tprintf(
"Linespacing model only moves current line by %g for row at:",
274 bounding_box_.
print();
276 }
else if (debug > 1) {
277 tprintf(
"Linespacing model not close enough to any mode for row at:");
278 bounding_box_.
print();
static double SpacingModelError(double perp_disp, double line_spacing, double line_offset)
int direction(EDGEPT *point)
double PerpDisp(const FCOORD &direction) const
◆ AdjustBaselineToParallel()
void tesseract::BaselineRow::AdjustBaselineToParallel |
( |
int |
debug, |
|
|
const FCOORD & |
direction |
|
) |
| |
Definition at line 214 of file baselinedetect.cpp.
217 if (displacement_modes_.
empty())
220 if (bounding_box_.
bottom() < kDebugYCoord &&
221 bounding_box_.
top() > kDebugYCoord && debug < 3)
224 FitConstrainedIfBetter(debug,
direction, 0.0, displacement_modes_[0]);
int direction(EDGEPT *point)
◆ BaselineAngle()
double tesseract::BaselineRow::BaselineAngle |
( |
| ) |
const |
Definition at line 98 of file baselinedetect.cpp.
99 FCOORD baseline_dir(baseline_pt2_ - baseline_pt1_);
100 double angle = baseline_dir.angle();
103 return fmod(angle + M_PI * 1.5, M_PI) - M_PI * 0.5;
◆ bounding_box()
const TBOX& tesseract::BaselineRow::bounding_box |
( |
| ) |
const |
|
inline |
◆ FitBaseline()
bool tesseract::BaselineRow::FitBaseline |
( |
bool |
use_box_bottoms | ) |
|
Definition at line 142 of file baselinedetect.cpp.
147 BLOBNBOX_IT blob_it(blobs_);
149 for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
153 int x_middle = (box.
left() + box.
right()) / 2;
155 if (box.
bottom() < kDebugYCoord && box.
top() > kDebugYCoord) {
156 tprintf(
"Box bottom = %d, baseline pos=%d for box at:",
166 baseline_error_ = fitter_.
Fit(&pt1, &pt2);
169 if (baseline_error_ > max_baseline_error_ &&
175 if (error < baseline_error_ / 2.0) {
176 baseline_error_ = error;
184 debug = bounding_box_.
bottom() < kDebugYCoord &&
185 bounding_box_.
top() > kDebugYCoord
192 good_baseline_ =
false;
193 FitConstrainedIfBetter(debug,
direction, 0.0, target_offset);
199 if (fabs(angle) > M_PI * 0.25) {
202 baseline_pt2_ = baseline_pt1_ +
FCOORD(1.0f, llsq.
m());
205 double c = llsq.
c(m);
206 baseline_error_ = llsq.
rms(m, c);
207 good_baseline_ =
false;
209 return good_baseline_;
const TBOX & bounding_box() const
double rms(double m, double c) const
double Fit(ICOORD *pt1, ICOORD *pt2)
void Add(const ICOORD &pt)
void add(double x, double y)
int baseline_position() const
bool SufficientPointsForIndependentFit() const
int direction(EDGEPT *point)
void EstimateBaselinePosition()
FCOORD mean_point() const
double BaselineAngle() const
◆ PerpDisp()
double tesseract::BaselineRow::PerpDisp |
( |
const FCOORD & |
direction | ) |
const |
Definition at line 121 of file baselinedetect.cpp.
122 float middle_x = (bounding_box_.
left() + bounding_box_.
right()) / 2.0f;
int direction(EDGEPT *point)
double StraightYAtX(double x) const
◆ Print()
void tesseract::BaselineRow::Print |
( |
| ) |
const |
Definition at line 87 of file baselinedetect.cpp.
88 tprintf(
"Baseline (%g,%g)->(%g,%g), angle=%g, intercept=%g\n",
89 baseline_pt1_.
x(), baseline_pt1_.
y(),
90 baseline_pt2_.
x(), baseline_pt2_.
y(),
92 tprintf(
"Quant factor=%g, error=%g, good=%d, box:",
93 disp_quant_factor_, baseline_error_, good_baseline_);
94 bounding_box_.
print();
double StraightYAtX(double x) const
double BaselineAngle() const
◆ SetupOldLineParameters()
void tesseract::BaselineRow::SetupOldLineParameters |
( |
TO_ROW * |
row | ) |
const |
Definition at line 77 of file baselinedetect.cpp.
82 row->
set_line(gradient, para_c, baseline_error_);
void set_parallel_line(float gradient, float new_c, float new_error)
double StraightYAtX(double x) const
void set_line(float new_m, float new_c, float new_error)
double BaselineAngle() const
◆ SpaceBetween()
double tesseract::BaselineRow::SpaceBetween |
( |
const BaselineRow & |
other | ) |
const |
Definition at line 108 of file baselinedetect.cpp.
110 float x = (
MAX(bounding_box_.
left(), other.bounding_box_.left()) +
111 MIN(bounding_box_.
right(), other.bounding_box_.right())) / 2.0f;
113 float y = (
StraightYAtX(x) + other.StraightYAtX(x)) / 2.0f;
116 return PerpDistanceFromBaseline(pt) + other.PerpDistanceFromBaseline(pt);
double StraightYAtX(double x) const
◆ StraightYAtX()
double tesseract::BaselineRow::StraightYAtX |
( |
double |
x | ) |
const |
Definition at line 129 of file baselinedetect.cpp.
130 double denominator = baseline_pt2_.
x() - baseline_pt1_.
x();
131 if (denominator == 0.0)
132 return (baseline_pt1_.
y() + baseline_pt2_.
y()) / 2.0;
133 return baseline_pt1_.
y() +
134 (x - baseline_pt1_.
x()) * (baseline_pt2_.
y() - baseline_pt1_.
y()) /
The documentation for this class was generated from the following files: