tesseract 4.1.1
Loading...
Searching...
No Matches
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 auto* 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:349
ICOORD pos
Definition: crakedge.h:30
Definition: ocrblock.h:31
C_BLOB_LIST * blob_list()
get blobs
Definition: ocrblock.h:128
integer coordinate
Definition: points.h:32

◆ 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 243 of file linefind.cpp.

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

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