Leptonica
1.54
|
#include "allheaders.h"
BOXA* boxaClipToBox | ( | BOXA * | boxas, |
BOX * | box | ||
) |
Input: boxas box (for clipping) Return boxad (boxa with boxes in boxas clipped to box), or null on error
Notes: (1) All boxes in boxa not intersecting with box are removed, and the remaining boxes are clipped to box.
BOXA* boxaCombineOverlaps | ( | BOXA * | boxas | ) |
Input: boxas Return: boxad (where each set of boxes in boxas that overlap are combined into a single bounding box in boxad), or null on error.
Notes: (1) If there are no overlapping boxes, it simply returns a copy of . (2) The alternative method of painting each rectanle and finding the 4-connected components gives the wrong result, because two non-overlapping rectangles, when rendered, can still be 4-connected, and hence they will be joined. (3) A bad case is to have n boxes, none of which overlap. Then you have one iteration with O(n^2) compares. This is still faster than painting each rectangle and finding the connected components, even for thousands of rectangles.
BOXA* boxaContainedInBox | ( | BOXA * | boxas, |
BOX * | box | ||
) |
Input: boxas box (for containment) Return: boxad (boxa with all boxes in boxas that are entirely contained in box), or null on error
Notes: (1) All boxes in boxa that are entirely outside box are removed.
BOX* boxAdjustSides | ( | BOX * | boxd, |
BOX * | boxs, | ||
l_int32 | delleft, | ||
l_int32 | delright, | ||
l_int32 | deltop, | ||
l_int32 | delbot | ||
) |
Input: boxd (<optional>; this can be null, equal to boxs, or different from boxs) boxs (starting box; to have sides adjusted) delleft, delright, deltop, delbot (changes in location of each side) Return: boxd, or null on error or if the computed boxd has width or height <= 0.
Notes: (1) Set boxd == NULL to get new box; boxd == boxs for in-place; or otherwise to resize existing boxd. (2) For usage, suggest one of these: boxd = boxAdjustSides(NULL, boxs, ...); // new boxAdjustSides(boxs, boxs, ...); // in-place boxAdjustSides(boxd, boxs, ...); // other (1) New box dimensions are cropped at left and top to x >= 0 and y >= 0. (2) For example, to expand in-place by 20 pixels on each side, use boxAdjustSides(box, box, -20, 20, -20, 20);
l_int32 boxaEqual | ( | BOXA * | boxa1, |
BOXA * | boxa2, | ||
l_int32 | maxdist, | ||
NUMA ** | pnaindex, | ||
l_int32 * | psame | ||
) |
Input: boxa1 boxa2 maxdist &naindex (<optional return>=""> index array of correspondences &same (<return> 1 if equal; 0 otherwise) Return 0 if OK, 1 on error
Notes: (1) The two boxa are the "same" if they contain the same boxes and each box is within of its counterpart in their positions within the boxa. This allows for small rearrangements. Use 0 for maxdist if the boxa must be identical. (2) This applies only to geometry and ordering; refcounts are not considered. (3) allows some latitude in the ordering of the boxes. For the boxa to be the "same", corresponding boxes must be within of each other. Note that for large , we should use a hash function for efficiency. (4) naindex[i] gives the position of the box in boxa2 that corresponds to box i in boxa1. It is only returned if the boxa are equal.
BOX* boxaGetNearestToPt | ( | BOXA * | boxa, |
l_int32 | x, | ||
l_int32 | y | ||
) |
Input: boxa x, y (point) Return box (box with centroid closest to the given point [x,y]), or NULL if no boxes in boxa)
Notes: (1) Uses euclidean distance between centroid and point.
BOXA* boxaIntersectsBox | ( | BOXA * | boxas, |
BOX * | box | ||
) |
Input: boxas box (for intersecting) Return boxad (boxa with all boxes in boxas that intersect box), or null on error
Notes: (1) All boxes in boxa that intersect with box (i.e., are completely or partially contained in box) are retained.
Input: boxad (dest boxa; add to this one) boxas (source boxa; add from this one) istart (starting index in nas) iend (ending index in nas; use 0 to cat all) Return: 0 if OK, 1 on error
Notes: (1) This appends a clone of each indicated box in boxas to boxad (2) istart < 0 is taken to mean 'read from the start' (istart = 0) (3) iend <= 0 means 'read to the end'
BOXA* boxaMergeEvenOdd | ( | BOXA * | boxae, |
BOXA * | boxao | ||
) |
Input: boxae (boxes to go in even positions in merged boxa) boxao (boxes to go in odd positions in merged boxa) Return: boxad (merged), or null on error
Notes: (1) Boxes are alternatingly selected from boxae and boxao. Both boxae and boxao are of the same size.
l_int32 boxaSplitEvenOdd | ( | BOXA * | boxa, |
BOXA ** | pboxae, | ||
BOXA ** | pboxao | ||
) |
Input: boxa &boxae, &boxao (<return> save even and odd boxes in their separate boxa, setting the other type to invalid boxes.) Return: 0 if OK, 1 on error
Notes: (1) For example, boxae copies of the even boxes, in their original location, that are in boxa. Invalid boxes are placed in the odd array locations.
BOX* boxBoundingRegion | ( | BOX * | box1, |
BOX * | box2 | ||
) |
Input: box1, box2 (two boxes) Return: box (of bounding region containing the input boxes), or null on error
BOX* boxClipToRectangle | ( | BOX * | box, |
l_int32 | wi, | ||
l_int32 | hi | ||
) |
Input: box wi, hi (rectangle representing image) Return: part of box within given rectangle, or NULL on error or if box is entirely outside the rectangle
Notes: (1) This can be used to clip a rectangle to an image. The clipping rectangle is assumed to have a UL corner at (0, 0), and a LR corner at (wi - 1, hi - 1).
l_int32 boxContains | ( | BOX * | box1, |
BOX * | box2, | ||
l_int32 * | presult | ||
) |
Input: box1, box2 &result (<return> 1 if box2 is entirely contained within box1, and 0 otherwise) Return: 0 if OK, 1 on error
Input: box x, y (a point) &contains (<return> 1 if box contains point; 0 otherwise) Return: 0 if OK, 1 on error.
Input: box1 box2 &same (<return> 1 if equal; 0 otherwise) Return 0 if OK, 1 on error
l_int32 boxGetCenter | ( | BOX * | box, |
l_float32 * | pcx, | ||
l_float32 * | pcy | ||
) |
Input: box &cx, &cy (<return> location of center of box) Return 0 if OK, 1 on error
l_int32 boxIntersectByLine | ( | BOX * | box, |
l_int32 | x, | ||
l_int32 | y, | ||
l_float32 | slope, | ||
l_int32 * | px1, | ||
l_int32 * | py1, | ||
l_int32 * | px2, | ||
l_int32 * | py2, | ||
l_int32 * | pn | ||
) |
Input: box x, y (point that line goes through) slope (of line) (&x1, &y1) (<return> 1st point of intersection with box) (&x2, &y2) (<return> 2nd point of intersection with box) &n (<return> number of points of intersection) Return: 0 if OK, 1 on error
Notes: (1) If the intersection is at only one point (a corner), the coordinates are returned in (x1, y1). (2) Represent a vertical line by one with a large but finite slope.
l_int32 boxIntersects | ( | BOX * | box1, |
BOX * | box2, | ||
l_int32 * | presult | ||
) |
Input: box1, box2 &result (<return> 1 if any part of box2 is contained in box1, and 0 otherwise) Return: 0 if OK, 1 on error
l_int32 boxOverlapFraction | ( | BOX * | box1, |
BOX * | box2, | ||
l_float32 * | pfract | ||
) |
Input: box1, box2 (two boxes) &fract (<return> the fraction of box2 overlapped by box1) Return: 0 if OK, 1 on error.
Notes: (1) The result depends on the order of the input boxes, because the overlap is taken as a fraction of box2.
BOX* boxOverlapRegion | ( | BOX * | box1, |
BOX * | box2 | ||
) |
Input: box1, box2 (two boxes) Return: box (of overlap region between input boxes), or null if no overlap or on error
Input: boxd (<optional>; this can be null, equal to boxs, or different from boxs); boxs (starting box; to have one side relocated) loc (new location of the side that is changing) sideflag (L_FROM_LEFT, etc., indicating the side that moves) Return: boxd, or null on error or if the computed boxd has width or height <= 0.
Notes: (1) Set boxd == NULL to get new box; boxd == boxs for in-place; or otherwise to resize existing boxd. (2) For usage, suggest one of these: boxd = boxRelocateOneSide(NULL, boxs, ...); // new boxRelocateOneSide(boxs, boxs, ...); // in-place boxRelocateOneSide(boxd, boxs, ...); // other