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 | Protected Member Functions | Protected Attributes
tesseract::PageIterator Class Reference

`#include <pageiterator.h>`

Inheritance diagram for tesseract::PageIterator:

List of all members.

## Public Member Functions

| PageIterator (PAGE_RES *page_res, Tesseract *tesseract, int scale, int scaled_yres, int rect_left, int rect_top, int rect_width, int rect_height)
virtual | ~PageIterator ()
| PageIterator (const PageIterator &src)
const PageIterator & | operator= (const PageIterator &src)
bool | PositionedAtSameWord (const PAGE_RES_IT *other) const
virtual void | Begin ()
virtual void | RestartParagraph ()
bool | IsWithinFirstTextlineOfParagraph () const
virtual void | RestartRow ()
virtual bool | Next (PageIteratorLevel level)
virtual bool | IsAtBeginningOf (PageIteratorLevel level) const
virtual bool | IsAtFinalElement (PageIteratorLevel level, PageIteratorLevel element) const
int | Cmp (const PageIterator &other) const
bool | BoundingBox (PageIteratorLevel level, int *left, int *top, int *right, int *bottom) const
bool | BoundingBoxInternal (PageIteratorLevel level, int *left, int *top, int *right, int *bottom) const
bool | Empty (PageIteratorLevel level) const
PolyBlockType | BlockType () const
Pix * | GetBinaryImage (PageIteratorLevel level) const
Pix * | GetImage (PageIteratorLevel level, int padding, int *left, int *top) const
bool | Baseline (PageIteratorLevel level, int *x1, int *y1, int *x2, int *y2) const
void | Orientation (tesseract::Orientation *orientation, tesseract::WritingDirection *writing_direction, tesseract::TextlineOrder *textline_order, float *deskew_angle) const
void | ParagraphInfo (tesseract::ParagraphJustification *justification, bool *is_list_item, bool *is_crown, int *first_line_indent) const

## Protected Member Functions

TESS_LOCAL void | BeginWord (int offset)

## Protected Attributes

PAGE_RES * | page_res_
Tesseract * | tesseract_
PAGE_RES_IT * | it_
WERD * | word_
int | word_length_
int | blob_index_
C_BLOB_IT * | cblob_it_
int | scale_
int | scaled_yres_
int | rect_left_
int | rect_top_
int | rect_width_
int | rect_height_

## Detailed Description

Class to iterate over tesseract page structure, providing access to all levels of the page hierarchy, without including any tesseract headers or having to handle any tesseract structures. WARNING! This class points to data held within the TessBaseAPI class, and therefore can only be used while the TessBaseAPI class still exists and has not been subjected to a call of Init, SetImage, Recognize, Clear, End DetectOS, or anything else that changes the internal PAGE_RES. See apitypes.h for the definition of PageIteratorLevel. See also ResultIterator, derived from PageIterator, which adds in the ability to access OCR output with text-specific methods.

Definition at line 51 of file pageiterator.h.

## Constructor & Destructor Documentation

tesseract::PageIterator::PageIterator | ( | PAGE_RES * | page_res,
|  | Tesseract * | tesseract,
|  | int | scale,
|  | int | scaled_yres,
|  | int | rect_left,
|  | int | rect_top,
|  | int | rect_width,
|  | int | rect_height
| ) |  |

page_res and tesseract come directly from the BaseAPI. The rectangle parameters are copied indirectly from the Thresholder, via the BaseAPI. They represent the coordinates of some rectangle in an original image (in top-left-origin coordinates) and therefore the top-left needs to be added to any output boxes in order to specify coordinates in the original image. See TessBaseAPI::SetRectangle. The scale and scaled_yres are in case the Thresholder scaled the image rectangle prior to thresholding. Any coordinates in tesseract's image must be divided by scale before adding (rect_left, rect_top). The scaled_yres indicates the effective resolution of the binary image that tesseract has been given by the Thresholder. After the constructor, Begin has already been called.

Definition at line 29 of file pageiterator.cpp.

: page_res_(page_res), tesseract_(tesseract),
word_(NULL), word_length_(0), blob_index_(0), cblob_it_(NULL),
scale_(scale), scaled_yres_(scaled_yres),
rect_left_(rect_left), rect_top_(rect_top),
rect_width_(rect_width), rect_height_(rect_height) {
it_ = new PAGE_RES_IT(page_res);
PageIterator::Begin();
}

tesseract::PageIterator::~PageIterator | ( |  | ) |

virtual

Definition at line 42 of file pageiterator.cpp.

{
delete it_;
delete cblob_it_;
}

tesseract::PageIterator::PageIterator | ( | const PageIterator & | src | ) |

Page/ResultIterators may be copied! This makes it possible to iterate over all the objects at a lower level, while maintaining an iterator to objects at a higher level. These constructors DO NOT CALL Begin, so iterations will continue from the location of src.

PageIterators may be copied! This makes it possible to iterate over all the objects at a lower level, while maintaining an iterator to objects at a higher level.

Definition at line 52 of file pageiterator.cpp.

: page_res_(src.page_res_), tesseract_(src.tesseract_),
word_(NULL), word_length_(src.word_length_),
blob_index_(src.blob_index_), cblob_it_(NULL),
scale_(src.scale_), scaled_yres_(src.scaled_yres_),
rect_left_(src.rect_left_), rect_top_(src.rect_top_),
rect_width_(src.rect_width_), rect_height_(src.rect_height_) {
it_ = new PAGE_RES_IT(*src.it_);
BeginWord(src.blob_index_);
}

## Member Function Documentation

bool tesseract::PageIterator::Baseline | ( | PageIteratorLevel | level,
|  | int * | x1,
|  | int * | y1,
|  | int * | x2,
|  | int * | y2
| ) |  | const

Returns the baseline of the current object at the given level. The baseline is the line that passes through (x1, y1) and (x2, y2). WARNING: with vertical text, baselines may be vertical! Returns false if there is no baseline at the current position.

Returns the baseline of the current object at the given level. The baseline is the line that passes through (x1, y1) and (x2, y2). WARNING: with vertical text, baselines may be vertical!

Definition at line 448 of file pageiterator.cpp.

{
if (it_->word() == NULL) return false; // Already at the end!
ROW* row = it_->row()->row;
WERD* word = it_->word()->word;
TBOX box = (level == RIL_WORD || level == RIL_SYMBOL)
? word->bounding_box()
: row->bounding_box();
int left = box.left();
ICOORD startpt(left, static_cast<inT16>(row->base_line(left) + 0.5));
int right = box.right();
ICOORD endpt(right, static_cast<inT16>(row->base_line(right) + 0.5));
// Rotate to image coordinates and convert to global image coords.
startpt.rotate(it_->block()->block->re_rotation());
endpt.rotate(it_->block()->block->re_rotation());
*x1 = startpt.x() / scale_ + rect_left_;
*y1 = (rect_height_ - startpt.y()) / scale_ + rect_top_;
*x2 = endpt.x() / scale_ + rect_left_;
*y2 = (rect_height_ - endpt.y()) / scale_ + rect_top_;
return true;
}

void tesseract::PageIterator::Begin | ( |  | ) |

virtual

Moves the iterator to point to the start of the page to begin an iteration.

Resets the iterator to point to the start of the page.

Reimplemented in tesseract::ResultIterator.

Definition at line 86 of file pageiterator.cpp.

{
it_->restart_page_with_empties();
BeginWord(0);
}

void tesseract::PageIterator::BeginWord | ( | int | offset | ) |

protected

Sets up the internal data for iterating the blobs of a new word, then moves the iterator to the given offset.

Definition at line 536 of file pageiterator.cpp.

{
WERD_RES* word_res = it_->word();
if (word_res == NULL) {
// This is a non-text block, so there is no word.
word_length_ = 0;
blob_index_ = 0;
word_ = NULL;
return;
}
if (word_res->best_choice != NULL) {
// Recognition has been done, so we are using the box_word, which
// is already baseline denormalized.
word_length_ = word_res->best_choice->length();
ASSERT_HOST(word_res->box_word != NULL);
if (word_res->box_word->length() != word_length_) {
tprintf("Corrupted word! best_choice[len=%d] = %s, box_word[len=%d]: ",
word_length_, word_res->best_choice->unichar_string().string(),
word_res->box_word->length());
word_res->box_word->bounding_box().print();
}
ASSERT_HOST(word_res->box_word->length() == word_length_);
word_ = NULL;
// We will be iterating the box_word.
if (cblob_it_ != NULL) {
delete cblob_it_;
cblob_it_ = NULL;
}
} else {
// No recognition yet, so a "symbol" is a cblob.
word_ = word_res->word;
ASSERT_HOST(word_->cblob_list() != NULL);
word_length_ = word_->cblob_list()->length();
if (cblob_it_ == NULL) cblob_it_ = new C_BLOB_IT;
cblob_it_->set_to_list(word_->cblob_list());
}
for (blob_index_ = 0; blob_index_ < offset; ++blob_index_) {
if (cblob_it_ != NULL)
cblob_it_->forward();
}
}

PolyBlockType tesseract::PageIterator::BlockType | ( |  | ) | const

Returns the type of the current block. See apitypes.h for PolyBlockType.

Definition at line 330 of file pageiterator.cpp.

{
if (it_->block() == NULL || it_->block()->block == NULL)
return PT_UNKNOWN; // Already at the end!
if (it_->block()->block->poly_block() == NULL)
return PT_FLOWING_TEXT; // No layout analysis used - assume text.
return it_->block()->block->poly_block()->isA();
}

bool tesseract::PageIterator::BoundingBox | ( | PageIteratorLevel | level,
|  | int * | left,
|  | int * | top,
|  | int * | right,
|  | int * | bottom
| ) |  | const

Returns the bounding rectangle of the current object at the given level. See comment on coordinate system above. Returns false if there is no such object at the current position. The returned bounding box is guaranteed to match the size and position of the image returned by GetBinaryImage, but may clip foreground pixels from a grey image. The padding argument to GetImage can be used to expand the image to include more foreground pixels. See GetImage below.

Returns the bounding rectangle of the current object at the given level in coordinates of the original image. See comment on coordinate system above. Returns false if there is no such object at the current position.

Definition at line 303 of file pageiterator.cpp.

{
if (!BoundingBoxInternal(level, left, top, right, bottom))
return false;
// Convert to the coordinate system of the original image.
*left = ClipToRange(*left / scale_ + rect_left_,
rect_left_, rect_left_ + rect_width_);
*top = ClipToRange(*top / scale_ + rect_top_,
rect_top_, rect_top_ + rect_height_);
*right = ClipToRange((*right + scale_ - 1) / scale_ + rect_left_,
*left, rect_left_ + rect_width_);
*bottom = ClipToRange((*bottom + scale_ - 1) / scale_ + rect_top_,
*top, rect_top_ + rect_height_);
return true;
}

bool tesseract::PageIterator::BoundingBoxInternal | ( | PageIteratorLevel | level,
|  | int * | left,
|  | int * | top,
|  | int * | right,
|  | int * | bottom
| ) |  | const

Returns the bounding rectangle of the object in a coordinate system of the working image rectangle having its origin at (rect_left_, rect_top_) with respect to the original image and is scaled by a factor scale_.

Returns the bounding rectangle of the current object at the given level in the coordinates of the working image that is pix_binary(). See comment on coordinate system above. Returns false if there is no such object at the current position.

Definition at line 246 of file pageiterator.cpp.

{
if (Empty(level))
return false;
TBOX box;
PARA *para = NULL;
switch (level) {
case RIL_BLOCK:
box = it_->block()->block->bounding_box();
break;
case RIL_PARA:
para = it_->row()->row->para();
// explicit fall-through.
case RIL_TEXTLINE:
box = it_->row()->row->bounding_box();
break;
case RIL_WORD:
box = it_->word()->word->bounding_box();
break;
case RIL_SYMBOL:
if (cblob_it_ == NULL)
box = it_->word()->box_word->BlobBox(blob_index_);
else
box = cblob_it_->data()->bounding_box();
}
if (level == RIL_PARA) {
PageIterator other = *this;
other.Begin();
do {
if (other.it_->block() &&
other.it_->block()->block == it_->block()->block &&
other.it_->row() && other.it_->row()->row &&
other.it_->row()->row->para() == para) {
box = box.bounding_union(other.it_->row()->row->bounding_box());
}
} while (other.Next(RIL_TEXTLINE));
}
if (level != RIL_SYMBOL || cblob_it_ != NULL)
box.rotate(it_->block()->block->re_rotation());
// Now we have a box in tesseract coordinates relative to the image rectangle,
// we have to convert the coords to a top-down system.
const int pix_height = pixGetHeight(tesseract_->pix_binary());
const int pix_width = pixGetWidth(tesseract_->pix_binary());
*left = ClipToRange(static_cast<int>(box.left()), 0, pix_width);
*top = ClipToRange(pix_height - box.top(), 0, pix_height);
*right = ClipToRange(static_cast<int>(box.right()), *left, pix_width);
*bottom = ClipToRange(pix_height - box.bottom(), *top, pix_height);
return true;
}

int tesseract::PageIterator::Cmp | ( | const PageIterator & | other | ) | const

Returns whether this iterator is positioned before other: -1 equal to other: 0 after other: 1

Definition at line 216 of file pageiterator.cpp.

{
int word_cmp = it_->cmp(*other.it_);
if (word_cmp != 0)
return word_cmp;
if (blob_index_ < other.blob_index_)
return -1;
if (blob_index_ == other.blob_index_)
return 0;
return 1;
}

bool tesseract::PageIterator::Empty | ( | PageIteratorLevel | level | ) | const

Returns whether there is no object of a given level.

Return that there is no such object at a given level.

Definition at line 321 of file pageiterator.cpp.

{
if (it_->block() == NULL) return true; // Already at the end!
if (it_->word() == NULL && level != RIL_BLOCK) return true; // image block
if (level == RIL_SYMBOL && blob_index_ >= word_length_)
return true; // Zero length word, or already at the end of it.
return false;
}

Pix * tesseract::PageIterator::GetBinaryImage | ( | PageIteratorLevel | level | ) | const

Returns a binary image of the current object at the given level. The position and size match the return from BoundingBoxInternal, and so this could be upscaled with respect to the original input image. Use pixDestroy to delete the image after use.

Returns a binary image of the current object at the given level. The position and size match the return from BoundingBoxInternal, and so this could be upscaled with respect to the original input image. Use pixDestroy to delete the image after use. The following methods are used to generate the images: RIL_BLOCK: mask the page image with the block polygon. RIL_TEXTLINE: Clip the rectangle of the line box from the page image. TODO(rays) fix this to generate and use a line polygon. RIL_WORD: Clip the rectangle of the word box from the page image. RIL_SYMBOL: Render the symbol outline to an image for cblobs (prior to recognition) or the bounding box otherwise. A reconstruction of the original image (using xor to check for double representation) should be reasonably accurate, apart from removed noise, at the block level. Below the block level, the reconstruction will be missing images and line separators. At the symbol level, kerned characters will be invade the bounding box if rendered after recognition, making an xor reconstruction inaccurate, but an or construction better. Before recognition, symbol-level reconstruction should be good, even with xor, since the images come from the connected components.

Definition at line 360 of file pageiterator.cpp.

{
int left, top, right, bottom;
if (!BoundingBoxInternal(level, &left, &top, &right, &bottom))
return NULL;
Pix* pix = NULL;
switch (level) {
case RIL_BLOCK:
case RIL_PARA:
int bleft, btop, bright, bbottom;
BoundingBoxInternal(RIL_BLOCK, &bleft, &btop, &bright, &bbottom);
pix = it_->block()->block->render_mask();
// AND the mask and the image.
pixRasterop(pix, 0, 0, pixGetWidth(pix), pixGetHeight(pix),
PIX_SRC & PIX_DST, tesseract_->pix_binary(),
bleft, btop);
if (level == RIL_PARA) {
// RIL_PARA needs further attention:
// clip the paragraph from the block mask.
Box* box = boxCreate(left - bleft, top - btop,
right - left, bottom - top);
Pix* pix2 = pixClipRectangle(pix, box, NULL);
boxDestroy(&box);
pixDestroy(&pix);
pix = pix2;
}
break;
case RIL_TEXTLINE:
case RIL_WORD:
case RIL_SYMBOL:
if (level == RIL_SYMBOL && cblob_it_ != NULL &&
cblob_it_->data()->area() != 0)
return cblob_it_->data()->render();
// Just clip from the bounding box.
Box* box = boxCreate(left, top, right - left, bottom - top);
pix = pixClipRectangle(tesseract_->pix_binary(), box, NULL);
boxDestroy(&box);
break;
}
return pix;
}

Pix * tesseract::PageIterator::GetImage | ( | PageIteratorLevel | level,
|  | int | padding,
|  | int * | left,
|  | int * | top
| ) |  | const

Returns an image of the current object at the given level in greyscale if available in the input. To guarantee a binary image use BinaryImage. NOTE that in order to give the best possible image, the bounds are expanded slightly over the binary connected component, by the supplied padding, so the top-left position of the returned image is returned in (left,top). These will most likely not match the coordinates returned by BoundingBox. Use pixDestroy to delete the image after use.

Definition at line 411 of file pageiterator.cpp.

{
int right, bottom;
if (!BoundingBox(level, left, top, &right, &bottom))
return NULL;
Pix* pix = tesseract_->pix_grey();
if (pix == NULL)
return GetBinaryImage(level);
// Expand the box.
*left = MAX(*left - padding, 0);
*top = MAX(*top - padding, 0);
right = MIN(right + padding, rect_width_);
bottom = MIN(bottom + padding, rect_height_);
Box* box = boxCreate(*left, *top, right - *left, bottom - *top);
Pix* grey_pix = pixClipRectangle(pix, box, NULL);
boxDestroy(&box);
if (level == RIL_BLOCK) {
Pix* mask = it_->block()->block->render_mask();
Pix* expanded_mask = pixCreate(right - *left, bottom - *top, 1);
pixRasterop(expanded_mask, padding, padding,
pixGetWidth(mask), pixGetHeight(mask),
PIX_SRC, mask, 0, 0);
pixDestroy(&mask);
pixDilateBrick(expanded_mask, expanded_mask, 2*padding + 1, 2*padding + 1);
pixInvert(expanded_mask, expanded_mask);
pixSetMasked(grey_pix, expanded_mask, 255);
pixDestroy(&expanded_mask);
}
return grey_pix;
}

bool tesseract::PageIterator::IsAtBeginningOf | ( | PageIteratorLevel | level | ) | const

virtual

Returns true if the iterator is at the start of an object at the given level.

For instance, suppose an iterator it is pointed to the first symbol of the first word of the third line of the second paragraph of the first block in a page, then: it.IsAtBeginningOf(RIL_BLOCK) = false it.IsAtBeginningOf(RIL_PARA) = false it.IsAtBeginningOf(RIL_TEXTLINE) = true it.IsAtBeginningOf(RIL_WORD) = true it.IsAtBeginningOf(RIL_SYMBOL) = true

Returns true if the iterator is at the start of an object at the given level. Possible uses include determining if a call to Next(RIL_WORD) moved to the start of a RIL_PARA.

Reimplemented in tesseract::ResultIterator.

Definition at line 166 of file pageiterator.cpp.

{
if (it_->block() == NULL) return false; // Already at the end!
if (it_->word() == NULL) return true; // In an image block.
switch (level) {
case RIL_BLOCK:
return blob_index_ == 0 && it_->block() != it_->prev_block();
case RIL_PARA:
return blob_index_ == 0 &&
(it_->block() != it_->prev_block() ||
it_->row()->row->para() != it_->prev_row()->row->para());
case RIL_TEXTLINE:
return blob_index_ == 0 && it_->row() != it_->prev_row();
case RIL_WORD:
return blob_index_ == 0;
case RIL_SYMBOL:
return true;
}
return false;
}

bool tesseract::PageIterator::IsAtFinalElement | ( | PageIteratorLevel | level,
|  | PageIteratorLevel | element
| ) |  | const

virtual

Returns whether the iterator is positioned at the last element in a given level. (e.g. the last word in a line, the last line in a block)

    Here's some two-paragraph example

text. It starts off innocuously enough but quickly turns bizarre. The author inserts a cornucopia of words to guard against confused references.

Now take an iterator it pointed to the start of "bizarre." it.IsAtFinalElement(RIL_PARA, RIL_SYMBOL) = false it.IsAtFinalElement(RIL_PARA, RIL_WORD) = true it.IsAtFinalElement(RIL_BLOCK, RIL_WORD) = false

Returns whether the iterator is positioned at the last element in a given level. (e.g. the last word in a line, the last line in a block)

Reimplemented in tesseract::ResultIterator.

Definition at line 190 of file pageiterator.cpp.

{
if (Empty(element)) return true; // Already at the end!
// The result is true if we step forward by element and find we are
// at the the end of the page or at beginning of *all* levels in:
// [level, element).
// When there is more than one level difference between element and level,
// we could for instance move forward one symbol and still be at the first
// word on a line, so we also have to be at the first symbol in a word.
PageIterator next(*this);
next.Next(element);
if (next.Empty(element)) return true; // Reached the end of the page.
while (element > level) {
element = static_cast< PageIteratorLevel >(element - 1);
if (!next.IsAtBeginningOf(element))
return false;
}
return true;
}

bool tesseract::PageIterator::IsWithinFirstTextlineOfParagraph | ( |  | ) | const

Return whether this iterator points anywhere in the first textline of a paragraph.

Definition at line 104 of file pageiterator.cpp.

{
PageIterator p_start(*this);
p_start.RestartParagraph();
return p_start.it_->row() == it_->row();
}

bool tesseract::PageIterator::Next | ( | PageIteratorLevel | level | ) |

virtual

Moves to the start of the next object at the given level in the page hierarchy, and returns false if the end of the page was reached. NOTE that RIL_SYMBOL will skip non-text blocks, but all other PageIteratorLevel level values will visit each non-text block once. Think of non text blocks as containing a single para, with a single line, with a single imaginary word. Calls to Next with different levels may be freely intermixed. This function iterates words in right-to-left scripts correctly, if the appropriate language has been loaded into Tesseract.

Moves to the start of the next object at the given level in the page hierarchy, and returns false if the end of the page was reached. NOTE (CHANGED!) that ALL PageIteratorLevel level values will visit each non-text block at least once. Think of non text blocks as containing a single para, with at least one line, with a single imaginary word, containing a single symbol. The bounding boxes mark out any polygonal nature of the block, and PTIsTextType(BLockType()) is false for non-text blocks. Calls to Next with different levels may be freely intermixed. This function iterates words in right-to-left scripts correctly, if the appropriate language has been loaded into Tesseract.

Reimplemented in tesseract::ResultIterator.

Definition at line 128 of file pageiterator.cpp.

{
if (it_->block() == NULL) return false; // Already at the end!
if (it_->word() == NULL)
level = RIL_BLOCK;
switch (level) {
case RIL_BLOCK:
it_->forward_block();
break;
case RIL_PARA:
it_->forward_paragraph();
break;
case RIL_TEXTLINE:
for (it_->forward_with_empties(); it_->row() == it_->prev_row();
it_->forward_with_empties());
break;
case RIL_WORD:
it_->forward_with_empties();
break;
case RIL_SYMBOL:
if (cblob_it_ != NULL)
cblob_it_->forward();
++blob_index_;
if (blob_index_ >= word_length_)
it_->forward_with_empties();
else
return true;
break;
}
BeginWord(0);
return it_->block() != NULL;
}

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

Definition at line 63 of file pageiterator.cpp.

{
page_res_ = src.page_res_;
tesseract_ = src.tesseract_;
scale_ = src.scale_;
scaled_yres_ = src.scaled_yres_;
rect_left_ = src.rect_left_;
rect_top_ = src.rect_top_;
rect_width_ = src.rect_width_;
rect_height_ = src.rect_height_;
if (it_ != NULL) delete it_;
it_ = new PAGE_RES_IT(*src.it_);
BeginWord(src.blob_index_);
return *this;
}

void tesseract::PageIterator::Orientation | ( | tesseract::Orientation * | orientation,
|  | tesseract::WritingDirection * | writing_direction,
|  | tesseract::TextlineOrder * | textline_order,
|  | float * | deskew_angle
| ) |  | const

Returns orientation for the block the iterator points to. orientation, writing_direction, textline_order: see publictypes.h deskew_angle: after rotating the block so the text orientation is upright, how many radians does one have to rotate the block anti-clockwise for it to be level? -Pi/4 <= deskew_angle <= Pi/4

Definition at line 470 of file pageiterator.cpp.

{
BLOCK* block = it_->block()->block;
// Orientation
FCOORD up_in_image(0.0, 1.0);
up_in_image.unrotate(block->classify_rotation());
up_in_image.rotate(block->re_rotation());
if (up_in_image.x() == 0.0F) {
if (up_in_image.y() > 0.0F) {
*orientation = ORIENTATION_PAGE_UP;
} else {
*orientation = ORIENTATION_PAGE_DOWN;
}
} else if (up_in_image.x() > 0.0F) {
*orientation = ORIENTATION_PAGE_RIGHT;
} else {
*orientation = ORIENTATION_PAGE_LEFT;
}
// Writing direction
bool is_vertical_text = (block->classify_rotation().x() == 0.0);
bool right_to_left = block->right_to_left();
*writing_direction =
is_vertical_text
? WRITING_DIRECTION_TOP_TO_BOTTOM
: (right_to_left
? WRITING_DIRECTION_RIGHT_TO_LEFT
: WRITING_DIRECTION_LEFT_TO_RIGHT);
// Textline Order
bool is_mongolian = false; // TODO(eger): fix me
*textline_order = is_vertical_text
? (is_mongolian
? TEXTLINE_ORDER_LEFT_TO_RIGHT
: TEXTLINE_ORDER_RIGHT_TO_LEFT)
: TEXTLINE_ORDER_TOP_TO_BOTTOM;
// Deskew angle
FCOORD skew = block->skew(); // true horizontal for textlines
*deskew_angle = -skew.angle();
}

void tesseract::PageIterator::ParagraphInfo | ( | tesseract::ParagraphJustification * | justification,
|  | bool * | is_list_item,
|  | bool * | is_crown,
|  | int * | first_line_indent
| ) |  | const

Returns information about the current paragraph, if available.

justification - LEFT if ragged right, or fully justified and script is left-to-right. RIGHT if ragged left, or fully justified and script is right-to-left. unknown if it looks like source code or we have very few lines. is_list_item - true if we believe this is a member of an ordered or unordered list. is_crown - true if the first line of the paragraph is aligned with the other lines of the paragraph even though subsequent paragraphs have first line indents. This typically indicates that this is the continuation of a previous paragraph or that it is the very first paragraph in the chapter. first_line_indent - For LEFT aligned paragraphs, the first text line of paragraphs of this kind are indented this many pixels from the left edge of the rest of the paragraph. for RIGHT aligned paragraphs, the first text line of paragraphs of this kind are indented this many pixels from the right edge of the rest of the paragraph. NOTE 1: This value may be negative. NOTE 2: if *is_crown == true, the first line of this paragraph is actually flush, and first_line_indent is set to the "common" first_line_indent for subsequent paragraphs in this block of text.

Definition at line 516 of file pageiterator.cpp.

{
*just = tesseract::JUSTIFICATION_UNKNOWN;
if (!it_->row() || !it_->row()->row || !it_->row()->row->para() ||
!it_->row()->row->para()->model)
return;
PARA *para = it_->row()->row->para();
*is_list_item = para->is_list_item;
*is_crown = para->is_very_first_or_continuation;
*first_line_indent = para->model->first_indent() -
para->model->body_indent();
}

bool tesseract::PageIterator::PositionedAtSameWord | ( | const PAGE_RES_IT * | other | ) | const

Are we positioned at the same location as other?

Definition at line 78 of file pageiterator.cpp.

{
return (it_ == NULL && it_ == other) ||
((other != NULL) && (it_ != NULL) && (*it_ == *other));
}

void tesseract::PageIterator::RestartParagraph | ( |  | ) |

virtual

Moves the iterator to the beginning of the paragraph. This class implements this functionality by moving it to the zero indexed blob of the first (leftmost) word on the first row of the paragraph.

Definition at line 91 of file pageiterator.cpp.

{
if (it_->block() == NULL) return; // At end of the document.
PAGE_RES_IT para(page_res_);
PAGE_RES_IT next_para(para);
next_para.forward_paragraph();
while (next_para.cmp(*it_) <= 0) {
para = next_para;
next_para.forward_paragraph();
}
*it_ = para;
BeginWord(0);
}

void tesseract::PageIterator::RestartRow | ( |  | ) |

virtual

Moves the iterator to the beginning of the text line. This class implements this functionality by moving it to the zero indexed blob of the first (leftmost) word of the row.

Definition at line 110 of file pageiterator.cpp.

{
it_->restart_row();
BeginWord(0);
}

## Member Data Documentation

int tesseract::PageIterator::blob_index_

protected

The current blob index within the word.

Definition at line 309 of file pageiterator.h.

C_BLOB_IT* tesseract::PageIterator::cblob_it_

protected

Iterator to the blobs within the word. If NULL, then we are iterating OCR results in the box_word. Owned by this ResultIterator.

Definition at line 315 of file pageiterator.h.

PAGE_RES_IT* tesseract::PageIterator::it_

protected

The iterator to the page_res_. Owned by this ResultIterator. A pointer just to avoid dragging in Tesseract includes.

Definition at line 300 of file pageiterator.h.

PAGE_RES* tesseract::PageIterator::page_res_

protected

Pointer to the page_res owned by the API.

Definition at line 293 of file pageiterator.h.

int tesseract::PageIterator::rect_height_

protected

Definition at line 322 of file pageiterator.h.

int tesseract::PageIterator::rect_left_

protected

Definition at line 319 of file pageiterator.h.

int tesseract::PageIterator::rect_top_

protected

Definition at line 320 of file pageiterator.h.

int tesseract::PageIterator::rect_width_

protected

Definition at line 321 of file pageiterator.h.

int tesseract::PageIterator::scale_

protected

Parameters saved from the Thresholder. Needed to rebuild coordinates.

Definition at line 317 of file pageiterator.h.

int tesseract::PageIterator::scaled_yres_

protected

Definition at line 318 of file pageiterator.h.

Tesseract* tesseract::PageIterator::tesseract_

protected

Pointer to the Tesseract object owned by the API.

Definition at line 295 of file pageiterator.h.

WERD* tesseract::PageIterator::word_

protected

The current input WERD being iterated. If there is an output from OCR, then word_ is NULL. Owned by the API

Definition at line 305 of file pageiterator.h.

int tesseract::PageIterator::word_length_

protected

The length of the current word_.

Definition at line 307 of file pageiterator.h.

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

- /mnt/data/src/tesseract-ocr/ccmain/pageiterator.h
- /mnt/data/src/tesseract-ocr/ccmain/pageiterator.cpp