#include <detlinefit.h>
|
| DetLineFit () |
|
| ~DetLineFit ()=default |
|
void | Clear () |
|
void | Add (const ICOORD &pt) |
|
void | Add (const ICOORD &pt, int halfwidth) |
|
double | Fit (ICOORD *pt1, ICOORD *pt2) |
|
double | Fit (int skip_first, int skip_last, ICOORD *pt1, ICOORD *pt2) |
|
double | ConstrainedFit (const FCOORD &direction, double min_dist, double max_dist, bool debug, ICOORD *line_pt) |
|
bool | SufficientPointsForIndependentFit () const |
|
double | Fit (float *m, float *c) |
|
double | ConstrainedFit (double m, float *c) |
|
Definition at line 54 of file detlinefit.h.
◆ DetLineFit()
tesseract::DetLineFit::DetLineFit |
( |
| ) |
|
◆ ~DetLineFit()
tesseract::DetLineFit::~DetLineFit |
( |
| ) |
|
|
default |
◆ Add() [1/2]
void tesseract::DetLineFit::Add |
( |
const ICOORD & |
pt | ) |
|
◆ Add() [2/2]
void tesseract::DetLineFit::Add |
( |
const ICOORD & |
pt, |
|
|
int |
halfwidth |
|
) |
| |
Definition at line 57 of file detlinefit.cpp.
58 pts_.emplace_back(pt, halfwidth);
◆ Clear()
void tesseract::DetLineFit::Clear |
( |
| ) |
|
◆ ConstrainedFit() [1/2]
double tesseract::DetLineFit::ConstrainedFit |
( |
const FCOORD & |
direction, |
|
|
double |
min_dist, |
|
|
double |
max_dist, |
|
|
bool |
debug, |
|
|
ICOORD * |
line_pt |
|
) |
| |
Definition at line 133 of file detlinefit.cpp.
135 ComputeConstrainedDistances(direction, min_dist, max_dist);
137 if (pts_.empty() || distances_.empty()) {
142 auto median_index = distances_.size() / 2;
143 std::nth_element(distances_.begin(), distances_.begin() + median_index, distances_.end());
144 *line_pt = distances_[median_index].data();
146 tprintf(
"Constrained fit to dir %g, %g = %d, %d :%zu distances:\n", direction.x(), direction.y(),
147 line_pt->x(), line_pt->y(), distances_.size());
148 for (
unsigned i = 0; i < distances_.size(); ++i) {
149 tprintf(
"%d: %d, %d -> %g\n", i, distances_[i].data().x(), distances_[i].data().y(),
150 distances_[i].key());
152 tprintf(
"Result = %zu\n", median_index);
155 double dist_origin = direction * *line_pt;
159 return sqrt(EvaluateLineFit());
UnicodeText::const_iterator::difference_type distance(const UnicodeText::const_iterator &first, const UnicodeText::const_iterator &last)
void tprintf(const char *format,...)
◆ ConstrainedFit() [2/2]
double tesseract::DetLineFit::ConstrainedFit |
( |
double |
m, |
|
|
float * |
c |
|
) |
| |
Definition at line 187 of file detlinefit.cpp.
193 double cos = 1.0 / sqrt(1.0 + m * m);
194 FCOORD direction(cos, m * cos);
196 double error =
ConstrainedFit(direction, -FLT_MAX, FLT_MAX,
false, &line_pt);
197 *c = line_pt.y() - line_pt.x() * m;
double ConstrainedFit(const FCOORD &direction, double min_dist, double max_dist, bool debug, ICOORD *line_pt)
◆ Fit() [1/3]
double tesseract::DetLineFit::Fit |
( |
float * |
m, |
|
|
float * |
c |
|
) |
| |
Definition at line 171 of file detlinefit.cpp.
173 double error =
Fit(&start, &end);
174 if (end.x() != start.x()) {
175 *m =
static_cast<float>(end.y() - start.y()) / (end.x() - start.x());
176 *c = start.y() - *m * start.x();
double Fit(ICOORD *pt1, ICOORD *pt2)
◆ Fit() [2/3]
double tesseract::DetLineFit::Fit |
( |
ICOORD * |
pt1, |
|
|
ICOORD * |
pt2 |
|
) |
| |
|
inline |
◆ Fit() [3/3]
double tesseract::DetLineFit::Fit |
( |
int |
skip_first, |
|
|
int |
skip_last, |
|
|
ICOORD * |
pt1, |
|
|
ICOORD * |
pt2 |
|
) |
| |
Definition at line 64 of file detlinefit.cpp.
73 int pt_count = pts_.size();
75 if (skip_first >= pt_count) {
76 skip_first = pt_count - 1;
80 for (
int i = skip_first; i < end_i; ++i) {
81 starts[start_count++] = &pts_[i].pt;
84 if (skip_last >= pt_count) {
85 skip_last = pt_count - 1;
89 for (
int i = pt_count - 1 - skip_last; i >= end_i; --i) {
90 ends[end_count++] = &pts_[i].pt;
105 double best_uq = -1.0;
107 for (
int i = 0; i < start_count; ++i) {
108 ICOORD *start = starts[i];
109 for (
int j = 0; j < end_count; ++j) {
110 ICOORD *end = ends[j];
111 if (*start != *end) {
112 ComputeDistances(*start, *end);
114 double dist = EvaluateLineFit();
115 if (dist < best_uq || best_uq < 0.0) {
124 return best_uq > 0.0 ? sqrt(best_uq) : best_uq;
◆ SufficientPointsForIndependentFit()
bool tesseract::DetLineFit::SufficientPointsForIndependentFit |
( |
| ) |
const |
The documentation for this class was generated from the following files: