Leptonica 1.68
C Image Processing Library

boxfunc1.c File Reference

Box intersection, union, containment; Boxa union, extent, permutation. More...

#include "allheaders.h"

Go to the source code of this file.

Functions

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)
BOXAboxaCombineOverlaps (BOXA *boxas)
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 boxGetCenter (BOX *box, l_float32 *pcx, l_float32 *pcy)
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)

Detailed Description


Function Documentation

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

Definition at line 72 of file boxfunc1.c.

References ERROR_INT, Box::h, PROCNAME, Box::w, Box::x, and Box::y.

Referenced by boxaContainedInBox().

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

Definition at line 102 of file boxfunc1.c.

References ERROR_INT, Box::h, PROCNAME, Box::w, Box::x, and Box::y.

Referenced by boxaCombineOverlaps(), boxaIntersectsBox(), and pixBlendGrayAdapt().

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.

Definition at line 142 of file boxfunc1.c.

References boxaAddBox(), boxaCreate(), boxaGetBox(), boxaGetCount(), boxContains(), boxDestroy(), ERROR_PTR, L_CLONE, L_COPY, NULL, and PROCNAME.

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.

Definition at line 184 of file boxfunc1.c.

References boxaAddBox(), boxaCreate(), boxaGetBox(), boxaGetCount(), boxDestroy(), boxIntersects(), ERROR_PTR, L_CLONE, L_COPY, NULL, and PROCNAME.

Referenced by boxaGetWhiteblocks().

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.

Definition at line 226 of file boxfunc1.c.

References boxaAddBox(), boxaCreate(), boxaGetBox(), boxaGetCount(), boxDestroy(), boxOverlapRegion(), ERROR_PTR, L_CLONE, L_INSERT, NULL, and PROCNAME.

BOXA* boxaCombineOverlaps ( BOXA boxas)

boxaCombineOverlaps()

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.

Definition at line 275 of file boxfunc1.c.

References boxaAddBox(), boxaCopy(), boxaCreate(), boxaDestroy(), boxaGetBox(), boxaGetCount(), boxaReplaceBox(), boxBoundingRegion(), boxDestroy(), boxIntersects(), ERROR_PTR, FALSE, L_CLONE, L_COPY, L_INSERT, NULL, PROCNAME, and TRUE.

Referenced by main().

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

Definition at line 345 of file boxfunc1.c.

References boxCreate(), ERROR_PTR, Box::h, L_MIN, NULL, PROCNAME, Box::w, Box::x, and Box::y.

Referenced by boxaClipToBox(), and boxOverlapFraction().

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

Definition at line 385 of file boxfunc1.c.

References boxCreate(), ERROR_PTR, Box::h, L_MAX, L_MIN, NULL, PROCNAME, Box::w, Box::x, and Box::y.

Referenced by boxaCombineOverlaps().

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.

Definition at line 421 of file boxfunc1.c.

References boxDestroy(), boxGetGeometry(), boxOverlapRegion(), ERROR_INT, NULL, and PROCNAME.

Referenced by boxaPruneSortedOnOverlap(), and boxCheckIfOverlapIsBig().

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.

Definition at line 458 of file boxfunc1.c.

References boxGetGeometry(), ERROR_INT, and PROCNAME.

Referenced by ptaGetInsideBox().

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.

Definition at line 491 of file boxfunc1.c.

References boxaGetBox(), boxaGetCount(), boxDestroy(), boxGetCenter(), ERROR_PTR, L_CLONE, L_COPY, NULL, and PROCNAME.

l_int32 boxGetCenter ( BOX box,
l_float32 pcx,
l_float32 pcy 
)

boxGetCenter()

Input: box &cx, &cy (<return> location of center of box) Return 0 if OK, 1 on error

Definition at line 533 of file boxfunc1.c.

References boxGetGeometry(), ERROR_INT, and PROCNAME.

Referenced by boxaGetNearestToPt(), and boxaSelectPivotBox().

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.

Definition at line 571 of file boxfunc1.c.

References boxGetGeometry(), ERROR_INT, PROCNAME, ptaAddPt(), ptaCreate(), ptaDestroy(), ptaGetCount(), and ptaGetIPt().

Referenced by generatePtaHashBox().

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

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).

Definition at line 668 of file boxfunc1.c.

References boxCopy(), ERROR_PTR, Box::h, NULL, PROCNAME, Box::w, Box::x, and Box::y.

Referenced by boxaGetCoverage(), pixClipRectangle(), pixMeanInRectangle(), pixScanForEdge(), pixScanForForeground(), pixSetInRectArbitrary(), pixSumPixelValues(), and pixVarianceInRectangle().

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

Definition at line 719 of file boxfunc1.c.

References boxCopy(), boxGetGeometry(), boxSetGeometry(), ERROR_PTR, L_FROM_BOTTOM, L_FROM_LEFT, L_FROM_RIGHT, L_FROM_TOP, NULL, and PROCNAME.

Referenced by pixClipBoxToEdges().

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);

Definition at line 769 of file boxfunc1.c.

References boxCreate(), boxGetGeometry(), boxSetGeometry(), ERROR_PTR, L_MAX, NULL, and PROCNAME.

Referenced by pixaAddBorderGeneral().

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

Definition at line 812 of file boxfunc1.c.

References ERROR_INT, Box::h, PROCNAME, Box::w, Box::x, and Box::y.

Referenced by boxaEqual().

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.

Definition at line 857 of file boxfunc1.c.

References boxaGetBox(), boxaGetCount(), boxDestroy(), boxEqual(), CALLOC, ERROR_INT, FALSE, FREE, L_CLONE, L_MAX, L_MIN, NULL, numaDestroy(), numaMakeConstant(), numaReplaceNumber(), PROCNAME, and TRUE.

Referenced by BoxaSortTest(), pixaEqual(), and PixaSortTest().

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'

Definition at line 936 of file boxfunc1.c.

References boxaAddBox(), boxaGetBox(), boxaGetCount(), ERROR_INT, L_CLONE, L_INFO, L_INSERT, and PROCNAME.

Referenced by pixaJoin(), and pixSplitIntoBoxa().

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. (2) If there are no boxes, returned w and h are 0 and all parameters in the returned box are 0.

Definition at line 994 of file boxfunc1.c.

References boxaGetBoxGeometry(), boxaGetCount(), boxCreate(), ERROR_INT, L_MAX, L_MIN, NULL, and PROCNAME.

Referenced by boxaaDisplay(), boxaaWriteStream(), boxaGetWhiteblocks(), main(), pixaaDisplay(), pixaCreateFromBoxa(), pixaDisplay(), pixaDisplayOnColor(), and pixaDisplayRandomCmap().

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.

Definition at line 1054 of file boxfunc1.c.

References boxaGetBox(), boxaGetCount(), boxClipToRectangle(), boxDestroy(), boxGetGeometry(), ERROR_INT, L_CLONE, NULL, PIX_SET, pixCountPixels(), pixCreate(), pixDestroy(), pixRasterop(), and PROCNAME.

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

Definition at line 1114 of file boxfunc1.c.

References boxaGetBoxGeometry(), boxaGetCount(), ERROR_INT, NULL, and PROCNAME.

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

Definition at line 1162 of file boxfunc1.c.

References boxaGetBoxGeometry(), boxaGetCount(), ERROR_INT, NULL, and PROCNAME.

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.

Definition at line 1225 of file boxfunc1.c.

References boxaMakeSizeIndicator(), boxaSelectWithIndicator(), ERROR_PTR, FALSE, L_SELECT_HEIGHT, L_SELECT_IF_BOTH, L_SELECT_IF_EITHER, L_SELECT_IF_GT, L_SELECT_IF_GTE, L_SELECT_IF_LT, L_SELECT_IF_LTE, L_SELECT_WIDTH, NULL, numaDestroy(), and PROCNAME.

Referenced by jbGetComponents(), main(), pixGetWordBoxesInTextlines(), and pixGetWordsInTextlines().

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.

Definition at line 1280 of file boxfunc1.c.

References boxaGetBoxGeometry(), boxaGetCount(), ERROR_PTR, L_SELECT_HEIGHT, L_SELECT_IF_BOTH, L_SELECT_IF_EITHER, L_SELECT_IF_GT, L_SELECT_IF_GTE, L_SELECT_IF_LT, L_SELECT_IF_LTE, L_SELECT_WIDTH, L_WARNING, NULL, numaAddNumber(), numaCreate(), and PROCNAME.

Referenced by boxaSelectBySize(), and pixaSelectBySize().

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).

Definition at line 1359 of file boxfunc1.c.

References boxaAddBox(), boxaCopy(), boxaCreate(), boxaGetBox(), ERROR_PTR, FALSE, L_CLONE, L_INSERT, NULL, numaGetCount(), numaGetIValue(), PROCNAME, and TRUE.

Referenced by boxaSelectBySize().

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().

Definition at line 1411 of file boxfunc1.c.

References boxaGetCount(), boxaSortByIndex(), ERROR_PTR, NULL, numaDestroy(), numaPseudorandomSequence(), and PROCNAME.

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.

Definition at line 1449 of file boxfunc1.c.

References boxaCopy(), boxaGetCount(), boxaSwapBoxes(), ERROR_PTR, L_COPY, L_MAX, NULL, and PROCNAME.

Referenced by main().

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

Definition at line 1485 of file boxfunc1.c.

References Boxa::box, boxaGetCount(), ERROR_INT, and PROCNAME.

Referenced by boxaPermuteRandom().

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.

Definition at line 1524 of file boxfunc1.c.

References boxaGetBoxGeometry(), boxaGetCount(), ERROR_PTR, NULL, PROCNAME, ptaAddPt(), and ptaCreate().

Referenced by boxaAffineTransform(), boxaRotate(), boxaScale(), and boxaTranslate().

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.

Definition at line 1570 of file boxfunc1.c.

References boxaAddBox(), boxaCreate(), boxCreate(), ERROR_PTR, L_INSERT, L_MAX, L_MIN, NULL, PROCNAME, ptaGetCount(), ptaGetIPt(), x1, x2, x3, x4, y1, y2, y3, and y4.

Referenced by boxaAffineTransform(), boxaRotate(), boxaScale(), and boxaTranslate().

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines