MCPcopy Create free account
hub / github.com/creatale/node-dv / ptaConvertToBoxa

Function ptaConvertToBoxa

deps/leptonica/src/boxfunc4.c:807–846  ·  view source on GitHub ↗

! * \brief ptaConvertToBoxa() * * \param[in] pta * \param[in] 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 de

Source from the content-addressed store, hash-verified

805 * </pre>
806 */
807BOXA *
808ptaConvertToBoxa(PTA *pta,
809 l_int32 ncorners)
810{
811l_int32 i, n, nbox, x1, y1, x2, y2, x3, y3, x4, y4, x, y, xmax, ymax;
812BOX *box;
813BOXA *boxa;
814
815 PROCNAME("ptaConvertToBoxa");
816
817 if (!pta)
818 return (BOXA *)ERROR_PTR("pta not defined", procName, NULL);
819 if (ncorners != 2 && ncorners != 4)
820 return (BOXA *)ERROR_PTR("ncorners not 2 or 4", procName, NULL);
821 n = ptaGetCount(pta);
822 if (n % ncorners != 0)
823 return (BOXA *)ERROR_PTR("size % ncorners != 0", procName, NULL);
824 nbox = n / ncorners;
825 if ((boxa = boxaCreate(nbox)) == NULL)
826 return (BOXA *)ERROR_PTR("boxa not made", procName, NULL);
827 for (i = 0; i < n; i += ncorners) {
828 ptaGetIPt(pta, i, &x1, &y1);
829 ptaGetIPt(pta, i + 1, &x2, &y2);
830 if (ncorners == 2) {
831 box = boxCreate(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
832 boxaAddBox(boxa, box, L_INSERT);
833 continue;
834 }
835 ptaGetIPt(pta, i + 2, &x3, &y3);
836 ptaGetIPt(pta, i + 3, &x4, &y4);
837 x = L_MIN(x1, x3);
838 y = L_MIN(y1, y2);
839 xmax = L_MAX(x2, x4);
840 ymax = L_MAX(y3, y4);
841 box = boxCreate(x, y, xmax - x + 1, ymax - y + 1);
842 boxaAddBox(boxa, box, L_INSERT);
843 }
844
845 return boxa;
846}
847
848
849/*!

Callers 4

boxaTranslateFunction · 0.85
boxaScaleFunction · 0.85
boxaRotateFunction · 0.85
boxaAffineTransformFunction · 0.85

Calls 5

ptaGetCountFunction · 0.85
boxaCreateFunction · 0.85
ptaGetIPtFunction · 0.85
boxCreateFunction · 0.85
boxaAddBoxFunction · 0.85

Tested by

no test coverage detected