Файл src/boxfunc1.c

#include <stdio.h>
#include <stdlib.h>
#include "allheaders.h"

Функции

l_int32 boxContains (BOX *box1, BOX *box2, l_int32 *presult)
l_int32 boxIntersects (BOX *box1, BOX *box2, l_int32 *presult)
BOXAboxaContainedInBox (BOXA *boxas, BOX *box)
BOXAboxaIntersectsBox (BOXA *boxas, BOX *box)
BOXAboxaClipToBox (BOXA *boxas, BOX *box)
BOXboxOverlapRegion (BOX *box1, BOX *box2)
BOXboxBoundingRegion (BOX *box1, BOX *box2)
l_int32 boxOverlapFraction (BOX *box1, BOX *box2, l_float32 *pfract)
l_int32 boxContainsPt (BOX *box, l_float32 x, l_float32 y, l_int32 *pcontains)
BOXboxaGetNearestToPt (BOXA *boxa, l_int32 x, l_int32 y)
l_int32 boxGetCentroid (BOX *box, l_int32 *px, l_int32 *py)
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)
BOXboxClipToRectangle (BOX *box, l_int32 wi, l_int32 hi)
BOXboxRelocateOneSide (BOX *boxd, BOX *boxs, l_int32 loc, l_int32 sideflag)
BOXboxAdjustSides (BOX *boxd, BOX *boxs, l_int32 delleft, l_int32 delright, l_int32 deltop, l_int32 delbot)
l_int32 boxEqual (BOX *box1, BOX *box2, l_int32 *psame)
l_int32 boxaEqual (BOXA *boxa1, BOXA *boxa2, l_int32 maxdist, NUMA **pnaindex, l_int32 *psame)
l_int32 boxaJoin (BOXA *boxad, BOXA *boxas, l_int32 istart, l_int32 iend)
l_int32 boxaGetExtent (BOXA *boxa, l_int32 *pw, l_int32 *ph, BOX **pbox)
l_int32 boxaGetCoverage (BOXA *boxa, l_int32 wc, l_int32 hc, l_int32 exactflag, l_float32 *pfract)
l_int32 boxaSizeRange (BOXA *boxa, l_int32 *pminw, l_int32 *pminh, l_int32 *pmaxw, l_int32 *pmaxh)
l_int32 boxaLocationRange (BOXA *boxa, l_int32 *pminx, l_int32 *pminy, l_int32 *pmaxx, l_int32 *pmaxy)
BOXAboxaSelectBySize (BOXA *boxas, l_int32 width, l_int32 height, l_int32 type, l_int32 relation, l_int32 *pchanged)
NUMAboxaMakeSizeIndicator (BOXA *boxa, l_int32 width, l_int32 height, l_int32 type, l_int32 relation)
BOXAboxaSelectWithIndicator (BOXA *boxas, NUMA *na, l_int32 *pchanged)
BOXAboxaPermutePseudorandom (BOXA *boxas)
BOXAboxaPermuteRandom (BOXA *boxad, BOXA *boxas)
l_int32 boxaSwapBoxes (BOXA *boxa, l_int32 i, l_int32 j)
PTAboxaConvertToPta (BOXA *boxa, l_int32 ncorners)
BOXAptaConvertToBoxa (PTA *pta, l_int32 ncorners)

Функции

BOXA* boxaClipToBox ( BOXA boxas,
BOX box 
)

boxaClipToBox()

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* boxaContainedInBox ( BOXA boxas,
BOX box 
)

boxaContainedInBox()

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.

PTA* boxaConvertToPta ( BOXA boxa,
l_int32  ncorners 
)

boxaConvertToPta()

Input: boxa ncorners (2 or 4 for the representation of each box) Return: pta (with points for each box in the boxa), or null on error

Notes: (1) If ncorners == 2, we select the UL and LR corners. Otherwise we save all 4 corners in this order: UL, UR, LL, LR.

BOX* boxAdjustSides ( BOX boxd,
BOX boxs,
l_int32  delleft,
l_int32  delright,
l_int32  deltop,
l_int32  delbot 
)

boxAdjustSides()

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 
)

boxaEqual()

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.

l_int32 boxaGetCoverage ( BOXA boxa,
l_int32  wc,
l_int32  hc,
l_int32  exactflag,
l_float32 pfract 
)

boxaGetCoverage()

Input: boxa wc, hc (dimensions of overall clipping rectangle with UL corner at (0, 0) that is covered by the boxes. exactflag (1 for guaranteeing an exact result; 0 for getting an exact result only if the boxes do not overlap) &fract (<return> sum of box area as fraction of w * h) Return: 0 if OK, 1 on error

Notes: (1) The boxes in boxa are clipped to the input rectangle. (2) * When == 1, we generate a 1 bpp pix of size wc x hc, paint all the boxes black, and count the fg pixels. This can take 1 msec on a large page with many boxes. * When == 0, we clip each box to the wc x hc region and sum the resulting areas. This is faster. * The results are the same when none of the boxes overlap within the wc x hc region.

l_int32 boxaGetExtent ( BOXA boxa,
l_int32 pw,
l_int32 ph,
BOX **  pbox 
)

boxaGetExtent()

Input: boxa &w (<optional return>=""> width) &h (<optional return>=""> height) &box (<optional return>="">, minimum box containing all boxes in boxa) Return: 0 if OK, 1 on error

Notes: (1) The returned w and h are the minimum size image that would contain all boxes untranslated.

BOX* boxaGetNearestToPt ( BOXA boxa,
l_int32  x,
l_int32  y 
)

boxaGetNearestToPt()

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 
)

boxaIntersectsBox()

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.

l_int32 boxaJoin ( BOXA boxad,
BOXA boxas,
l_int32  istart,
l_int32  iend 
)

boxaJoin()

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'

l_int32 boxaLocationRange ( BOXA boxa,
l_int32 pminx,
l_int32 pminy,
l_int32 pmaxx,
l_int32 pmaxy 
)

boxaLocationRange()

Input: boxa &minx, &miny, &maxx, &maxy (<optional return>=""> range of UL corner positions) Return: 0 if OK, 1 on error

NUMA* boxaMakeSizeIndicator ( BOXA boxa,
l_int32  width,
l_int32  height,
l_int32  type,
l_int32  relation 
)

boxaMakeSizeIndicator()

Input: boxa width, height (threshold dimensions) type (L_SELECT_WIDTH, L_SELECT_HEIGHT, L_SELECT_IF_EITHER, L_SELECT_IF_BOTH) relation (L_SELECT_IF_LT, L_SELECT_IF_GT, L_SELECT_IF_LTE, L_SELECT_IF_GTE) Return: na (indicator array), or null on error

Notes: (1) The args specify constraints on the size of the components that are kept. (2) If the selection type is L_SELECT_WIDTH, the input height is ignored, and v.v. (3) To keep small components, use relation = L_SELECT_IF_LT or L_SELECT_IF_LTE. To keep large components, use relation = L_SELECT_IF_GT or L_SELECT_IF_GTE.

BOXA* boxaPermutePseudorandom ( BOXA boxas  ) 

boxaPermutePseudorandom()

Input: boxas (input boxa) Return: boxad (with boxes permuted), or null on error

Notes: (1) This does a pseudorandom in-place permutation of the boxes. (2) The result is guaranteed not to have any boxes in their original position, but it is not very random. If you need randomness, use boxaPermuteRandom().

BOXA* boxaPermuteRandom ( BOXA boxad,
BOXA boxas 
)

boxaPermuteRandom()

Input: boxad (<optional> can be null or equal to boxas) boxas (input boxa) Return: boxad (with boxes permuted), or null on error

Notes: (1) If boxad is null, make a copy of boxas and permute the copy. Otherwise, boxad must be equal to boxas, and the operation is done in-place. (2) This does a random in-place permutation of the boxes, by swapping each box in turn with a random box. The result is almost guaranteed not to have any boxes in their original position. (3) MSVC rand() has MAX_RAND = 2^15 - 1, so it will not do a proper permutation is the number of boxes exceeds this.

BOXA* boxaSelectBySize ( BOXA boxas,
l_int32  width,
l_int32  height,
l_int32  type,
l_int32  relation,
l_int32 pchanged 
)

boxaSelectBySize()

Input: boxas width, height (threshold dimensions) type (L_SELECT_WIDTH, L_SELECT_HEIGHT, L_SELECT_IF_EITHER, L_SELECT_IF_BOTH) relation (L_SELECT_IF_LT, L_SELECT_IF_GT, L_SELECT_IF_LTE, L_SELECT_IF_GTE) &changed (<optional return>=""> 1 if changed; 0 if clone returned) Return: boxad (filtered set), or null on error

Notes: (1) The args specify constraints on the size of the components that are kept. (2) Uses box clones in the new boxa. (3) If the selection type is L_SELECT_WIDTH, the input height is ignored, and v.v. (4) To keep small components, use relation = L_SELECT_IF_LT or L_SELECT_IF_LTE. To keep large components, use relation = L_SELECT_IF_GT or L_SELECT_IF_GTE.

BOXA* boxaSelectWithIndicator ( BOXA boxas,
NUMA na,
l_int32 pchanged 
)

boxaSelectWithIndicator()

Input: boxas na (indicator numa) &changed (<optional return>=""> 1 if changed; 0 if clone returned) Return: boxad, or null on error

Notes: (1) Returns a boxa clone if no components are removed. (2) Uses box clones in the new boxa. (3) The indicator numa has values 0 (ignore) and 1 (accept).

l_int32 boxaSizeRange ( BOXA boxa,
l_int32 pminw,
l_int32 pminh,
l_int32 pmaxw,
l_int32 pmaxh 
)

boxaSizeRange()

Input: boxa &minw, &minh, &maxw, &maxh (<optional return>=""> range of dimensions of box in the array) Return: 0 if OK, 1 on error

l_int32 boxaSwapBoxes ( BOXA boxa,
l_int32  i,
l_int32  j 
)

boxaSwapBoxes()

Input: boxa i, j (two indices of boxes, that are to be swapped) Return: 0 if OK, 1 on error

BOX* boxBoundingRegion ( BOX box1,
BOX box2 
)

boxBoundingRegion()

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 
)

boxClipToRectangle()

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

Note: the rectangle is assumed to go from (0,0) to (wi - 1, hi - 1)

l_int32 boxContains ( BOX box1,
BOX box2,
l_int32 presult 
)

boxContains()

Input: box1, box2 &result (<return> 1 if box2 is entirely contained within box1, and 0 otherwise) Return: 0 if OK, 1 on error

l_int32 boxContainsPt ( BOX box,
l_float32  x,
l_float32  y,
l_int32 pcontains 
)

boxContainsPt()

Input: box x, y (a point) &contains (<return> 1 if box contains point; 0 otherwise) Return: 0 if OK, 1 on error.

l_int32 boxEqual ( BOX box1,
BOX box2,
l_int32 psame 
)

boxEqual()

Input: box1 box2 &same (<return> 1 if equal; 0 otherwise) Return 0 if OK, 1 on error

l_int32 boxGetCentroid ( BOX box,
l_int32 px,
l_int32 py 
)

boxGetCentroid()

Input: box &x, &y (<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 
)

boxIntersectByLine()

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 
)

boxIntersects()

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 
)

boxOverlapFraction()

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 
)

boxOverlapRegion()

Input: box1, box2 (two boxes) Return: box (of overlap region between input boxes), or null if no overlap or on error

BOX* boxRelocateOneSide ( BOX boxd,
BOX boxs,
l_int32  loc,
l_int32  sideflag 
)

boxRelocateOneSide()

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

BOXA* ptaConvertToBoxa ( PTA pta,
l_int32  ncorners 
)

ptaConvertToBoxa()

Input: pta ncorners (2 or 4 for the representation of each box) Return: boxa (with one box for each 2 or 4 points in the pta), or null on error

Notes: (1) For 2 corners, the order of the 2 points is UL, LR. For 4 corners, the order of points is UL, UR, LL, LR. (2) Each derived box is the minimum szie containing all corners.


Документация по Leptonica. Последние изменения: Fri Aug 7 20:31:35 2009. Создано системой  doxygen 1.5.9