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::BoxWord Class Reference

`#include <boxword.h>`

List of all members.

## Public Member Functions
| BoxWord ()
| BoxWord (const BoxWord &src)
| ~BoxWord ()
BoxWord & | operator= (const BoxWord &src)
void | CopyFrom (const BoxWord &src)
void | SetScriptPositions (const UNICHARSET &unicharset, bool small_caps, TWERD *tessword, WERD_CHOICE *best_choice)
void | ClipToOriginalWord (const BLOCK *block, WERD *original_word)
void | MergeBoxes (int start, int end)
void | InsertBox (int index, const TBOX &box)
void | DeleteBox (int index)
void | DeleteAllBoxes ()
void | ProcessMatchedBlobs (const TWERD &other, TessCallback1< int > *cb) const
const TBOX & | bounding_box () const
const int | length () const
const TBOX & | BlobBox (int index) const
ScriptPos | BlobPosition (int index) const

## Static Public Member Functions
static BoxWord * | CopyFromNormalized (const DENORM *denorm, TWERD *tessword)

## Detailed Description

Definition at line 47 of file boxword.h.

## Constructor & Destructor Documentation

tesseract::BoxWord::BoxWord | ( |  | ) |

Definition at line 39 of file boxword.cpp.

: length_(0) {
}

tesseract::BoxWord::BoxWord | ( | const BoxWord & | src | ) |
| explicit

Definition at line 42 of file boxword.cpp.

{
CopyFrom(src);
}

tesseract::BoxWord::~BoxWord | ( |  | ) |

Definition at line 46 of file boxword.cpp.

{
}

## Member Function Documentation

const TBOX& tesseract::BoxWord::BlobBox | ( | int | index | ) | const
| inline

Definition at line 102 of file boxword.h.

{
return boxes_[index];
}

ScriptPos tesseract::BoxWord::BlobPosition | ( | int | index | ) | const
| inline

Definition at line 105 of file boxword.h.

{
if (index < 0 || index >= script_pos_.size())
return SP_NORMAL;
return script_pos_[index];
}

const TBOX& tesseract::BoxWord::bounding_box | ( |  | ) | const
| inline

Definition at line 96 of file boxword.h.

{
return bbox_;
}

void tesseract::BoxWord::ClipToOriginalWord | ( | const BLOCK * | block,
|  | WERD * | original_word
| ) |  |

Definition at line 138 of file boxword.cpp.

{
for (int i = 0; i < length_; ++i) {
TBOX box = boxes_[i];
// Expand by a single pixel, as the poly approximation error is 1 pixel.
box = TBOX(box.left() - 1, box.bottom() - 1,
box.right() + 1, box.top() + 1);
// Now find the original box that matches.
TBOX original_box;
C_BLOB_IT b_it(original_word->cblob_list());
for (b_it.mark_cycle_pt(); !b_it.cycled_list(); b_it.forward()) {
TBOX blob_box = b_it.data()->bounding_box();
if (block != NULL)
blob_box.rotate(block->re_rotation());
if (blob_box.major_overlap(box)) {
original_box += blob_box;
}
}
if (!original_box.null_box()) {
if (NearlyEqual<int>(original_box.left(), box.left(), kBoxClipTolerance))
box.set_left(original_box.left());
if (NearlyEqual<int>(original_box.right(), box.right(),
kBoxClipTolerance))
box.set_right(original_box.right());
if (NearlyEqual<int>(original_box.top(), box.top(), kBoxClipTolerance))
box.set_top(original_box.top());
if (NearlyEqual<int>(original_box.bottom(), box.bottom(),
kBoxClipTolerance))
box.set_bottom(original_box.bottom());
}
original_box = original_word->bounding_box();
if (block != NULL)
original_box.rotate(block->re_rotation());
boxes_[i] = box.intersection(original_box);
}
ComputeBoundingBox();
}

void tesseract::BoxWord::CopyFrom | ( | const BoxWord & | src | ) |

Definition at line 54 of file boxword.cpp.

{
bbox_ = src.bbox_;
length_ = src.length_;
boxes_.clear();
boxes_.reserve(length_);
for (int i = 0; i < length_; ++i)
boxes_.push_back(src.boxes_[i]);
}

BoxWord * tesseract::BoxWord::CopyFromNormalized | ( | const DENORM * | denorm,
|  | TWERD * | tessword
| ) |  |
| static

Definition at line 67 of file boxword.cpp.

{
BoxWord* boxword = new BoxWord();
// Count the blobs.
boxword->length_ = 0;
for (TBLOB* tblob = tessword->blobs; tblob != NULL; tblob = tblob->next)
++boxword->length_;
// Allocate memory.
boxword->boxes_.reserve(boxword->length_);
for (TBLOB* tblob = tessword->blobs; tblob != NULL; tblob = tblob->next) {
TBOX blob_box;
for (TESSLINE* outline = tblob->outlines; outline != NULL;
outline = outline->next) {
EDGEPT* edgept = outline->loop;
// Iterate over the edges.
do {
if (!edgept->IsHidden() || !edgept->prev->IsHidden()) {
ICOORD pos(edgept->pos.x, edgept->pos.y);
if (denorm != NULL) {
TPOINT denormed;
denorm->DenormTransform(edgept->pos, &denormed);
pos.set_x(denormed.x);
pos.set_y(denormed.y);
}
TBOX pt_box(pos, pos);
blob_box += pt_box;
}
edgept = edgept->next;
} while (edgept != outline->loop);
}
boxword->boxes_.push_back(blob_box);
}
boxword->ComputeBoundingBox();
return boxword;
}

void tesseract::BoxWord::DeleteAllBoxes | ( |  | ) |

Definition at line 213 of file boxword.cpp.

{
length_ = 0;
boxes_.clear();
bbox_ = TBOX();
}

void tesseract::BoxWord::DeleteBox | ( | int | index | ) |

Definition at line 205 of file boxword.cpp.

{
ASSERT_HOST(0 <= index && index < length_);
boxes_.remove(index);
--length_;
ComputeBoundingBox();
}

void tesseract::BoxWord::InsertBox | ( | int | index,
|  | const TBOX & | box
| ) |  |

Definition at line 194 of file boxword.cpp.

{
if (index < length_)
boxes_.insert(box, index);
else
boxes_.push_back(box);
length_ = boxes_.size();
ComputeBoundingBox();
}

const int tesseract::BoxWord::length | ( |  | ) | const
| inline

Definition at line 99 of file boxword.h.

{
return length_;
}

void tesseract::BoxWord::MergeBoxes | ( | int | start,
|  | int | end
| ) |  |

Definition at line 177 of file boxword.cpp.

{
start = ClipToRange(start, 0, length_);
end = ClipToRange(end, 0, length_);
if (end <= start + 1)
return;
for (int i = start + 1; i < end; ++i) {
boxes_[start] += boxes_[i];
}
int shrinkage = end - 1 - start;
length_ -= shrinkage;
for (int i = start + 1; i < length_; ++i)
boxes_[i] = boxes_[i + shrinkage];
boxes_.truncate(length_);
}

BoxWord & tesseract::BoxWord::operator= | ( | const BoxWord & | src | ) |

Definition at line 49 of file boxword.cpp.

{
CopyFrom(src);
return *this;
}

void tesseract::BoxWord::ProcessMatchedBlobs | ( | const TWERD & | other,
|  | TessCallback1< int > * | cb
| ) |  | const

Definition at line 229 of file boxword.cpp.

{
TBLOB* blob = other.blobs;
for (int i = 0; i < length_ && blob != NULL; ++i, blob = blob->next) {
TBOX blob_box = blob->bounding_box();
if (blob_box == boxes_[i])
cb->Run(i);
}
delete cb;
}

void tesseract::BoxWord::SetScriptPositions | ( | const UNICHARSET & | unicharset,
|  | bool | small_caps,
|  | TWERD * | tessword,
|  | WERD_CHOICE * | best_choice
| ) |  |

Definition at line 108 of file boxword.cpp.

{
// Allocate memory.
script_pos_.init_to_size(length_, SP_NORMAL);
int blob_index = 0;
for (TBLOB* tblob = tessword->blobs; tblob != NULL; tblob = tblob->next,
++blob_index) {
int class_id = best_choice->unichar_id(blob_index);
TBOX blob_box = tblob->bounding_box();
int top = blob_box.top();
int bottom = blob_box.bottom();
int min_bottom, max_bottom, min_top, max_top;
unicharset.get_top_bottom(class_id, &min_bottom, &max_bottom,
&min_top, &max_top);
if (bottom <= kMaxDropCapBottom) {
script_pos_[blob_index] = SP_DROPCAP;
} else if (!small_caps) {
if (top + kMinSubscriptOffset < min_top) {
script_pos_[blob_index] = SP_SUBSCRIPT;
} else if (bottom - kMinSuperscriptOffset > max_bottom) {
script_pos_[blob_index] = SP_SUPERSCRIPT;
}
}
}
}

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

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