207 #include "allheaders.h" 215 static const l_int32 JB_ADDED_PIXELS = 6;
219 static const l_int32 MAX_DIFF_WIDTH = 2;
220 static const l_int32 MAX_DIFF_HEIGHT = 2;
229 static const l_int32 MAX_CONN_COMP_WIDTH = 350;
230 static const l_int32 MAX_CHAR_COMP_WIDTH = 350;
231 static const l_int32 MAX_WORD_COMP_WIDTH = 1000;
232 static const l_int32 MAX_COMP_HEIGHT = 120;
248 static JBCLASSER * jbCorrelationInitInternal(l_int32 components,
249 l_int32 maxwidth, l_int32 maxheight, l_float32 thresh,
250 l_float32 weightfactor, l_int32 keep_components);
254 static l_int32 findSimilarSizedTemplatesNext(
JBFINDCTX *context);
255 static void findSimilarSizedTemplatesDestroy(
JBFINDCTX **pcontext);
256 static l_int32 finalPositioningForAlignment(
PIX *pixs, l_int32 x, l_int32 y,
257 l_int32 idelx, l_int32 idely,
PIX *pixt,
258 l_int32 *sumtab, l_int32 *pdx, l_int32 *pdy);
260 #ifndef NO_CONSOLE_IO 261 #define DEBUG_CORRELATION_SCORE 0 283 jbRankHausInit(l_int32 components,
291 PROCNAME(
"jbRankHausInit");
293 if (components != JB_CONN_COMPS && components != JB_CHARACTERS &&
294 components != JB_WORDS)
295 return (
JBCLASSER *)ERROR_PTR(
"invalid components", procName, NULL);
296 if (size < 1 || size > 10)
297 return (
JBCLASSER *)ERROR_PTR(
"size not reasonable", procName, NULL);
298 if (rank < 0.5 || rank > 1.0)
299 return (
JBCLASSER *)ERROR_PTR(
"rank not in [0.5-1.0]", procName, NULL);
301 if (components == JB_CONN_COMPS)
302 maxwidth = MAX_CONN_COMP_WIDTH;
303 else if (components == JB_CHARACTERS)
304 maxwidth = MAX_CHAR_COMP_WIDTH;
306 maxwidth = MAX_WORD_COMP_WIDTH;
309 maxheight = MAX_COMP_HEIGHT;
311 if ((classer = jbClasserCreate(JB_RANKHAUS, components)) == NULL)
312 return (
JBCLASSER *)ERROR_PTR(
"classer not made", procName, NULL);
344 jbCorrelationInit(l_int32 components,
348 l_float32 weightfactor)
350 return jbCorrelationInitInternal(components, maxwidth, maxheight, thresh,
371 jbCorrelationInitWithoutComponents(l_int32 components,
375 l_float32 weightfactor)
377 return jbCorrelationInitInternal(components, maxwidth, maxheight, thresh,
383 jbCorrelationInitInternal(l_int32 components,
387 l_float32 weightfactor,
388 l_int32 keep_components)
392 PROCNAME(
"jbCorrelationInitInternal");
394 if (components != JB_CONN_COMPS && components != JB_CHARACTERS &&
395 components != JB_WORDS)
396 return (
JBCLASSER *)ERROR_PTR(
"invalid components", procName, NULL);
397 if (thresh < 0.4 || thresh > 0.98)
398 return (
JBCLASSER *)ERROR_PTR(
"thresh not in range [0.4 - 0.98]",
400 if (weightfactor < 0.0 || weightfactor > 1.0)
401 return (
JBCLASSER *)ERROR_PTR(
"weightfactor not in range [0.0 - 1.0]",
404 if (components == JB_CONN_COMPS)
405 maxwidth = MAX_CONN_COMP_WIDTH;
406 else if (components == JB_CHARACTERS)
407 maxwidth = MAX_CHAR_COMP_WIDTH;
409 maxwidth = MAX_WORD_COMP_WIDTH;
412 maxheight = MAX_COMP_HEIGHT;
415 if ((classer = jbClasserCreate(JB_CORRELATION, components)) == NULL)
416 return (
JBCLASSER *)ERROR_PTR(
"classer not made", procName, NULL);
451 PROCNAME(
"jbAddPages");
454 return ERROR_INT(
"classer not defined", procName, 1);
456 return ERROR_INT(
"safiles not defined", procName, 1);
460 for (i = 0; i < nfiles; i++) {
462 if ((pix =
pixRead(fname)) == NULL) {
463 L_WARNING(
"image file %d not read\n", procName, i);
466 if (pixGetDepth(pix) != 1) {
467 L_WARNING(
"image file %d not 1 bpp\n", procName, i);
470 jbAddPage(classer, pix);
492 PROCNAME(
"jbAddPage");
495 return ERROR_INT(
"classer not defined", procName, 1);
496 if (!pixs || pixGetDepth(pixs) != 1)
497 return ERROR_INT(
"pixs not defined or not 1 bpp", procName, 1);
499 classer->
w = pixGetWidth(pixs);
500 classer->
h = pixGetHeight(pixs);
505 return ERROR_INT(
"components not made", procName, 1);
508 jbAddPageComponents(classer, pixs, boxas, pixas);
538 PROCNAME(
"jbAddPageComponents");
541 return ERROR_INT(
"classer not defined", procName, 1);
543 return ERROR_INT(
"pix not defined", procName, 1);
555 if (classer->
method == JB_RANKHAUS) {
556 if (jbClassifyRankHaus(classer, boxas, pixas))
557 return ERROR_INT(
"rankhaus classification failed", procName, 1);
559 if (jbClassifyCorrelation(classer, boxas, pixas))
560 return ERROR_INT(
"correlation classification failed", procName, 1);
567 if (jbGetULCorners(classer, pixs, boxas))
568 return ERROR_INT(
"UL corners not found", procName, 1);
595 l_int32 n, nt, i, wt, ht, iclass, size, found, testval;
596 l_int32 npages, area1, area3;
598 l_float32 rank, x1, y1, x2, y2;
600 NUMA *naclass, *napage;
605 PIX *pix, *pix1, *pix2, *pix3, *pix4;
606 PIXA *pixa, *pixa1, *pixa2, *pixat, *pixatd;
608 PTA *pta, *ptac, *ptact;
611 PROCNAME(
"jbClassifyRankHaus");
614 return ERROR_INT(
"classer not found", procName, 1);
616 return ERROR_INT(
"boxa not found", procName, 1);
618 return ERROR_INT(
"pixas not found", procName, 1);
629 for (i = 0; i < n; i++) {
632 JB_ADDED_PIXELS, JB_ADDED_PIXELS, 0);
642 ptac = classer->
ptac;
644 ptact = classer->
ptact;
661 pixaa = classer->
pixaa;
664 pixat = classer->
pixat;
690 for (i = 0; i < n; i++) {
696 findcontext = findSimilarSizedTemplatesInit(classer, pix1);
697 while ((iclass = findSimilarSizedTemplatesNext(findcontext)) > -1) {
702 testval = pixHaustest(pix1, pix2, pix3, pix4, x1 - x2, y1 - y2,
703 MAX_DIFF_WIDTH, MAX_DIFF_HEIGHT);
721 findSimilarSizedTemplatesDestroy(&findcontext);
722 if (found == FALSE) {
728 wt = pixGetWidth(pix);
729 ht = pixGetHeight(pix);
744 return ERROR_INT(
"nafg not made", procName, 1);
745 nafgt = classer->
nafgt;
747 for (i = 0; i < n; i++) {
754 findcontext = findSimilarSizedTemplatesInit(classer, pix1);
755 while ((iclass = findSimilarSizedTemplatesNext(findcontext)) > -1) {
761 testval = pixRankHaustest(pix1, pix2, pix3, pix4,
763 MAX_DIFF_WIDTH, MAX_DIFF_HEIGHT,
764 area1, area3, rank, tab8);
782 findSimilarSizedTemplatesDestroy(&findcontext);
783 if (found == FALSE) {
789 wt = pixGetWidth(pix);
790 ht = pixGetHeight(pix);
845 pixHaustest(
PIX *pix1,
854 l_int32 wi, hi, wt, ht, delw, delh, idelx, idely, boolmatch;
858 wi = pixGetWidth(pix1);
859 hi = pixGetHeight(pix1);
860 wt = pixGetWidth(pix3);
861 ht = pixGetHeight(pix3);
862 delw = L_ABS(wi - wt);
865 delh = L_ABS(hi - ht);
872 idelx = (l_int32)(delx + 0.5);
874 idelx = (l_int32)(delx - 0.5);
876 idely = (l_int32)(dely + 0.5);
878 idely = (l_int32)(dely - 0.5);
890 if (boolmatch == 0) {
943 pixRankHaustest(
PIX *pix1,
956 l_int32 wi, hi, wt, ht, delw, delh, idelx, idely, boolmatch;
957 l_int32 thresh1, thresh3;
961 wi = pixGetWidth(pix1);
962 hi = pixGetHeight(pix1);
963 wt = pixGetWidth(pix3);
964 ht = pixGetHeight(pix3);
965 delw = L_ABS(wi - wt);
968 delh = L_ABS(hi - ht);
973 thresh1 = (l_int32)(area1 * (1. - rank) + 0.5);
974 thresh3 = (l_int32)(area3 * (1. - rank) + 0.5);
979 idelx = (l_int32)(delx + 0.5);
981 idelx = (l_int32)(delx - 0.5);
983 idely = (l_int32)(dely + 0.5);
985 idely = (l_int32)(dely - 0.5);
997 if (boolmatch == 1) {
1030 jbClassifyCorrelation(
JBCLASSER *classer,
1034 l_int32 n, nt, i, iclass, wt, ht, found, area, area1, area2, npages,
1036 l_int32 *sumtab, *centtab;
1037 l_uint32 *row, word;
1038 l_float32 x1, y1, x2, y2, xsum, ysum;
1039 l_float32 thresh, weight, threshold;
1041 NUMA *naclass, *napage;
1046 PIX *pix, *pix1, *pix2;
1047 PIXA *pixa, *pixa1, *pixat;
1049 PTA *pta, *ptac, *ptact;
1051 l_int32 **pixrowcts;
1052 l_int32 x, y, rowcount, downcount, wpl;
1055 PROCNAME(
"jbClassifyCorrelation");
1058 return ERROR_INT(
"classer not found", procName, 1);
1060 return ERROR_INT(
"boxa not found", procName, 1);
1062 return ERROR_INT(
"pixas not found", procName, 1);
1064 npages = classer->
npages;
1069 L_WARNING(
"pixas is empty\n", procName);
1073 for (i = 0; i < n; i++) {
1076 JB_ADDED_PIXELS, JB_ADDED_PIXELS, 0);
1083 napage = classer->
napage;
1086 nafgt = classer->
nafgt;
1089 pixcts = (l_int32 *)LEPT_CALLOC(n,
sizeof(*pixcts));
1090 pixrowcts = (l_int32 **)LEPT_CALLOC(n,
sizeof(*pixrowcts));
1101 for (i = 0; i < n; i++) {
1103 pixrowcts[i] = (l_int32 *)LEPT_CALLOC(pixGetHeight(pix),
1104 sizeof(**pixrowcts));
1107 wpl = pixGetWpl(pix);
1108 row =
pixGetData(pix) + (pixGetHeight(pix) - 1) * wpl;
1110 for (y = pixGetHeight(pix) - 1; y >= 0; y--, row -= wpl) {
1111 pixrowcts[i][y] = downcount;
1113 for (x = 0; x < wpl; x++) {
1116 rowcount += sumtab[byte];
1117 xsum += centtab[byte] + (x * 32 + 24) * sumtab[byte];
1118 byte = (word >> 8) & 0xff;
1119 rowcount += sumtab[byte];
1120 xsum += centtab[byte] + (x * 32 + 16) * sumtab[byte];
1121 byte = (word >> 16) & 0xff;
1122 rowcount += sumtab[byte];
1123 xsum += centtab[byte] + (x * 32 + 8) * sumtab[byte];
1124 byte = (word >> 24) & 0xff;
1125 rowcount += sumtab[byte];
1126 xsum += centtab[byte] + x * 32 * sumtab[byte];
1128 downcount += rowcount;
1129 ysum += rowcount * y;
1131 pixcts[i] = downcount;
1132 if (downcount > 0) {
1134 xsum / (l_float32)downcount, ysum / (l_float32)downcount);
1136 L_ERROR(
"downcount == 0 !\n", procName);
1137 ptaAddPt(pta, pixGetWidth(pix) / 2, pixGetHeight(pix) / 2);
1142 ptac = classer->
ptac;
1144 ptact = classer->
ptact;
1157 pixaa = classer->
pixaa;
1160 pixat = classer->
pixat;
1180 thresh = classer->
thresh;
1182 naarea = classer->
naarea;
1183 dahash = classer->
dahash;
1184 for (i = 0; i < n; i++) {
1190 findcontext = findSimilarSizedTemplatesInit(classer, pix1);
1191 while ( (iclass = findSimilarSizedTemplatesNext(findcontext)) > -1) {
1200 threshold = thresh + (1. - thresh) * weight * area2 / area;
1206 overthreshold = pixCorrelationScoreThresholded(pix1, pix2,
1207 area1, area2, x1 - x2, y1 - y2,
1208 MAX_DIFF_WIDTH, MAX_DIFF_HEIGHT,
1209 sumtab, pixrowcts[i], threshold);
1210 #if DEBUG_CORRELATION_SCORE 1212 l_float32 score, testscore;
1213 l_int32 count, testcount;
1214 pixCorrelationScore(pix1, pix2, area1, area2, x1 - x2, y1 - y2,
1215 MAX_DIFF_WIDTH, MAX_DIFF_HEIGHT,
1218 pixCorrelationScoreSimple(pix1, pix2, area1, area2,
1219 x1 - x2, y1 - y2, MAX_DIFF_WIDTH,
1220 MAX_DIFF_HEIGHT, sumtab, &testscore);
1221 count = (l_int32)rint(sqrt(score * area1 * area2));
1222 testcount = (l_int32)rint(sqrt(testscore * area1 * area2));
1223 if ((score >= threshold) != (testscore >= threshold)) {
1224 fprintf(stderr,
"Correlation score mismatch: " 1225 "%d(%g,%d) vs %d(%g,%d) (%g)\n",
1226 count, score, score >= threshold,
1227 testcount, testscore, testscore >= threshold,
1231 if ((score >= threshold) != overthreshold) {
1232 fprintf(stderr,
"Mismatch between correlation/threshold " 1233 "comparison: %g(%g,%d) >= %g(%g) vs %s\n",
1234 score, score*area1*area2, count, threshold,
1235 threshold*area1*area2,
1236 (overthreshold ?
"true" :
"false"));
1242 if (overthreshold) {
1258 findSimilarSizedTemplatesDestroy(&findcontext);
1259 if (found == FALSE) {
1265 wt = pixGetWidth(pix);
1266 ht = pixGetHeight(pix);
1274 area = (pixGetWidth(pix1) - 2 * JB_ADDED_PIXELS) *
1275 (pixGetHeight(pix1) - 2 * JB_ADDED_PIXELS);
1285 for (i = 0; i < n; i++) {
1286 LEPT_FREE(pixrowcts[i]);
1288 LEPT_FREE(pixrowcts);
1312 jbGetComponents(
PIX *pixs,
1319 l_int32 empty, res, redfactor;
1321 PIX *pix1, *pix2, *pix3;
1324 PROCNAME(
"jbGetComponents");
1327 return ERROR_INT(
"&boxad not defined", procName, 1);
1330 return ERROR_INT(
"&pixad not defined", procName, 1);
1333 return ERROR_INT(
"pixs not defined", procName, 1);
1334 if (components != JB_CONN_COMPS && components != JB_CHARACTERS &&
1335 components != JB_WORDS)
1336 return ERROR_INT(
"invalid components", procName, 1);
1358 if (components == JB_CONN_COMPS) {
1360 }
else if (components == JB_CHARACTERS) {
1373 res = pixGetXRes(pixs);
1377 }
else if (res <= 400) {
1387 pixWordMaskByDilation(pix1, &pix2, NULL, NULL);
1454 pixWordMaskByDilation(
PIX *pixs,
1459 l_int32 i, n, ndil, maxdiff, diff, ibest;
1460 l_int32 check, count, total, xres;
1464 NUMA *nacc, *nadiff;
1467 PROCNAME(
"pixWordMaskByDilation");
1469 if (ppixm) *ppixm = NULL;
1470 if (psize) *psize = 0;
1471 if (!pixs || pixGetDepth(pixs) != 1)
1472 return ERROR_INT(
"pixs undefined or not 1 bpp", procName, 1);
1473 if (!ppixm && !psize)
1474 return ERROR_INT(
"no output requested", procName, 1);
1482 for (i = 0; i <= ndil; i++) {
1490 if (i == 0) total = ncc[0];
1492 diff = ncc[i - 1] - ncc[i];
1509 for (i = 1; i < n; i++) {
1511 if (check && count < 0.3 * total) {
1522 xres = pixGetXRes(pixs);
1523 if (xres == 0) xres = 150;
1524 if (xres > 110) ibest++;
1526 L_INFO(
"setting ibest to minimum allowed value of 2\n", procName);
1535 L_INFO(
"Best dilation: %d\n", procName, L_MAX(3, ibest + 1));
1537 gplot =
gplotCreate(
"/tmp/lept/jb/numcc", GPLOT_PNG,
1538 "Number of cc vs. horizontal dilation",
1539 "Sel horiz",
"Number of cc");
1543 pix3 =
pixRead(
"/tmp/lept/jb/numcc.png");
1547 gplot =
gplotCreate(
"/tmp/lept/jb/diffcc", GPLOT_PNG,
1548 "Diff count of cc vs. horizontal dilation",
1549 "Sel horiz",
"Diff in cc");
1553 pix3 =
pixRead(
"/tmp/lept/jb/diffcc.png");
1563 if (psize) *psize = ibest + 1;
1593 pixWordBoxesByDilation(
PIX *pixs,
1602 BOXA *boxa1, *boxa2;
1605 PROCNAME(
"pixWordBoxesByDilation");
1607 if (psize) *psize = 0;
1608 if (!pixs || pixGetDepth(pixs) != 1)
1609 return ERROR_INT(
"pixs undefined or not 1 bpp", procName, 1);
1611 return ERROR_INT(
"&boxa not defined", procName, 1);
1615 if (pixWordMaskByDilation(pixs, &pix1, psize, pixadb))
1616 return ERROR_INT(
"pixWordMaskByDilation() failed", procName, 1);
1655 jbAccumulateComposites(
PIXAA *pixaa,
1659 l_int32 n, nt, i, j, d, minw, maxw, minh, maxh, xdiff, ydiff;
1660 l_float32 x, y, xave, yave;
1662 PIX *pix, *pixt1, *pixt2, *pixsum;
1666 PROCNAME(
"jbAccumulateComposites");
1669 return (
PIXA *)ERROR_PTR(
"&ptat not defined", procName, NULL);
1672 return (
PIXA *)ERROR_PTR(
"&na not defined", procName, NULL);
1675 return (
PIXA *)ERROR_PTR(
"pixaa not defined", procName, NULL);
1679 return (
PIXA *)ERROR_PTR(
"ptat not made", procName, NULL);
1685 for (i = 0; i < n; i++) {
1690 L_WARNING(
"empty pixa found!\n", procName);
1696 d = pixGetDepth(pix);
1704 for (j = 0; j < nt; j++) {
1709 xave = xave / (l_float32)nt;
1710 yave = yave / (l_float32)nt;
1713 for (j = 0; j < nt; j++) {
1716 xdiff = (l_int32)(x - xave);
1717 ydiff = (l_int32)(y - yave);
1745 jbTemplatesFromComposites(
PIXA *pixac,
1755 PROCNAME(
"jbTemplatesFromComposites");
1758 return (
PIXA *)ERROR_PTR(
"pixac not defined", procName, NULL);
1760 return (
PIXA *)ERROR_PTR(
"na not defined", procName, NULL);
1764 for (i = 0; i < n; i++) {
1790 jbClasserCreate(l_int32 method,
1795 PROCNAME(
"jbClasserCreate");
1797 if (method != JB_RANKHAUS && method != JB_CORRELATION)
1798 return (
JBCLASSER *)ERROR_PTR(
"invalid method", procName, NULL);
1799 if (components != JB_CONN_COMPS && components != JB_CHARACTERS &&
1800 components != JB_WORDS)
1801 return (
JBCLASSER *)ERROR_PTR(
"invalid component", procName, NULL);
1804 classer->
method = method;
1834 if ((classer = *pclasser) == NULL)
1884 PROCNAME(
"jbDataSave");
1887 return (
JBDATA *)ERROR_PTR(
"classer not defined", procName, NULL);
1894 return (
JBDATA *)ERROR_PTR(
"data not made", procName, NULL);
1899 data->
w = classer->
w;
1900 data->
h = classer->
h;
1918 jbDataDestroy(
JBDATA **pdata)
1924 if ((data = *pdata) == NULL)
1950 jbDataWrite(
const char *rootout,
1954 l_int32 w, h, nclass, npages, cellw, cellh, ncomp, i, x, y, iclass, ipage;
1955 NUMA *naclass, *napage;
1960 PROCNAME(
"jbDataWrite");
1963 return ERROR_INT(
"no rootout", procName, 1);
1965 return ERROR_INT(
"no jbdata", procName, 1);
1976 ptaul = jbdata->
ptaul;
1979 pixWrite(buf, pixt, IFF_PNG);
1981 snprintf(buf,
L_BUF_SIZE,
"%s%s", rootout, JB_DATA_EXT);
1983 return ERROR_INT(
"stream not opened", procName, 1);
1985 fprintf(fp,
"jb data file\n");
1986 fprintf(fp,
"num pages = %d\n", npages);
1987 fprintf(fp,
"page size: w = %d, h = %d\n", w, h);
1988 fprintf(fp,
"num components = %d\n", ncomp);
1989 fprintf(fp,
"num classes = %d\n", nclass);
1990 fprintf(fp,
"template lattice size: w = %d, h = %d\n", cellw, cellh);
1991 for (i = 0; i < ncomp; i++) {
1995 fprintf(fp,
"%d %d %d %d\n", ipage, iclass, x, y);
2010 jbDataRead(
const char *rootname)
2015 l_int32 nsa, i, w, h, cellw, cellh, x, y, iclass, ipage;
2016 l_int32 npages, nclass, ncomp, ninit;
2019 NUMA *naclass, *napage;
2024 PROCNAME(
"jbDataRead");
2027 return (
JBDATA *)ERROR_PTR(
"rootname not defined", procName, NULL);
2030 if ((pixs =
pixRead(fname)) == NULL)
2031 return (
JBDATA *)ERROR_PTR(
"pix not read", procName, NULL);
2033 snprintf(fname,
L_BUF_SIZE,
"%s%s", rootname, JB_DATA_EXT);
2036 return (
JBDATA *)ERROR_PTR(
"data not read", procName, NULL);
2042 return (
JBDATA *)ERROR_PTR(
"sa not made", procName, NULL);
2046 if (strcmp(linestr,
"jb data file") != 0) {
2050 return (
JBDATA *)ERROR_PTR(
"invalid jb data file", procName, NULL);
2053 sscanf(linestr,
"num pages = %d", &npages);
2055 sscanf(linestr,
"page size: w = %d, h = %d", &w, &h);
2057 sscanf(linestr,
"num components = %d", &ncomp);
2059 sscanf(linestr,
"num classes = %d\n", &nclass);
2061 sscanf(linestr,
"template lattice size: w = %d, h = %d\n", &cellw, &cellh);
2064 fprintf(stderr,
"num pages = %d\n", npages);
2065 fprintf(stderr,
"page size: w = %d, h = %d\n", w, h);
2066 fprintf(stderr,
"num components = %d\n", ncomp);
2067 fprintf(stderr,
"num classes = %d\n", nclass);
2068 fprintf(stderr,
"template lattice size: w = %d, h = %d\n", cellw, cellh);
2072 if (ncomp > 1000000) {
2073 L_WARNING(
"ncomp > 1M\n", procName);
2079 for (i = 6; i < nsa; i++) {
2081 sscanf(linestr,
"%d %d %d %d\n", &ipage, &iclass, &x, &y);
2097 jbdata->
ptaul = ptaul;
2115 jbDataRender(
JBDATA *data,
2118 l_int32 i, w, h, cellw, cellh, x, y, iclass, ipage;
2119 l_int32 npages, nclass, ncomp, wp, hp;
2121 NUMA *naclass, *napage;
2122 PIX *pixt, *pixt2, *pix, *pixd;
2128 PROCNAME(
"jbDataRender");
2131 return (
PIXA *)ERROR_PTR(
"data not defined", procName, NULL);
2142 ptaul = data->
ptaul;
2149 return (
PIXA *)ERROR_PTR(
"pixad not made", procName, NULL);
2150 for (i = 0; i < npages; i++) {
2151 if (debugflag == FALSE) {
2167 return (
PIXA *)ERROR_PTR(
"pixat not made", procName, NULL);
2171 for (i = 0; i < ncomp; i++) {
2175 wp = pixGetWidth(pix);
2176 hp = pixGetHeight(pix);
2179 if (debugflag == FALSE) {
2228 l_int32 i, baseindex, index, n, iclass, idelx, idely, x, y, dx, dy;
2230 l_float32 x1, x2, y1, y2, delx, dely;
2234 PTA *ptac, *ptact, *ptaul;
2236 PROCNAME(
"jbGetULCorners");
2239 return ERROR_INT(
"classer not defined", procName, 1);
2241 return ERROR_INT(
"pixs not defined", procName, 1);
2243 return ERROR_INT(
"boxa not defined", procName, 1);
2246 ptaul = classer->
ptaul;
2248 ptac = classer->
ptac;
2249 ptact = classer->
ptact;
2252 for (i = 0; i < n; i++) {
2253 index = baseindex + i;
2260 idelx = (l_int32)(delx + 0.5);
2262 idelx = (l_int32)(delx - 0.5);
2264 idely = (l_int32)(dely + 0.5);
2266 idely = (l_int32)(dely - 0.5);
2269 return ERROR_INT(
"box not found", procName, 1);
2275 finalPositioningForAlignment(pixs, x, y, idelx, idely,
2276 pixt, sumtab, &dx, &dy);
2279 ptaAddPt(ptaul, x - idelx + dx, y - idely + dy);
2318 l_int32 i, iclass, n, x1, y1, h;
2324 PROCNAME(
"jbGetLLCorners");
2327 return ERROR_INT(
"classer not defined", procName, 1);
2329 ptaul = classer->
ptaul;
2331 pixat = classer->
pixat;
2336 classer->
ptall = ptall;
2343 for (i = 0; i < n; i++) {
2347 h = pixGetHeight(pix);
2348 ptaAddPt(ptall, x1, y1 + h - 1 - 2 * JB_ADDED_PIXELS);
2363 static int two_by_two_walk[50] = {
2399 findSimilarSizedTemplatesInit(
JBCLASSER *classer,
2405 state->w = pixGetWidth(pixs) - 2 * JB_ADDED_PIXELS;
2406 state->h = pixGetHeight(pixs) - 2 * JB_ADDED_PIXELS;
2407 state->classer = classer;
2413 findSimilarSizedTemplatesDestroy(
JBFINDCTX **pstate)
2417 PROCNAME(
"findSimilarSizedTemplatesDestroy");
2419 if (pstate == NULL) {
2420 L_WARNING(
"ptr address is null\n", procName);
2423 if ((state = *pstate) == NULL)
2451 findSimilarSizedTemplatesNext(
JBFINDCTX *state)
2453 l_int32 desiredh, desiredw, size, templ;
2457 if (state->i >= 25) {
2461 desiredw = state->w + two_by_two_walk[2 * state->i];
2462 desiredh = state->h + two_by_two_walk[2 * state->i + 1];
2463 if (desiredh < 1 || desiredw < 1) {
2471 (l_uint64)desiredh * desiredw,
L_CLONE);
2482 for ( ; state->n < size; ) {
2483 templ = (l_int32)(state->dna->
array[state->n++] + 0.5);
2485 if (pixGetWidth(pixt) - 2 * JB_ADDED_PIXELS == desiredw &&
2486 pixGetHeight(pixt) - 2 * JB_ADDED_PIXELS == desiredh) {
2518 finalPositioningForAlignment(
PIX *pixs,
2528 l_int32 w, h, i, j, minx, miny, count, mincount;
2533 PROCNAME(
"finalPositioningForAlignment");
2536 return ERROR_INT(
"pixs not defined", procName, 1);
2538 return ERROR_INT(
"pixt not defined", procName, 1);
2540 return ERROR_INT(
"&dx and &dy not both defined", procName, 1);
2542 return ERROR_INT(
"sumtab not defined", procName, 1);
2547 box =
boxCreate(x - idelx - JB_ADDED_PIXELS,
2548 y - idely - JB_ADDED_PIXELS, w, h);
2552 return ERROR_INT(
"pixi not made", procName, 1);
2554 pixr =
pixCreate(pixGetWidth(pixi), pixGetHeight(pixi), 1);
2555 mincount = 0x7fffffff;
2556 for (i = -1; i <= 1; i++) {
2557 for (j = -1; j <= 1; j++) {
2561 if (count < mincount) {
void gplotDestroy(GPLOT **pgplot)
gplotDestroy()
PIX * pixUnpackBinary(PIX *pixs, l_int32 depth, l_int32 invert)
pixUnpackBinary()
void pixaaDestroy(PIXAA **ppaa)
pixaaDestroy()
PIXAA * pixaaCreate(l_int32 n)
pixaaCreate()
l_ok numaGetFValue(NUMA *na, l_int32 index, l_float32 *pval)
numaGetFValue()
l_int32 lept_mkdir(const char *subdir)
lept_mkdir()
L_DNA * l_dnaHashGetDna(L_DNAHASH *dahash, l_uint64 key, l_int32 copyflag)
l_dnaHashGetDna()
l_ok gplotAddPlot(GPLOT *gplot, NUMA *nax, NUMA *nay, l_int32 plotstyle, const char *plottitle)
gplotAddPlot()
l_int32 l_dnaGetCount(L_DNA *da)
l_dnaGetCount()
SARRAY * sarrayCopy(SARRAY *sa)
sarrayCopy()
l_int32 * makePixelCentroidTab8(void)
makePixelCentroidTab8()
l_ok pixMultConstAccumulate(PIX *pixs, l_float32 factor, l_uint32 offset)
pixMultConstAccumulate()
struct L_DnaHash * dahash
PIX * pixCloseBrick(PIX *pixd, PIX *pixs, l_int32 hsize, l_int32 vsize)
pixCloseBrick()
l_ok ptaAddPt(PTA *pta, l_float32 x, l_float32 y)
ptaAddPt()
l_ok numaAddNumber(NUMA *na, l_float32 val)
numaAddNumber()
PTA * pixaCentroids(PIXA *pixa)
pixaCentroids()
PIXA * pixaCreate(l_int32 n)
pixaCreate()
void l_dnaDestroy(L_DNA **pda)
l_dnaDestroy()
l_ok gplotMakeOutput(GPLOT *gplot)
gplotMakeOutput()
GPLOT * gplotCreate(const char *rootname, l_int32 outformat, const char *title, const char *xlabel, const char *ylabel)
gplotCreate()
void l_dnaHashDestroy(L_DNAHASH **pdahash)
l_dnaHashDestroy()
BOXA * boxaSelectBySize(BOXA *boxas, l_int32 width, l_int32 height, l_int32 type, l_int32 relation, l_int32 *pchanged)
boxaSelectBySize()
l_ok pixRasterop(PIX *pixd, l_int32 dx, l_int32 dy, l_int32 dw, l_int32 dh, l_int32 op, PIX *pixs, l_int32 sx, l_int32 sy)
pixRasterop()
PTA * ptaCreate(l_int32 n)
ptaCreate()
PIXA * pixaaGetPixa(PIXAA *paa, l_int32 index, l_int32 accesstype)
pixaaGetPixa()
l_int32 pixaaGetCount(PIXAA *paa, NUMA **pna)
pixaaGetCount()
PIX * pixaDisplayOnLattice(PIXA *pixa, l_int32 cellw, l_int32 cellh, l_int32 *pncols, BOXA **pboxa)
pixaDisplayOnLattice()
PIX * pixCreate(l_int32 width, l_int32 height, l_int32 depth)
pixCreate()
NUMA * numaCreate(l_int32 n)
numaCreate()
l_int32 ptaGetCount(PTA *pta)
ptaGetCount()
void boxaDestroy(BOXA **pboxa)
boxaDestroy()
l_uint32 * pixGetData(PIX *pix)
pixGetData()
PIX * pixCreateTemplate(PIX *pixs)
pixCreateTemplate()
PIX * pixClipRectangle(PIX *pixs, BOX *box, BOX **pboxc)
pixClipRectangle()
l_ok pixThresholdPixelSum(PIX *pix, l_int32 thresh, l_int32 *pabove, l_int32 *tab8)
pixThresholdPixelSum()
l_ok pixSetColormap(PIX *pix, PIXCMAP *colormap)
pixSetColormap()
l_ok ptaJoin(PTA *ptad, PTA *ptas, l_int32 istart, l_int32 iend)
ptaJoin()
PIXCMAP * pixcmapCreate(l_int32 depth)
pixcmapCreate()
l_int32 * numaGetIArray(NUMA *na)
numaGetIArray()
l_ok l_dnaHashAdd(L_DNAHASH *dahash, l_uint64 key, l_float64 value)
l_dnaHashAdd()
l_uint8 * l_binaryRead(const char *filename, size_t *pnbytes)
l_binaryRead()
BOXA * pixConnComp(PIX *pixs, PIXA **ppixa, l_int32 connectivity)
pixConnComp()
l_ok numaGetIValue(NUMA *na, l_int32 index, l_int32 *pival)
numaGetIValue()
l_ok pixaAddPix(PIXA *pixa, PIX *pix, l_int32 copyflag)
pixaAddPix()
l_int32 numaGetCount(NUMA *na)
numaGetCount()
PIX * pixConvert1To2Cmap(PIX *pixs)
pixConvert1To2Cmap()
l_ok pixClearAll(PIX *pix)
pixClearAll()
PTA * ptaClone(PTA *pta)
ptaClone()
void selDestroy(SEL **psel)
selDestroy()
BOXA * pixConnCompBB(PIX *pixs, l_int32 connectivity)
pixConnCompBB()
PIXA * pixaCreateFromPix(PIX *pixs, l_int32 n, l_int32 cellw, l_int32 cellh)
pixaCreateFromPix()
PIX * pixInitAccumulate(l_int32 w, l_int32 h, l_uint32 offset)
pixInitAccumulate()
PIX * pixMorphSequence(PIX *pixs, const char *sequence, l_int32 dispsep)
pixMorphSequence()
l_ok pixAccumulate(PIX *pixd, PIX *pixs, l_int32 op)
pixAccumulate()
l_ok pixCountPixels(PIX *pixs, l_int32 *pcount, l_int32 *tab8)
pixCountPixels()
PIXA * pixaSelectBySize(PIXA *pixas, l_int32 width, l_int32 height, l_int32 type, l_int32 relation, l_int32 *pchanged)
pixaSelectBySize()
l_ok ptaGetPt(PTA *pta, l_int32 index, l_float32 *px, l_float32 *py)
ptaGetPt()
l_int32 * makePixelSumTab8(void)
makePixelSumTab8()
SEL * selCreateBrick(l_int32 h, l_int32 w, l_int32 cy, l_int32 cx, l_int32 type)
selCreateBrick()
char * sarrayGetString(SARRAY *sa, l_int32 index, l_int32 copyflag)
sarrayGetString()
PIX * pixClone(PIX *pixs)
pixClone()
PIX * pixScaleToSize(PIX *pixs, l_int32 wd, l_int32 hd)
pixScaleToSize()
PIX * pixFinalAccumulate(PIX *pixs, l_uint32 offset, l_int32 depth)
pixFinalAccumulate()
void pixDestroy(PIX **ppix)
pixDestroy()
NUMA * numaMakeSequence(l_float32 startval, l_float32 increment, l_int32 size)
numaMakeSequence()
BOX * boxaGetBox(BOXA *boxa, l_int32 index, l_int32 accessflag)
boxaGetBox()
SARRAY * sarrayCreateLinesFromString(const char *string, l_int32 blankflag)
sarrayCreateLinesFromString()
void numaDestroy(NUMA **pna)
numaDestroy()
l_ok pixGetDimensions(const PIX *pix, l_int32 *pw, l_int32 *ph, l_int32 *pd)
pixGetDimensions()
FILE * fopenWriteStream(const char *filename, const char *modestring)
fopenWriteStream()
NUMA * pixaCountPixels(PIXA *pixa)
pixaCountPixels()
l_ok pixaSizeRange(PIXA *pixa, l_int32 *pminw, l_int32 *pminh, l_int32 *pmaxw, l_int32 *pmaxh)
pixaSizeRange()
l_int32 sarrayGetCount(SARRAY *sa)
sarrayGetCount()
PIX * pixRead(const char *filename)
pixRead()
PIX * pixExpandReplicate(PIX *pixs, l_int32 factor)
pixExpandReplicate()
l_ok pixRenderBoxaArb(PIX *pix, BOXA *boxa, l_int32 width, l_uint8 rval, l_uint8 gval, l_uint8 bval)
pixRenderBoxaArb()
PIX * pixaGetPix(PIXA *pixa, l_int32 index, l_int32 accesstype)
pixaGetPix()
l_ok pixRenderBoxArb(PIX *pix, BOX *box, l_int32 width, l_uint8 rval, l_uint8 gval, l_uint8 bval)
pixRenderBoxArb()
l_ok pixaaAddPixa(PIXAA *paa, PIXA *pixa, l_int32 copyflag)
pixaaAddPixa()
void ptaDestroy(PTA **ppta)
ptaDestroy()
l_ok pixZero(PIX *pix, l_int32 *pempty)
pixZero()
BOXA * boxaCreate(l_int32 n)
boxaCreate()
PIX * pixCopy(PIX *pixd, PIX *pixs)
pixCopy()
PIXA * pixaClipToPix(PIXA *pixas, PIX *pixs)
pixaClipToPix()
void boxDestroy(BOX **pbox)
boxDestroy()
NUMA * numaClone(NUMA *na)
numaClone()
l_int32 boxaGetCount(BOXA *boxa)
boxaGetCount()
l_ok ptaGetIPt(PTA *pta, l_int32 index, l_int32 *px, l_int32 *py)
ptaGetIPt()
PIX * pixDilate(PIX *pixd, PIX *pixs, SEL *sel)
pixDilate()
L_DNAHASH * l_dnaHashCreate(l_int32 nbuckets, l_int32 initsize)
l_dnaHashCreate()
l_ok pixcmapAddColor(PIXCMAP *cmap, l_int32 rval, l_int32 gval, l_int32 bval)
pixcmapAddColor()
l_ok pixaAddBox(PIXA *pixa, BOX *box, l_int32 copyflag)
pixaAddBox()
l_ok boxGetGeometry(BOX *box, l_int32 *px, l_int32 *py, l_int32 *pw, l_int32 *ph)
boxGetGeometry()
PIX * pixReduceRankBinaryCascade(PIX *pixs, l_int32 level1, l_int32 level2, l_int32 level3, l_int32 level4)
pixReduceRankBinaryCascade()
void pixaDestroy(PIXA **ppixa)
pixaDestroy()
BOX * boxCreate(l_int32 x, l_int32 y, l_int32 w, l_int32 h)
boxCreate()
l_int32 pixaGetCount(PIXA *pixa)
pixaGetCount()
PIX * pixAddBorderGeneral(PIX *pixs, l_int32 left, l_int32 right, l_int32 top, l_int32 bot, l_uint32 val)
pixAddBorderGeneral()
static const l_int32 L_BUF_SIZE
void sarrayDestroy(SARRAY **psa)
sarrayDestroy()