diff --git a/src/ccmain/paragraphs.cpp b/src/ccmain/paragraphs.cpp index d995a6b3f0..f3d9aa92cd 100644 --- a/src/ccmain/paragraphs.cpp +++ b/src/ccmain/paragraphs.cpp @@ -2610,7 +2610,6 @@ void DetectParagraphs(int debug_level, bool after_text_recognition, // Run the paragraph detection algorithm. std::vector row_owners; - std::vector the_paragraphs; if (!is_image_block) { DetectParagraphs(debug_level, &row_infos, &row_owners, block->para_list(), models); } else { diff --git a/src/ccstruct/stepblob.cpp b/src/ccstruct/stepblob.cpp index 3311f0c6f3..50bf0becc3 100644 --- a/src/ccstruct/stepblob.cpp +++ b/src/ccstruct/stepblob.cpp @@ -43,7 +43,7 @@ const double kMaxPerimeterWidthRatio = 8.0; **********************************************************************/ static void position_outline( // put in place C_OUTLINE *outline, // thing to place - C_OUTLINE_LIST *destlist // desstination list + C_OUTLINE_LIST *destlist // destination list ) { C_OUTLINE_IT it = destlist; // iterator // iterator on children diff --git a/src/textord/alignedblob.cpp b/src/textord/alignedblob.cpp index 4acfc9bc33..781f641841 100644 --- a/src/textord/alignedblob.cpp +++ b/src/textord/alignedblob.cpp @@ -167,7 +167,7 @@ ScrollView *AlignedBlob::DisplayTabs(const char *window_name, ScrollView *tab_wi tab_win = MakeWindow(0, 50, window_name); } // For every tab in the grid, display it. - GridSearch gsearch(this); + BlobGridSearch gsearch(this); gsearch.StartFullSearch(); BLOBNBOX *bbox; while ((bbox = gsearch.NextFullSearch()) != nullptr) { @@ -409,7 +409,7 @@ BLOBNBOX *AlignedBlob::FindAlignedBlob(const AlignedBlobParams &p, bool top_to_b xmin -= p.min_gutter; } // Setup a vertical search for an aligned blob. - GridSearch vsearch(this); + BlobGridSearch vsearch(this); if (WithinTestRegion(2, x_start, start_y)) { tprintf("Starting %s %s search at %d-%d,%d, search_size=%d, gutter=%d\n", p.ragged ? "Ragged" : "Aligned", p.right_tab ? "Right" : "Left", xmin, xmax, start_y, diff --git a/src/textord/colfind.cpp b/src/textord/colfind.cpp index 3e97c2858e..9e1ce820cf 100644 --- a/src/textord/colfind.cpp +++ b/src/textord/colfind.cpp @@ -142,7 +142,7 @@ ColumnFinder::~ColumnFinder() { } // Performs initial processing on the blobs in the input_block: -// Setup the part_grid, stroke_width_, nontext_map. +// Setup the part_grid_, stroke_width_, nontext_map. // Obvious noise blobs are filtered out and used to mark the nontext_map_. // Initial stroke-width analysis is used to get local text alignment // direction, so the textline projection_ map can be setup. @@ -971,7 +971,7 @@ void ColumnFinder::ReleaseBlobsAndCleanupUnused(TO_BLOCK *block) { // Splits partitions that cross columns where they have nothing in the gap. void ColumnFinder::GridSplitPartitions() { // Iterate the ColPartitions in the grid. - GridSearch gsearch(&part_grid_); + ColPartitionGridSearch gsearch(&part_grid_); gsearch.StartFullSearch(); ColPartition *dont_repeat = nullptr; ColPartition *part; @@ -1438,7 +1438,7 @@ void ColumnFinder::TransformToBlocks(BLOCK_LIST *blocks, TO_BLOCK_LIST *to_block // like horizontal lines going before the text lines above them. ColPartition_CLIST temp_part_list; // Iterate the ColPartitions in the grid. It starts at the top - GridSearch gsearch(&part_grid_); + ColPartitionGridSearch gsearch(&part_grid_); gsearch.StartFullSearch(); int prev_grid_y = -1; ColPartition *part; diff --git a/src/textord/makerow.cpp b/src/textord/makerow.cpp index 4c067e67f7..837a3e3104 100644 --- a/src/textord/makerow.cpp +++ b/src/textord/makerow.cpp @@ -2485,8 +2485,8 @@ OVERLAP_STATE most_overlapping_row( // find best row row_it->forward(); test_row = row_it->data(); if (test_row->min_y() <= top && test_row->max_y() >= bottom) { - merge_top = test_row->max_y() > row->max_y() ? test_row->max_y() : row->max_y(); - merge_bottom = test_row->min_y() < row->min_y() ? test_row->min_y() : row->min_y(); + merge_top = std::max(test_row->max_y(),row->max_y()); + merge_bottom = std::min(test_row->min_y(),row->min_y()); if (merge_top - merge_bottom <= rowsize) { if (testing_blob && textord_debug_blob) { tprintf("Merging rows at (%g,%g), (%g,%g)\n", row->min_y(), row->max_y(), diff --git a/src/textord/strokewidth.h b/src/textord/strokewidth.h index bc88d8fd59..cdab5345fe 100644 --- a/src/textord/strokewidth.h +++ b/src/textord/strokewidth.h @@ -89,7 +89,7 @@ class StrokeWidth : public BlobGrid { // Corrects the data structures for the given rotation. void CorrectForRotation(const FCOORD &rerotation, ColPartitionGrid *part_grid); - // Finds leader partitions and inserts them into the give grid. + // Finds leader partitions and inserts them into the given grid. void FindLeaderPartitions(TO_BLOCK *block, ColPartitionGrid *part_grid); // Finds and marks noise those blobs that look like bits of vertical lines diff --git a/src/textord/tabfind.cpp b/src/textord/tabfind.cpp index 462d0ff9b9..f6ba2b8477 100644 --- a/src/textord/tabfind.cpp +++ b/src/textord/tabfind.cpp @@ -562,7 +562,7 @@ ScrollView *TabFind::FindTabBoxes(int min_gutter_width, double tabfind_aligned_g left_tab_boxes_.clear(); right_tab_boxes_.clear(); // For every bbox in the grid, determine whether it uses a tab on an edge. - GridSearch gsearch(this); + BlobGridSearch gsearch(this); gsearch.StartFullSearch(); BLOBNBOX *bbox; while ((bbox = gsearch.NextFullSearch()) != nullptr) { diff --git a/src/textord/tablefind.cpp b/src/textord/tablefind.cpp index 843754cbd8..2ed4e495e7 100644 --- a/src/textord/tablefind.cpp +++ b/src/textord/tablefind.cpp @@ -679,8 +679,7 @@ void TableFinder::SetVerticalSpacing(ColPartition *part) { TBOX part_box = part->bounding_box(); // Start a rect search - GridSearch rectsearch( - &clean_part_grid_); + ColPartitionGridSearch rectsearch(&clean_part_grid_); rectsearch.StartRectSearch(box); ColPartition *neighbor; int min_space_above = kMaxVerticalSpacing; @@ -843,8 +842,7 @@ void TableFinder::MarkTablePartitions() { // 4- Partitions with leaders before/after them. void TableFinder::MarkPartitionsUsingLocalInformation() { // Iterate the ColPartitions in the grid. - GridSearch gsearch( - &clean_part_grid_); + ColPartitionGridSearch gsearch(&clean_part_grid_); gsearch.StartFullSearch(); ColPartition *part = nullptr; while ((part = gsearch.NextFullSearch()) != nullptr) { @@ -1190,8 +1188,7 @@ void TableFinder::SetColumnsType(ColSegment_LIST *column_blocks) { TBOX box = seg->bounding_box(); int num_table_cells = 0; int num_text_cells = 0; - GridSearch rsearch( - &clean_part_grid_); + ColPartitionGridSearch rsearch(&clean_part_grid_); rsearch.SetUniqueMode(true); rsearch.StartRectSearch(box); ColPartition *part = nullptr; @@ -1320,8 +1317,7 @@ void TableFinder::GridMergeColumnBlocks() { void TableFinder::GetTableColumns(ColSegment_LIST *table_columns) { ColSegment_IT it(table_columns); // Iterate the ColPartitions in the grid. - GridSearch gsearch( - &clean_part_grid_); + ColPartitionGridSearch gsearch(&clean_part_grid_); gsearch.StartFullSearch(); ColPartition *part; while ((part = gsearch.NextFullSearch()) != nullptr) { @@ -1335,8 +1331,7 @@ void TableFinder::GetTableColumns(ColSegment_LIST *table_columns) { // Start a search below the current cell to find bottom neighbours // Note: a full search will always process things above it first, so // this should be starting at the highest cell and working its way down. - GridSearch vsearch( - &clean_part_grid_); + ColPartitionGridSearch vsearch(&clean_part_grid_); vsearch.StartVerticalSearch(box.left(), box.right(), box.bottom()); ColPartition *neighbor = nullptr; bool found_neighbours = false; @@ -1503,8 +1498,7 @@ bool TableFinder::BelongToOneTable(const TBOX &box1, const TBOX &box2) { // Check for ColPartitions spanning both table regions TBOX bbox = box1.bounding_union(box2); // Start a rect search on bbox - GridSearch rectsearch( - &clean_part_grid_); + ColPartitionGridSearch rectsearch(&clean_part_grid_); rectsearch.StartRectSearch(bbox); ColPartition *part = nullptr; while ((part = rectsearch.NextRectSearch()) != nullptr) { @@ -1783,8 +1777,7 @@ void TableFinder::DeleteSingleColumnTables() { table_xprojection[i] = 0; } // Start a rect search on table_box - GridSearch rectsearch( - &clean_part_grid_); + ColPartitionGridSearch rectsearch(&clean_part_grid_); rectsearch.SetUniqueMode(true); rectsearch.StartRectSearch(table_box); ColPartition *part; @@ -1972,7 +1965,7 @@ void TableFinder::DisplayColPartitions(ScrollView *win, ColPartitionGrid *grid, ScrollView::Color table_color) { ScrollView::Color color = default_color; // Iterate the ColPartitions in the grid. - GridSearch gsearch(grid); + ColPartitionGridSearch gsearch(grid); gsearch.StartFullSearch(); ColPartition *part = nullptr; while ((part = gsearch.NextFullSearch()) != nullptr) { @@ -2002,7 +1995,7 @@ void TableFinder::DisplayColPartitionConnections(ScrollView *win, ColPartitionGrid *grid, ScrollView::Color color) { // Iterate the ColPartitions in the grid. - GridSearch gsearch(grid); + ColPartitionGridSearch gsearch(grid); gsearch.StartFullSearch(); ColPartition *part = nullptr; while ((part = gsearch.NextFullSearch()) != nullptr) { @@ -2048,7 +2041,7 @@ void TableFinder::MakeTableBlocks(ColPartitionGrid *grid, const WidthCallback &width_cb) { // Since we have table blocks already, remove table tags from all // colpartitions - GridSearch gsearch(grid); + ColPartitionGridSearch gsearch(grid); gsearch.StartFullSearch(); ColPartition *part = nullptr; @@ -2066,8 +2059,7 @@ void TableFinder::MakeTableBlocks(ColPartitionGrid *grid, while ((table = table_search.NextFullSearch()) != nullptr) { const TBOX &table_box = table->bounding_box(); // Start a rect search on table_box - GridSearch rectsearch( - grid); + ColPartitionGridSearch rectsearch(grid); rectsearch.StartRectSearch(table_box); ColPartition *part; ColPartition *table_partition = nullptr; diff --git a/src/textord/tordmain.cpp b/src/textord/tordmain.cpp index a7f2a168f3..b704c89279 100644 --- a/src/textord/tordmain.cpp +++ b/src/textord/tordmain.cpp @@ -533,16 +533,17 @@ bool Textord::clean_noise_from_row( // remove empties } } } + // TODO: check whether `&& super_norm_count < textord_noise_sncount`should always be added here. + bool rejected = dot_count > norm_count * textord_noise_normratio && + dot_count > 2; if (textord_noise_debug) { tprintf("Row ending at (%d,%g):", blob_box.right(), row->base_line(blob_box.right())); tprintf(" R=%g, dc=%d, nc=%d, %s\n", norm_count > 0 ? static_cast(dot_count) / norm_count : 9999, dot_count, norm_count, - dot_count > norm_count * textord_noise_normratio && dot_count > 2 ? "REJECTED" - : "ACCEPTED"); + rejected? "REJECTED": "ACCEPTED"); } - return super_norm_count < textord_noise_sncount && - dot_count > norm_count * textord_noise_rowratio && dot_count > 2; + return super_norm_count < textord_noise_sncount && rejected; } /**********************************************************************