tesseract  5.0.0
tesseract::LineFinder Class Reference

#include <linefind.h>

Static Public Member Functions

static void FindAndRemoveLines (int resolution, bool debug, Image pix, int *vertical_x, int *vertical_y, Image *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 316 of file linefind.cpp.

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

◆ FindAndRemoveLines()

void tesseract::LineFinder::FindAndRemoveLines ( int  resolution,
bool  debug,
Image  pix,
int *  vertical_x,
int *  vertical_y,
Image 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 240 of file linefind.cpp.

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

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