tesseract  4.00.00dev
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 321 of file linefind.cpp.

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

◆ 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 != NULL, 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 243 of file linefind.cpp.

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

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