#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 67 of file baselinedetect.cpp.
69 baseline_pt1_(0.0f, 0.0f), baseline_pt2_(0.0f, 0.0f),
70 baseline_error_(0.0), good_baseline_(
false) {
const double kMaxBaselineError
const double kFitHalfrangeFactor
const double kOffsetQuantizationFactor
BLOBNBOX_LIST * blob_list()
◆ AdjustBaselineToGrid()
double tesseract::BaselineRow::AdjustBaselineToGrid |
( |
int |
debug, |
|
|
const FCOORD & |
direction, |
|
|
double |
line_spacing, |
|
|
double |
line_offset |
|
) |
| |
Definition at line 231 of file baselinedetect.cpp.
235 if (blobs_->empty()) {
238 bounding_box_.
print();
243 double best_error = 0.0;
245 for (
int i = 0; i < displacement_modes_.
size(); ++i) {
246 double blob_y = displacement_modes_[i];
250 tprintf(
"Mode at %g has error %g from model \n", blob_y, error);
252 if (best_index < 0 || error < best_error) {
259 double model_margin = max_baseline_error_ - best_error;
260 if (best_index >= 0 && model_margin > 0.0) {
264 double shift = displacement_modes_[best_index] - perp_disp;
265 if (fabs(shift) > max_baseline_error_) {
267 tprintf(
"Attempting linespacing model fit with mode %g to row at:",
268 displacement_modes_[best_index]);
269 bounding_box_.
print();
271 FitConstrainedIfBetter(debug,
direction, model_margin,
272 displacement_modes_[best_index]);
273 }
else if (debug > 1) {
274 tprintf(
"Linespacing model only moves current line by %g for row at:",
276 bounding_box_.
print();
278 }
else if (debug > 1) {
279 tprintf(
"Linespacing model not close enough to any mode for row at:");
280 bounding_box_.
print();
int direction(EDGEPT *point)
double PerpDisp(const FCOORD &direction) const
static double SpacingModelError(double perp_disp, double line_spacing, double line_offset)
DLLSYM void tprintf(const char *format,...)
◆ AdjustBaselineToParallel()
void tesseract::BaselineRow::AdjustBaselineToParallel |
( |
int |
debug, |
|
|
const FCOORD & |
direction |
|
) |
| |
Definition at line 216 of file baselinedetect.cpp.
219 if (displacement_modes_.
empty())
222 if (bounding_box_.
bottom() < kDebugYCoord &&
223 bounding_box_.
top() > kDebugYCoord && debug < 3)
226 FitConstrainedIfBetter(debug,
direction, 0.0, displacement_modes_[0]);
int direction(EDGEPT *point)
◆ BaselineAngle()
double tesseract::BaselineRow::BaselineAngle |
( |
| ) |
const |
Definition at line 100 of file baselinedetect.cpp.
101 FCOORD baseline_dir(baseline_pt2_ - baseline_pt1_);
102 double angle = baseline_dir.angle();
105 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 144 of file baselinedetect.cpp.
149 BLOBNBOX_IT blob_it(blobs_);
151 for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
155 int x_middle = (box.
left() + box.
right()) / 2;
157 if (box.
bottom() < kDebugYCoord && box.
top() > kDebugYCoord) {
158 tprintf(
"Box bottom = %d, baseline pos=%d for box at:",
168 baseline_error_ = fitter_.
Fit(&pt1, &pt2);
171 if (baseline_error_ > max_baseline_error_ &&
177 if (error < baseline_error_ / 2.0) {
178 baseline_error_ = error;
186 debug = bounding_box_.
bottom() < kDebugYCoord &&
187 bounding_box_.
top() > kDebugYCoord
194 good_baseline_ =
false;
195 FitConstrainedIfBetter(debug,
direction, 0.0, target_offset);
201 if (fabs(angle) > M_PI * 0.25) {
204 baseline_pt2_ = baseline_pt1_ +
FCOORD(1.0f, llsq.
m());
207 double c = llsq.
c(m);
208 baseline_error_ = llsq.
rms(m, c);
209 good_baseline_ =
false;
211 return good_baseline_;
int direction(EDGEPT *point)
double BaselineAngle() const
void add(double x, double y)
bool SufficientPointsForIndependentFit() const
FCOORD mean_point() const
void Add(const ICOORD &pt)
void EstimateBaselinePosition()
double Fit(ICOORD *pt1, ICOORD *pt2)
DLLSYM void tprintf(const char *format,...)
double rms(double m, double c) const
const TBOX & bounding_box() const
int baseline_position() const
◆ PerpDisp()
double tesseract::BaselineRow::PerpDisp |
( |
const FCOORD & |
direction | ) |
const |
Definition at line 123 of file baselinedetect.cpp.
124 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 89 of file baselinedetect.cpp.
90 tprintf(
"Baseline (%g,%g)->(%g,%g), angle=%g, intercept=%g\n",
91 baseline_pt1_.
x(), baseline_pt1_.
y(),
92 baseline_pt2_.
x(), baseline_pt2_.
y(),
94 tprintf(
"Quant factor=%g, error=%g, good=%d, box:",
95 disp_quant_factor_, baseline_error_, good_baseline_);
96 bounding_box_.
print();
double BaselineAngle() const
DLLSYM void tprintf(const char *format,...)
double StraightYAtX(double x) const
◆ SetupOldLineParameters()
void tesseract::BaselineRow::SetupOldLineParameters |
( |
TO_ROW * |
row | ) |
const |
Definition at line 79 of file baselinedetect.cpp.
84 row->
set_line(gradient, para_c, baseline_error_);
double BaselineAngle() const
void set_line(float new_m, float new_c, float new_error)
void set_parallel_line(float gradient, float new_c, float new_error)
double StraightYAtX(double x) const
◆ SpaceBetween()
double tesseract::BaselineRow::SpaceBetween |
( |
const BaselineRow & |
other | ) |
const |
Definition at line 110 of file baselinedetect.cpp.
112 float x = (std::max(bounding_box_.
left(), other.bounding_box_.left()) +
113 std::min(bounding_box_.
right(), other.bounding_box_.right())) / 2.0f;
115 float y = (
StraightYAtX(x) + other.StraightYAtX(x)) / 2.0f;
118 return PerpDistanceFromBaseline(pt) + other.PerpDistanceFromBaseline(pt);
double StraightYAtX(double x) const
◆ StraightYAtX()
double tesseract::BaselineRow::StraightYAtX |
( |
double |
x | ) |
const |
Definition at line 131 of file baselinedetect.cpp.
132 double denominator = baseline_pt2_.
x() - baseline_pt1_.
x();
133 if (denominator == 0.0)
134 return (baseline_pt1_.
y() + baseline_pt2_.
y()) / 2.0;
135 return baseline_pt1_.
y() +
136 (x - baseline_pt1_.
x()) * (baseline_pt2_.
y() - baseline_pt1_.
y()) /
The documentation for this class was generated from the following files: