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 | Static Public Member Functions
tesseract::ConComp Class Reference

`#include <con_comp.h>`

List of all members.

## Public Member Functions

| ConComp ()
virtual | ~ConComp ()
ConCompPt * | Head ()
int | Left () const
int | Top () const
int | Right () const
int | Bottom () const
int | Width () const
int | Height () const
bool | LeftMost () const
bool | RightMost () const
void | SetLeftMost (bool left_most)
void | SetRightMost (bool right_most)
int | ID () const
void | SetID (int id)
int | PtCnt () const
bool | Add (int x, int y)
bool | Merge (ConComp *con_comp)
void | Shift (int dx, int dy)
ConComp ** | Segment (int max_hist_wnd, int *concomp_cnt)
int * | CreateHistogram (int max_hist_wnd)
int * | SegmentHistogram (int *hist_array, int *seg_pt_cnt)

## Static Public Member Functions

static int | Left2RightComparer (const void *comp1, const void *comp2)
static int | Right2LeftComparer (const void *comp1, const void *comp2)

## Detailed Description

Definition at line 59 of file con_comp.h.

## Constructor & Destructor Documentation

tesseract::ConComp::ConComp | ( |  | ) |

Definition at line 27 of file con_comp.cpp.

{
head_ = NULL;
tail_ = NULL;
left_ = 0;
top_ = 0;
right_ = 0;
bottom_ = 0;
left_most_ = false;
right_most_ = false;
id_ = -1;
pt_cnt_ = 0;
}

tesseract::ConComp::~ConComp | ( |  | ) |

virtual

Definition at line 40 of file con_comp.cpp.

{
if (head_ != NULL) {
ConCompPt *pt_ptr = head_;
while (pt_ptr != NULL) {
ConCompPt *pptNext = pt_ptr->Next();
delete pt_ptr;
pt_ptr = pptNext;
}
head_ = NULL;
}
}

## Member Function Documentation

bool tesseract::ConComp::Add | ( | int | x,
|  | int | y
| ) |  |

Definition at line 53 of file con_comp.cpp.

{
ConCompPt *pt_ptr = new ConCompPt(x, y);
if (pt_ptr == NULL) {
return false;
}
if (head_ == NULL) {
left_ = x;
right_ = x;
top_ = y;
bottom_ = y;
head_ = pt_ptr;
} else {
left_ = left_ <= x ? left_ : x;
top_ = top_ <= y ? top_ : y;
right_ = right_ >= x ? right_ : x;
bottom_ = bottom_ >= y ? bottom_ : y;
}
if (tail_ != NULL) {
tail_->SetNext(pt_ptr);
}
tail_ = pt_ptr;
pt_cnt_++;
return true;
}

int tesseract::ConComp::Bottom | ( |  | ) | const

inline

Definition at line 68 of file con_comp.h.

{ return bottom_; }

int * tesseract::ConComp::CreateHistogram | ( | int | max_hist_wnd | ) |

Definition at line 106 of file con_comp.cpp.

{
int wid = right_ - left_ + 1,
hgt = bottom_ - top_ + 1,
hist_wnd = static_cast<int>(hgt * HIST_WND_RATIO);
if (hist_wnd > max_hist_wnd) {
hist_wnd = max_hist_wnd;
}
// alloc memo for histogram
int *hist_array = new int[wid];
if (hist_array == NULL) {
return NULL;
}
memset(hist_array, 0, wid * sizeof(*hist_array));
// compute windowed histogram
ConCompPt *pt_ptr = head_;
while (pt_ptr != NULL) {
int x = pt_ptr->x() - left_,
xw = x - hist_wnd;
for (int xdel = -hist_wnd; xdel <= hist_wnd; xdel++, xw++) {
if (xw >= 0 && xw < wid) {
hist_array[xw]++;
}
}
pt_ptr = pt_ptr->Next();
}
return hist_array;
}

ConCompPt* tesseract::ConComp::Head | ( |  | ) |

inline

Definition at line 64 of file con_comp.h.

{ return head_; }

int tesseract::ConComp::Height | ( |  | ) | const

inline

Definition at line 70 of file con_comp.h.

{ return bottom_ - top_ + 1; }

int tesseract::ConComp::ID | ( |  | ) | const

inline

Definition at line 94 of file con_comp.h.

{ return id_; }

int tesseract::ConComp::Left | ( |  | ) | const

inline

Definition at line 65 of file con_comp.h.

{ return left_; }

static int tesseract::ConComp::Left2RightComparer | ( | const void * | comp1,
|  | const void * | comp2
| ) |  |

inline static

Definition at line 73 of file con_comp.h.

{
return (*(reinterpret_cast<ConComp * const *>(comp1)))->left_ +
(*(reinterpret_cast<ConComp * const *>(comp1)))->right_ -
(*(reinterpret_cast<ConComp * const *>(comp2)))->left_ -
(*(reinterpret_cast<ConComp * const *>(comp2)))->right_;
}

bool tesseract::ConComp::LeftMost | ( |  | ) | const

inline

Definition at line 89 of file con_comp.h.

{ return left_most_; }

bool tesseract::ConComp::Merge | ( | ConComp * | con_comp | ) |

Definition at line 83 of file con_comp.cpp.

{
if (head_ == NULL || tail_ == NULL ||
concomp->head_ == NULL || concomp->tail_ == NULL) {
return false;
}
tail_->SetNext(concomp->head_);
tail_ = concomp->tail_;
left_ = left_ <= concomp->left_ ? left_ : concomp->left_;
top_ = top_ <= concomp->top_ ? top_ : concomp->top_;
right_ = right_ >= concomp->right_ ? right_ : concomp->right_;
bottom_ = bottom_ >= concomp->bottom_ ? bottom_ : concomp->bottom_;
pt_cnt_ += concomp->pt_cnt_;
concomp->head_ = NULL;
concomp->tail_ = NULL;
return true;
}

int tesseract::ConComp::PtCnt | ( |  | ) | const

inline

Definition at line 96 of file con_comp.h.

{ return pt_cnt_; }

int tesseract::ConComp::Right | ( |  | ) | const

inline

Definition at line 67 of file con_comp.h.

{ return right_; }

static int tesseract::ConComp::Right2LeftComparer | ( | const void * | comp1,
|  | const void * | comp2
| ) |  |

inline static

Definition at line 82 of file con_comp.h.

{
return (*(reinterpret_cast<ConComp * const *>(comp2)))->right_ -
(*(reinterpret_cast<ConComp * const *>(comp1)))->right_;
}

bool tesseract::ConComp::RightMost | ( |  | ) | const

inline

Definition at line 90 of file con_comp.h.

{ return right_most_; }

ConComp ** tesseract::ConComp::Segment | ( | int | max_hist_wnd,
|  | int * | concomp_cnt
| ) |  |

Definition at line 189 of file con_comp.cpp.

{
// init
(*concomp_cnt) = 0;
// No pts
if (head_ == NULL) {
return NULL;
}
int seg_pt_cnt = 0;
// create the histogram
int *hist_array = CreateHistogram(max_hist_wnd);
if (hist_array == NULL) {
return NULL;
}
int *x_seg_pt = SegmentHistogram(hist_array, &seg_pt_cnt);
// free histogram
delete []hist_array;
// no segments, nothing to do
if (seg_pt_cnt == 0) {
return NULL;
}
// create concomp array
ConComp **concomp_array = new ConComp *[seg_pt_cnt + 1];
if (concomp_array == NULL) {
delete []x_seg_pt;
return NULL;
}
for (int concomp = 0; concomp <= seg_pt_cnt; concomp++) {
concomp_array[concomp] = new ConComp();
if (concomp_array[concomp] == NULL) {
delete []x_seg_pt;
delete []concomp_array;
return NULL;
}
// split concomps inherit the ID this concomp
concomp_array[concomp]->SetID(id_);
}
// set the left and right most attributes of the
// appropriate concomps
concomp_array[0]->left_most_ = true;
concomp_array[seg_pt_cnt]->right_most_ = true;
// assign pts to concomps
ConCompPt *pt_ptr = head_;
while (pt_ptr != NULL) {
int seg_pt;
// find the first seg-pt that exceeds the x value
// of the pt
for (seg_pt = 0; seg_pt < seg_pt_cnt; seg_pt++) {
if ((x_seg_pt[seg_pt] + left_) > pt_ptr->x()) {
break;
}
}
// add the pt to the proper concomp
if (concomp_array[seg_pt]->Add(pt_ptr->x(), pt_ptr->y()) == false) {
delete []x_seg_pt;
delete []concomp_array;
return NULL;
}
pt_ptr = pt_ptr->Next();
}
delete []x_seg_pt;
(*concomp_cnt) = (seg_pt_cnt + 1);
return concomp_array;
}

int * tesseract::ConComp::SegmentHistogram | ( | int * | hist_array,
|  | int * | seg_pt_cnt
| ) |  |

Definition at line 143 of file con_comp.cpp.

{
// init
(*seg_pt_cnt) = 0;
int wid = right_ - left_ + 1,
hgt = bottom_ - top_ + 1;
int *x_seg_pt = new int[wid];
if (x_seg_pt == NULL) {
return NULL;
}
int seg_pt_wnd = static_cast<int>(hgt * SEG_PT_WND_RATIO);
if (seg_pt_wnd > 1) {
seg_pt_wnd = 1;
}
for (int x = 2; x < (wid - 2); x++) {
if (hist_array[x] < hist_array[x - 1] &&
hist_array[x] < hist_array[x - 2] &&
hist_array[x] <= hist_array[x + 1] &&
hist_array[x] <= hist_array[x + 2]) {
x_seg_pt[(*seg_pt_cnt)++] = x;
x += seg_pt_wnd;
} else if (hist_array[x] <= hist_array[x - 1] &&
hist_array[x] <= hist_array[x - 2] &&
hist_array[x] < hist_array[x + 1] &&
hist_array[x] < hist_array[x + 2]) {
x_seg_pt[(*seg_pt_cnt)++] = x;
x += seg_pt_wnd;
}
}
// no segments, nothing to do
if ((*seg_pt_cnt) == 0) {
delete []x_seg_pt;
return NULL;
}
return x_seg_pt;
}

void tesseract::ConComp::SetID | ( | int | id | ) |

inline

Definition at line 95 of file con_comp.h.

{ id_ = id; }

void tesseract::ConComp::SetLeftMost | ( | bool | left_most | ) |

inline

Definition at line 91 of file con_comp.h.

{ left_most_ = left_most; }

void tesseract::ConComp::SetRightMost | ( | bool | right_most | ) |

inline

Definition at line 92 of file con_comp.h.

{ right_most_ = right_most;
}

void tesseract::ConComp::Shift | ( | int | dx,
|  | int | dy
| ) |  |

Definition at line 271 of file con_comp.cpp.

{
ConCompPt *pt_ptr = head_;
while (pt_ptr != NULL) {
pt_ptr->Shift(dx, dy);
pt_ptr = pt_ptr->Next();
}
left_ += dx;
right_ += dx;
top_ += dy;
bottom_ += dy;
}

int tesseract::ConComp::Top | ( |  | ) | const

inline

Definition at line 66 of file con_comp.h.

{ return top_; }

int tesseract::ConComp::Width | ( |  | ) | const

inline

Definition at line 69 of file con_comp.h.

{ return right_ - left_ + 1; }

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

- /mnt/data/src/tesseract-ocr/cube/con_comp.h
- /mnt/data/src/tesseract-ocr/cube/con_comp.cpp