#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 64 of file baselinedetect.cpp.
66 baseline_pt1_(0.0f, 0.0f), baseline_pt2_(0.0f, 0.0f),
67 baseline_error_(0.0), good_baseline_(
false) {
◆ AdjustBaselineToGrid()
double tesseract::BaselineRow::AdjustBaselineToGrid |
( |
int |
debug, |
|
|
const FCOORD & |
direction, |
|
|
double |
line_spacing, |
|
|
double |
line_offset |
|
) |
| |
Definition at line 228 of file baselinedetect.cpp.
232 if (blobs_->empty()) {
235 bounding_box_.
print();
240 double best_error = 0.0;
242 for (
int i = 0; i < displacement_modes_.
size(); ++i) {
243 double blob_y = displacement_modes_[i];
247 tprintf(
"Mode at %g has error %g from model \n", blob_y, error);
249 if (best_index < 0 || error < best_error) {
256 double model_margin = max_baseline_error_ - best_error;
257 if (best_index >= 0 && model_margin > 0.0) {
260 double perp_disp =
PerpDisp(direction);
261 double shift = displacement_modes_[best_index] - perp_disp;
262 if (fabs(shift) > max_baseline_error_) {
264 tprintf(
"Attempting linespacing model fit with mode %g to row at:",
265 displacement_modes_[best_index]);
266 bounding_box_.
print();
268 FitConstrainedIfBetter(debug, direction, model_margin,
269 displacement_modes_[best_index]);
270 }
else if (debug > 1) {
271 tprintf(
"Linespacing model only moves current line by %g for row at:",
273 bounding_box_.
print();
275 }
else if (debug > 1) {
276 tprintf(
"Linespacing model not close enough to any mode for row at:");
277 bounding_box_.
print();
279 return fmod(
PerpDisp(direction), line_spacing);
◆ AdjustBaselineToParallel()
void tesseract::BaselineRow::AdjustBaselineToParallel |
( |
int |
debug, |
|
|
const FCOORD & |
direction |
|
) |
| |
Definition at line 213 of file baselinedetect.cpp.
215 SetupBlobDisplacements(direction);
216 if (displacement_modes_.
empty())
219 if (bounding_box_.
bottom() < kDebugYCoord &&
220 bounding_box_.
top() > kDebugYCoord && debug < 3)
223 FitConstrainedIfBetter(debug, direction, 0.0, displacement_modes_[0]);
◆ BaselineAngle()
double tesseract::BaselineRow::BaselineAngle |
( |
| ) |
const |
Definition at line 97 of file baselinedetect.cpp.
98 FCOORD baseline_dir(baseline_pt2_ - baseline_pt1_);
99 double angle = baseline_dir.angle();
102 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 141 of file baselinedetect.cpp.
146 BLOBNBOX_IT blob_it(blobs_);
148 for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
152 int x_middle = (box.
left() + box.
right()) / 2;
154 if (box.
bottom() < kDebugYCoord && box.
top() > kDebugYCoord) {
155 tprintf(
"Box bottom = %d, baseline pos=%d for box at:",
165 baseline_error_ = fitter_.
Fit(&pt1, &pt2);
168 if (baseline_error_ > max_baseline_error_ &&
174 if (error < baseline_error_ / 2.0) {
175 baseline_error_ = error;
183 debug = bounding_box_.
bottom() < kDebugYCoord &&
184 bounding_box_.
top() > kDebugYCoord
189 FCOORD direction(pt2 - pt1);
190 double target_offset = direction * pt1;
191 good_baseline_ =
false;
192 FitConstrainedIfBetter(debug, direction, 0.0, target_offset);
198 if (fabs(angle) > M_PI * 0.25) {
201 baseline_pt2_ = baseline_pt1_ +
FCOORD(1.0f, llsq.
m());
204 double c = llsq.
c(m);
205 baseline_error_ = llsq.
rms(m, c);
206 good_baseline_ =
false;
208 return good_baseline_;
◆ PerpDisp()
double tesseract::BaselineRow::PerpDisp |
( |
const FCOORD & |
direction | ) |
const |
Definition at line 120 of file baselinedetect.cpp.
121 float middle_x = (bounding_box_.
left() + bounding_box_.
right()) / 2.0f;
123 return direction * middle_pos / direction.
length();
◆ Print()
void tesseract::BaselineRow::Print |
( |
| ) |
const |
Definition at line 86 of file baselinedetect.cpp.
87 tprintf(
"Baseline (%g,%g)->(%g,%g), angle=%g, intercept=%g\n",
88 baseline_pt1_.
x(), baseline_pt1_.
y(),
89 baseline_pt2_.
x(), baseline_pt2_.
y(),
91 tprintf(
"Quant factor=%g, error=%g, good=%d, box:",
92 disp_quant_factor_, baseline_error_, good_baseline_);
93 bounding_box_.
print();
◆ SetupOldLineParameters()
void tesseract::BaselineRow::SetupOldLineParameters |
( |
TO_ROW * |
row | ) |
const |
◆ SpaceBetween()
double tesseract::BaselineRow::SpaceBetween |
( |
const BaselineRow & |
other | ) |
const |
Definition at line 107 of file baselinedetect.cpp.
109 float x = (std::max(bounding_box_.
left(), other.bounding_box_.left()) +
110 std::min(bounding_box_.
right(), other.bounding_box_.right())) / 2.0f;
112 float y = (
StraightYAtX(x) + other.StraightYAtX(x)) / 2.0f;
115 return PerpDistanceFromBaseline(pt) + other.PerpDistanceFromBaseline(pt);
◆ StraightYAtX()
double tesseract::BaselineRow::StraightYAtX |
( |
double |
x | ) |
const |
Definition at line 128 of file baselinedetect.cpp.
129 double denominator = baseline_pt2_.
x() - baseline_pt1_.
x();
130 if (denominator == 0.0)
131 return (baseline_pt1_.
y() + baseline_pt2_.
y()) / 2.0;
132 return baseline_pt1_.
y() +
133 (x - baseline_pt1_.
x()) * (baseline_pt2_.
y() - baseline_pt1_.
y()) /
The documentation for this class was generated from the following files: