TableRecognizer: Adding functions in order to calculate row and columns bounding boxes

This commit is contained in:
Stefan Brechtken 2020-02-19 12:23:26 +01:00
parent 2954367c62
commit 877ef39c40
2 changed files with 37 additions and 0 deletions

View File

@ -304,6 +304,36 @@ void StructuredTable::Display(ScrollView* window, ScrollView::Color color) {
#endif
}
std::vector<TBOX> StructuredTable::getRows()
{
if(cell_y_.size() < 2)
return std::vector<TBOX>();
std::vector<TBOX> 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<TBOX> StructuredTable::getCols()
{
if(cell_x_.size() < 2)
return std::vector<TBOX>();
std::vector<TBOX> 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();

View File

@ -22,6 +22,8 @@
#include "colpartitiongrid.h"
#include <tesseract/genericvector.h>
#include <vector>
#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<TBOX> getRows();
/// calcualte bounding boxes of the columns and return them
std::vector<TBOX> getCols();
protected:
// Clear the structure information.