49 void ExpectCellX(
int x_min,
int second,
int add,
int almost_done,
int x_max) {
50 ASSERT_EQ(0, (almost_done - second) % add);
54 for (
unsigned i = 1;
i <
cell_x_.size() - 1; ++
i) {
61 for (
unsigned i = 1;
i <
cell_x_.size(); ++
i) {
70 std::locale::global(std::locale(
""));
73 text_grid_ = std::make_unique<ColPartitionGrid>(5, bleft, tright);
74 line_grid_ = std::make_unique<ColPartitionGrid>(5, bleft, tright);
79 for (memory.mark_cycle_pt(); !memory.cycled_list(); memory.forward()) {
80 memory.data()->DeleteBoxes();
85 for (
int row = 0; row < 800; row += 20) {
86 for (
int col = 0; col < 500; col += 25) {
93 TBOX box(left, bottom, right, top);
100 add_it.add_after_stay_put(part);
106 for (
int i = 10;
i <= 50;
i += 10) {
109 for (
int i = 100;
i <= 450;
i += 50) {
113 for (
int i = 100;
i <= 200;
i += 20) {
124 add_it.add_after_stay_put(part);
132 add_it.add_after_stay_put(part);
136 for (
int y = 10;
y <= 50;
y += 10) {
137 for (
int x = 100;
x <= 450;
x += 50) {
153 recognizer_ = std::make_unique<TestableTableRecognizer>();
166 table_ = std::make_unique<TestableStructuredTable>();
172 std::unique_ptr<TestableStructuredTable>
table_;
177 TBOX smaller_guess(120, 15, 370, 45);
178 TBOX larger_guess(90, 5, 490, 70);
179 EXPECT_TRUE(recognizer_->HasSignificantLines(line_box_));
180 EXPECT_TRUE(recognizer_->HasSignificantLines(larger_guess));
181 EXPECT_TRUE(recognizer_->HasSignificantLines(smaller_guess));
186 TBOX box(370, 35, 500, 45);
192 TBOX box(0, 100, 200, 200);
198 TBOX box(0, 0, 200, 50);
199 bool result = recognizer_->FindLinesBoundingBox(&box);
209 TBOX guess(120, 15, 370, 45);
214 EXPECT_TRUE(recognizer_->RecognizeLinedTable(guess, &table));
228 TBOX guess(0, 0, 500, 800);
233 EXPECT_TRUE(recognizer_->RecognizeWhitespacedTable(guess, &table));
246 table_->set_bounding_box(
TBOX(0, 0, 1000, 1000));
247 InsertPartition(0, 0, 100, 10);
248 InsertPartition(1, 12, 43, 21);
249 EXPECT_EQ(2, table_->CountVerticalIntersections(4));
250 EXPECT_EQ(2, table_->CountVerticalIntersections(20));
251 EXPECT_EQ(2, table_->CountVerticalIntersections(40));
252 EXPECT_EQ(1, table_->CountVerticalIntersections(50));
253 EXPECT_EQ(1, table_->CountVerticalIntersections(60));
254 EXPECT_EQ(1, table_->CountVerticalIntersections(80));
255 EXPECT_EQ(1, table_->CountVerticalIntersections(95));
256 EXPECT_EQ(0, table_->CountVerticalIntersections(104));
257 EXPECT_EQ(0, table_->CountVerticalIntersections(150));
261 table_->set_bounding_box(
TBOX(0, 0, 1000, 1000));
262 InsertPartition(0, 3, 100, 10);
263 InsertPartition(110, 5, 200, 16);
265 EXPECT_EQ(0, table_->CountHorizontalIntersections(0));
266 EXPECT_EQ(1, table_->CountHorizontalIntersections(4));
267 EXPECT_EQ(2, table_->CountHorizontalIntersections(8));
268 EXPECT_EQ(1, table_->CountHorizontalIntersections(12));
269 EXPECT_EQ(0, table_->CountHorizontalIntersections(20));
273 for (
int y = 10;
y <= 50;
y += 10) {
274 table_->InjectCellY(
y);
276 for (
int x = 100;
x <= 450;
x += 50) {
277 table_->InjectCellX(
x);
280 InsertCellsInLines();
281 table_->set_bounding_box(line_box_);
286 for (
int y = 10;
y <= 50;
y += 10) {
287 table_->InjectCellY(
y);
289 for (
int x = 100;
x <= 450;
x += 50) {
290 table_->InjectCellX(
x);
293 InsertCellsInLines();
294 InsertPartition(101, 11, 299, 19);
295 table_->set_bounding_box(line_box_);
300 for (
int y = 10;
y <= 50;
y += 10) {
301 table_->InjectCellY(
y);
303 for (
int x = 100;
x <= 450;
x += 50) {
304 table_->InjectCellX(
x);
307 InsertCellsInLines();
308 InsertPartition(151, 21, 199, 39);
309 table_->set_bounding_box(line_box_);
315 TBOX guess(0, 0, 500, 800);
316 table_->set_bounding_box(guess);
317 table_->FindWhitespacedColumns();
318 table_->ExpectCellX(1, 25, 25, 475, 499);
323 TBOX guess(0, 0, 500, 800);
324 table_->set_bounding_box(guess);
325 table_->FindWhitespacedColumns();
326 table_->ExpectSortedX();
#define ASSERT_EQ(val1, val2)
#define EXPECT_EQ(val1, val2)
#define EXPECT_GT(val1, val2)
#define EXPECT_TRUE(condition)
#define EXPECT_FALSE(condition)
#define EXPECT_LT(val1, val2)
TEST_F(EuroText, FastLatinOCR)
void set_to_given_coords(int x_min, int y_min, int x_max, int y_max)
TDimension bottom() const
static ColPartition * FakePartition(const TBOX &box, PolyBlockType block_type, BlobRegionType blob_type, BlobTextFlowType flow)
void set_median_width(int width)
void set_median_height(int height)
bool VerifyLinedTableCells()
std::vector< int > cell_y_
unsigned column_count() const
const TBOX & bounding_box() const
std::vector< int > cell_x_
unsigned cell_count() const
bool FindWhitespacedStructure()
void FindWhitespacedColumns()
bool FindLinedStructure()
void set_line_grid(ColPartitionGrid *lines)
int CountHorizontalIntersections(int y)
int CountVerticalIntersections(int x)
void set_text_grid(ColPartitionGrid *text)
unsigned row_count() const
bool RecognizeLinedTable(const TBOX &guess_box, StructuredTable *table)
bool FindLinesBoundingBox(TBOX *bounding_box)
bool HasSignificantLines(const TBOX &guess)
bool RecognizeWhitespacedTable(const TBOX &guess_box, StructuredTable *table)
StructuredTable * RecognizeTable(const TBOX &guess_box)
void ExpectCellX(int x_min, int second, int add, int almost_done, int x_max)
ColPartition_LIST allocated_parts_
std::unique_ptr< ColPartitionGrid > text_grid_
std::unique_ptr< ColPartitionGrid > line_grid_
void InsertCellsInLines()
void InsertVerticalLine(int x, int bottom, int top)
void InsertHorizontalLine(int left, int right, int y)
void InsertPartition(int left, int bottom, int right, int top)
std::unique_ptr< TestableTableRecognizer > recognizer_
std::unique_ptr< TestableStructuredTable > table_