![]() |
Leptonica
1.82.0
Image processing and image analysis suite
|
#include <math.h>
#include "allheaders.h"
Go to the source code of this file.
Functions | |
BOXA * | boxaTransform (BOXA *boxas, l_int32 shiftx, l_int32 shifty, l_float32 scalex, l_float32 scaley) |
BOX * | boxTransform (BOX *box, l_int32 shiftx, l_int32 shifty, l_float32 scalex, l_float32 scaley) |
BOXA * | boxaTransformOrdered (BOXA *boxas, l_int32 shiftx, l_int32 shifty, l_float32 scalex, l_float32 scaley, l_int32 xcen, l_int32 ycen, l_float32 angle, l_int32 order) |
BOX * | boxTransformOrdered (BOX *boxs, l_int32 shiftx, l_int32 shifty, l_float32 scalex, l_float32 scaley, l_int32 xcen, l_int32 ycen, l_float32 angle, l_int32 order) |
BOXA * | boxaRotateOrth (BOXA *boxas, l_int32 w, l_int32 h, l_int32 rotation) |
BOX * | boxRotateOrth (BOX *box, l_int32 w, l_int32 h, l_int32 rotation) |
BOXA * | boxaShiftWithPta (BOXA *boxas, PTA *pta, l_int32 dir) |
BOXA * | boxaSort (BOXA *boxas, l_int32 sorttype, l_int32 sortorder, NUMA **pnaindex) |
BOXA * | boxaBinSort (BOXA *boxas, l_int32 sorttype, l_int32 sortorder, NUMA **pnaindex) |
BOXA * | boxaSortByIndex (BOXA *boxas, NUMA *naindex) |
BOXAA * | boxaSort2d (BOXA *boxas, NUMAA **pnaad, l_int32 delta1, l_int32 delta2, l_int32 minh1) |
BOXAA * | boxaSort2dByIndex (BOXA *boxas, NUMAA *naa) |
l_ok | boxaExtractAsNuma (BOXA *boxa, NUMA **pnal, NUMA **pnat, NUMA **pnar, NUMA **pnab, NUMA **pnaw, NUMA **pnah, l_int32 keepinvalid) |
l_ok | boxaExtractAsPta (BOXA *boxa, PTA **pptal, PTA **pptat, PTA **pptar, PTA **pptab, PTA **pptaw, PTA **pptah, l_int32 keepinvalid) |
PTA * | boxaExtractCorners (BOXA *boxa, l_int32 loc) |
l_ok | boxaGetRankVals (BOXA *boxa, l_float32 fract, l_int32 *px, l_int32 *py, l_int32 *pr, l_int32 *pb, l_int32 *pw, l_int32 *ph) |
l_ok | boxaGetMedianVals (BOXA *boxa, l_int32 *px, l_int32 *py, l_int32 *pr, l_int32 *pb, l_int32 *pw, l_int32 *ph) |
l_ok | boxaGetAverageSize (BOXA *boxa, l_float32 *pw, l_float32 *ph) |
l_ok | boxaaGetExtent (BOXAA *baa, l_int32 *pw, l_int32 *ph, BOX **pbox, BOXA **pboxa) |
BOXA * | boxaaFlattenToBoxa (BOXAA *baa, NUMA **pnaindex, l_int32 copyflag) |
BOXA * | boxaaFlattenAligned (BOXAA *baa, l_int32 num, BOX *fillerbox, l_int32 copyflag) |
BOXAA * | boxaEncapsulateAligned (BOXA *boxa, l_int32 num, l_int32 copyflag) |
BOXAA * | boxaaTranspose (BOXAA *baas) |
l_ok | boxaaAlignBox (BOXAA *baa, BOX *box, l_int32 delta, l_int32 *pindex) |
Variables | |
static const l_int32 | MinCompsForBinSort = 200 |
Boxa/Box transform (shift, scale) and orthogonal rotation BOXA *boxaTransform() BOX *boxTransform() BOXA *boxaTransformOrdered() BOX *boxTransformOrdered() BOXA *boxaRotateOrth() BOX *boxRotateOrth() BOXA *boxaShiftWithPta()
Boxa sort BOXA *boxaSort() BOXA *boxaBinSort() BOXA *boxaSortByIndex() BOXAA *boxaSort2d() BOXAA *boxaSort2dByIndex()
Boxa statistics l_int32 boxaGetRankVals() l_int32 boxaGetMedianVals() l_int32 boxaGetAverageSize()
Boxa array extraction l_int32 boxaExtractAsNuma() l_int32 boxaExtractAsPta() PTA *boxaExtractCorners()
Other Boxaa functions l_int32 boxaaGetExtent() BOXA *boxaaFlattenToBoxa() BOXA *boxaaFlattenAligned() BOXAA *boxaEncapsulateAligned() BOXAA *boxaaTranspose() l_int32 boxaaAlignBox()
Definition in file boxfunc2.c.
[in] | baa | |
[in] | box | to be aligned with bext boxa in the baa, if possible |
[in] | delta | amount by which consecutive components can miss in overlap and still be included in the array |
[out] | pindex | index of boxa with best overlap, or if none match, this is the index of the next boxa to be generated |
Notes: (1) This is not greedy. It finds the boxa whose vertical extent has the closest overlap with the input box.
Definition at line 1883 of file boxfunc2.c.
References boxaaGetBoxa(), boxaaGetCount(), boxaDestroy(), boxaGetCount(), boxaGetExtent(), boxDestroy(), boxGetGeometry(), and L_CLONE.
Referenced by boxaSort2d().
[in] | baa | |
[in] | num | number extracted from each |
[in] | fillerbox | [optional] that fills if necessary |
[in] | copyflag | L_COPY or L_CLONE |
Notes: (1) This 'flattens' the baa to a boxa, taking the first num boxes from each boxa. (2) In each boxa, if there are less than num boxes, we preserve the alignment between the input baa and the output boxa by inserting one or more fillerbox(es) or, if fillerbox == NULL, one or more invalid placeholder boxes.
Definition at line 1712 of file boxfunc2.c.
References boxaAddBox(), boxaaGetBoxa(), boxaaGetCount(), boxaCreate(), boxaDestroy(), boxaGetBox(), boxaGetCount(), boxCreate(), L_CLONE, L_COPY, and L_INSERT.
[in] | baa | |
[out] | pnaindex | [optional] the boxa index in the baa |
[in] | copyflag | L_COPY or L_CLONE |
Notes: (1) This 'flattens' the baa to a boxa, taking the boxes in order in the first boxa, then the second, etc. (2) If a boxa is empty, we generate an invalid, placeholder box of zero size. This is useful when converting from a baa where each boxa has either 0 or 1 boxes, and it is necessary to maintain a 1:1 correspondence between the initial boxa array and the resulting box array. (3) If &naindex is defined, we generate a Numa that gives, for each box in the baa, the index of the boxa to which it belongs.
Definition at line 1646 of file boxfunc2.c.
References boxaAddBox(), boxaaGetBoxa(), boxaaGetCount(), boxaCreate(), boxaDestroy(), boxaGetBox(), boxaGetCount(), boxCreate(), L_CLONE, L_COPY, L_INSERT, numaAddNumber(), and numaCreate().
Referenced by pixGetWordBoxesInTextlines().
[in] | baa | |
[out] | pw | [optional] width |
[out] | ph | [optional] height |
[out] | pbox | [optional] minimum box containing all boxa in boxaa |
[out] | pboxa | [optional] boxa containing all boxes in each boxa in the boxaa |
Notes: (1) The returned w and h are the minimum size image that would contain all boxes untranslated. (2) Each box in the returned boxa is the minimum box required to hold all the boxes in the respective boxa of baa. (3) If there are no valid boxes in a boxa, the box corresponding to its extent has all fields set to 0 (an invalid box).
Definition at line 1566 of file boxfunc2.c.
References boxaAddBox(), boxaaGetBoxa(), boxaaGetCount(), boxaCreate(), boxaDestroy(), boxaGetExtent(), boxCreate(), boxGetGeometry(), L_CLONE, and L_INSERT.
Referenced by boxaaDisplay(), and boxaSort2d().
[in] | baas |
Notes: (1) If you think of a boxaa as a 2D array of boxes that is accessed row major, then each row is represented by one of the boxa. This function creates a new boxaa related to the input boxaa as a column major traversal of the input boxaa. (2) For example, if baas has 2 boxa, each with 10 boxes, then baad will have 10 boxa, each with 2 boxes. (3) Require for this transpose operation that each boxa in baas has the same number of boxes. This operation is useful when the i-th boxes in each boxa are meaningfully related.
Definition at line 1824 of file boxfunc2.c.
References boxaaAddBoxa(), boxaaCreate(), boxaAddBox(), boxaaGetBox(), boxaaGetBoxa(), boxaaGetCount(), boxaCreate(), boxaDestroy(), boxaGetCount(), L_CLONE, L_COPY, and L_INSERT.
[in] | boxas | |
[in] | sorttype | L_SORT_BY_X, L_SORT_BY_Y, L_SORT_BY_WIDTH, L_SORT_BY_HEIGHT, L_SORT_BY_PERIMETER |
[in] | sortorder | L_SORT_INCREASING, L_SORT_DECREASING |
[out] | pnaindex | [optional] index of sorted order into original array |
Notes: (1) For a large number of boxes (say, greater than 1000), this O(n) binsort is much faster than the O(nlogn) shellsort. For 5000 components, this is over 20x faster than boxaSort(). (2) Consequently, boxaSort() calls this function if it will likely go much faster.
Definition at line 761 of file boxfunc2.c.
References boxaCopy(), boxaGetBoxGeometry(), boxaGetCount(), boxaSortByIndex(), L_COPY, L_SORT_BY_HEIGHT, L_SORT_BY_PERIMETER, L_SORT_BY_WIDTH, L_SORT_BY_X, L_SORT_BY_Y, L_SORT_DECREASING, L_SORT_INCREASING, numaAddNumber(), numaCreate(), numaDestroy(), and numaGetBinSortIndex().
[in] | boxa | |
[in] | num | number put into each boxa in the baa |
[in] | copyflag | L_COPY or L_CLONE |
Notes: (1) This puts num boxes from the input boxa into each of a set of boxa within an output baa. (2) This assumes that the boxes in boxa are in sets of num each.
Definition at line 1770 of file boxfunc2.c.
References boxaaAddBoxa(), boxaaCreate(), boxaAddBox(), boxaCreate(), boxaGetBox(), boxaGetCount(), L_CLONE, L_COPY, and L_INSERT.
l_ok boxaExtractAsNuma | ( | BOXA * | boxa, |
NUMA ** | pnal, | ||
NUMA ** | pnat, | ||
NUMA ** | pnar, | ||
NUMA ** | pnab, | ||
NUMA ** | pnaw, | ||
NUMA ** | pnah, | ||
l_int32 | keepinvalid | ||
) |
[in] | boxa | |
[out] | pnal | [optional] array of left locations |
[out] | pnat | [optional] array of top locations |
[out] | pnar | [optional] array of right locations |
[out] | pnab | [optional] array of bottom locations |
[out] | pnaw | [optional] array of widths |
[out] | pnah | [optional] array of heights |
[in] | keepinvalid | 1 to keep invalid boxes; 0 to remove them |
Notes: (1) If you are counting or sorting values, such as determining rank order, you must remove invalid boxes. (2) If you are parametrizing the values, or doing an evaluation where the position in the boxa sequence is important, you must replace the invalid boxes with valid ones before doing the extraction. This is easily done with boxaFillSequence().
Definition at line 1171 of file boxfunc2.c.
References boxaGetBoxGeometry(), boxaGetCount(), boxaGetValidCount(), numaAddNumber(), and numaCreate().
Referenced by boxaGetRankVals(), and boxaWindowedMedian().
l_ok boxaExtractAsPta | ( | BOXA * | boxa, |
PTA ** | pptal, | ||
PTA ** | pptat, | ||
PTA ** | pptar, | ||
PTA ** | pptab, | ||
PTA ** | pptaw, | ||
PTA ** | pptah, | ||
l_int32 | keepinvalid | ||
) |
[in] | boxa | |
[out] | pptal | [optional] array of left locations vs. index |
[out] | pptat | [optional] array of top locations vs. index |
[out] | pptar | [optional] array of right locations vs. index |
[out] | pptab | [optional] array of bottom locations vs. index |
[out] | pptaw | [optional] array of widths vs. index |
[out] | pptah | [optional] array of heights vs. index |
[in] | keepinvalid | 1 to keep invalid boxes; 0 to remove them |
Notes: (1) For most applications, such as counting, sorting, fitting to some parametrized form, plotting or filtering in general, you should remove the invalid boxes. Each pta saves the box index in the x array, so replacing invalid boxes by filling with boxaFillSequence(), which is required for boxaExtractAsNuma(), is not necessary. (2) If invalid boxes are retained, each one will result in entries (typically 0) in all selected output pta. (3) Other boxa --> pta functions are: * boxaExtractCorners(): extracts any of the four corners as a pta. * boxaConvertToPta(): extracts sufficient number of corners to allow reconstruction of the original boxa from the pta.
Definition at line 1252 of file boxfunc2.c.
References boxaGetBoxGeometry(), boxaGetCount(), boxaGetValidCount(), ptaAddPt(), and ptaCreate().
[in] | boxa | |
[in] | loc | L_UPPER_LEFT, L_UPPER_RIGHT, L_LOWER_LEFT, L_LOWER_RIGHT, L_BOX_CENTER |
Notes: (1) Extracts (0,0) for invalid boxes. (2) Other boxa --> pta functions are: * boxaExtractAsPta(): allows extraction of any dimension and/or side location, with each in a separate pta. * boxaConvertToPta(): extracts sufficient number of corners to allow reconstruction of the original boxa from the pta.
Definition at line 1322 of file boxfunc2.c.
References boxaGetBoxGeometry(), boxaGetCount(), L_BOX_CENTER, L_LOWER_LEFT, L_LOWER_RIGHT, L_UPPER_LEFT, L_UPPER_RIGHT, ptaAddPt(), and ptaCreate().
l_ok boxaGetAverageSize | ( | BOXA * | boxa, |
l_float32 * | pw, | ||
l_float32 * | ph | ||
) |
[in] | boxa | |
[out] | pw | [optional] average width |
[out] | ph | [optional] average height |
Definition at line 1511 of file boxfunc2.c.
References boxaGetBoxGeometry(), and boxaGetCount().
l_ok boxaGetMedianVals | ( | BOXA * | boxa, |
l_int32 * | px, | ||
l_int32 * | py, | ||
l_int32 * | pr, | ||
l_int32 * | pb, | ||
l_int32 * | pw, | ||
l_int32 * | ph | ||
) |
[in] | boxa | |
[out] | px | [optional] median value of x (left side) |
[out] | py | [optional] median value of y (top side) |
[out] | pr | [optional] median value of right side |
[out] | pb | [optional] median value of bottom side |
[out] | pw | [optional] median value of width |
[out] | ph | [optional] median value of height |
Notes: (1) See boxaGetRankVals()
Definition at line 1483 of file boxfunc2.c.
References boxaGetRankVals(), and boxaGetValidCount().
Referenced by boxaMedianDimensions(), and boxaReconcileSizeByMedian().
l_ok boxaGetRankVals | ( | BOXA * | boxa, |
l_float32 | fract, | ||
l_int32 * | px, | ||
l_int32 * | py, | ||
l_int32 * | pr, | ||
l_int32 * | pb, | ||
l_int32 * | pw, | ||
l_int32 * | ph | ||
) |
[in] | boxa | |
[in] | fract | use 0.0 for smallest, 1.0 for largest width and height |
[out] | px | [optional] rank value of x (left side) |
[out] | py | [optional] rank value of y (top side) |
[out] | pr | [optional] rank value of right side |
[out] | pb | [optional] rank value of bottom side |
[out] | pw | [optional] rank value of width |
[out] | ph | [optional] rank value of height |
Notes: (1) This function does not assume that all boxes in the boxa are valid (2) The six box parameters are sorted independently. For rank order, the width and height are sorted in increasing order. But what does it mean to sort x and y in "rank order"? If the boxes are of comparable size and somewhat aligned (e.g., from multiple images), it makes some sense to give a "rank order" for x and y by sorting them in decreasing order. (By the same argument, we choose to sort the r and b sides in increasing order.) In general, the interpretation of a rank order on x and y (or on r and b) is highly application dependent. In summary: ~ x and y are sorted in decreasing order ~ r and b are sorted in increasing order ~ w and h are sorted in increasing order
Definition at line 1401 of file boxfunc2.c.
References boxaExtractAsNuma(), boxaGetValidCount(), numaDestroy(), and numaGetRankValue().
Referenced by boxaGetMedianVals().
[in] | boxas | |
[in] | w,h | of image in which the boxa is embedded |
[in] | rotation | 0 = noop, 1 = 90 deg, 2 = 180 deg, 3 = 270 deg; all rotations are clockwise |
Notes: (1) See boxRotateOrth() for details.
Definition at line 470 of file boxfunc2.c.
References boxaAddBox(), boxaCopy(), boxaCreate(), boxaDestroy(), boxaGetBox(), boxaGetCount(), boxDestroy(), boxRotateOrth(), L_CLONE, L_COPY, and L_INSERT.
[in] | boxas | |
[in] | pta | aligned with the boxes; determines shift amount |
[in] | dir | +1 to shift by the values in pta; -1 to shift by the negative of the values in the pta. |
Notes: (1) In use, pta may come from the UL corners of of a boxa, each of whose boxes contains the corresponding box of boxas within it. The output boxad is then a boxa in the (global) coordinates of the containing boxa. So the input pta could come from boxaExtractCorners(). (2) The operations with dir == 1 and dir == -1 are inverses if called in order (1, -1). Starting with an input boxa and calling twice with these values of dir results in a boxa identical to the input. However, because box parameters can never be negative, calling in the order (-1, 1) may result in clipping at the left side and the top.
Definition at line 577 of file boxfunc2.c.
References boxaAddBox(), boxaCreate(), boxaGetBox(), boxaGetCount(), boxaIsFull(), boxDestroy(), boxTransform(), L_COPY, L_INSERT, ptaGetCount(), and ptaGetIPt().
[in] | boxas | |
[in] | sorttype | L_SORT_BY_X, L_SORT_BY_Y, L_SORT_BY_RIGHT, L_SORT_BY_BOT, L_SORT_BY_WIDTH, L_SORT_BY_HEIGHT, L_SORT_BY_MIN_DIMENSION, L_SORT_BY_MAX_DIMENSION, L_SORT_BY_PERIMETER, L_SORT_BY_AREA, L_SORT_BY_ASPECT_RATIO |
[in] | sortorder | L_SORT_INCREASING, L_SORT_DECREASING |
[out] | pnaindex | [optional] index of sorted order into original array |
Notes: (1) An empty boxa returns a copy, with a warning.
Definition at line 637 of file boxfunc2.c.
References boxaCopy(), boxaGetCount(), L_COPY, L_SORT_BY_AREA, L_SORT_BY_ASPECT_RATIO, L_SORT_BY_BOT, L_SORT_BY_HEIGHT, L_SORT_BY_MAX_DIMENSION, L_SORT_BY_MIN_DIMENSION, L_SORT_BY_PERIMETER, L_SORT_BY_RIGHT, L_SORT_BY_WIDTH, L_SORT_BY_X, L_SORT_BY_Y, L_SORT_DECREASING, and L_SORT_INCREASING.
Referenced by boxaSelectLargeULBox(), and boxaSort2d().
[in] | boxas | |
[out] | pnaad | [optional] numaa with sorted indices whose values are the indices of the input array |
[in] | delta1 | min separation that permits aggregation of a box onto a boxa of horizontally-aligned boxes; pass 1 |
[in] | delta2 | min separation that permits aggregation of a box onto a boxa of horizontally-aligned boxes; pass 2 |
[in] | minh1 | components less than this height either join an existing boxa or are set aside for pass 2 |
Notes: (1) The final result is a sort where the 'fast scan' direction is left to right, and the 'slow scan' direction is from top to bottom. Each boxa in the baa represents a sorted set of boxes from left to right. (2) Three passes are used to aggregate the boxas, which can correspond to characters or words in a line of text. In pass 1, only taller components, which correspond to xheight or larger, are permitted to start a new boxa. In pass 2, the remaining vertically-challenged components are allowed to join an existing boxa or start a new one. In pass 3, boxa whose extent is overlapping are joined. After that, the boxes in each boxa are sorted horizontally, and finally the boxa are sorted vertically. (3) If delta1 > 0, the first pass allows aggregation when boxes in the same boxa do not overlap vertically. In fact, delta1 is the max distance by which they can miss and still be aggregated. If delta1 < 0, the box must have vertical overlap of at least abs(delta1) with the boxa before it can be merged. Similar for delta2 on the second pass. (4) On the first pass, any component of height less than minh1 cannot start a new boxa; it's put aside for later insertion. (5) On the second pass, any small component that doesn't align with an existing boxa can start a new one. (6) This can be used to identify lines of text from character or word bounding boxes. (7) Typical values for the input parameters on 300 ppi text are: delta1 ~ 0 delta2 ~ 0 minh1 ~ 5
Definition at line 915 of file boxfunc2.c.
References boxaaAddBox(), boxaaAddBoxa(), boxaaAlignBox(), boxaaCreate(), boxaAddBox(), boxaaDestroy(), boxaaGetBoxa(), boxaaGetCount(), boxaaGetExtent(), boxaaReplaceBoxa(), boxaCreate(), boxaDestroy(), boxaGetBox(), boxaGetCount(), boxaHandleOverlaps(), boxaJoin(), boxaSort(), boxGetGeometry(), L_CLONE, L_COPY, L_INSERT, L_REMOVE_SMALL, L_SORT_BY_X, L_SORT_BY_Y, L_SORT_INCREASING, numaaAddNuma(), numaaAddNumber(), numaaCreate(), numaAddNumber(), numaaDestroy(), numaaGetNuma(), numaaReplaceNuma(), numaCreate(), numaDestroy(), numaGetIValue(), numaJoin(), and numaSortByIndex().
Referenced by pixGetWordBoxesInTextlines(), and pixGetWordsInTextlines().
[in] | boxas | |
[in] | naa | numaa that maps from the new baa to the input boxa |
Definition at line 1102 of file boxfunc2.c.
References boxaaAddBoxa(), boxaaCreate(), boxaAddBox(), boxaCreate(), boxaGetBox(), boxaGetCount(), L_CLONE, L_COPY, L_INSERT, numaaGetCount(), numaaGetNuma(), numaaGetNumberCount(), numaDestroy(), numaGetCount(), and numaGetIValue().
[in] | boxas | |
[in] | naindex | na that maps from the new boxa to the input boxa |
Definition at line 838 of file boxfunc2.c.
References boxaAddBox(), boxaCopy(), boxaCreate(), boxaGetBox(), boxaGetCount(), L_COPY, L_INSERT, and numaGetIValue().
Referenced by boxaBinSort(), and boxaPermutePseudorandom().
BOXA* boxaTransform | ( | BOXA * | boxas, |
l_int32 | shiftx, | ||
l_int32 | shifty, | ||
l_float32 | scalex, | ||
l_float32 | scaley | ||
) |
[in] | boxas | |
[in] | shiftx | |
[in] | shifty | |
[in] | scalex | |
[in] | scaley |
Notes: (1) This is a very simple function that first shifts, then scales. (2) The UL corner coordinates of all boxes in the output boxad (3) For the boxes in the output boxad, the UL corner coordinates must be non-negative, and the width and height of valid boxes must be at least 1.
Definition at line 102 of file boxfunc2.c.
References boxaAddBox(), boxaCreate(), boxaDestroy(), boxaGetBox(), boxaGetCount(), boxDestroy(), boxTransform(), L_CLONE, and L_INSERT.
Referenced by boxaCompareRegions(), and pixaTranslate().
BOXA* boxaTransformOrdered | ( | BOXA * | boxas, |
l_int32 | shiftx, | ||
l_int32 | shifty, | ||
l_float32 | scalex, | ||
l_float32 | scaley, | ||
l_int32 | xcen, | ||
l_int32 | ycen, | ||
l_float32 | angle, | ||
l_int32 | order | ||
) |
[in] | boxas | |
[in] | shiftx | |
[in] | shifty | |
[in] | scalex | |
[in] | scaley | |
[in] | xcen,ycen | center of rotation |
[in] | angle | in radians; clockwise is positive |
[in] | order | one of 6 combinations: L_TR_SC_RO, ... |
shift, scaling and rotation, and the order of the transforms is specified. (2) Although these operations appear to be on an infinite 2D plane, in practice the region of interest is clipped to a finite image. The center of rotation is usually taken with respect to the image (either the UL corner or the center). A translation can have two very different effects: (a) Moves the boxes across the fixed image region. (b) Moves the image origin, causing a change in the image region and an opposite effective translation of the boxes. This function should only be used for (a), where the image region is fixed on translation. If the image region is changed by the translation, use instead the functions in affinecompose.c, where the image region and rotation center can be computed from the actual clipping due to translation of the image origin. (3) See boxTransformOrdered() for usage and implementation details.
Definition at line 206 of file boxfunc2.c.
References boxaAddBox(), boxaCreate(), boxaDestroy(), boxaGetBox(), boxaGetCount(), boxDestroy(), boxTransformOrdered(), L_CLONE, and L_INSERT.
[in] | box | |
[in] | w,h | of image in which the box is embedded |
[in] | rotation | 0 = noop, 1 = 90 deg, 2 = 180 deg, 3 = 270 deg; all rotations are clockwise |
Notes: (1) Rotate the image with the embedded box by the specified amount. (2) After rotation, the rotated box is always measured with respect to the UL corner of the image.
Definition at line 522 of file boxfunc2.c.
References boxCopy(), boxCreate(), and boxGetGeometry().
Referenced by boxaRotateOrth(), and pixaRotateOrth().
[in] | box | |
[in] | shiftx | |
[in] | shifty | |
[in] | scalex | |
[in] | scaley |
Notes: (1) This is a very simple function that first shifts, then scales. (2) If the box is invalid, a new invalid box is returned. (3) The UL corner coordinates must be non-negative, and the width and height of valid boxes must be at least 1.
Definition at line 152 of file boxfunc2.c.
References boxCreate(), Box::h, Box::w, Box::x, and Box::y.
Referenced by boxaShiftWithPta(), and boxaTransform().
BOX* boxTransformOrdered | ( | BOX * | boxs, |
l_int32 | shiftx, | ||
l_int32 | shifty, | ||
l_float32 | scalex, | ||
l_float32 | scaley, | ||
l_int32 | xcen, | ||
l_int32 | ycen, | ||
l_float32 | angle, | ||
l_int32 | order | ||
) |
[in] | boxs | |
[in] | shiftx | |
[in] | shifty | |
[in] | scalex | |
[in] | scaley | |
[in] | xcen,ycen | center of rotation |
[in] | angle | in radians; clockwise is positive |
[in] | order | one of 6 combinations: L_TR_SC_RO, ... |
Notes: (1) This allows a sequence of linear transforms, composed of shift, scaling and rotation, where the order of the transforms is specified. (2) The rotation is taken about a point specified by (xcen, ycen). Let the components of the vector from the center of rotation to the box center be (xdif, ydif): xdif = (bx + 0.5 * bw) - xcen ydif = (by + 0.5 * bh) - ycen Then the box center after rotation has new components: bxcen = xcen + xdif * cosa + ydif * sina bycen = ycen + ydif * cosa - xdif * sina where cosa and sina are the cos and sin of the angle, and the enclosing box for the rotated box has size: rw = |bw * cosa| + |bh * sina| rh = |bh * cosa| + |bw * sina| where bw and bh are the unrotated width and height. Then the box UL corner (rx, ry) is rx = bxcen - 0.5 * rw ry = bycen - 0.5 * rh (3) The center of rotation specified by args xcen and ycen is the point BEFORE any translation or scaling. If the rotation is not the first operation, this function finds the actual center at the time of rotation. It does this by making the following assumptions: (1) Any scaling is with respect to the UL corner, so that the center location scales accordingly. (2) A translation does not affect the center of the image; it just moves the boxes. We always use assumption (1). However, assumption (2) will be incorrect if the apparent translation is due to a clipping operation that, in effect, moves the origin of the image. In that case, you should NOT use these simple functions. Instead, use the functions in affinecompose.c, where the rotation center can be computed from the actual clipping due to translation of the image origin.
Definition at line 296 of file boxfunc2.c.
References boxCreate(), boxGetGeometry(), L_RO_SC_TR, L_RO_TR_SC, L_SC_RO_TR, L_SC_TR_RO, L_TR_RO_SC, and L_TR_SC_RO.
Referenced by boxaTransformOrdered().