mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2024-11-24 02:59:07 +08:00
Merge pull request #2826 from bertsky/clip-blockpolygon
make BlockPolygon usable
This commit is contained in:
commit
79f191fe20
@ -370,14 +370,22 @@ Pta* PageIterator::BlockPolygon() const {
|
||||
return nullptr; // Already at the end!
|
||||
if (it_->block()->block->pdblk.poly_block() == nullptr)
|
||||
return nullptr; // No layout analysis used - no polygon.
|
||||
ICOORDELT_IT it(it_->block()->block->pdblk.poly_block()->points());
|
||||
// Copy polygon, so we can unrotate it to image coordinates.
|
||||
POLY_BLOCK* internal_poly = it_->block()->block->pdblk.poly_block();
|
||||
ICOORDELT_LIST vertices;
|
||||
vertices.deep_copy(internal_poly->points(), ICOORDELT::deep_copy);
|
||||
POLY_BLOCK poly(&vertices, internal_poly->isA());
|
||||
poly.rotate(it_->block()->block->re_rotation());
|
||||
ICOORDELT_IT it(poly.points());
|
||||
Pta* pta = ptaCreate(it.length());
|
||||
int num_pts = 0;
|
||||
for (it.mark_cycle_pt(); !it.cycled_list(); it.forward(), ++num_pts) {
|
||||
ICOORD* pt = it.data();
|
||||
// Convert to top-down coords within the input image.
|
||||
float x = static_cast<float>(pt->x()) / scale_ + rect_left_;
|
||||
float y = rect_top_ + rect_height_ - static_cast<float>(pt->y()) / scale_;
|
||||
int x = static_cast<float>(pt->x()) / scale_ + rect_left_;
|
||||
int y = rect_top_ + rect_height_ - static_cast<float>(pt->y()) / scale_;
|
||||
x = ClipToRange(x, rect_left_, rect_left_ + rect_width_);
|
||||
y = ClipToRange(y, rect_top_, rect_top_ + rect_height_);
|
||||
ptaAddPt(pta, x, y);
|
||||
}
|
||||
return pta;
|
||||
|
Loading…
Reference in New Issue
Block a user