tesseract  4.0.0-1-g2a2b
tesseract::LineFinder Class Reference

#include <linefind.h>

Static Public Member Functions

static void FindAndRemoveLines (int resolution, bool debug, Pix *pix, int *vertical_x, int *vertical_y, Pix **pix_music_mask, TabVector_LIST *v_lines, TabVector_LIST *h_lines)
 
static void ConvertBoxaToBlobs (int image_width, int image_height, Boxa **boxes, C_BLOB_LIST *blobs)
 

Detailed Description

The LineFinder class is a simple static function wrapper class that mainly exposes the FindVerticalLines function.

Definition at line 39 of file linefind.h.

Member Function Documentation

◆ ConvertBoxaToBlobs()

void tesseract::LineFinder::ConvertBoxaToBlobs ( int  image_width,
int  image_height,
Boxa **  boxes,
C_BLOB_LIST *  blobs 
)
static

Converts the Boxa array to a list of C_BLOB, getting rid of severely overlapping outlines and those that are children of a bigger one.

The output is a list of C_BLOBs that are owned by the list.

The C_OUTLINEs in the C_BLOBs contain no outline data - just empty bounding boxes. The Boxa is consumed and destroyed.

Definition at line 319 of file linefind.cpp.

320  {
321  C_OUTLINE_LIST outlines;
322  C_OUTLINE_IT ol_it = &outlines;
323  // Iterate the boxes to convert to outlines.
324  int nboxes = boxaGetCount(*boxes);
325  for (int i = 0; i < nboxes; ++i) {
326  l_int32 x, y, width, height;
327  boxaGetBoxGeometry(*boxes, i, &x, &y, &width, &height);
328  // Make a C_OUTLINE from the leptonica box. This is a bit of a hack,
329  // as there is no outline, just a bounding box, but with some very
330  // small changes to coutln.cpp, it works nicely.
331  ICOORD top_left(x, y);
332  ICOORD bot_right(x + width, y + height);
333  CRACKEDGE startpt;
334  startpt.pos = top_left;
335  C_OUTLINE* outline = new C_OUTLINE(&startpt, top_left, bot_right, 0);
336  ol_it.add_after_then_move(outline);
337  }
338  // Use outlines_to_blobs to convert the outlines to blobs and find
339  // overlapping and contained objects. The output list of blobs in the block
340  // has all the bad ones filtered out and deleted.
341  BLOCK block;
342  ICOORD page_tl(0, 0);
343  ICOORD page_br(image_width, image_height);
344  outlines_to_blobs(&block, page_tl, page_br, &outlines);
345  // Transfer the created blobs to the output list.
346  C_BLOB_IT blob_it(blobs);
347  blob_it.add_list_after(block.blob_list());
348  // The boxes aren't needed any more.
349  boxaDestroy(boxes);
350 }
void outlines_to_blobs(BLOCK *block, ICOORD bleft, ICOORD tright, C_OUTLINE_LIST *outlines)
Definition: edgblob.cpp:354
C_BLOB_LIST * blob_list()
get blobs
Definition: ocrblock.h:130
integer coordinate
Definition: points.h:32
ICOORD pos
Definition: crakedge.h:30
Definition: ocrblock.h:30
class DLLSYM C_OUTLINE
Definition: coutln.h:68

◆ FindAndRemoveLines()

void tesseract::LineFinder::FindAndRemoveLines ( int  resolution,
bool  debug,
Pix *  pix,
int *  vertical_x,
int *  vertical_y,
Pix **  pix_music_mask,
TabVector_LIST *  v_lines,
TabVector_LIST *  h_lines 
)
static

Finds vertical and horizontal line objects in the given pix and removes them.

Uses the given resolution to determine size thresholds instead of any that may be present in the pix.

The output vertical_x and vertical_y contain a sum of the output vectors, thereby giving the mean vertical direction.

If pix_music_mask != nullptr, and music is detected, a mask of the staves and anything that is connected (bars, notes etc.) will be returned in pix_music_mask, the mask subtracted from pix, and the lines will not appear in v_lines or h_lines.

The output vectors are owned by the list and Frozen (cannot refit) by having no boxes, as there is no need to refit or merge separator lines.

The detected lines are removed from the pix.

Definition at line 241 of file linefind.cpp.

245  {
246  PERF_COUNT_START("FindAndRemoveLines")
247  if (pix == nullptr || vertical_x == nullptr || vertical_y == nullptr) {
248  tprintf("Error in parameters for LineFinder::FindAndRemoveLines\n");
249  return;
250  }
251  Pix* pix_vline = nullptr;
252  Pix* pix_non_vline = nullptr;
253  Pix* pix_hline = nullptr;
254  Pix* pix_non_hline = nullptr;
255  Pix* pix_intersections = nullptr;
256  Pixa* pixa_display = debug ? pixaCreate(0) : nullptr;
257  GetLineMasks(resolution, pix, &pix_vline, &pix_non_vline, &pix_hline,
258  &pix_non_hline, &pix_intersections, pix_music_mask,
259  pixa_display);
260  // Find lines, convert to TabVector_LIST and remove those that are used.
261  FindAndRemoveVLines(resolution, pix_intersections, vertical_x, vertical_y,
262  &pix_vline, pix_non_vline, pix, v_lines);
263  if (pix_hline != nullptr) {
264  // Recompute intersections and re-filter false positive h-lines.
265  if (pix_vline != nullptr)
266  pixAnd(pix_intersections, pix_vline, pix_hline);
267  else
268  pixDestroy(&pix_intersections);
269  if (!FilterFalsePositives(resolution, pix_non_hline, pix_intersections,
270  pix_hline)) {
271  pixDestroy(&pix_hline);
272  }
273  }
274  FindAndRemoveHLines(resolution, pix_intersections, *vertical_x, *vertical_y,
275  &pix_hline, pix_non_hline, pix, h_lines);
276  if (pixa_display != nullptr && pix_vline != nullptr)
277  pixaAddPix(pixa_display, pix_vline, L_CLONE);
278  if (pixa_display != nullptr && pix_hline != nullptr)
279  pixaAddPix(pixa_display, pix_hline, L_CLONE);
280  if (pix_vline != nullptr && pix_hline != nullptr) {
281  // Remove joins (intersections) where lines cross, and the residue.
282  // Recalculate the intersections, since some lines have been deleted.
283  pixAnd(pix_intersections, pix_vline, pix_hline);
284  // Fatten up the intersections and seed-fill to get the intersection
285  // residue.
286  Pix* pix_join_residue = pixDilateBrick(nullptr, pix_intersections, 5, 5);
287  pixSeedfillBinary(pix_join_residue, pix_join_residue, pix, 8);
288  // Now remove the intersection residue.
289  pixSubtract(pix, pix, pix_join_residue);
290  pixDestroy(&pix_join_residue);
291  }
292  // Remove any detected music.
293  if (pix_music_mask != nullptr && *pix_music_mask != nullptr) {
294  if (pixa_display != nullptr)
295  pixaAddPix(pixa_display, *pix_music_mask, L_CLONE);
296  pixSubtract(pix, pix, *pix_music_mask);
297  }
298  if (pixa_display != nullptr)
299  pixaAddPix(pixa_display, pix, L_CLONE);
300 
301  pixDestroy(&pix_vline);
302  pixDestroy(&pix_non_vline);
303  pixDestroy(&pix_hline);
304  pixDestroy(&pix_non_hline);
305  pixDestroy(&pix_intersections);
306  if (pixa_display != nullptr) {
307  pixaConvertToPdf(pixa_display, resolution, 1.0f, 0, 0, "LineFinding",
308  "vhlinefinding.pdf");
309  pixaDestroy(&pixa_display);
310  }
312 }
#define PERF_COUNT_START(FUNCT_NAME)
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:37
#define PERF_COUNT_END

The documentation for this class was generated from the following files: