示例#1
0
/* ----------------------------------------------------- */
void PixaDisplayNumbered(PIXA        *pixa,
                         const char  *basename)
{
char     buf[64];
l_int32  fill, color, d;
L_BMF   *bmf;
PIX     *pix1;
PIXA    *pixa1, *pixa2;

    bmf = bmfCreate(NULL, 4);
    pixaGetPixDimensions(pixa, 0, NULL, NULL, &d);
    fill = (d == 8) ? 0xff : 0;
    color = (d == 8) ? 0x00000000 : 0xffffff00;
    pixa1 = pixaAddBorderGeneral(NULL, pixa, 10, 10, 0, 0, fill);
    pixa2 = pixaAddTextNumber(pixa1, bmf, NULL, color, L_ADD_BELOW);
    snprintf(buf, sizeof(buf), "%s.pa", basename);
    pixaWrite(buf, pixa2);
    pix1 = pixaDisplayTiledInColumns(pixa2, 20, 2.5, 15, 2);
    snprintf(buf, sizeof(buf), "%s.png", basename);
    pixWrite(buf, pix1, IFF_PNG);
    pixDisplay(pix1, 500, 500);
    pixDestroy(&pix1);
    pixaDestroy(&pixa1);
    pixaDestroy(&pixa2);
    bmfDestroy(&bmf);
}
示例#2
0
/*!
 *  pixaSaveFont()
 *
 *      Input:  indir (directory holding image of character set)
 *              outdir (directory into which the output pixa file
 *                      will be written)
 *              size (in pts, at 300 ppi)
 *      Return: 0 if OK, 1 on error
 *
 *  Notes:
 *      (1) This saves a font of a particular size.
 *      (2) prog/genfonts calls this function for each of the
 *          nine font sizes, to generate all the font pixa files.
 */
l_int32
pixaSaveFont(const char  *indir,
             const char  *outdir,
             l_int32      size)
{
char    *pathname;
l_int32  bl1, bl2, bl3;
PIXA    *pixa;

    PROCNAME("pixaSaveFont");

    if (size < 4 || size > 20 || (size % 2))
        return ERROR_INT("size must be in {4, 6, ..., 20}", procName, 1);

    if ((pixa = pixaGenerateFont(indir, size, &bl1, &bl2, &bl3)) == NULL)
        return ERROR_INT("pixa not made", procName, 1);
    pathname = genPathname(outdir, outputfonts[(size - 4) / 2]);
    pixaWrite(pathname, pixa);

#if  DEBUG_FONT_GEN
    fprintf(stderr, "Found %d chars in font size %d\n",
            pixaGetCount(pixa), size);
    fprintf(stderr, "Baselines are at: %d, %d, %d\n", bl1, bl2, bl3);
#endif  /* DEBUG_FONT_GEN */

    FREE(pathname);
    pixaDestroy(&pixa);
    return 0;
}
示例#3
0
l_int32 main(int argc,
             char **argv) {
    l_int32 i, same;
    PIXA *pixa;

    for (i = 0; i < 2; i++) {
        pixa = (PIXA *) l_autodecode_137(i);  /* this is the dispatcher */
        pixaWrite("/tmp/junkpa.pa", pixa);
        filesAreIdentical("/tmp/junkpa.pa", files[i], &same);
        if (same)
            fprintf(stderr, "Files are the same for %s\n", files[i]);
        else
            fprintf(stderr, "Error: files are different for %s\n", files[i]);
        pixaDestroy(&pixa);
    }

    return 0;
}
示例#4
0
/*!
 *  recogWritePixa()
 *
 *      Input:  filename
 *              recog
 *      Return: 0 if OK, 1 on error
 *
 *  Notes:
 *      (1) This generates a pixa of all the unscaled images in the
 *          recognizer, where each one has its character string in
 *          the pix text field, by flattening pixaa_u to a pixa.
 *      (2) As a side-effect, the character class label is written
 *          into each pix in recog.
 */
l_int32
recogWritePixa(const char  *filename,
               L_RECOG     *recog)
{
PIXA  *pixa;

    PROCNAME("recogWritePixa");

    if (!filename)
        return ERROR_INT("filename not defined", procName, 1);
    if (!recog)
        return ERROR_INT("recog not defined", procName, 1);

    recogAddCharstrLabels(recog);
    pixa = pixaaFlattenToPixa(recog->pixaa_u, NULL, L_CLONE);
    pixaWrite(filename, pixa);
    pixaDestroy(&pixa);
    return 0;
}
示例#5
0
PIXA *MakeBootnum2(void)
{
char     *fname;
l_int32   i, n, w, h;
BOX      *box;
PIX      *pix;
PIXA     *pixa;
L_RECOG  *recog;
SARRAY   *sa;

        /* Phase 1: generate recog from the digit data */
    recog = recogCreate(20, 32, L_USE_ALL, 120, 1);
    sa = getSortedPathnamesInDirectory("recog/bootnums", "png", 0, 0);
    n = sarrayGetCount(sa);
    for (i = 0; i < n; i++) {
            /* Read each pix: grayscale, multi-character, labelled */
        fname = sarrayGetString(sa, i, L_NOCOPY);
        if ((pix = pixRead(fname)) == NULL) {
            fprintf(stderr, "Can't read %s\n", fname);
            continue;
        }

            /* Convert to a set of 1 bpp, single character, labelled */
        pixGetDimensions(pix, &w, &h, NULL);
        box = boxCreate(0, 0, w, h);
        recogTrainLabelled(recog, pix, box, NULL, 1, 0);
        pixDestroy(&pix);
        boxDestroy(&box);
    }
    recogTrainingFinished(recog, 1);
    sarrayDestroy(&sa);

        /* Phase 2: generate pixa consisting of 1 bpp, single character pix */
    pixa = recogExtractPixa(recog);
    pixaWrite("/tmp/lept/recog/digits/bootnum2.pa", pixa);
    recogDestroy(&recog);
    return pixa;
}
/*!
 *  pixaSaveFont()
 *
 *      Input:  indir (<optional> directory holding image of character set)
 *              outdir (directory into which the output pixa file
 *                      will be written)
 *              fontsize (in pts, at 300 ppi)
 *      Return: 0 if OK, 1 on error
 *
 *  Notes:
 *      (1) This saves a font of a particular size.
 *      (2) If @dir == null, this generates the font bitmaps from a
 *          compiled string.
 *      (3) prog/genfonts calls this function for each of the
 *          nine font sizes, to generate all the font pixa files.
 */
l_int32
pixaSaveFont(const char  *indir,
             const char  *outdir,
             l_int32      fontsize)
{
char    *pathname;
l_int32  bl1, bl2, bl3;
PIXA    *pixa;

    PROCNAME("pixaSaveFont");

    if (fontsize < 4 || fontsize > 20 || (fontsize % 2))
        return ERROR_INT("fontsize must be in {4, 6, ..., 20}", procName, 1);

    if (!indir) {  /* Generate from a string */
        L_INFO("Generating pixa of bitmap fonts from string\n", procName);
        pixa = pixaGenerateFontFromString(fontsize, &bl1, &bl2, &bl3);
    } else {  /* Generate from an image file */
        L_INFO("Generating pixa of bitmap fonts from a file\n", procName);
        pixa = pixaGenerateFontFromFile(indir, fontsize, &bl1, &bl2, &bl3);
    }
    if (!pixa)
        return ERROR_INT("pixa not made", procName, 1);

    pathname = genPathname(outdir, outputfonts[(fontsize - 4) / 2]);
    pixaWrite(pathname, pixa);

#if  DEBUG_FONT_GEN
    L_INFO("Found %d chars in font size %d\n", procName, pixaGetCount(pixa),
           fontsize);
    L_INFO("Baselines are at: %d, %d, %d\n", procName, bl1, bl2, bl3);
#endif  /* DEBUG_FONT_GEN */

    FREE(pathname);
    pixaDestroy(&pixa);
    return 0;
}
示例#7
0
main(int    argc,
     char **argv)
{
char        *filein;
l_int32      i, n, ns;
BOX         *box;
BOXA        *boxa, *boxas;
PIX         *pixs, *pixt;
PIXA        *pixa, *pixas, *pixas2;
static char  mainName[] = "sorttest";

    if (argc != 2)
	exit(ERROR_INT(" Syntax:  sorttest filein", mainName, 1));

    filein = argv[1];

    if ((pixs = pixRead(filein)) == NULL)
	exit(ERROR_INT("pixs not made", mainName, 1));

#if 0
    boxa = pixConnComp(pixs, NULL, 8);
    n = boxaGetCount(boxa);

    boxas = boxaSort(boxa, L_SORT_BY_PERIMETER, L_SORT_DECREASING, NULL);
    ns = boxaGetCount(boxas);
    fprintf(stderr, "Number of cc: n = %d, ns = %d\n", n, ns);
    boxaWrite("/tmp/junkboxa.ba", boxas);

    for (i = 0; i < n; i++) {
	box = boxaGetBox(boxas, i, L_CLONE);
	pixRenderBox(pixs, box, 2, L_FLIP_PIXELS);
	boxDestroy(&box);
    }
    pixWrite("/tmp/junkout.png", pixs, IFF_PNG);
    boxaDestroy(&boxa);
    boxaDestroy(&boxas);
#endif


#if 1
    boxa = pixConnComp(pixs, &pixa, 8);
    n = pixaGetCount(pixa);

    pixas = pixaSort(pixa, L_SORT_BY_Y, L_SORT_INCREASING, NULL, L_CLONE);
    ns = pixaGetCount(pixas);
    fprintf(stderr, "Number of cc: n = %d, ns = %d\n", n, ns);
    pixaWrite("/tmp/junkpixa.pa", pixas);
    pixas2 = pixaRead("/tmp/junkpixa.pa");
    pixaWrite("/tmp/junkpixa2.pa", pixas2);

    pixt = pixaDisplayOnLattice(pixas, 100, 100);
    pixWrite("/tmp/junkpix.png", pixt, IFF_PNG);
    boxaWrite("/tmp/junkboxa.ba", pixas->boxa);
    pixDestroy(&pixt);
    pixaDestroy(&pixa);
    pixaDestroy(&pixas);
    pixaDestroy(&pixas2);
    boxaDestroy(&boxa);
#endif

    pixDestroy(&pixs);
    return 0;
}
示例#8
0
int main(int    argc,
         char **argv)
{
char          buf[512];
char         *pathname, *datastr, *formstr;
l_uint8      *data1, *data2;
l_int32       i, bl1, bl2, bl3, sbytes, formbytes, fontsize, rbytes;
size_t        nbytes;
PIX          *pix1, *pix2, *pixd;
PIXA         *pixa;
L_REGPARAMS  *rp;

    if (regTestSetup(argc, argv, &rp))
        return 1;

    /* ------------  Generate pixa char bitmap files from file ----------- */
    lept_rmdir("filefonts");
    lept_mkdir("filefonts");
    for (i = 0; i < 9; i++) {
        pixaSaveFont("fonts", "/tmp/filefonts", sizes[i]);
        pathname = genPathname("/tmp/filefonts", outputfonts[i]);
        pixa = pixaRead(pathname);
        if (rp->display) {
            fprintf(stderr, "Found %d chars in font size %d\n",
                    pixaGetCount(pixa), sizes[i]);
        }
        pixd = pixaDisplayTiled(pixa, 1500, 0, 15);
        regTestWritePixAndCheck(rp, pixd, IFF_PNG);  /* 0 - 8 */
        if (i == 2) pixDisplayWithTitle(pixd, 100, 0, NULL, rp->display);
        pixDestroy(&pixd);
        pixaDestroy(&pixa);
        lept_free(pathname);
    }
    lept_rmdir("filefonts");

    /* ----------  Generate pixa char bitmap files from string --------- */
    lept_rmdir("strfonts");
    lept_mkdir("strfonts");
    for (i = 0; i < 9; i++) {
        pixaSaveFont(NULL, "/tmp/strfonts", sizes[i]);
        pathname = genPathname("/tmp/strfonts", outputfonts[i]);
        pixa = pixaRead(pathname);
        if (rp->display) {
            fprintf(stderr, "Found %d chars in font size %d\n",
                    pixaGetCount(pixa), sizes[i]);
        }
        pixd = pixaDisplayTiled(pixa, 1500, 0, 15);
        regTestWritePixAndCheck(rp, pixd, IFF_PNG);  /* 9 - 17 */
        if (i == 2) pixDisplayWithTitle(pixd, 100, 150, NULL, rp->display);
        pixDestroy(&pixd);
        pixaDestroy(&pixa);
        lept_free(pathname);
    }

    /* -----  Use pixaGetFont() and write the result out  -----*/
    lept_rmdir("pafonts");
    lept_mkdir("pafonts");
    for (i = 0; i < 9; i++) {
        pixa = pixaGetFont("/tmp/strfonts", sizes[i], &bl1, &bl2, &bl3);
        fprintf(stderr, "Baselines are at: %d, %d, %d\n", bl1, bl2, bl3);
        snprintf(buf, sizeof(buf), "/tmp/pafonts/chars-%d.pa", sizes[i]);
        pixaWrite(buf, pixa);
        if (i == 2) {
            pixd = pixaDisplayTiled(pixa, 1500, 0, 15);
            pixDisplayWithTitle(pixd, 100, 300, NULL, rp->display);
            pixDestroy(&pixd);
        }
        pixaDestroy(&pixa);
    }
    lept_rmdir("pafonts");

    /* -------  Generate 4/3 encoded ascii strings from tiff files ------ */
    lept_rmdir("fontencode");
    lept_mkdir("fontencode");
    for (i = 0; i < 9; i++) {
        fontsize = 2 * i + 4;
        pathname = genPathname("fonts", inputfonts[i]);
        data1 = l_binaryRead(pathname, &nbytes);
        datastr = encodeBase64(data1, nbytes, &sbytes);
        if (rp->display)
            fprintf(stderr, "nbytes = %lu, sbytes = %d\n",
                    (unsigned long)nbytes, sbytes);
        formstr = reformatPacked64(datastr, sbytes, 4, 72, 1, &formbytes);
        snprintf(buf, sizeof(buf), "/tmp/fontencode/formstr_%d.txt", fontsize);
        l_binaryWrite(buf, "w", formstr, formbytes);
        regTestCheckFile(rp, buf);  /* 18-26 */
        if (i == 8)
            pix1 = pixReadMem(data1, nbytes);  /* original */
        FREE(data1);

        data2 = decodeBase64(datastr, sbytes, &rbytes);
        snprintf(buf, sizeof(buf), "/tmp/fontencode/image_%d.tif", fontsize);
        l_binaryWrite(buf, "w", data2, rbytes);
        if (i == 8) {
            pix2 = pixReadMem(data2, rbytes);  /* encode/decode */
            regTestComparePix(rp, pix1, pix2);  /* 27 */
            pixDestroy(&pix1);
            pixDestroy(&pix2);
        }
        FREE(data2);

        FREE(pathname);
        FREE(datastr);
        FREE(formstr);
    }

    /* ------------  Get timing for font generation ----------- */
    startTimer();
    for (i = 0; i < 100; i++) {
        pixa = pixaGenerateFontFromString(sizes[5], &bl1, &bl2, &bl3);
        pixaDestroy(&pixa);
    }
    fprintf(stderr, "Time for font gen = %7.4f sec\n", stopTimer() / 100.0);

    return regTestCleanup(rp);
}
示例#9
0
/* ----------------------------------------------------- */
void ProcessDigits(l_int32  index)
{
char       rootname[8] = "digit5";
char       buf[64];
l_int32    i, nc, ns, same;
NUMA      *na1;
PIX       *pix1, *pix2, *pix3, *pix4, *pix5, *pix6;
PIXA      *pixa1, *pixa2, *pixa3;

        /* Read the unfiltered, unscaled pixa of twenty-five 5s */
    snprintf(buf, sizeof(buf), "digits/%s.orig-25.pa", rootname);
    pixa1 = pixaRead(buf);

        /* Number and show the input images */
    snprintf(buf, sizeof(buf), "/tmp/lept/digit/%s.orig-num", rootname);
    PixaDisplayNumbered(pixa1, buf);

        /* Remove some of them */
    na1 = numaCreateFromString(removeset);
    pixaRemoveSelected(pixa1, na1);
    numaDestroy(&na1);
    snprintf(buf, sizeof(buf), "/tmp/lept/digit/%s.filt.pa", rootname);
    pixaWrite(buf, pixa1);

        /* Number and show the filtered images */
    snprintf(buf, sizeof(buf), "/tmp/lept/digit/%s.filt-num", rootname);
    PixaDisplayNumbered(pixa1, buf);

        /* Extract the largest c.c., clip to the foreground,
         * and scale the result to a fixed size. */
    nc = pixaGetCount(pixa1);
    pixa2 = pixaCreate(nc);
    for (i = 0; i < nc; i++) {
        pix1 = pixaGetPix(pixa1, i, L_CLONE);
            /* A threshold of 140 gives reasonable results */
        pix2 = pixThresholdToBinary(pix1, 140);
            /* Join nearly touching pieces */
        pix3 = pixCloseSafeBrick(NULL, pix2, 5, 5);
            /* Take the largest (by area) connected component */
        pix4 = pixFilterComponentBySize(pix3, 0, L_SELECT_BY_AREA, 8, NULL);
            /* Extract the original 1 bpp pixels that have been
             * covered by the closing operation */
        pixAnd(pix4, pix4, pix2);
            /* Grab the result as an image with no surrounding whitespace */
        pixClipToForeground(pix4, &pix5, NULL);
            /* Rescale the result to the canonical size */
        pix6 = pixScaleToSize(pix5, 20, 30);
        pixaAddPix(pixa2, pix6, L_INSERT);
        pixDestroy(&pix1);
        pixDestroy(&pix2);
        pixDestroy(&pix3);
        pixDestroy(&pix4);
        pixDestroy(&pix5);
    }

        /* Add the index (a "5") in the text field of each pix; save pixa2 */
    snprintf(buf, sizeof(buf), "%d", index);
    for (i = 0; i < nc; i++) {
        pix1 = pixaGetPix(pixa2, i, L_CLONE);
        pixSetText(pix1, buf);
        pixDestroy(&pix1);
    }
    snprintf(buf, sizeof(buf), "/tmp/lept/digit/%s.comp.pa", rootname);
    pixaWrite(buf, pixa2);

        /* Number and show the resulting binary templates */
    snprintf(buf, sizeof(buf), "/tmp/lept/digit/%s.comp-num", rootname);
    PixaDisplayNumbered(pixa2, buf);

        /* Save the binary templates as a packed tiling (tiff g4).
         * This is the most efficient way to represent the templates. */
    pix1 = pixaDisplayOnLattice(pixa2, 20, 30, NULL, NULL);
    pixDisplay(pix1, 1000, 500);
    snprintf(buf, sizeof(buf), "/tmp/lept/digit/%s.comp.tif", rootname);
    pixWrite(buf, pix1, IFF_TIFF_G4);

        /* The number of templates is in the pix text string; check it. */
    pix2 = pixRead(buf);
    if (sscanf(pixGetText(pix2), "n = %d", &ns) != 1)
        fprintf(stderr, "Failed to read the number of templates!\n");
    if (ns != nc)
        fprintf(stderr, "(stored = %d) != (actual number = %d)\n", ns, nc);

        /* Reconstruct the pixa of templates from the tiled compressed
         * image, and verify that the resulting pixa is the same.  */
    pixa3 = pixaMakeFromTiledPix(pix1, 20, 30, 0, 0, NULL);
    pixaEqual(pixa2, pixa3, 0, NULL, &same);
    if (!same)
        fprintf(stderr, "Pixa are not the same!\n");

    pixDestroy(&pix1);
    pixDestroy(&pix2);
    pixaDestroy(&pixa1);
    pixaDestroy(&pixa2);
    pixaDestroy(&pixa3);
}
示例#10
0
int main(int    argc,
         char **argv)
{
l_int32       i, n;
l_float32     pi, angle, val;
BOX          *box;
BOXA         *boxa, *boxa1, *boxa2;
NUMA         *na1, *na2;
PIX          *pix, *pix1, *pix2;
PIXA         *pixa1, *pixa2, *pixa3, *pixa4;
L_REGPARAMS  *rp;

    if (regTestSetup(argc, argv, &rp))
        return 1;

    lept_rmfile("/tmp/regout/insert3.ba");
    lept_rmfile("/tmp/regout/insert4.ba");
    lept_rmfile("/tmp/regout/insert6.pa");
    lept_rmfile("/tmp/regout/insert7.pa");
    lept_rmfile("/tmp/regout/insert9.pa");
    lept_rmfile("/tmp/regout/insert10.pa");

    /* ----------------- Test numa operations -------------------- */
    pi = 3.1415926535;
    na1 = numaCreate(500);
    for (i = 0; i < 500; i++) {
        angle = 0.02293 * i * pi;
        val = (l_float32)sin(angle);
        numaAddNumber(na1, val);
    }
    numaWrite("/tmp/regout/insert0.na", na1);
    na2 = numaCopy(na1);
    n = numaGetCount(na2);
    for (i = 0; i < n; i++) {
        numaGetFValue(na2, i, &val);
        numaRemoveNumber(na2, i);
        numaInsertNumber(na2, i, val);
    }
    numaWrite("/tmp/regout/insert1.na", na2);
    regTestCheckFile(rp, "/tmp/regout/insert0.na");  /* 0 */
    regTestCheckFile(rp, "/tmp/regout/insert1.na");  /* 1 */
    regTestCompareFiles(rp, 0, 1);  /* 2 */
    numaDestroy(&na1);
    numaDestroy(&na2);

    /* ----------------- Test boxa operations -------------------- */
    pix1 = pixRead("feyn.tif");
    box = boxCreate(1138, 1666, 1070, 380);
    pix2 = pixClipRectangle(pix1, box, NULL);
    boxDestroy(&box);
    boxa1 = pixConnComp(pix2, NULL, 8);
    boxaWrite("/tmp/regout/insert3.ba", boxa1);
    boxa2 = boxaCopy(boxa1, L_COPY);
    n = boxaGetCount(boxa2);
    for (i = 0; i < n; i++) {
        boxaRemoveBoxAndSave(boxa2, i, &box);
        boxaInsertBox(boxa2, i, box);
    }
    boxaWrite("/tmp/regout/insert4.ba", boxa2);
    regTestCheckFile(rp, "/tmp/regout/insert3.ba");  /* 3 */
    regTestCheckFile(rp, "/tmp/regout/insert4.ba");  /* 4 */
    regTestCompareFiles(rp, 3, 4);  /* 5 */
    pixDestroy(&pix1);
    pixDestroy(&pix2);
    boxaDestroy(&boxa1);
    boxaDestroy(&boxa2);

    /* ----------------- Test pixa operations -------------------- */
    pix1 = pixRead("feyn.tif");
    box = boxCreate(1138, 1666, 1070, 380);
    pix2 = pixClipRectangle(pix1, box, NULL);
    boxDestroy(&box);
    boxa = pixConnComp(pix2, &pixa1, 8);
    boxaDestroy(&boxa);
    pixaWrite("/tmp/regout/insert6.pa", pixa1);
    regTestCheckFile(rp, "/tmp/regout/insert6.pa");  /* 6 */
    pixDestroy(&pix1);
    pixDestroy(&pix2);

        /* Remove and insert each one */
    pixa2 = pixaCopy(pixa1, L_COPY);
    n = pixaGetCount(pixa2);
    for (i = 0; i < n; i++) {
        pixaRemovePixAndSave(pixa2, i, &pix, &box);
        pixaInsertPix(pixa2, i, pix, box);
    }
    pixaWrite("/tmp/regout/insert7.pa", pixa2);
    regTestCheckFile(rp, "/tmp/regout/insert7.pa");  /* 7 */
    regTestCompareFiles(rp, 6, 7);  /* 8 */

        /* Move the last to the beginning; do it n times */
    pixa3 = pixaCopy(pixa2, L_COPY);
    for (i = 0; i < n; i++) {
        pix = pixaGetPix(pixa3, n - 1, L_CLONE);
        box = pixaGetBox(pixa3, n - 1, L_CLONE);
        pixaInsertPix(pixa3, 0, pix, box);
        pixaRemovePix(pixa3, n);
    }
    pixaWrite("/tmp/regout/insert9.pa", pixa3);
    regTestCheckFile(rp, "/tmp/regout/insert9.pa");  /* 9 */

        /* Move the first one to the end; do it n times */
    pixa4 = pixaCopy(pixa3, L_COPY);
    for (i = 0; i < n; i++) {
        pix = pixaGetPix(pixa4, 0, L_CLONE);
        box = pixaGetBox(pixa4, 0, L_CLONE);
        pixaInsertPix(pixa4, n, pix, box);  /* make sure insert works at end */
        pixaRemovePix(pixa4, 0);
    }
    pixaWrite("/tmp/regout/insert10.pa", pixa4);
    regTestCheckFile(rp, "/tmp/regout/insert10.pa");  /* 10 */
    regTestCompareFiles(rp, 9, 10);  /* 11 */
    pixaDestroy(&pixa1);
    pixaDestroy(&pixa2);
    pixaDestroy(&pixa3);
    pixaDestroy(&pixa4);

    return regTestCleanup(rp);
}
示例#11
0
l_int32 main(int    argc,
             char **argv)
{
char         *dir, *path;
char         *str1 = NULL;
char         *chara, *chara2;
char          buf[256];
l_uint8      *data1, *data2, *data3, *data4;
l_int32       w, h, i, n, bx, by, bw, bh, nchar, nbytes, ret;
l_int32      *rtable64;
l_uint32      pixval;
size_t        nbytes1, nbytes2, nout, nout2, nout3;
L_BMF        *bmf;
BOX          *box1, *box2;
BOXA         *boxa;
PIX          *pix, *pixs, *pixm, *pixg, *pixd;
PIX          *pix0, *pix1, *pix2, *pix3, *pix4, *pix5, *pix6;
PIXA         *pixas, *pixa1, *pixa2, *pixa3;
L_RECOG      *recog;
L_STRCODE    *strc;

    if (argc != 1) {
        fprintf(stderr, " Syntax: recog_bootnum\n");
        return 1;
    }

    lept_mkdir("lept/recog/digits");

    /* ----------------------- Bootnum 1 --------------------- */
        /* Make the bootnum pixa from the images */
    pixa1 = MakeBootnum1();
    pixaWrite("/tmp/lept/recog/digits/bootnum1.pa", pixa1);
    pix1 = pixaDisplayTiledWithText(pixa1, 1500, 1.0, 10, 2, 6, 0xff000000);
    pixDisplay(pix1, 100, 0);
    pixDestroy(&pix1);
    pixaDestroy(&pixa1);

        /* Generate the code to make the bootnum1 pixa.
         * Note: the actual code we use is in bootnumgen1.c, and
         * has already been compiled into the library. */
    strc = strcodeCreate(101);  /* arbitrary integer */
    strcodeGenerate(strc, "/tmp/lept/recog/digits/bootnum1.pa", "PIXA");
    strcodeFinalize(&strc, "/tmp/lept/auto");
    lept_free(strc);

        /* Generate the bootnum1 pixa from the generated code */
    pixa1 = (PIXA *)l_bootnum_gen1();
    pix1 = pixaDisplayTiledWithText(pixa1, 1500, 1.0, 10, 2, 6, 0xff000000);
/*    pix1 = pixaDisplayTiled(pixa1, 1500, 0, 30); */
    pixDisplay(pix1, 100, 0);
    pixDestroy(&pix1);

        /* Extend the bootnum1 pixa by erosion */
    pixa3 = pixaExtendIterative(pixa1, L_MORPH_ERODE, 2, NULL, 1);
    pix1 = pixaDisplayTiledWithText(pixa3, 1500, 1.0, 10, 2, 6, 0xff000000);
    pixDisplay(pix1, 100, 0);
    pixDestroy(&pix1);
    pixaDestroy(&pixa1);
    pixaDestroy(&pixa3);

    /* ----------------------- Bootnum 2 --------------------- */
        /* Make the bootnum pixa from the images */
    L_INFO("the 4 errors below are due to bad input\n", "recog_bootnum");
    pixa2 = MakeBootnum2();
    pix1 = pixaDisplayTiledWithText(pixa2, 1500, 1.0, 10, 2, 6, 0xff000000);
    pixDisplay(pix1, 100, 700);
    pixDestroy(&pix1);
    pixaDestroy(&pixa2);

        /* Generate the code to make the bootnum2 pixa.
         * Note: the actual code we use is in bootnumgen2.c. */
    strc = strcodeCreate(102);  /* another arbitrary integer */
    strcodeGenerate(strc, "/tmp/lept/recog/digits/bootnum2.pa", "PIXA");
    strcodeFinalize(&strc, "/tmp/lept/auto");
    lept_free(strc);

        /* Generate the bootnum2 pixa from the generated code */
    pixa2 = (PIXA *)l_bootnum_gen2();
/*    pix1 = pixaDisplayTiled(pixa2, 1500, 0, 30);  */
    pix1 = pixaDisplayTiledWithText(pixa2, 1500, 1.0, 10, 2, 6, 0xff000000);
    pixDisplay(pix1, 100, 700);
    pixDestroy(&pix1);
    pixaDestroy(&pixa2);


#if 0
    pixas = (PIXA *)l_bootnum_gen1();
/*    pixas = pixaRead("recog/digits/bootnum1.pa"); */
    pixaWrite("/tmp/junk.pa", pixas);
    pixa1 = pixaRead("/tmp/junk.pa");
    pixaWrite("/tmp/junk1.pa", pixa1);
    pixa = pixaRead("/tmp/junk1.pa");
    n = pixaGetCount(pixa);
    for (i = 0; i < n; i++) {
        pix = pixaGetPix(pixa, i, L_CLONE);
        fprintf(stderr, "i = %d, text = %s\n", i, pixGetText(pix));
        pixDestroy(&pix);
    }
#endif

    return 0;
}
示例#12
0
main(int    argc,
     char **argv)
{
l_int32     i, n;
l_float32   pi, angle, val;
BOX        *box;
BOXA       *boxa, *boxa1, *boxa2;
NUMA       *na1, *na2;
PIX        *pix, *pix1, *pix2, *pix3, *pixd;
PIXA       *pixa1, *pixa2, *pixa3, *pixa4;
static char     mainName[] = "inserttest";

#if 1
    pi = 3.1415926535;
    na1 = numaCreate(500);
    for (i = 0; i < 500; i++) {
        angle = 0.02293 * i * pi;
        val = (l_float32)sin(angle);
        numaAddNumber(na1, val);
    }
    numaWrite("/tmp/junknuma1", na1);
    na2 = numaCopy(na1);
    n = numaGetCount(na2);
    for (i = 0; i < n; i++) {
      numaGetFValue(na2, i, &val);
      numaRemoveNumber(na2, i);
      numaInsertNumber(na2, i, val);
    }
    numaWrite("/tmp/junknuma2", na2);
    numaDestroy(&na1);
    numaDestroy(&na2);
#endif

#if 1
    pix1 = pixRead("feyn.tif");
    box = boxCreate(1138, 1666, 1070, 380);
    pix2 = pixClipRectangle(pix1, box, NULL);
    boxDestroy(&box);
    boxa1 = pixConnComp(pix2, NULL, 8);
    boxaWrite("/tmp/junkboxa1", boxa1);
    boxa2 = boxaCopy(boxa1, L_COPY);
    n = boxaGetCount(boxa2);
    for (i = 0; i < n; i++) {
      box = boxaGetBox(boxa2, i, L_COPY);
      boxaRemoveBox(boxa2, i);
      boxaInsertBox(boxa2, i, box);
    }
    boxaWrite("/tmp/junkboxa2", boxa2);
    pixDestroy(&pix1);
    pixDestroy(&pix2);
    boxaDestroy(&boxa1);
    boxaDestroy(&boxa2);
#endif

#if 1
    pix1 = pixRead("feyn.tif");
    box = boxCreate(1138, 1666, 1070, 380);
    pix2 = pixClipRectangle(pix1, box, NULL);
    boxDestroy(&box);
    boxa = pixConnComp(pix2, &pixa1, 8);
    boxaDestroy(&boxa);
    pixaWrite("/tmp/junkpixa1", pixa1);

    pixa2 = pixaCopy(pixa1, L_COPY);
    n = pixaGetCount(pixa2);
        /* Remove and insert each one */
    for (i = 0; i < n; i++) {
      pix = pixaGetPix(pixa2, i, L_COPY);
      box = pixaGetBox(pixa2, i, L_COPY);
      pixaRemovePix(pixa2, i);
      pixaInsertPix(pixa2, i, pix, box);
    }
    pixaWrite("/tmp/junkpixa2", pixa2);

        /* Move the last to the beginning; do it n times */
    pixa3 = pixaCopy(pixa2, L_COPY);
    for (i = 0; i < n; i++) {
      pix = pixaGetPix(pixa3, n - 1, L_CLONE);
      box = pixaGetBox(pixa3, n - 1, L_CLONE);
      pixaInsertPix(pixa3, 0, pix, box);
      pixaRemovePix(pixa3, n);
    }
    pixaWrite("/tmp/junkpixa3", pixa3);

        /* Move the first one to the end; do it n times */
    pixa4 = pixaCopy(pixa3, L_COPY);
    for (i = 0; i < n; i++) {
      pix = pixaGetPix(pixa4, 0, L_CLONE);
      box = pixaGetBox(pixa4, 0, L_CLONE);
      pixaInsertPix(pixa4, n, pix, box);  /* make sure insert works at end */
      pixaRemovePix(pixa4, 0);
    }
    pixaWrite("/tmp/junkpixa4", pixa4);

    pixDestroy(&pix1);
    pixDestroy(&pix2);
    pixaDestroy(&pixa1);
    pixaDestroy(&pixa2);
    pixaDestroy(&pixa3);
    pixaDestroy(&pixa4);
#endif

    return 0;
}