Adding workflow order to table detector java debug output + adding final column and row calculation

This commit is contained in:
Stefan Brechtken 2020-02-19 12:08:16 +01:00
parent 95befed6b1
commit 46f16b8430

View File

@ -265,14 +265,15 @@ void TableFinder::LocateTables(ColPartitionGrid* grid,
#ifndef GRAPHICS_DISABLED
if (textord_show_tables) {
ScrollView* table_win = MakeWindow(0, 300, "Column Partitions & Neighbors");
ScrollView* table_win = MakeWindow(0, 300,
"Step 1: Column Partitions & Neighbors");
DisplayColPartitions(table_win, &clean_part_grid_, ScrollView::BLUE);
DisplayColPartitions(table_win, &leader_and_ruling_grid_,
ScrollView::AQUAMARINE);
DisplayColPartitionConnections(table_win, &clean_part_grid_,
ScrollView::ORANGE);
table_win = MakeWindow(100, 300, "Fragmented Text");
table_win = MakeWindow(100, 300, "Step 2: Fragmented Text");
DisplayColPartitions(table_win, &fragmented_text_grid_, ScrollView::BLUE);
}
#endif // GRAPHICS_DISABLED
@ -307,7 +308,8 @@ void TableFinder::LocateTables(ColPartitionGrid* grid,
#ifndef GRAPHICS_DISABLED
if (textord_tablefind_show_mark) {
ScrollView* table_win = MakeWindow(1200, 300, "Table Columns and Regions");
ScrollView* table_win = MakeWindow(1200, 300,
"Step 7: Table Columns and Regions");
DisplayColSegments(table_win, &table_columns, ScrollView::DARK_TURQUOISE);
DisplayColSegments(table_win, &table_regions, ScrollView::YELLOW);
}
@ -329,7 +331,8 @@ void TableFinder::LocateTables(ColPartitionGrid* grid,
#ifndef GRAPHICS_DISABLED
if (textord_show_tables) {
ScrollView* table_win = MakeWindow(1200, 300, "Detected Table Locations");
ScrollView* table_win = MakeWindow(1200, 300,
"Step 8: Detected Table Locations");
DisplayColPartitions(table_win, &clean_part_grid_, ScrollView::BLUE);
DisplayColSegments(table_win, &table_columns, ScrollView::KHAKI);
table_grid_.DisplayBoxes(table_win);
@ -343,7 +346,8 @@ void TableFinder::LocateTables(ColPartitionGrid* grid,
#ifndef GRAPHICS_DISABLED
if (textord_show_tables) {
ScrollView* table_win = MakeWindow(1400, 600, "Recognized Tables");
ScrollView* table_win = MakeWindow(1400, 600,
"Step 10: Recognized Tables");
DisplayColPartitions(table_win, &clean_part_grid_,
ScrollView::BLUE, ScrollView::BLUE);
table_grid_.DisplayBoxes(table_win);
@ -358,7 +362,7 @@ void TableFinder::LocateTables(ColPartitionGrid* grid,
#ifndef GRAPHICS_DISABLED
if (textord_show_tables) {
ScrollView* table_win = MakeWindow(1500, 300, "Detected Tables");
ScrollView* table_win = MakeWindow(1500, 300, "Step 11: Detected Tables");
DisplayColPartitions(table_win, &clean_part_grid_,
ScrollView::BLUE, ScrollView::BLUE);
table_grid_.DisplayBoxes(table_win);
@ -789,28 +793,32 @@ void TableFinder::FindNeighbors() {
void TableFinder::MarkTablePartitions() {
MarkPartitionsUsingLocalInformation();
if (textord_tablefind_show_mark) {
ScrollView* table_win = MakeWindow(300, 300, "Initial Table Partitions");
ScrollView* table_win = MakeWindow(300, 300,
"Step 3: Initial Table Partitions");
DisplayColPartitions(table_win, &clean_part_grid_, ScrollView::BLUE);
DisplayColPartitions(table_win, &leader_and_ruling_grid_,
ScrollView::AQUAMARINE);
}
FilterFalseAlarms();
if (textord_tablefind_show_mark) {
ScrollView* table_win = MakeWindow(600, 300, "Filtered Table Partitions");
ScrollView* table_win = MakeWindow(600, 300,
"Step 4: Filtered Table Partitions");
DisplayColPartitions(table_win, &clean_part_grid_, ScrollView::BLUE);
DisplayColPartitions(table_win, &leader_and_ruling_grid_,
ScrollView::AQUAMARINE);
}
SmoothTablePartitionRuns();
if (textord_tablefind_show_mark) {
ScrollView* table_win = MakeWindow(900, 300, "Smoothed Table Partitions");
ScrollView* table_win = MakeWindow(900, 300,
"Step 5: Smoothed Table Partitions");
DisplayColPartitions(table_win, &clean_part_grid_, ScrollView::BLUE);
DisplayColPartitions(table_win, &leader_and_ruling_grid_,
ScrollView::AQUAMARINE);
}
FilterFalseAlarms();
if (textord_tablefind_show_mark || textord_show_tables) {
ScrollView* table_win = MakeWindow(900, 300, "Final Table Partitions");
ScrollView* table_win = MakeWindow(900, 300,
"Step 6: Final Table Partitions");
DisplayColPartitions(table_win, &clean_part_grid_, ScrollView::BLUE);
DisplayColPartitions(table_win, &leader_and_ruling_grid_,
ScrollView::AQUAMARINE);
@ -1815,13 +1823,13 @@ bool TableFinder::GapInXProjection(int* xprojection, int length) {
// (rejected before)
// Overall, this just needs some more work.
void TableFinder::RecognizeTables() {
ScrollView* table_win = nullptr;
if (textord_show_tables) {
table_win = MakeWindow(0, 0, "Table Structure");
DisplayColPartitions(table_win, &fragmented_text_grid_,
ScrollView::BLUE, ScrollView::LIGHT_BLUE);
// table_grid_.DisplayBoxes(table_win);
}
// ScrollView* table_win = nullptr;
// if (textord_show_tables) {
// table_win = MakeWindow(0, 0, "Step 9: Table Structure");
// DisplayColPartitions(table_win, &fragmented_text_grid_,
// ScrollView::BLUE, ScrollView::LIGHT_BLUE);
// // table_grid_.DisplayBoxes(table_win);
// }
TableRecognizer recognizer;
@ -1849,9 +1857,9 @@ void TableFinder::RecognizeTables() {
// Process a table. Good tables are inserted into the grid again later on
// We can't change boxes in the grid while it is running a search.
if (table_structure != nullptr) {
if (textord_show_tables) {
table_structure->Display(table_win, ScrollView::LIME_GREEN);
}
// if (textord_show_tables) {
// table_structure->Display(table_win, ScrollView::LIME_GREEN);
// }
found_table->set_bounding_box(table_structure->bounding_box());
delete table_structure;
good_it.add_after_then_move(found_table);
@ -1997,6 +2005,25 @@ void TableFinder::DisplayColPartitionConnections(
void TableFinder::MakeTableBlocks(ColPartitionGrid* grid,
ColPartitionSet** all_columns,
WidthCallback width_cb) {
#ifndef GRAPHICS_DISABLED
ScrollView* table_win = nullptr;
if (textord_show_tables) {
table_win = MakeWindow(0, 0, "Step 12: Final tables");
DisplayColPartitions(table_win, &fragmented_text_grid_,
ScrollView::BLUE, ScrollView::LIGHT_BLUE);
}
#endif // GRAPHICS_DISABLED
// initializing recognizer in order to extract table row and columnd info
TableRecognizer recognizer;
{
recognizer.Init();
recognizer.set_line_grid(&leader_and_ruling_grid_);
recognizer.set_text_grid(&fragmented_text_grid_);
recognizer.set_max_text_height(global_median_xheight_ * 2.0);
recognizer.set_min_height(1.5 * gridheight());
}
// Since we have table blocks already, remove table tags from all
// colpartitions
GridSearch<ColPartition, ColPartition_CLIST, ColPartition_C_IT>
@ -2053,8 +2080,26 @@ void TableFinder::MakeTableBlocks(ColPartitionGrid* grid,
table_partition->set_flow(BTFT_CHAIN);
table_partition->SetBlobTypes();
grid->InsertBBox(true, true, table_partition);
// Insert table columns and rows into an api accessible object
StructuredTable* table_structure = recognizer.RecognizeTable(table_box);
if (table_structure != nullptr) {
#ifndef GRAPHICS_DISABLED
if (textord_show_tables) {
table_structure->Display(table_win, ScrollView::LIME_GREEN);
}
#endif // GRAPHICS_DISABLED
delete table_structure;
}
}
}
#ifndef GRAPHICS_DISABLED
if (textord_show_tables) {
table_grid_.DisplayBoxes(table_win);
}
#endif // GRAPHICS_DISABLED
}
//////// ColSegment code