Skip to content

Commit

Permalink
more diagnostics for the line finding part of the OCR (pre)process.
Browse files Browse the repository at this point in the history
  • Loading branch information
GerHobbelt committed Jul 27, 2024
1 parent 5b8c08f commit 5608dba
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
54 changes: 51 additions & 3 deletions src/textord/linefind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ static void GetLineBoxes(bool horizontal_lines, Image pix_lines, Image pix_inter
// The output list of TabVector makes no reference to the input BLOBNBOXes.
void LineFinder::FindLineVectors(const ICOORD &bleft, const ICOORD &tright,
BLOBNBOX_LIST *line_bblobs, int *vertical_x, int *vertical_y,
TabVector_LIST *vectors) {
TabVector_LIST *vectors, bool vertical_search) {
BLOBNBOX_IT bbox_it(line_bblobs);
int b_count = 0;
// Put all the blobs into the grid to find the lines, and move the blobs
Expand Down Expand Up @@ -364,6 +364,8 @@ void LineFinder::FindLineVectors(const ICOORD &bleft, const ICOORD &tright,
tprintDebug("Finding line vector starting at bbox ({},{})\n", box.left(), box.bottom());
}
AlignedBlobParams align_params(*vertical_x, *vertical_y, box.width());
if (!vertical_search)
align_params.max_v_gap *= 3;
TabVector *vector =
blob_grid.FindVerticalAlignment(align_params, bbox, vertical_x, vertical_y);
if (vector != nullptr) {
Expand Down Expand Up @@ -619,7 +621,7 @@ void LineFinder::FindAndRemoveVLines(Image pix_intersections, int *vertical_x,
int height = pixGetHeight(src_pix);
ICOORD bleft(0, 0);
ICOORD tright(width, height);
FindLineVectors(bleft, tright, &line_bblobs, vertical_x, vertical_y, vectors);
FindLineVectors(bleft, tright, &line_bblobs, vertical_x, vertical_y, vectors, true);
if (!vectors->empty()) {
RemoveUnusedLineSegments(false, &line_bblobs, *pix_vline);
SubtractLinesAndResidue(*pix_vline, pix_non_vline, src_pix);
Expand Down Expand Up @@ -654,7 +656,7 @@ void LineFinder::FindAndRemoveHLines(Image pix_intersections, int vertical_x,
int height = pixGetHeight(src_pix);
ICOORD bleft(0, 0);
ICOORD tright(height, width);
FindLineVectors(bleft, tright, &line_bblobs, &vertical_x, &vertical_y, vectors);
FindLineVectors(bleft, tright, &line_bblobs, &vertical_x, &vertical_y, vectors, false);
if (!vectors->empty()) {
RemoveUnusedLineSegments(true, &line_bblobs, *pix_hline);
SubtractLinesAndResidue(*pix_hline, pix_non_hline, src_pix);
Expand Down Expand Up @@ -701,6 +703,34 @@ void LineFinder::FindAndRemoveLines(int resolution, Image pix, int *vertical_x,

GetLineMasks(resolution, pix, &pix_vline, &pix_non_vline, &pix_hline, &pix_non_hline,
&pix_intersections, pix_music_mask);

if (tesseract_->debug_line_finding) {
#if !GRAPHICS_DISABLED
if (!tesseract_->interactive_display_mode && (pix_vline != nullptr || pix_hline != nullptr)) {
int width = pixGetWidth(pix);
int height = pixGetHeight(pix);
ScrollViewReference win = ScrollViewManager::MakeScrollView(tesseract_, "LinesMask", 0, 0, width, height, width, height);

if (pix_vline != nullptr) {
win->Draw(pix_vline, 0, 0, "find & remove H/V lines : vline mask");
}

if (pix_hline != nullptr) {
win->Draw(pix_hline, 0, 0, "find & remove H/V lines : hline mask");
}

win->Update();
}
#endif

if (pix_vline != nullptr) {
tesseract_->AddPixDebugPage(pix_vline, "find & remove H/V lines : vline mask");
}
if (pix_hline != nullptr) {
tesseract_->AddPixDebugPage(pix_hline, "find & remove H/V lines : hline mask");
}
}

// Find lines, convert to TabVector_LIST and remove those that are used.
FindAndRemoveVLines(pix_intersections, vertical_x, vertical_y, &pix_vline,
pix_non_vline, pix, v_lines);
Expand All @@ -718,6 +748,24 @@ void LineFinder::FindAndRemoveLines(int resolution, Image pix, int *vertical_x,
FindAndRemoveHLines(pix_intersections, *vertical_x, *vertical_y, &pix_hline,
pix_non_hline, pix, h_lines);
if (tesseract_->debug_line_finding) {
#if !GRAPHICS_DISABLED
if (!tesseract_->interactive_display_mode && (pix_vline != nullptr || pix_hline != nullptr)) {
int width = pixGetWidth(pix);
int height = pixGetHeight(pix);
ScrollViewReference win = ScrollViewManager::MakeScrollView(tesseract_, "LinesMask", 0, 0, width, height, width, height);

if (pix_vline != nullptr) {
win->Draw(pix_vline, 0, 0, "find & remove H/V lines : vline");
}

if (pix_hline != nullptr) {
win->Draw(pix_hline, 0, 0, "find & remove H/V lines : hline");
}

win->Update();
}
#endif

if (pix_vline != nullptr) {
tesseract_->AddPixDebugPage(pix_vline, "find & remove H/V lines : vline");
}
Expand Down
2 changes: 1 addition & 1 deletion src/textord/linefind.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class LineFinder {
// The output list of TabVector makes no reference to the input BLOBNBOXes.
void FindLineVectors(const ICOORD& bleft, const ICOORD& tright,
BLOBNBOX_LIST* line_bblobs, int* vertical_x, int* vertical_y,
TabVector_LIST* vectors);
TabVector_LIST* vectors, bool vertical_search);

// Finds vertical line objects in pix_vline and removes them from src_pix.
// Uses the given resolution to determine size thresholds instead of any
Expand Down

0 comments on commit 5608dba

Please sign in to comment.