! * \brief pixSplitComponentIntoBoxa() * * \param[in] pix 1 bpp * \param[in] box [optional] location of pix w/rt an origin * \param[in] minsum minimum pixels to trigger propagation * \param[in] skipdist distance before computing sum for propagation * \param[in] delta difference required to stop propagation * \param[in] maxbg maximum number of allowed bg pixels in ref s
| 940 | * </pre> |
| 941 | */ |
| 942 | BOXA * |
| 943 | pixSplitComponentIntoBoxa(PIX *pix, |
| 944 | BOX *box, |
| 945 | l_int32 minsum, |
| 946 | l_int32 skipdist, |
| 947 | l_int32 delta, |
| 948 | l_int32 maxbg, |
| 949 | l_int32 maxcomps, |
| 950 | l_int32 remainder) |
| 951 | { |
| 952 | l_int32 i, w, h, boxx, boxy, bx, by, bw, bh, maxdir, maxscore; |
| 953 | l_int32 iter; |
| 954 | BOX *boxs; /* shrinks as rectangular regions are removed */ |
| 955 | BOX *boxt1, *boxt2, *boxt3; |
| 956 | BOXA *boxat; /* stores rectangle data for each side in an iteration */ |
| 957 | BOXA *boxad; |
| 958 | NUMA *nascore, *nas; |
| 959 | PIX *pixs; |
| 960 | |
| 961 | PROCNAME("pixSplitComponentIntoBoxa"); |
| 962 | |
| 963 | if (!pix || pixGetDepth(pix) != 1) |
| 964 | return (BOXA *)ERROR_PTR("pix undefined or not 1 bpp", procName, NULL); |
| 965 | |
| 966 | pixs = pixCopy(NULL, pix); |
| 967 | pixGetDimensions(pixs, &w, &h, NULL); |
| 968 | if (box) |
| 969 | boxGetGeometry(box, &boxx, &boxy, NULL, NULL); |
| 970 | else |
| 971 | boxx = boxy = 0; |
| 972 | boxs = boxCreate(0, 0, w, h); |
| 973 | boxad = boxaCreate(0); |
| 974 | |
| 975 | iter = 0; |
| 976 | while (boxs != NULL) { |
| 977 | boxGetGeometry(boxs, &bx, &by, &bw, &bh); |
| 978 | boxat = boxaCreate(4); /* potential rectangular regions */ |
| 979 | nascore = numaCreate(4); |
| 980 | for (i = 0; i < 4; i++) { |
| 981 | pixSearchForRectangle(pixs, boxs, minsum, skipdist, delta, maxbg, |
| 982 | i, boxat, nascore); |
| 983 | } |
| 984 | nas = numaGetSortIndex(nascore, L_SORT_DECREASING); |
| 985 | numaGetIValue(nas, 0, &maxdir); |
| 986 | numaGetIValue(nascore, maxdir, &maxscore); |
| 987 | #if DEBUG_SPLIT |
| 988 | fprintf(stderr, "Iteration: %d\n", iter); |
| 989 | boxPrintStreamInfo(stderr, boxs); |
| 990 | boxaWriteStream(stderr, boxat); |
| 991 | fprintf(stderr, "\nmaxdir = %d, maxscore = %d\n\n", maxdir, maxscore); |
| 992 | #endif /* DEBUG_SPLIT */ |
| 993 | if (maxscore > 0) { /* accept this */ |
| 994 | boxt1 = boxaGetBox(boxat, maxdir, L_CLONE); |
| 995 | boxt2 = boxTransform(boxt1, boxx, boxy, 1.0, 1.0); |
| 996 | boxaAddBox(boxad, boxt2, L_INSERT); |
| 997 | pixClearInRect(pixs, boxt1); |
| 998 | boxDestroy(&boxt1); |
| 999 | pixClipBoxToForeground(pixs, boxs, NULL, &boxt3); |
no test coverage detected