206 #include <config_auto.h> 211 #include "allheaders.h" 213 #define L_BUF_SIZE 512 219 static const l_int32 JB_ADDED_PIXELS = 6;
223 static const l_int32 MAX_DIFF_WIDTH = 2;
224 static const l_int32 MAX_DIFF_HEIGHT = 2;
233 static const l_int32 MAX_CONN_COMP_WIDTH = 350;
234 static const l_int32 MAX_CHAR_COMP_WIDTH = 350;
235 static const l_int32 MAX_WORD_COMP_WIDTH = 1000;
236 static const l_int32 MAX_COMP_HEIGHT = 120;
252 static JBCLASSER * jbCorrelationInitInternal(l_int32 components,
253 l_int32 maxwidth, l_int32 maxheight, l_float32 thresh,
254 l_float32 weightfactor, l_int32 keep_components);
258 static l_int32 findSimilarSizedTemplatesNext(
JBFINDCTX *context);
259 static void findSimilarSizedTemplatesDestroy(
JBFINDCTX **pcontext);
260 static l_int32 finalPositioningForAlignment(
PIX *pixs, l_int32 x, l_int32 y,
261 l_int32 idelx, l_int32 idely,
PIX *pixt,
262 l_int32 *sumtab, l_int32 *pdx, l_int32 *pdy);
264 #ifndef NO_CONSOLE_IO 265 #define DEBUG_CORRELATION_SCORE 0 286 jbRankHausInit(l_int32 components,
294 PROCNAME(
"jbRankHausInit");
296 if (components != JB_CONN_COMPS && components != JB_CHARACTERS &&
297 components != JB_WORDS)
298 return (
JBCLASSER *)ERROR_PTR(
"invalid components", procName, NULL);
299 if (size < 1 || size > 10)
300 return (
JBCLASSER *)ERROR_PTR(
"size not reasonable", procName, NULL);
301 if (rank < 0.5 || rank > 1.0)
302 return (
JBCLASSER *)ERROR_PTR(
"rank not in [0.5-1.0]", procName, NULL);
304 if (components == JB_CONN_COMPS)
305 maxwidth = MAX_CONN_COMP_WIDTH;
306 else if (components == JB_CHARACTERS)
307 maxwidth = MAX_CHAR_COMP_WIDTH;
309 maxwidth = MAX_WORD_COMP_WIDTH;
312 maxheight = MAX_COMP_HEIGHT;
314 if ((classer = jbClasserCreate(JB_RANKHAUS, components)) == NULL)
315 return (
JBCLASSER *)ERROR_PTR(
"classer not made", procName, NULL);
347 jbCorrelationInit(l_int32 components,
351 l_float32 weightfactor)
353 return jbCorrelationInitInternal(components, maxwidth, maxheight, thresh,
374 jbCorrelationInitWithoutComponents(l_int32 components,
378 l_float32 weightfactor)
380 return jbCorrelationInitInternal(components, maxwidth, maxheight, thresh,
386 jbCorrelationInitInternal(l_int32 components,
390 l_float32 weightfactor,
391 l_int32 keep_components)
395 PROCNAME(
"jbCorrelationInitInternal");
397 if (components != JB_CONN_COMPS && components != JB_CHARACTERS &&
398 components != JB_WORDS)
399 return (
JBCLASSER *)ERROR_PTR(
"invalid components", procName, NULL);
400 if (thresh < 0.4 || thresh > 0.98)
401 return (
JBCLASSER *)ERROR_PTR(
"thresh not in range [0.4 - 0.98]",
403 if (weightfactor < 0.0 || weightfactor > 1.0)
404 return (
JBCLASSER *)ERROR_PTR(
"weightfactor not in range [0.0 - 1.0]",
407 if (components == JB_CONN_COMPS)
408 maxwidth = MAX_CONN_COMP_WIDTH;
409 else if (components == JB_CHARACTERS)
410 maxwidth = MAX_CHAR_COMP_WIDTH;
412 maxwidth = MAX_WORD_COMP_WIDTH;
415 maxheight = MAX_COMP_HEIGHT;
418 if ((classer = jbClasserCreate(JB_CORRELATION, components)) == NULL)
419 return (
JBCLASSER *)ERROR_PTR(
"classer not made", procName, NULL);
454 PROCNAME(
"jbAddPages");
457 return ERROR_INT(
"classer not defined", procName, 1);
459 return ERROR_INT(
"safiles not defined", procName, 1);
463 for (i = 0; i < nfiles; i++) {
465 if ((pix =
pixRead(fname)) == NULL) {
466 L_WARNING(
"image file %d not read\n", procName, i);
469 if (pixGetDepth(pix) != 1) {
470 L_WARNING(
"image file %d not 1 bpp\n", procName, i);
473 jbAddPage(classer, pix);
495 PROCNAME(
"jbAddPage");
498 return ERROR_INT(
"classer not defined", procName, 1);
499 if (!pixs || pixGetDepth(pixs) != 1)
500 return ERROR_INT(
"pixs not defined or not 1 bpp", procName, 1);
502 classer->
w = pixGetWidth(pixs);
503 classer->
h = pixGetHeight(pixs);
508 return ERROR_INT(
"components not made", procName, 1);
511 jbAddPageComponents(classer, pixs, boxas, pixas);
541 PROCNAME(
"jbAddPageComponents");
544 return ERROR_INT(
"classer not defined", procName, 1);
546 return ERROR_INT(
"pix not defined", procName, 1);
558 if (classer->
method == JB_RANKHAUS) {
559 if (jbClassifyRankHaus(classer, boxas, pixas))
560 return ERROR_INT(
"rankhaus classification failed", procName, 1);
562 if (jbClassifyCorrelation(classer, boxas, pixas))
563 return ERROR_INT(
"correlation classification failed", procName, 1);
570 if (jbGetULCorners(classer, pixs, boxas))
571 return ERROR_INT(
"UL corners not found", procName, 1);
598 l_int32 n, nt, i, wt, ht, iclass, size, found, testval;
599 l_int32 npages, area1, area3;
601 l_float32 rank, x1, y1, x2, y2;
603 NUMA *naclass, *napage;
608 PIX *pix, *pix1, *pix2, *pix3, *pix4;
609 PIXA *pixa, *pixa1, *pixa2, *pixat, *pixatd;
611 PTA *pta, *ptac, *ptact;
614 PROCNAME(
"jbClassifyRankHaus");
617 return ERROR_INT(
"classer not defined", procName, 1);
619 return ERROR_INT(
"boxa not defined", procName, 1);
621 return ERROR_INT(
"pixas not defined", procName, 1);
623 return ERROR_INT(
"pixas is empty", procName, 1);
625 return ERROR_INT(
"fg counting failed", procName, 1);
635 for (i = 0; i < n; i++) {
638 JB_ADDED_PIXELS, JB_ADDED_PIXELS, 0);
648 ptac = classer->
ptac;
650 ptact = classer->
ptact;
667 pixaa = classer->
pixaa;
670 pixat = classer->
pixat;
696 for (i = 0; i < n; i++) {
702 findcontext = findSimilarSizedTemplatesInit(classer, pix1);
703 while ((iclass = findSimilarSizedTemplatesNext(findcontext)) > -1) {
708 testval = pixHaustest(pix1, pix2, pix3, pix4, x1 - x2, y1 - y2,
709 MAX_DIFF_WIDTH, MAX_DIFF_HEIGHT);
727 findSimilarSizedTemplatesDestroy(&findcontext);
728 if (found == FALSE) {
734 wt = pixGetWidth(pix);
735 ht = pixGetHeight(pix);
749 nafgt = classer->
nafgt;
751 for (i = 0; i < n; i++) {
758 findcontext = findSimilarSizedTemplatesInit(classer, pix1);
759 while ((iclass = findSimilarSizedTemplatesNext(findcontext)) > -1) {
765 testval = pixRankHaustest(pix1, pix2, pix3, pix4,
767 MAX_DIFF_WIDTH, MAX_DIFF_HEIGHT,
768 area1, area3, rank, tab8);
786 findSimilarSizedTemplatesDestroy(&findcontext);
787 if (found == FALSE) {
793 wt = pixGetWidth(pix);
794 ht = pixGetHeight(pix);
849 pixHaustest(
PIX *pix1,
858 l_int32 wi, hi, wt, ht, delw, delh, idelx, idely, boolmatch;
862 wi = pixGetWidth(pix1);
863 hi = pixGetHeight(pix1);
864 wt = pixGetWidth(pix3);
865 ht = pixGetHeight(pix3);
866 delw = L_ABS(wi - wt);
869 delh = L_ABS(hi - ht);
876 idelx = (l_int32)(delx + 0.5);
878 idelx = (l_int32)(delx - 0.5);
880 idely = (l_int32)(dely + 0.5);
882 idely = (l_int32)(dely - 0.5);
894 if (boolmatch == 0) {
947 pixRankHaustest(
PIX *pix1,
960 l_int32 wi, hi, wt, ht, delw, delh, idelx, idely, boolmatch;
961 l_int32 thresh1, thresh3;
965 wi = pixGetWidth(pix1);
966 hi = pixGetHeight(pix1);
967 wt = pixGetWidth(pix3);
968 ht = pixGetHeight(pix3);
969 delw = L_ABS(wi - wt);
972 delh = L_ABS(hi - ht);
977 thresh1 = (l_int32)(area1 * (1. - rank) + 0.5);
978 thresh3 = (l_int32)(area3 * (1. - rank) + 0.5);
983 idelx = (l_int32)(delx + 0.5);
985 idelx = (l_int32)(delx - 0.5);
987 idely = (l_int32)(dely + 0.5);
989 idely = (l_int32)(dely - 0.5);
1001 if (boolmatch == 1) {
1034 jbClassifyCorrelation(
JBCLASSER *classer,
1038 l_int32 n, nt, i, iclass, wt, ht, found, area, area1, area2, npages,
1040 l_int32 *sumtab, *centtab;
1041 l_uint32 *row, word;
1042 l_float32 x1, y1, x2, y2, xsum, ysum;
1043 l_float32 thresh, weight, threshold;
1045 NUMA *naclass, *napage;
1050 PIX *pix, *pix1, *pix2;
1051 PIXA *pixa, *pixa1, *pixat;
1053 PTA *pta, *ptac, *ptact;
1055 l_int32 **pixrowcts;
1056 l_int32 x, y, rowcount, downcount, wpl;
1059 PROCNAME(
"jbClassifyCorrelation");
1062 return ERROR_INT(
"classer not found", procName, 1);
1064 return ERROR_INT(
"boxa not found", procName, 1);
1066 return ERROR_INT(
"pixas not found", procName, 1);
1068 npages = classer->
npages;
1073 L_WARNING(
"pixas is empty\n", procName);
1077 for (i = 0; i < n; i++) {
1080 JB_ADDED_PIXELS, JB_ADDED_PIXELS, 0);
1087 napage = classer->
napage;
1090 nafgt = classer->
nafgt;
1093 pixcts = (l_int32 *)LEPT_CALLOC(n,
sizeof(*pixcts));
1094 pixrowcts = (l_int32 **)LEPT_CALLOC(n,
sizeof(*pixrowcts));
1105 for (i = 0; i < n; i++) {
1107 pixrowcts[i] = (l_int32 *)LEPT_CALLOC(pixGetHeight(pix),
1108 sizeof(**pixrowcts));
1111 wpl = pixGetWpl(pix);
1112 row =
pixGetData(pix) + (pixGetHeight(pix) - 1) * wpl;
1114 for (y = pixGetHeight(pix) - 1; y >= 0; y--, row -= wpl) {
1115 pixrowcts[i][y] = downcount;
1117 for (x = 0; x < wpl; x++) {
1120 rowcount += sumtab[byte];
1121 xsum += centtab[byte] + (x * 32 + 24) * sumtab[
byte];
1122 byte = (word >> 8) & 0xff;
1123 rowcount += sumtab[byte];
1124 xsum += centtab[byte] + (x * 32 + 16) * sumtab[
byte];
1125 byte = (word >> 16) & 0xff;
1126 rowcount += sumtab[byte];
1127 xsum += centtab[byte] + (x * 32 + 8) * sumtab[
byte];
1128 byte = (word >> 24) & 0xff;
1129 rowcount += sumtab[byte];
1130 xsum += centtab[byte] + x * 32 * sumtab[byte];
1132 downcount += rowcount;
1133 ysum += rowcount * y;
1135 pixcts[i] = downcount;
1136 if (downcount > 0) {
1138 xsum / (l_float32)downcount, ysum / (l_float32)downcount);
1140 L_ERROR(
"downcount == 0 !\n", procName);
1141 ptaAddPt(pta, pixGetWidth(pix) / 2, pixGetHeight(pix) / 2);
1146 ptac = classer->
ptac;
1148 ptact = classer->
ptact;
1161 pixaa = classer->
pixaa;
1164 pixat = classer->
pixat;
1184 thresh = classer->
thresh;
1186 naarea = classer->
naarea;
1187 dahash = classer->
dahash;
1188 for (i = 0; i < n; i++) {
1194 findcontext = findSimilarSizedTemplatesInit(classer, pix1);
1195 while ( (iclass = findSimilarSizedTemplatesNext(findcontext)) > -1) {
1204 threshold = thresh + (1. - thresh) * weight * area2 / area;
1210 overthreshold = pixCorrelationScoreThresholded(pix1, pix2,
1211 area1, area2, x1 - x2, y1 - y2,
1212 MAX_DIFF_WIDTH, MAX_DIFF_HEIGHT,
1213 sumtab, pixrowcts[i], threshold);
1214 #if DEBUG_CORRELATION_SCORE 1216 l_float32 score, testscore;
1217 l_int32 count, testcount;
1218 pixCorrelationScore(pix1, pix2, area1, area2, x1 - x2, y1 - y2,
1219 MAX_DIFF_WIDTH, MAX_DIFF_HEIGHT,
1222 pixCorrelationScoreSimple(pix1, pix2, area1, area2,
1223 x1 - x2, y1 - y2, MAX_DIFF_WIDTH,
1224 MAX_DIFF_HEIGHT, sumtab, &testscore);
1225 count = (l_int32)rint(sqrt(score * area1 * area2));
1226 testcount = (l_int32)rint(sqrt(testscore * area1 * area2));
1227 if ((score >= threshold) != (testscore >= threshold)) {
1229 "%d(%g,%d) vs %d(%g,%d) (%g)\n",
1230 count, score, score >= threshold,
1231 testcount, testscore, testscore >= threshold,
1235 if ((score >= threshold) != overthreshold) {
1236 lept_stderr(
"Mismatch between correlation/threshold " 1237 "comparison: %g(%g,%d) >= %g(%g) vs %s\n",
1238 score, score*area1*area2, count, threshold,
1239 threshold*area1*area2,
1240 (overthreshold ?
"true" :
"false"));
1246 if (overthreshold) {
1262 findSimilarSizedTemplatesDestroy(&findcontext);
1263 if (found == FALSE) {
1269 wt = pixGetWidth(pix);
1270 ht = pixGetHeight(pix);
1278 area = (pixGetWidth(pix1) - 2 * JB_ADDED_PIXELS) *
1279 (pixGetHeight(pix1) - 2 * JB_ADDED_PIXELS);
1289 for (i = 0; i < n; i++) {
1290 LEPT_FREE(pixrowcts[i]);
1292 LEPT_FREE(pixrowcts);
1316 jbGetComponents(
PIX *pixs,
1323 l_int32 empty, res, redfactor;
1325 PIX *pix1, *pix2, *pix3;
1328 PROCNAME(
"jbGetComponents");
1331 return ERROR_INT(
"&boxad not defined", procName, 1);
1334 return ERROR_INT(
"&pixad not defined", procName, 1);
1337 return ERROR_INT(
"pixs not defined", procName, 1);
1338 if (components != JB_CONN_COMPS && components != JB_CHARACTERS &&
1339 components != JB_WORDS)
1340 return ERROR_INT(
"invalid components", procName, 1);
1362 if (components == JB_CONN_COMPS) {
1364 }
else if (components == JB_CHARACTERS) {
1377 res = pixGetXRes(pixs);
1381 }
else if (res <= 400) {
1391 pixWordMaskByDilation(pix1, &pix2, NULL, NULL);
1458 pixWordMaskByDilation(
PIX *pixs,
1463 l_int32 i, n, ndil, maxdiff, diff, ibest;
1464 l_int32 check, count, total, xres;
1468 NUMA *nacc, *nadiff;
1471 PROCNAME(
"pixWordMaskByDilation");
1473 if (ppixm) *ppixm = NULL;
1474 if (psize) *psize = 0;
1475 if (!pixs || pixGetDepth(pixs) != 1)
1476 return ERROR_INT(
"pixs undefined or not 1 bpp", procName, 1);
1477 if (!ppixm && !psize)
1478 return ERROR_INT(
"no output requested", procName, 1);
1486 for (i = 0; i <= ndil; i++) {
1494 if (i == 0) total = ncc[0];
1496 diff = ncc[i - 1] - ncc[i];
1513 for (i = 1; i < n; i++) {
1515 if (check && count < 0.3 * total) {
1526 xres = pixGetXRes(pixs);
1527 if (xres == 0) xres = 150;
1528 if (xres > 110) ibest++;
1530 L_INFO(
"setting ibest to minimum allowed value of 2\n", procName);
1538 L_INFO(
"Best dilation: %d\n", procName, L_MAX(3, ibest + 1));
1541 "/tmp/lept/jb/numcc",
1542 "Number of cc vs. horizontal dilation",
1543 "Sel horiz",
"Number of cc");
1548 "/tmp/lept/jb/diffcc",
1549 "Diff count of cc vs. horizontal dilation",
1550 "Sel horiz",
"Diff in cc");
1560 if (psize) *psize = ibest + 1;
1590 pixWordBoxesByDilation(
PIX *pixs,
1599 BOXA *boxa1, *boxa2;
1602 PROCNAME(
"pixWordBoxesByDilation");
1604 if (psize) *psize = 0;
1605 if (!pixs || pixGetDepth(pixs) != 1)
1606 return ERROR_INT(
"pixs undefined or not 1 bpp", procName, 1);
1608 return ERROR_INT(
"&boxa not defined", procName, 1);
1612 if (pixWordMaskByDilation(pixs, &pix1, psize, pixadb))
1613 return ERROR_INT(
"pixWordMaskByDilation() failed", procName, 1);
1652 jbAccumulateComposites(
PIXAA *pixaa,
1656 l_int32 n, nt, i, j, d, minw, maxw, minh, maxh, xdiff, ydiff;
1657 l_float32 x, y, xave, yave;
1659 PIX *pix, *pixt1, *pixt2, *pixsum;
1663 PROCNAME(
"jbAccumulateComposites");
1666 return (
PIXA *)ERROR_PTR(
"&ptat not defined", procName, NULL);
1669 return (
PIXA *)ERROR_PTR(
"&na not defined", procName, NULL);
1672 return (
PIXA *)ERROR_PTR(
"pixaa not defined", procName, NULL);
1676 return (
PIXA *)ERROR_PTR(
"ptat not made", procName, NULL);
1682 for (i = 0; i < n; i++) {
1687 L_WARNING(
"empty pixa found!\n", procName);
1693 d = pixGetDepth(pix);
1701 for (j = 0; j < nt; j++) {
1706 xave = xave / (l_float32)nt;
1707 yave = yave / (l_float32)nt;
1710 for (j = 0; j < nt; j++) {
1713 xdiff = (l_int32)(x - xave);
1714 ydiff = (l_int32)(y - yave);
1742 jbTemplatesFromComposites(
PIXA *pixac,
1752 PROCNAME(
"jbTemplatesFromComposites");
1755 return (
PIXA *)ERROR_PTR(
"pixac not defined", procName, NULL);
1757 return (
PIXA *)ERROR_PTR(
"na not defined", procName, NULL);
1761 for (i = 0; i < n; i++) {
1787 jbClasserCreate(l_int32 method,
1792 PROCNAME(
"jbClasserCreate");
1794 if (method != JB_RANKHAUS && method != JB_CORRELATION)
1795 return (
JBCLASSER *)ERROR_PTR(
"invalid method", procName, NULL);
1796 if (components != JB_CONN_COMPS && components != JB_CHARACTERS &&
1797 components != JB_WORDS)
1798 return (
JBCLASSER *)ERROR_PTR(
"invalid component", procName, NULL);
1801 classer->
method = method;
1831 if ((classer = *pclasser) == NULL)
1880 PROCNAME(
"jbDataSave");
1883 return (
JBDATA *)ERROR_PTR(
"classer not defined", procName, NULL);
1890 return (
JBDATA *)ERROR_PTR(
"data not made", procName, NULL);
1895 data->
w = classer->
w;
1896 data->
h = classer->
h;
1914 jbDataDestroy(
JBDATA **pdata)
1920 if ((data = *pdata) == NULL)
1945 jbDataWrite(
const char *rootout,
1949 l_int32 w, h, nclass, npages, cellw, cellh, ncomp, i, x, y, iclass, ipage;
1950 NUMA *naclass, *napage;
1955 PROCNAME(
"jbDataWrite");
1958 return ERROR_INT(
"no rootout", procName, 1);
1960 return ERROR_INT(
"no jbdata", procName, 1);
1971 ptaul = jbdata->
ptaul;
1974 pixWrite(buf, pixt, IFF_PNG);
1976 snprintf(buf,
L_BUF_SIZE,
"%s%s", rootout, JB_DATA_EXT);
1978 return ERROR_INT(
"stream not opened", procName, 1);
1980 fprintf(fp,
"jb data file\n");
1981 fprintf(fp,
"num pages = %d\n", npages);
1982 fprintf(fp,
"page size: w = %d, h = %d\n", w, h);
1983 fprintf(fp,
"num components = %d\n", ncomp);
1984 fprintf(fp,
"num classes = %d\n", nclass);
1985 fprintf(fp,
"template lattice size: w = %d, h = %d\n", cellw, cellh);
1986 for (i = 0; i < ncomp; i++) {
1990 fprintf(fp,
"%d %d %d %d\n", ipage, iclass, x, y);
2005 jbDataRead(
const char *rootname)
2010 l_int32 nsa, i, w, h, cellw, cellh, x, y, iclass, ipage;
2011 l_int32 npages, nclass, ncomp, ninit;
2014 NUMA *naclass, *napage;
2019 PROCNAME(
"jbDataRead");
2022 return (
JBDATA *)ERROR_PTR(
"rootname not defined", procName, NULL);
2025 if ((pixs =
pixRead(fname)) == NULL)
2026 return (
JBDATA *)ERROR_PTR(
"pix not read", procName, NULL);
2028 snprintf(fname,
L_BUF_SIZE,
"%s%s", rootname, JB_DATA_EXT);
2031 return (
JBDATA *)ERROR_PTR(
"data not read", procName, NULL);
2037 return (
JBDATA *)ERROR_PTR(
"sa not made", procName, NULL);
2041 if (strcmp(linestr,
"jb data file") != 0) {
2045 return (
JBDATA *)ERROR_PTR(
"invalid jb data file", procName, NULL);
2048 sscanf(linestr,
"num pages = %d", &npages);
2050 sscanf(linestr,
"page size: w = %d, h = %d", &w, &h);
2052 sscanf(linestr,
"num components = %d", &ncomp);
2054 sscanf(linestr,
"num classes = %d\n", &nclass);
2056 sscanf(linestr,
"template lattice size: w = %d, h = %d\n", &cellw, &cellh);
2063 lept_stderr(
"template lattice size: w = %d, h = %d\n", cellw, cellh);
2067 if (ncomp > 1000000) {
2068 L_WARNING(
"ncomp > 1M\n", procName);
2074 for (i = 6; i < nsa; i++) {
2076 sscanf(linestr,
"%d %d %d %d\n", &ipage, &iclass, &x, &y);
2092 jbdata->
ptaul = ptaul;
2110 jbDataRender(
JBDATA *data,
2113 l_int32 i, w, h, cellw, cellh, x, y, iclass, ipage;
2114 l_int32 npages, nclass, ncomp, wp, hp;
2116 NUMA *naclass, *napage;
2117 PIX *pixt, *pixt2, *pix, *pixd;
2123 PROCNAME(
"jbDataRender");
2126 return (
PIXA *)ERROR_PTR(
"data not defined", procName, NULL);
2137 ptaul = data->
ptaul;
2144 return (
PIXA *)ERROR_PTR(
"pixad not made", procName, NULL);
2145 for (i = 0; i < npages; i++) {
2146 if (debugflag == FALSE) {
2162 return (
PIXA *)ERROR_PTR(
"pixat not made", procName, NULL);
2166 for (i = 0; i < ncomp; i++) {
2170 wp = pixGetWidth(pix);
2171 hp = pixGetHeight(pix);
2174 if (debugflag == FALSE) {
2223 l_int32 i, baseindex, index, n, iclass, idelx, idely, x, y, dx, dy;
2225 l_float32 x1, x2, y1, y2, delx, dely;
2229 PTA *ptac, *ptact, *ptaul;
2231 PROCNAME(
"jbGetULCorners");
2234 return ERROR_INT(
"classer not defined", procName, 1);
2236 return ERROR_INT(
"pixs not defined", procName, 1);
2238 return ERROR_INT(
"boxa not defined", procName, 1);
2241 ptaul = classer->
ptaul;
2243 ptac = classer->
ptac;
2244 ptact = classer->
ptact;
2247 for (i = 0; i < n; i++) {
2248 index = baseindex + i;
2255 idelx = (l_int32)(delx + 0.5);
2257 idelx = (l_int32)(delx - 0.5);
2259 idely = (l_int32)(dely + 0.5);
2261 idely = (l_int32)(dely - 0.5);
2264 return ERROR_INT(
"box not found", procName, 1);
2270 finalPositioningForAlignment(pixs, x, y, idelx, idely,
2271 pixt, sumtab, &dx, &dy);
2274 ptaAddPt(ptaul, x - idelx + dx, y - idely + dy);
2313 l_int32 i, iclass, n, x1, y1, h;
2319 PROCNAME(
"jbGetLLCorners");
2322 return ERROR_INT(
"classer not defined", procName, 1);
2324 ptaul = classer->
ptaul;
2326 pixat = classer->
pixat;
2331 classer->
ptall = ptall;
2338 for (i = 0; i < n; i++) {
2342 h = pixGetHeight(pix);
2343 ptaAddPt(ptall, x1, y1 + h - 1 - 2 * JB_ADDED_PIXELS);
2358 static int two_by_two_walk[50] = {
2394 findSimilarSizedTemplatesInit(
JBCLASSER *classer,
2400 state->w = pixGetWidth(pixs) - 2 * JB_ADDED_PIXELS;
2401 state->h = pixGetHeight(pixs) - 2 * JB_ADDED_PIXELS;
2402 state->classer = classer;
2408 findSimilarSizedTemplatesDestroy(
JBFINDCTX **pstate)
2412 PROCNAME(
"findSimilarSizedTemplatesDestroy");
2414 if (pstate == NULL) {
2415 L_WARNING(
"ptr address is null\n", procName);
2418 if ((state = *pstate) == NULL)
2446 findSimilarSizedTemplatesNext(
JBFINDCTX *state)
2448 l_int32 desiredh, desiredw, size, templ;
2452 if (state->i >= 25) {
2456 desiredw = state->w + two_by_two_walk[2 * state->i];
2457 desiredh = state->h + two_by_two_walk[2 * state->i + 1];
2458 if (desiredh < 1 || desiredw < 1) {
2466 (l_uint64)desiredh * desiredw,
L_CLONE);
2477 for ( ; state->n < size; ) {
2478 templ = (l_int32)(state->dna->
array[state->n++] + 0.5);
2480 if (pixGetWidth(pixt) - 2 * JB_ADDED_PIXELS == desiredw &&
2481 pixGetHeight(pixt) - 2 * JB_ADDED_PIXELS == desiredh) {
2513 finalPositioningForAlignment(
PIX *pixs,
2523 l_int32 w, h, i, j, minx, miny, count, mincount;
2528 PROCNAME(
"finalPositioningForAlignment");
2531 return ERROR_INT(
"pixs not defined", procName, 1);
2533 return ERROR_INT(
"pixt not defined", procName, 1);
2535 return ERROR_INT(
"&dx and &dy not both defined", procName, 1);
2537 return ERROR_INT(
"sumtab not defined", procName, 1);
2542 box =
boxCreate(x - idelx - JB_ADDED_PIXELS,
2543 y - idely - JB_ADDED_PIXELS, w, h);
2547 return ERROR_INT(
"pixi not made", procName, 1);
2549 pixr =
pixCreate(pixGetWidth(pixi), pixGetHeight(pixi), 1);
2550 mincount = 0x7fffffff;
2551 for (i = -1; i <= 1; i++) {
2552 for (j = -1; j <= 1; j++) {
2556 if (count < mincount) {
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_int32 l_dnaGetCount(L_DNA *da)
l_dnaGetCount()
SARRAY * sarrayCopy(SARRAY *sa)
sarrayCopy()
l_int32 * makePixelCentroidTab8(void)
makePixelCentroidTab8()
PIX * pixCreateTemplate(const PIX *pixs)
pixCreateTemplate()
l_ok pixMultConstAccumulate(PIX *pixs, l_float32 factor, l_uint32 offset)
pixMultConstAccumulate()
PIX * gplotGeneralPix2(NUMA *na1, NUMA *na2, l_int32 plotstyle, const char *rootname, const char *title, const char *xlabel, const char *ylabel)
gplotGeneralPix2()
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()
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()
PIX * pixCopy(PIX *pixd, const PIX *pixs)
pixCopy()
l_int32 pixaaGetCount(PIXAA *paa, NUMA **pna)
pixaaGetCount()
void lept_stderr(const char *fmt,...)
lept_stderr()
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 * 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()
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()
void sarrayDestroy(SARRAY **psa)
sarrayDestroy()