206 #include <config_auto.h>
211 #include "allheaders.h"
214 #define L_BUF_SIZE 512
220 static const l_int32 JB_ADDED_PIXELS = 6;
224 static const l_int32 MAX_DIFF_WIDTH = 2;
225 static const l_int32 MAX_DIFF_HEIGHT = 2;
234 static const l_int32 MAX_CONN_COMP_WIDTH = 350;
235 static const l_int32 MAX_CHAR_COMP_WIDTH = 350;
236 static const l_int32 MAX_WORD_COMP_WIDTH = 1000;
237 static const l_int32 MAX_COMP_HEIGHT = 120;
253 static JBCLASSER * jbCorrelationInitInternal(l_int32 components,
254 l_int32 maxwidth, l_int32 maxheight, l_float32 thresh,
255 l_float32 weightfactor, l_int32 keep_components);
259 static l_int32 findSimilarSizedTemplatesNext(
JBFINDCTX *context);
260 static void findSimilarSizedTemplatesDestroy(
JBFINDCTX **pcontext);
261 static l_int32 finalPositioningForAlignment(
PIX *pixs, l_int32 x, l_int32 y,
262 l_int32 idelx, l_int32 idely,
PIX *pixt,
263 l_int32 *sumtab, l_int32 *pdx, l_int32 *pdy);
265 #ifndef NO_CONSOLE_IO
266 #define DEBUG_CORRELATION_SCORE 0
287 jbRankHausInit(l_int32 components,
295 if (components != JB_CONN_COMPS && components != JB_CHARACTERS &&
296 components != JB_WORDS)
297 return (
JBCLASSER *)ERROR_PTR(
"invalid components", __func__, NULL);
298 if (size < 1 || size > 10)
299 return (
JBCLASSER *)ERROR_PTR(
"size not reasonable", __func__, NULL);
300 if (rank < 0.5 || rank > 1.0)
301 return (
JBCLASSER *)ERROR_PTR(
"rank not in [0.5-1.0]", __func__, NULL);
303 if (components == JB_CONN_COMPS)
304 maxwidth = MAX_CONN_COMP_WIDTH;
305 else if (components == JB_CHARACTERS)
306 maxwidth = MAX_CHAR_COMP_WIDTH;
308 maxwidth = MAX_WORD_COMP_WIDTH;
311 maxheight = MAX_COMP_HEIGHT;
313 if ((classer = jbClasserCreate(JB_RANKHAUS, components)) == NULL)
314 return (
JBCLASSER *)ERROR_PTR(
"classer not made", __func__, NULL);
346 jbCorrelationInit(l_int32 components,
350 l_float32 weightfactor)
352 return jbCorrelationInitInternal(components, maxwidth, maxheight, thresh,
373 jbCorrelationInitWithoutComponents(l_int32 components,
377 l_float32 weightfactor)
379 return jbCorrelationInitInternal(components, maxwidth, maxheight, thresh,
385 jbCorrelationInitInternal(l_int32 components,
389 l_float32 weightfactor,
390 l_int32 keep_components)
394 if (components != JB_CONN_COMPS && components != JB_CHARACTERS &&
395 components != JB_WORDS)
396 return (
JBCLASSER *)ERROR_PTR(
"invalid components", __func__, 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", __func__, NULL);
452 return ERROR_INT(
"classer not defined", __func__, 1);
454 return ERROR_INT(
"safiles not defined", __func__, 1);
458 for (i = 0; i < nfiles; i++) {
460 if ((pix =
pixRead(fname)) == NULL) {
461 L_WARNING(
"image file %d not read\n", __func__, i);
464 if (pixGetDepth(pix) != 1) {
465 L_WARNING(
"image file %d not 1 bpp\n", __func__, i);
468 jbAddPage(classer, pix);
491 return ERROR_INT(
"classer not defined", __func__, 1);
492 if (!pixs || pixGetDepth(pixs) != 1)
493 return ERROR_INT(
"pixs not defined or not 1 bpp", __func__, 1);
495 classer->
w = pixGetWidth(pixs);
496 classer->
h = pixGetHeight(pixs);
501 return ERROR_INT(
"components not made", __func__, 1);
504 jbAddPageComponents(classer, pixs, boxas, pixas);
535 return ERROR_INT(
"classer not defined", __func__, 1);
537 return ERROR_INT(
"pix not defined", __func__, 1);
549 if (classer->
method == JB_RANKHAUS) {
550 if (jbClassifyRankHaus(classer, boxas, pixas))
551 return ERROR_INT(
"rankhaus classification failed", __func__, 1);
553 if (jbClassifyCorrelation(classer, boxas, pixas))
554 return ERROR_INT(
"correlation classification failed", __func__, 1);
561 if (jbGetULCorners(classer, pixs, boxas))
562 return ERROR_INT(
"UL corners not found", __func__, 1);
589 l_int32 n, nt, i, wt, ht, iclass, size, found, testval;
590 l_int32 npages, area1, area3;
592 l_float32 rank, x1, y1, x2, y2;
594 NUMA *naclass, *napage;
599 PIX *pix, *pix1, *pix2, *pix3, *pix4;
600 PIXA *pixa, *pixa1, *pixa2, *pixat, *pixatd;
602 PTA *pta, *ptac, *ptact;
606 return ERROR_INT(
"classer not defined", __func__, 1);
608 return ERROR_INT(
"boxa not defined", __func__, 1);
610 return ERROR_INT(
"pixas not defined", __func__, 1);
612 return ERROR_INT(
"pixas is empty", __func__, 1);
614 return ERROR_INT(
"fg counting failed", __func__, 1);
624 for (i = 0; i < n; i++) {
627 JB_ADDED_PIXELS, JB_ADDED_PIXELS, 0);
637 ptac = classer->
ptac;
639 ptact = classer->
ptact;
656 pixaa = classer->
pixaa;
659 pixat = classer->
pixat;
685 for (i = 0; i < n; i++) {
691 findcontext = findSimilarSizedTemplatesInit(classer, pix1);
692 while ((iclass = findSimilarSizedTemplatesNext(findcontext)) > -1) {
697 testval = pixHaustest(pix1, pix2, pix3, pix4, x1 - x2, y1 - y2,
698 MAX_DIFF_WIDTH, MAX_DIFF_HEIGHT);
716 findSimilarSizedTemplatesDestroy(&findcontext);
717 if (found == FALSE) {
723 wt = pixGetWidth(pix);
724 ht = pixGetHeight(pix);
738 nafgt = classer->
nafgt;
740 for (i = 0; i < n; i++) {
747 findcontext = findSimilarSizedTemplatesInit(classer, pix1);
748 while ((iclass = findSimilarSizedTemplatesNext(findcontext)) > -1) {
754 testval = pixRankHaustest(pix1, pix2, pix3, pix4,
756 MAX_DIFF_WIDTH, MAX_DIFF_HEIGHT,
757 area1, area3, rank, tab8);
775 findSimilarSizedTemplatesDestroy(&findcontext);
776 if (found == FALSE) {
782 wt = pixGetWidth(pix);
783 ht = pixGetHeight(pix);
838 pixHaustest(
PIX *pix1,
847 l_int32 wi, hi, wt, ht, delw, delh, idelx, idely, boolmatch;
851 wi = pixGetWidth(pix1);
852 hi = pixGetHeight(pix1);
853 wt = pixGetWidth(pix3);
854 ht = pixGetHeight(pix3);
855 delw = L_ABS(wi - wt);
858 delh = L_ABS(hi - ht);
865 idelx = (l_int32)(delx + 0.5);
867 idelx = (l_int32)(delx - 0.5);
869 idely = (l_int32)(dely + 0.5);
871 idely = (l_int32)(dely - 0.5);
883 if (boolmatch == 0) {
936 pixRankHaustest(
PIX *pix1,
949 l_int32 wi, hi, wt, ht, delw, delh, idelx, idely, boolmatch;
950 l_int32 thresh1, thresh3;
954 wi = pixGetWidth(pix1);
955 hi = pixGetHeight(pix1);
956 wt = pixGetWidth(pix3);
957 ht = pixGetHeight(pix3);
958 delw = L_ABS(wi - wt);
961 delh = L_ABS(hi - ht);
966 thresh1 = (l_int32)(area1 * (1. - rank) + 0.5);
967 thresh3 = (l_int32)(area3 * (1. - rank) + 0.5);
972 idelx = (l_int32)(delx + 0.5);
974 idelx = (l_int32)(delx - 0.5);
976 idely = (l_int32)(dely + 0.5);
978 idely = (l_int32)(dely - 0.5);
990 if (boolmatch == 1) {
1023 jbClassifyCorrelation(
JBCLASSER *classer,
1027 l_int32 n, nt, i, iclass, wt, ht, found, area, area1, area2, npages,
1029 l_int32 *sumtab, *centtab;
1030 l_uint32 *row, word;
1031 l_float32 x1, y1, x2, y2, xsum, ysum;
1032 l_float32 thresh, weight, threshold;
1034 NUMA *naclass, *napage;
1039 PIX *pix, *pix1, *pix2;
1040 PIXA *pixa, *pixa1, *pixat;
1042 PTA *pta, *ptac, *ptact;
1044 l_int32 **pixrowcts;
1045 l_int32 x, y, rowcount, downcount, wpl;
1049 return ERROR_INT(
"classer not found", __func__, 1);
1051 return ERROR_INT(
"boxa not found", __func__, 1);
1053 return ERROR_INT(
"pixas not found", __func__, 1);
1055 npages = classer->
npages;
1060 L_WARNING(
"pixas is empty\n", __func__);
1064 for (i = 0; i < n; i++) {
1067 JB_ADDED_PIXELS, JB_ADDED_PIXELS, 0);
1074 napage = classer->
napage;
1077 nafgt = classer->
nafgt;
1080 pixcts = (l_int32 *)LEPT_CALLOC(n,
sizeof(*pixcts));
1081 pixrowcts = (l_int32 **)LEPT_CALLOC(n,
sizeof(*pixrowcts));
1092 for (i = 0; i < n; i++) {
1094 pixrowcts[i] = (l_int32 *)LEPT_CALLOC(pixGetHeight(pix),
1095 sizeof(**pixrowcts));
1098 wpl = pixGetWpl(pix);
1099 row =
pixGetData(pix) + (pixGetHeight(pix) - 1) * wpl;
1101 for (y = pixGetHeight(pix) - 1; y >= 0; y--, row -= wpl) {
1102 pixrowcts[i][y] = downcount;
1104 for (x = 0; x < wpl; x++) {
1107 rowcount += sumtab[byte];
1108 xsum += centtab[byte] + (x * 32 + 24) * sumtab[
byte];
1109 byte = (word >> 8) & 0xff;
1110 rowcount += sumtab[byte];
1111 xsum += centtab[byte] + (x * 32 + 16) * sumtab[
byte];
1112 byte = (word >> 16) & 0xff;
1113 rowcount += sumtab[byte];
1114 xsum += centtab[byte] + (x * 32 + 8) * sumtab[
byte];
1115 byte = (word >> 24) & 0xff;
1116 rowcount += sumtab[byte];
1117 xsum += centtab[byte] + x * 32 * sumtab[byte];
1119 downcount += rowcount;
1120 ysum += rowcount * y;
1122 pixcts[i] = downcount;
1123 if (downcount > 0) {
1125 xsum / (l_float32)downcount, ysum / (l_float32)downcount);
1127 L_ERROR(
"downcount == 0 !\n", __func__);
1128 ptaAddPt(pta, pixGetWidth(pix) / 2, pixGetHeight(pix) / 2);
1133 ptac = classer->
ptac;
1135 ptact = classer->
ptact;
1148 pixaa = classer->
pixaa;
1151 pixat = classer->
pixat;
1171 thresh = classer->
thresh;
1173 naarea = classer->
naarea;
1174 dahash = classer->
dahash;
1175 for (i = 0; i < n; i++) {
1181 findcontext = findSimilarSizedTemplatesInit(classer, pix1);
1182 while ( (iclass = findSimilarSizedTemplatesNext(findcontext)) > -1) {
1191 threshold = thresh + (1. - thresh) * weight * area2 / area;
1197 overthreshold = pixCorrelationScoreThresholded(pix1, pix2,
1198 area1, area2, x1 - x2, y1 - y2,
1199 MAX_DIFF_WIDTH, MAX_DIFF_HEIGHT,
1200 sumtab, pixrowcts[i], threshold);
1201 #if DEBUG_CORRELATION_SCORE
1203 l_float32 score, testscore;
1204 l_int32 count, testcount;
1205 pixCorrelationScore(pix1, pix2, area1, area2, x1 - x2, y1 - y2,
1206 MAX_DIFF_WIDTH, MAX_DIFF_HEIGHT,
1209 pixCorrelationScoreSimple(pix1, pix2, area1, area2,
1210 x1 - x2, y1 - y2, MAX_DIFF_WIDTH,
1211 MAX_DIFF_HEIGHT, sumtab, &testscore);
1212 count = (l_int32)rint(sqrt(score * area1 * area2));
1213 testcount = (l_int32)rint(sqrt(testscore * area1 * area2));
1214 if ((score >= threshold) != (testscore >= threshold)) {
1216 "%d(%g,%d) vs %d(%g,%d) (%g)\n",
1217 count, score, score >= threshold,
1218 testcount, testscore, testscore >= threshold,
1222 if ((score >= threshold) != overthreshold) {
1223 lept_stderr(
"Mismatch between correlation/threshold "
1224 "comparison: %g(%g,%d) >= %g(%g) vs %s\n",
1225 score, score*area1*area2, count, threshold,
1226 threshold*area1*area2,
1227 (overthreshold ?
"true" :
"false"));
1233 if (overthreshold) {
1249 findSimilarSizedTemplatesDestroy(&findcontext);
1250 if (found == FALSE) {
1256 wt = pixGetWidth(pix);
1257 ht = pixGetHeight(pix);
1265 area = (pixGetWidth(pix1) - 2 * JB_ADDED_PIXELS) *
1266 (pixGetHeight(pix1) - 2 * JB_ADDED_PIXELS);
1276 for (i = 0; i < n; i++) {
1277 LEPT_FREE(pixrowcts[i]);
1279 LEPT_FREE(pixrowcts);
1303 jbGetComponents(
PIX *pixs,
1310 l_int32 empty, res, redfactor;
1312 PIX *pix1, *pix2, *pix3;
1316 return ERROR_INT(
"&boxad not defined", __func__, 1);
1319 return ERROR_INT(
"&pixad not defined", __func__, 1);
1322 return ERROR_INT(
"pixs not defined", __func__, 1);
1323 if (components != JB_CONN_COMPS && components != JB_CHARACTERS &&
1324 components != JB_WORDS)
1325 return ERROR_INT(
"invalid components", __func__, 1);
1347 if (components == JB_CONN_COMPS) {
1349 }
else if (components == JB_CHARACTERS) {
1362 res = pixGetXRes(pixs);
1366 }
else if (res <= 400) {
1376 pixWordMaskByDilation(pix1, &pix2, NULL, NULL);
1443 pixWordMaskByDilation(
PIX *pixs,
1448 l_int32 i, n, ndil, maxdiff, diff, ibest;
1449 l_int32 check, count, total, xres;
1453 NUMA *nacc, *nadiff;
1456 if (ppixm) *ppixm = NULL;
1457 if (psize) *psize = 0;
1458 if (!pixs || pixGetDepth(pixs) != 1)
1459 return ERROR_INT(
"pixs undefined or not 1 bpp", __func__, 1);
1460 if (!ppixm && !psize)
1461 return ERROR_INT(
"no output requested", __func__, 1);
1469 for (i = 0; i <= ndil; i++) {
1477 if (i == 0) total = ncc[0];
1479 diff = ncc[i - 1] - ncc[i];
1496 for (i = 1; i < n; i++) {
1498 if (check && count < 0.3 * total) {
1509 xres = pixGetXRes(pixs);
1510 if (xres == 0) xres = 150;
1511 if (xres > 110) ibest++;
1513 L_INFO(
"setting ibest to minimum allowed value of 2\n", __func__);
1521 L_INFO(
"Best dilation: %d\n", __func__, L_MAX(3, ibest + 1));
1524 "/tmp/lept/jb/numcc",
1525 "Number of cc vs. horizontal dilation",
1526 "Sel horiz",
"Number of cc");
1531 "/tmp/lept/jb/diffcc",
1532 "Diff count of cc vs. horizontal dilation",
1533 "Sel horiz",
"Diff in cc");
1543 if (psize) *psize = ibest + 1;
1573 pixWordBoxesByDilation(
PIX *pixs,
1582 BOXA *boxa1, *boxa2;
1585 if (psize) *psize = 0;
1586 if (!pixs || pixGetDepth(pixs) != 1)
1587 return ERROR_INT(
"pixs undefined or not 1 bpp", __func__, 1);
1589 return ERROR_INT(
"&boxa not defined", __func__, 1);
1593 if (pixWordMaskByDilation(pixs, &pix1, psize, pixadb))
1594 return ERROR_INT(
"pixWordMaskByDilation() failed", __func__, 1);
1633 jbAccumulateComposites(
PIXAA *pixaa,
1637 l_int32 n, nt, i, j, d, minw, maxw, minh, maxh, xdiff, ydiff;
1638 l_float32 x, y, xave, yave;
1640 PIX *pix, *pixt1, *pixt2, *pixsum;
1645 return (
PIXA *)ERROR_PTR(
"&ptat not defined", __func__, NULL);
1648 return (
PIXA *)ERROR_PTR(
"&na not defined", __func__, NULL);
1651 return (
PIXA *)ERROR_PTR(
"pixaa not defined", __func__, NULL);
1655 return (
PIXA *)ERROR_PTR(
"ptat not made", __func__, NULL);
1661 for (i = 0; i < n; i++) {
1666 L_WARNING(
"empty pixa found!\n", __func__);
1672 d = pixGetDepth(pix);
1680 for (j = 0; j < nt; j++) {
1685 xave = xave / (l_float32)nt;
1686 yave = yave / (l_float32)nt;
1689 for (j = 0; j < nt; j++) {
1692 xdiff = (l_int32)(x - xave);
1693 ydiff = (l_int32)(y - yave);
1721 jbTemplatesFromComposites(
PIXA *pixac,
1732 return (
PIXA *)ERROR_PTR(
"pixac not defined", __func__, NULL);
1734 return (
PIXA *)ERROR_PTR(
"na not defined", __func__, NULL);
1738 for (i = 0; i < n; i++) {
1764 jbClasserCreate(l_int32 method,
1769 if (method != JB_RANKHAUS && method != JB_CORRELATION)
1770 return (
JBCLASSER *)ERROR_PTR(
"invalid method", __func__, NULL);
1771 if (components != JB_CONN_COMPS && components != JB_CHARACTERS &&
1772 components != JB_WORDS)
1773 return (
JBCLASSER *)ERROR_PTR(
"invalid component", __func__, NULL);
1776 classer->
method = method;
1806 if ((classer = *pclasser) == NULL)
1856 return (
JBDATA *)ERROR_PTR(
"classer not defined", __func__, NULL);
1863 return (
JBDATA *)ERROR_PTR(
"data not made", __func__, NULL);
1868 data->
w = classer->
w;
1869 data->
h = classer->
h;
1887 jbDataDestroy(
JBDATA **pdata)
1893 if ((data = *pdata) == NULL)
1918 jbDataWrite(
const char *rootout,
1922 l_int32 w, h, nclass, npages, cellw, cellh, ncomp, i, x, y, iclass, ipage;
1923 NUMA *naclass, *napage;
1929 return ERROR_INT(
"no rootout", __func__, 1);
1931 return ERROR_INT(
"no jbdata", __func__, 1);
1942 ptaul = jbdata->
ptaul;
1945 pixWrite(buf, pixt, IFF_PNG);
1947 snprintf(buf,
L_BUF_SIZE,
"%s%s", rootout, JB_DATA_EXT);
1949 return ERROR_INT(
"stream not opened", __func__, 1);
1951 fprintf(fp,
"jb data file\n");
1952 fprintf(fp,
"num pages = %d\n", npages);
1953 fprintf(fp,
"page size: w = %d, h = %d\n", w, h);
1954 fprintf(fp,
"num components = %d\n", ncomp);
1955 fprintf(fp,
"num classes = %d\n", nclass);
1956 fprintf(fp,
"template lattice size: w = %d, h = %d\n", cellw, cellh);
1957 for (i = 0; i < ncomp; i++) {
1961 fprintf(fp,
"%d %d %d %d\n", ipage, iclass, x, y);
1976 jbDataRead(
const char *rootname)
1981 l_int32 nsa, i, w, h, cellw, cellh, x, y, iclass, ipage;
1982 l_int32 npages, nclass, ncomp, ninit;
1985 NUMA *naclass, *napage;
1991 return (
JBDATA *)ERROR_PTR(
"rootname not defined", __func__, NULL);
1994 if ((pixs =
pixRead(fname)) == NULL)
1995 return (
JBDATA *)ERROR_PTR(
"pix not read", __func__, NULL);
1997 snprintf(fname,
L_BUF_SIZE,
"%s%s", rootname, JB_DATA_EXT);
2000 return (
JBDATA *)ERROR_PTR(
"data not read", __func__, NULL);
2006 return (
JBDATA *)ERROR_PTR(
"sa not made", __func__, NULL);
2010 if (strcmp(linestr,
"jb data file") != 0) {
2014 return (
JBDATA *)ERROR_PTR(
"invalid jb data file", __func__, NULL);
2017 sscanf(linestr,
"num pages = %d", &npages);
2019 sscanf(linestr,
"page size: w = %d, h = %d", &w, &h);
2021 sscanf(linestr,
"num components = %d", &ncomp);
2023 sscanf(linestr,
"num classes = %d\n", &nclass);
2025 sscanf(linestr,
"template lattice size: w = %d, h = %d\n", &cellw, &cellh);
2032 lept_stderr(
"template lattice size: w = %d, h = %d\n", cellw, cellh);
2036 if (ncomp > 1000000) {
2037 L_WARNING(
"ncomp > 1M\n", __func__);
2043 for (i = 6; i < nsa; i++) {
2045 sscanf(linestr,
"%d %d %d %d\n", &ipage, &iclass, &x, &y);
2061 jbdata->
ptaul = ptaul;
2079 jbDataRender(
JBDATA *data,
2082 l_int32 i, w, h, cellw, cellh, x, y, iclass, ipage;
2083 l_int32 npages, nclass, ncomp, wp, hp;
2085 NUMA *naclass, *napage;
2086 PIX *pixt, *pixt2, *pix, *pixd;
2093 return (
PIXA *)ERROR_PTR(
"data not defined", __func__, NULL);
2104 ptaul = data->
ptaul;
2111 return (
PIXA *)ERROR_PTR(
"pixad not made", __func__, NULL);
2112 for (i = 0; i < npages; i++) {
2113 if (debugflag == FALSE) {
2129 return (
PIXA *)ERROR_PTR(
"pixat not made", __func__, NULL);
2133 for (i = 0; i < ncomp; i++) {
2137 wp = pixGetWidth(pix);
2138 hp = pixGetHeight(pix);
2141 if (debugflag == FALSE) {
2190 l_int32 i, baseindex, index, n, iclass, idelx, idely, x, y, dx, dy;
2192 l_float32 x1, x2, y1, y2, delx, dely;
2196 PTA *ptac, *ptact, *ptaul;
2199 return ERROR_INT(
"classer not defined", __func__, 1);
2201 return ERROR_INT(
"pixs not defined", __func__, 1);
2203 return ERROR_INT(
"boxa not defined", __func__, 1);
2206 ptaul = classer->
ptaul;
2208 ptac = classer->
ptac;
2209 ptact = classer->
ptact;
2212 for (i = 0; i < n; i++) {
2213 index = baseindex + i;
2220 idelx = (l_int32)(delx + 0.5);
2222 idelx = (l_int32)(delx - 0.5);
2224 idely = (l_int32)(dely + 0.5);
2226 idely = (l_int32)(dely - 0.5);
2229 return ERROR_INT(
"box not found", __func__, 1);
2235 finalPositioningForAlignment(pixs, x, y, idelx, idely,
2236 pixt, sumtab, &dx, &dy);
2239 ptaAddPt(ptaul, x - idelx + dx, y - idely + dy);
2278 l_int32 i, iclass, n, x1, y1, h;
2285 return ERROR_INT(
"classer not defined", __func__, 1);
2287 ptaul = classer->
ptaul;
2289 pixat = classer->
pixat;
2294 classer->
ptall = ptall;
2301 for (i = 0; i < n; i++) {
2305 h = pixGetHeight(pix);
2306 ptaAddPt(ptall, x1, y1 + h - 1 - 2 * JB_ADDED_PIXELS);
2321 static int two_by_two_walk[50] = {
2357 findSimilarSizedTemplatesInit(
JBCLASSER *classer,
2363 state->w = pixGetWidth(pixs) - 2 * JB_ADDED_PIXELS;
2364 state->h = pixGetHeight(pixs) - 2 * JB_ADDED_PIXELS;
2365 state->classer = classer;
2371 findSimilarSizedTemplatesDestroy(
JBFINDCTX **pstate)
2375 if (pstate == NULL) {
2376 L_WARNING(
"ptr address is null\n", __func__);
2379 if ((state = *pstate) == NULL)
2407 findSimilarSizedTemplatesNext(
JBFINDCTX *state)
2409 l_int32 desiredh, desiredw, size, templ;
2413 if (state->i >= 25) {
2417 desiredw = state->w + two_by_two_walk[2 * state->i];
2418 desiredh = state->h + two_by_two_walk[2 * state->i + 1];
2419 if (desiredh < 1 || desiredw < 1) {
2427 (l_uint64)desiredh * desiredw,
L_CLONE);
2438 for ( ; state->n < size; ) {
2439 templ = (l_int32)(state->dna->
array[state->n++] + 0.5);
2441 if (pixGetWidth(pixt) - 2 * JB_ADDED_PIXELS == desiredw &&
2442 pixGetHeight(pixt) - 2 * JB_ADDED_PIXELS == desiredh) {
2474 finalPositioningForAlignment(
PIX *pixs,
2484 l_int32 w, h, i, j, minx, miny, count, mincount;
2490 return ERROR_INT(
"pixs not defined", __func__, 1);
2492 return ERROR_INT(
"pixt not defined", __func__, 1);
2494 return ERROR_INT(
"&dx and &dy not both defined", __func__, 1);
2496 return ERROR_INT(
"sumtab not defined", __func__, 1);
2501 box =
boxCreate(x - idelx - JB_ADDED_PIXELS,
2502 y - idely - JB_ADDED_PIXELS, w, h);
2506 return ERROR_INT(
"pixi not made", __func__, 1);
2508 pixr =
pixCreate(pixGetWidth(pixi), pixGetHeight(pixi), 1);
2509 mincount = 0x7fffffff;
2510 for (i = -1; i <= 1; i++) {
2511 for (j = -1; j <= 1; j++) {
2515 if (count < mincount) {
PIX * pixReduceRankBinaryCascade(PIX *pixs, l_int32 level1, l_int32 level2, l_int32 level3, l_int32 level4)
pixReduceRankBinaryCascade()
l_ok boxGetGeometry(const BOX *box, l_int32 *px, l_int32 *py, l_int32 *pw, l_int32 *ph)
boxGetGeometry()
void boxDestroy(BOX **pbox)
boxDestroy()
void boxaDestroy(BOXA **pboxa)
boxaDestroy()
l_int32 boxaGetCount(const BOXA *boxa)
boxaGetCount()
BOX * boxaGetBox(BOXA *boxa, l_int32 index, l_int32 accessflag)
boxaGetBox()
BOX * boxCreate(l_int32 x, l_int32 y, l_int32 w, l_int32 h)
boxCreate()
BOXA * boxaCreate(l_int32 n)
boxaCreate()
BOXA * boxaSelectBySize(BOXA *boxas, l_int32 width, l_int32 height, l_int32 type, l_int32 relation, l_int32 *pchanged)
boxaSelectBySize()
PIXCMAP * pixcmapCreate(l_int32 depth)
pixcmapCreate()
l_ok pixcmapAddColor(PIXCMAP *cmap, l_int32 rval, l_int32 gval, l_int32 bval)
pixcmapAddColor()
BOXA * pixConnCompBB(PIX *pixs, l_int32 connectivity)
pixConnCompBB()
BOXA * pixConnComp(PIX *pixs, PIXA **ppixa, l_int32 connectivity)
pixConnComp()
void l_dnaDestroy(L_DNA **pda)
l_dnaDestroy()
l_int32 l_dnaGetCount(L_DNA *da)
l_dnaGetCount()
void l_dnaHashDestroy(L_DNAHASH **pdahash)
l_dnaHashDestroy()
L_DNAHASH * l_dnaHashCreate(l_int32 nbuckets, l_int32 initsize)
l_dnaHashCreate()
L_DNA * l_dnaHashGetDna(L_DNAHASH *dahash, l_uint64 key, l_int32 copyflag)
l_dnaHashGetDna()
l_ok l_dnaHashAdd(L_DNAHASH *dahash, l_uint64 key, l_float64 value)
l_dnaHashAdd()
PIX * gplotGeneralPix2(NUMA *na1, NUMA *na2, l_int32 plotstyle, const char *rootname, const char *title, const char *xlabel, const char *ylabel)
gplotGeneralPix2()
l_ok pixRenderBoxArb(PIX *pix, BOX *box, l_int32 width, l_uint8 rval, l_uint8 gval, l_uint8 bval)
pixRenderBoxArb()
l_ok pixRenderBoxaArb(PIX *pix, BOXA *boxa, l_int32 width, l_uint8 rval, l_uint8 gval, l_uint8 bval)
pixRenderBoxaArb()
PIX * pixDilate(PIX *pixd, PIX *pixs, SEL *sel)
pixDilate()
PIX * pixCloseBrick(PIX *pixd, PIX *pixs, l_int32 hsize, l_int32 vsize)
pixCloseBrick()
PTA * pixaCentroids(PIXA *pixa)
pixaCentroids()
PIX * pixMorphSequence(PIX *pixs, const char *sequence, l_int32 dispsep)
pixMorphSequence()
l_ok numaAddNumber(NUMA *na, l_float32 val)
numaAddNumber()
l_ok numaGetFValue(NUMA *na, l_int32 index, l_float32 *pval)
numaGetFValue()
NUMA * numaCreate(l_int32 n)
numaCreate()
NUMA * numaClone(NUMA *na)
numaClone()
void numaDestroy(NUMA **pna)
numaDestroy()
l_int32 numaGetCount(NUMA *na)
numaGetCount()
l_ok numaGetIValue(NUMA *na, l_int32 index, l_int32 *pival)
numaGetIValue()
l_int32 * numaGetIArray(NUMA *na)
numaGetIArray()
NUMA * numaMakeSequence(l_float32 startval, l_float32 increment, l_int32 size)
numaMakeSequence()
l_uint32 * pixGetData(PIX *pix)
pixGetData()
l_ok pixSetColormap(PIX *pix, PIXCMAP *colormap)
pixSetColormap()
void pixDestroy(PIX **ppix)
pixDestroy()
l_ok pixGetDimensions(const PIX *pix, l_int32 *pw, l_int32 *ph, l_int32 *pd)
pixGetDimensions()
PIX * pixCopy(PIX *pixd, const PIX *pixs)
pixCopy()
PIX * pixCreateTemplate(const PIX *pixs)
pixCreateTemplate()
PIX * pixCreate(l_int32 width, l_int32 height, l_int32 depth)
pixCreate()
PIX * pixClone(PIX *pixs)
pixClone()
l_ok pixClearAll(PIX *pix)
pixClearAll()
PIX * pixAddBorderGeneral(PIX *pixs, l_int32 left, l_int32 right, l_int32 top, l_int32 bot, l_uint32 val)
pixAddBorderGeneral()
l_ok pixZero(PIX *pix, l_int32 *pempty)
pixZero()
NUMA * pixaCountPixels(PIXA *pixa)
pixaCountPixels()
l_ok pixCountPixels(PIX *pixs, l_int32 *pcount, l_int32 *tab8)
pixCountPixels()
l_int32 * makePixelSumTab8(void)
makePixelSumTab8()
l_int32 * makePixelCentroidTab8(void)
makePixelCentroidTab8()
l_ok pixThresholdPixelSum(PIX *pix, l_int32 thresh, l_int32 *pabove, l_int32 *tab8)
pixThresholdPixelSum()
PIX * pixClipRectangle(PIX *pixs, BOX *box, BOX **pboxc)
pixClipRectangle()
PIXAA * pixaaCreate(l_int32 n)
pixaaCreate()
l_ok pixaAddPix(PIXA *pixa, PIX *pix, l_int32 copyflag)
pixaAddPix()
void pixaDestroy(PIXA **ppixa)
pixaDestroy()
l_ok pixaaAddPixa(PIXAA *paa, PIXA *pixa, l_int32 copyflag)
pixaaAddPixa()
PIXA * pixaCreate(l_int32 n)
pixaCreate()
l_int32 pixaGetCount(PIXA *pixa)
pixaGetCount()
l_ok pixaAddBox(PIXA *pixa, BOX *box, l_int32 copyflag)
pixaAddBox()
void pixaaDestroy(PIXAA **ppaa)
pixaaDestroy()
l_int32 pixaaGetCount(PIXAA *paa, NUMA **pna)
pixaaGetCount()
PIXA * pixaaGetPixa(PIXAA *paa, l_int32 index, l_int32 accesstype)
pixaaGetPixa()
PIX * pixaGetPix(PIXA *pixa, l_int32 index, l_int32 accesstype)
pixaGetPix()
PIXA * pixaCreateFromPix(PIX *pixs, l_int32 n, l_int32 cellw, l_int32 cellh)
pixaCreateFromPix()
l_ok pixaSizeRange(PIXA *pixa, l_int32 *pminw, l_int32 *pminh, l_int32 *pmaxw, l_int32 *pmaxh)
pixaSizeRange()
PIXA * pixaSelectBySize(PIXA *pixas, l_int32 width, l_int32 height, l_int32 type, l_int32 relation, l_int32 *pchanged)
pixaSelectBySize()
PIXA * pixaClipToPix(PIXA *pixas, PIX *pixs)
pixaClipToPix()
PIX * pixaDisplayOnLattice(PIXA *pixa, l_int32 cellw, l_int32 cellh, l_int32 *pncols, BOXA **pboxa)
pixaDisplayOnLattice()
l_ok pixMultConstAccumulate(PIX *pixs, l_float32 factor, l_uint32 offset)
pixMultConstAccumulate()
PIX * pixInitAccumulate(l_int32 w, l_int32 h, l_uint32 offset)
pixInitAccumulate()
PIX * pixFinalAccumulate(PIX *pixs, l_uint32 offset, l_int32 depth)
pixFinalAccumulate()
l_ok pixAccumulate(PIX *pixd, PIX *pixs, l_int32 op)
pixAccumulate()
PIX * pixUnpackBinary(PIX *pixs, l_int32 depth, l_int32 invert)
pixUnpackBinary()
PIX * pixConvert1To2Cmap(PIX *pixs)
pixConvert1To2Cmap()
l_ok ptaGetIPt(PTA *pta, l_int32 index, l_int32 *px, l_int32 *py)
ptaGetIPt()
PTA * ptaClone(PTA *pta)
ptaClone()
l_ok ptaAddPt(PTA *pta, l_float32 x, l_float32 y)
ptaAddPt()
l_ok ptaGetPt(PTA *pta, l_int32 index, l_float32 *px, l_float32 *py)
ptaGetPt()
l_int32 ptaGetCount(PTA *pta)
ptaGetCount()
PTA * ptaCreate(l_int32 n)
ptaCreate()
void ptaDestroy(PTA **ppta)
ptaDestroy()
l_ok ptaJoin(PTA *ptad, PTA *ptas, l_int32 istart, l_int32 iend)
ptaJoin()
PIX * pixRead(const char *filename)
pixRead()
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()
char * sarrayGetString(SARRAY *sa, l_int32 index, l_int32 copyflag)
sarrayGetString()
l_int32 sarrayGetCount(SARRAY *sa)
sarrayGetCount()
void sarrayDestroy(SARRAY **psa)
sarrayDestroy()
SARRAY * sarrayCreateLinesFromString(const char *string, l_int32 blankflag)
sarrayCreateLinesFromString()
SARRAY * sarrayCopy(SARRAY *sa)
sarrayCopy()
PIX * pixScaleToSize(PIX *pixs, l_int32 wd, l_int32 hd)
pixScaleToSize()
PIX * pixExpandReplicate(PIX *pixs, l_int32 factor)
pixExpandReplicate()
void selDestroy(SEL **psel)
selDestroy()
SEL * selCreateBrick(l_int32 h, l_int32 w, l_int32 cy, l_int32 cx, l_int32 type)
selCreateBrick()
struct L_DnaHash * dahash
void lept_stderr(const char *fmt,...)
lept_stderr()
FILE * fopenWriteStream(const char *filename, const char *modestring)
fopenWriteStream()
l_int32 lept_mkdir(const char *subdir)
lept_mkdir()
l_uint8 * l_binaryRead(const char *filename, size_t *pnbytes)
l_binaryRead()