Tesseract 3.02

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions
tesseract::DetLineFit Class Reference

`#include <detlinefit.h>`

List of all members.

## Public Member Functions
| DetLineFit ()
| ~DetLineFit ()
void | Clear ()
void | Add (const ICOORD &pt)
double | Fit (ICOORD *pt1, ICOORD *pt2)
double | Fit (float *m, float *c)
double | ConstrainedFit (double m, float *c)

## Detailed Description

Definition at line 54 of file detlinefit.h.

## Constructor & Destructor Documentation

tesseract::DetLineFit::DetLineFit | ( |  | ) |

Definition at line 29 of file detlinefit.cpp.

{
}

tesseract::DetLineFit::~DetLineFit | ( |  | ) |

Definition at line 32 of file detlinefit.cpp.

{
}

## Member Function Documentation

void tesseract::DetLineFit::Add | ( | const ICOORD & | pt | ) |

Definition at line 41 of file detlinefit.cpp.

{
ICOORDELT_IT it = &pt_list_;
ICOORDELT* new_pt = new ICOORDELT(pt);
it.add_to_end(new_pt);
}

void tesseract::DetLineFit::Clear | ( |  | ) |

Definition at line 36 of file detlinefit.cpp.

{
pt_list_.clear();
}

double tesseract::DetLineFit::ConstrainedFit | ( | double | m,
|  | float * | c
| ) |  |

Definition at line 159 of file detlinefit.cpp.

{
ICOORDELT_IT it(&pt_list_);
// Do something sensible with no points.
if (pt_list_.empty()) {
*c = 0.0f;
return 0.0;
}
// Count the points and find the first and last kNumEndPoints.
// Put the ends in a single array to make their use easier later.
ICOORD* pts[kNumEndPoints * 2];
int pt_count = 0;
for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
if (pt_count < kNumEndPoints) {
pts[pt_count] = it.data();
pts[kNumEndPoints + pt_count] = pts[pt_count];
} else {
for (int i = 1; i < kNumEndPoints; ++i)
pts[kNumEndPoints + i - 1] = pts[kNumEndPoints + i];
pts[kNumEndPoints * 2 - 1] = it.data();
}
++pt_count;
}
while (pt_count < kNumEndPoints) {
pts[pt_count] = NULL;
pts[kNumEndPoints + pt_count++] = NULL;
}
int* distances = new int[pt_count];
double best_uq = -1.0;
// Iterate each pair of points and find the best fitting line.
for (int i = 0; i < kNumEndPoints * 2; ++i) {
ICOORD* start = pts[i];
if (start == NULL) continue;
ICOORD end = ComputeEndFromGradient(*start, m);
// Compute the upper quartile error from the line.
double dist = ComputeErrors(*start, end, distances);
if (dist < best_uq || best_uq < 0.0) {
best_uq = dist;
*c = start->y() - start->x() * m;
}
}
delete [] distances;
// Finally compute the square root to return the true distance.
return best_uq > 0.0 ? sqrt(best_uq) : best_uq;
}

double tesseract::DetLineFit::Fit | ( | ICOORD * | pt1,
|  | ICOORD * | pt2
| ) |  |

Definition at line 49 of file detlinefit.cpp.

{
ICOORDELT_IT it(&pt_list_);
// Do something sensible with no points.
if (pt_list_.empty()) {
pt1->set_x(0);
pt1->set_y(0);
*pt2 = *pt1;
return 0.0;
}
// Count the points and find the first and last kNumEndPoints.
ICOORD* starts[kNumEndPoints];
ICOORD* ends[kNumEndPoints];
int pt_count = 0;
for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
if (pt_count < kNumEndPoints) {
starts[pt_count] = it.data();
ends[pt_count] = starts[pt_count];
} else {
for (int i = 1; i < kNumEndPoints; ++i)
ends[i - 1] = ends[i];
ends[kNumEndPoints - 1] = it.data();
}
++pt_count;
}
// 1 or 2 points need special treatment.
if (pt_count <= 2) {
*pt1 = *starts[0];
if (pt_count > 1)
*pt2 = *starts[1];
else
*pt2 = *pt1;
return 0.0;
}
int end_count = MIN(pt_count, kNumEndPoints);
int* distances = new int[pt_count];
double best_uq = -1.0;
// Iterate each pair of points and find the best fitting line.
for (int i = 0; i < end_count; ++i) {
ICOORD* start = starts[i];
for (int j = 0; j < end_count; ++j) {
ICOORD* end = ends[j];
if (start != end) {
// Compute the upper quartile error from the line.
double dist = ComputeErrors(*start, *end, distances);
if (dist < best_uq || best_uq < 0.0) {
best_uq = dist;
*pt1 = *start;
*pt2 = *end;
}
}
}
}
delete [] distances;
// Finally compute the square root to return the true distance.
return best_uq > 0.0 ? sqrt(best_uq) : best_uq;
}

double tesseract::DetLineFit::Fit | ( | float * | m,
|  | float * | c
| ) |  |

Definition at line 109 of file detlinefit.cpp.

{
ICOORD start, end;
double error = Fit(&start, &end);
if (end.x() != start.x()) {
*m = static_cast<float>(end.y() - start.y()) / (end.x() - start.x());
*c = start.y() - *m * start.x();
} else {
*m = 0.0f;
*c = 0.0f;
}
return error;
}

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

- /mnt/data/src/tesseract-ocr/ccstruct/detlinefit.h
- /mnt/data/src/tesseract-ocr/ccstruct/detlinefit.cpp