diff --git a/src/textord/tablerecog.cpp b/src/textord/tablerecog.cpp index 714173386..1d1333dc7 100644 --- a/src/textord/tablerecog.cpp +++ b/src/textord/tablerecog.cpp @@ -304,6 +304,36 @@ void StructuredTable::Display(ScrollView* window, ScrollView::Color color) { #endif } +std::vector StructuredTable::getRows() +{ + if(cell_y_.size() < 2) + return std::vector(); + + std::vector rows(cell_y_.size() - 1); + for(unsigned i = 0; i + 1 < cell_y_.size(); i++) { + const ICOORD left(bounding_box_.left(), cell_y_[i]); + const ICOORD right(bounding_box_.right(), cell_y_[i + 1]); + rows[i] = TBOX(left, right); + } + + return rows; +} + +std::vector StructuredTable::getCols() +{ + if(cell_x_.size() < 2) + return std::vector(); + + std::vector cols(cell_x_.size() - 1); + for(unsigned i = 0; i + 1 < cell_x_.size(); i++) { + const ICOORD top(cell_x_[i], bounding_box_.top()); + const ICOORD bot(cell_x_[i+1], bounding_box_.bottom()); + cols[i] = TBOX(top, bot); + } + + return cols; +} + // Clear structure information. void StructuredTable::ClearStructure() { cell_x_.clear(); diff --git a/src/textord/tablerecog.h b/src/textord/tablerecog.h index f993f301a..88e2443c2 100644 --- a/src/textord/tablerecog.h +++ b/src/textord/tablerecog.h @@ -22,6 +22,8 @@ #include "colpartitiongrid.h" #include +#include +#include "points.h" namespace tesseract { @@ -136,6 +138,11 @@ class StructuredTable { // Debug display, draws the table in the given color. If the table is not // valid, the table and "best" grid lines are still drawn in the given color. void Display(ScrollView* window, ScrollView::Color color); + + /// calcualte bounding boxes of the rows and return them + std::vector getRows(); + /// calcualte bounding boxes of the columns and return them + std::vector getCols(); protected: // Clear the structure information.