tesseract
5.0.0-alpha-619-ge9db
|
Go to the documentation of this file.
24 #include "config_auto.h"
70 : text_grid_(nullptr),
77 median_cell_height_(0),
78 median_cell_width_(0),
79 max_text_height_(INT32_MAX) {
233 int column_start,
int column_end) {
235 ASSERT_HOST(0 <= column_start && column_start <= column_end &&
239 for (
int row = row_start; row <= row_end; ++row) {
242 for (
int col = column_start; col <= column_end; ++col) {
274 gsearch.SetUniqueMode(
true);
275 gsearch.StartRectSearch(kCellBox);
276 double area_covered = 0;
278 while ((text = gsearch.NextRectSearch()) !=
nullptr) {
282 const int32_t current_area = kCellBox.
area();
283 if (current_area == 0) {
286 return std::min(1.0, area_covered / current_area);
290 #ifndef GRAPHICS_DISABLED
377 if (left_sides.
size() == 0 || right_sides.
size() == 0)
405 int min_bottom = INT32_MAX;
406 int max_top = INT32_MIN;
422 max_top = std::max(max_top, static_cast<int>(text->
bounding_box().
top()));
443 if (bottom_sides.
size() == 0 || top_sides.
size() == 0)
485 bool decrease)
const {
502 bool decrease)
const {
519 const int kMaxCellHeight = 1000;
520 const int kMaxCellWidth = 1000;
521 STATS height_stats(0, kMaxCellHeight + 1);
522 STATS width_stats(0, kMaxCellWidth + 1);
598 if (min_list.
size() == 0)
602 max_list.
get(max_list.
size() - 1));
607 int stacked_partitions = 0;
608 int last_cross_position = INT32_MAX;
612 while (min_index < min_list.
size()) {
614 if (min_list[min_index] < max_list[max_index]) {
615 ++stacked_partitions;
616 if (last_cross_position != INT32_MAX &&
617 stacked_partitions > max_merged) {
618 int mid = (last_cross_position + min_list[min_index]) / 2;
620 last_cross_position = INT32_MAX;
625 --stacked_partitions;
626 if (last_cross_position == INT32_MAX &&
627 stacked_partitions <= max_merged) {
628 last_cross_position = max_list[max_index];
643 vertical_box.
set_left(x - kGridSize);
668 horizontal_box.
set_top(y + kGridSize);
706 : text_grid_(nullptr),
710 max_text_height_(INT32_MAX) {
762 TBOX line_bound = guess_box;
780 int vertical_count = 0;
781 int horizontal_count = 0;
825 int old_area = bounding_box->
area();
830 changed = (bounding_box->
area() > old_area);
842 bool first_line =
true;
876 TBOX best_box = guess_box;
879 TBOX adjusted = guess_box;
884 const int kMidGuessY = (guess_box.
bottom() + guess_box.
top()) / 2;
889 bool found_good_border =
false;
894 int last_bottom = INT32_MAX;
904 int previous_below = 0;
905 const int kMaxChances = 10;
906 int chances = kMaxChances;
907 while (bottom != last_bottom) {
927 chances = kMaxChances;
936 found_good_border =
true;
947 last_bottom = bottom;
951 if (!found_good_border)
955 found_good_border =
false;
956 int last_top = INT32_MIN;
959 int previous_above = 0;
960 chances = kMaxChances;
963 while (last_top != top) {
974 chances = kMaxChances;
979 table->
row_height(last_row) < max_row_height)) {
983 found_good_border =
true;
999 if (!found_good_border)
1019 bool top_to_bottom) {
1032 if (top_to_bottom && (last_y >= y || last_y <= text_box.
top())) {
1033 last_y = std::min(last_y, static_cast<int>(text_box.
bottom()));
1036 if (!top_to_bottom && (last_y <= y || last_y >= text_box.
bottom())) {
1037 last_y = std::max(last_y, static_cast<int>(text_box.
top()));
1056 double threshold = 0.0;
ColPartitionGrid * text_grid_
void FindWhitespacedRows()
void StartRectSearch(const TBOX &rect)
void StartSideSearch(int x, int ymin, int ymax)
TBOX intersection(const TBOX &box) const
bool IsHorizontalType() const
const int kCellSplitRowThreshold
bool FindWhitespacedStructure()
void set_max_text_height(int height)
bool FindLinedStructure()
void StartVerticalSearch(int xmin, int xmax, int y)
void set_min_height(int height)
GenericVectorEqEq< int > cell_y_
int FindVerticalMargin(ColPartitionGrid *grid, int start_x, bool decrease) const
bool VerifyRowFilled(int row)
const double kHorizontalSpacing
int CountPartitions(const TBOX &box)
void set_max_text_height(int height)
bool FindLinesBoundingBoxIteration(TBOX *bounding_box)
void set_text_grid(ColPartitionGrid *text)
static bool IsWeakTableRow(StructuredTable *table, int row)
bool IsVerticalLine() const
int column_width(int column) const
bool DoesPartitionFit(const ColPartition &part) const
bool VerifyWhitespacedTable()
void set_line_grid(ColPartitionGrid *lines)
const int kGoodRowNumberOfColumnsSmallSize
BBC * NextSideSearch(bool right_to_left)
int CountVerticalIntersections(int x)
int NextHorizontalSplit(int left, int right, int y, bool top_to_bottom)
const double kMinFilledArea
const int kLinedTableMinHorizontalLines
double CalculateCellFilledPercentage(int row, int column)
void UpdateMargins(ColPartitionGrid *grid)
void set_bounding_box(const TBOX &box)
int row_height(int row) const
int CountFilledCellsInColumn(int column)
GenericVectorEqEq< int > cell_x_
bool FindLinesBoundingBox(TBOX *bounding_box)
StructuredTable * RecognizeTable(const TBOX &guess_box)
UnicodeText::const_iterator::difference_type distance(const UnicodeText::const_iterator &first, const UnicodeText::const_iterator &last)
const double kRequiredColumns
ColPartitionGrid * text_grid_
const double kVerticalSpacing
const int kCellSplitColumnThreshold
void set_text_grid(ColPartitionGrid *text)
BBC * NextVerticalSearch(bool top_to_bottom)
void FindWhitespacedColumns()
ColPartitionGrid * line_grid_
void set_min_width(int width)
const double kGoodRowNumberOfColumnsLarge
void Display(ScrollView *window, ScrollView::Color color)
const TBOX & bounding_box() const
void set_line_grid(ColPartitionGrid *lines)
bool VerifyLinedTableCells()
bool HasSignificantLines(const TBOX &guess)
int CountHorizontalIntersections(int y)
void add(int32_t value, int32_t count)
const double kMarginFactor
int FindHorizontalMargin(ColPartitionGrid *grid, int start_y, bool decrease) const
ColPartitionGrid * line_grid_
void Line(int x1, int y1, int x2, int y2)
bool RecognizeWhitespacedTable(const TBOX &guess_box, StructuredTable *table)
void SetUniqueMode(bool mode)
const int kLinedTableMinVerticalLines
const double kGoodRowNumberOfColumnsSmall[]
void Rectangle(int x1, int y1, int x2, int y2)
const TBOX & bounding_box() const
bool IsHorizontalLine() const
static void FindCellSplitLocations(const GenericVector< int > &min_list, const GenericVector< int > &max_list, int max_merged, GenericVector< int > *locations)
bool RecognizeLinedTable(const TBOX &guess_box, StructuredTable *table)
int CountFilledCellsInRow(int row)