예제 #1
0
/*!
 *  pixOrientDetectDwa()
 *
 *      Input:  pixs (1 bpp, deskewed, English text)
 *              &upconf (<optional return> ; may be null)
 *              &leftconf (<optional return> ; may be null)
 *              mincount (min number of up + down; use 0 for default)
 *              debug (1 for debug output; 0 otherwise)
 *      Return: 0 if OK, 1 on error
 *
 *  Notes:
 *      (1) Same interface as for pixOrientDetect().  See notes
 *          there for usage.
 *      (2) Uses auto-gen'd code for the Sels defined at the
 *          top of this file, with some renaming of functions.
 *          The auto-gen'd code is in fliphmtgen.c, and can
 *          be generated by a simple executable; see prog/flipselgen.c.
 *      (3) This runs about 2.5 times faster than the pixOrientDetect().
 */
l_int32
pixOrientDetectDwa(PIX        *pixs,
                   l_float32  *pupconf,
                   l_float32  *pleftconf,
                   l_int32     mincount,
                   l_int32     debug)
{
PIX  *pixt;

    PROCNAME("pixOrientDetectDwa");

    if (!pixs)
        return ERROR_INT("pixs not defined", procName, 1);
    if (pixGetDepth(pixs) != 1)
        return ERROR_INT("pixs not 1 bpp", procName, 1);
    if (!pupconf && !pleftconf)
        return ERROR_INT("nothing to do", procName, 1);
    if (mincount == 0)
        mincount = DEFAULT_MIN_UP_DOWN_COUNT;

    if (pupconf)
        pixUpDownDetectDwa(pixs, pupconf, mincount, debug);
    if (pleftconf) {
        pixt = pixRotate90(pixs, 1);
        pixUpDownDetectDwa(pixt, pleftconf, mincount, debug);
        pixDestroy(&pixt);
    }

    return 0;
}
예제 #2
0
/*!
 *  pixRotateOrth()
 *
 *      Input:  pixs (all depths)
 *              quads (0-3; number of 90 degree cw rotations)
 *      Return: pixd, or null on error
 */
PIX *
pixRotateOrth(PIX     *pixs,
              l_int32  quads)
{
    PROCNAME("pixRotateOrth");

    if (!pixs)
        return (PIX *)ERROR_PTR("pixs not defined", procName, NULL);
    if (quads < 0 || quads > 4)
        return (PIX *)ERROR_PTR("quads not in {0,1,2,3,4}", procName, NULL);

    if (quads == 0 || quads == 4)
        return pixCopy(NULL, pixs);
    else if (quads == 1)
        return pixRotate90(pixs, 1);
    else if (quads == 2)
        return pixRotate180(NULL, pixs);
    else /* quads == 3 */
        return pixRotate90(pixs, -1);
}
예제 #3
0
main(int    argc,
     char **argv)
{
char        *filein;
l_int32      i, orient;
l_float32    upconf1, upconf2, leftconf1, leftconf2, conf1, conf2;
PIX         *pixs, *pixt1, *pixt2;
static char  mainName[] = "flipdetect_reg";

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

    filein = argv[1];

    if ((pixt1 = pixRead(filein)) == NULL)
	exit(ERROR_INT("pixt1 not made", mainName, 1));
    pixs = pixConvertTo1(pixt1, 130);
    pixDestroy(&pixt1);
	    
    fprintf(stderr, "\nTest orientation detection\n");
    startTimer();
    pixOrientDetect(pixs, &upconf1, &leftconf1, 0, 0);
    fprintf(stderr, "Time for rop orient test: %7.3f sec\n", stopTimer());

    makeOrientDecision(upconf1, leftconf1, 0, 0, &orient, 1);

    startTimer();
    pixOrientDetectDwa(pixs, &upconf2, &leftconf2, 0, 0);
    fprintf(stderr, "Time for dwa orient test: %7.3f sec\n", stopTimer());

    if (upconf1 == upconf2 && leftconf1 == leftconf2) {
        printStarredMessage("Orient results identical");
        fprintf(stderr, "upconf = %7.3f, leftconf = %7.3f\n",
                upconf1, leftconf1);
    }
    else {
        printStarredMessage("Orient results differ");
        fprintf(stderr, "upconf1 = %7.3f, upconf2 = %7.3f\n", upconf1, upconf2);
        fprintf(stderr, "leftconf1 = %7.3f, leftconf2 = %7.3f\n",
                leftconf1, leftconf2);
    }

    pixt1 = pixCopy(NULL, pixs);
    fprintf(stderr, "\nTest orient detection for 4 orientations\n");
    for (i = 0; i < 4; i++) {
        pixOrientDetectDwa(pixt1, &upconf2, &leftconf2, 0, 0);
        makeOrientDecision(upconf2, leftconf2, 0, 0, &orient, 1);
        if (i == 3) break;
        pixt2 = pixRotate90(pixt1, 1);
        pixDestroy(&pixt1);
        pixt1 = pixt2;
    }
    pixDestroy(&pixt1);

    fprintf(stderr, "\nTest mirror reverse detection\n");
    startTimer();
    pixMirrorDetect(pixs, &conf1, 0, 1);
    fprintf(stderr, "Time for rop mirror flip test: %7.3f sec\n", stopTimer());

    startTimer();
    pixMirrorDetectDwa(pixs, &conf2, 0, 0);
    fprintf(stderr, "Time for dwa mirror flip test: %7.3f sec\n", stopTimer());

    if (conf1 == conf2) {
        printStarredMessage("Mirror results identical");
        fprintf(stderr, "conf = %7.3f\n", conf1);
    }
    else {
        printStarredMessage("Mirror results differ");
        fprintf(stderr, "conf1 = %7.3f, conf2 = %7.3f\n", conf1, conf2);
    }

    fprintf(stderr, "\nSafer version of up-down tests\n");
    pixUpDownDetectGeneral(pixs, &conf1, 0, 10, 1);
    pixUpDownDetectGeneralDwa(pixs, &conf2, 0, 10, 1);
    if (conf1 == conf2)
        fprintf(stderr, "Confidence results are identical\n");
    else
        fprintf(stderr, "Confidence results differ\n");

    pixDestroy(&pixs);
    exit(0);
}
예제 #4
0
int main(int    argc,
         char **argv)
{
char        *filein, *fileout, *fname;
char         buffer[512];
const char  *psfile = "/tmp/junk_split_image.ps";
l_int32      nx, ny, i, w, h, d, ws, hs, n, res, ignore;
l_float32    scale;
PIX         *pixs, *pixt, *pixr;
PIXA        *pixa;
static char  mainName[] = "splitimage2pdf";

    if (argc != 5)
        return ERROR_INT(" Syntax:  splitimage2pdf filein nx ny fileout",
                         mainName, 1);

    filein = argv[1];
    nx = atoi(argv[2]);
    ny = atoi(argv[3]);
    fileout = argv[4];

    lept_rm(NULL, "junk_split_image.ps");

    if ((pixs = pixRead(filein)) == NULL)
        return ERROR_INT("pixs not made", mainName, 1);
    d = pixGetDepth(pixs);
    if (d == 1 )
        lept_rm(NULL, "junk_split_image.tif");
    else if (d == 8 || d == 32)
        lept_rm(NULL, "junk_split_image.jpg");
    else
        return ERROR_INT("d not in {1,8,32} bpp", mainName, 1);

    pixGetDimensions(pixs, &ws, &hs, NULL);
    if (ny * ws > nx * hs)
        pixr = pixRotate90(pixs, 1);
    else
        pixr = pixClone(pixs);

    pixa = pixaSplitPix(pixr, nx, ny, 0, 0);
    n = pixaGetCount(pixa);
    res = 300;
    for (i = 0; i < n; i++) {
        pixt = pixaGetPix(pixa, i, L_CLONE);
        pixGetDimensions(pixt, &w, &h, NULL);
        scale = L_MIN(FILL_FACTOR * 2550 / w, FILL_FACTOR * 3300 / h);
        fname = NULL;
        if (d == 1) {
            fname = genPathname("/tmp", "junk_split_image.tif");
            pixWrite(fname, pixt, IFF_TIFF_G4);
            if (i == 0) {
                convertG4ToPS(fname, psfile, "w", 0, 0, 300,
                              scale, 1, FALSE, TRUE);
            } else {
                convertG4ToPS(fname, psfile, "a", 0, 0, 300,
                              scale, 1, FALSE, TRUE);
            }
        } else {
            fname = genPathname("/tmp", "junk_split_image.jpg");
            pixWrite(fname, pixt, IFF_JFIF_JPEG);
            if (i == 0) {
                convertJpegToPS(fname, psfile, "w", 0, 0, 300,
                                scale, 1, TRUE);
            } else {
                convertJpegToPS(fname, psfile, "a", 0, 0, 300,
                                scale, 1, TRUE);
            }
        }
        lept_free(fname);
        pixDestroy(&pixt);
    }

    snprintf(buffer, sizeof(buffer), "ps2pdf %s %s", psfile, fileout);
    ignore = system(buffer);  /* ps2pdf */

    pixaDestroy(&pixa);
    pixDestroy(&pixr);
    pixDestroy(&pixs);
    return 0;
}
예제 #5
0
void
RotateOrthTest(PIX          *pixs,
               L_REGPARAMS  *rp)
{
l_int32   zero, count;
PIX      *pixt, *pixd;
PIXCMAP  *cmap;

    cmap = pixGetColormap(pixs);

	/* Test 4 successive 90 degree rotations */
    pixt = pixRotate90(pixs, 1);
    pixd = pixRotate90(pixt, 1);
    pixDestroy(&pixt);
    pixt = pixRotate90(pixd, 1);
    pixDestroy(&pixd);
    pixd = pixRotate90(pixt, 1);
    pixDestroy(&pixt);
    regTestComparePix(rp, pixs, pixd);
    if (!cmap) {
        pixXor(pixd, pixd, pixs);
        pixZero(pixd, &zero);
        if (zero)
            fprintf(stderr, "OK.  Four 90-degree rotations gives I\n");
        else {
             pixCountPixels(pixd, &count, NULL);
             fprintf(stderr, "Failure for four 90-degree rots; count = %d\n",
                     count);
        }
    }
    pixDestroy(&pixd);

	/* Test 2 successive 180 degree rotations */
    pixt = pixRotate180(NULL, pixs);
    pixRotate180(pixt, pixt);
    regTestComparePix(rp, pixs, pixt);
    if (!cmap) {
        pixXor(pixt, pixt, pixs);
        pixZero(pixt, &zero);
        if (zero)
            fprintf(stderr, "OK.  Two 180-degree rotations gives I\n");
        else {
            pixCountPixels(pixt, &count, NULL);
            fprintf(stderr, "Failure for two 180-degree rots; count = %d\n",
                    count);
        }
    }
    pixDestroy(&pixt);

	/* Test 2 successive LR flips */
    pixt = pixFlipLR(NULL, pixs);
    pixFlipLR(pixt, pixt);
    regTestComparePix(rp, pixs, pixt);
    if (!cmap) {
        pixXor(pixt, pixt, pixs);
        pixZero(pixt, &zero);
        if (zero)
            fprintf(stderr, "OK.  Two LR flips gives I\n");
        else {
            pixCountPixels(pixt, &count, NULL);
            fprintf(stderr, "Failure for two LR flips; count = %d\n", count);
        }
    }
    pixDestroy(&pixt);

	/* Test 2 successive TB flips */
    pixt = pixFlipTB(NULL, pixs);
    pixFlipTB(pixt, pixt);
    regTestComparePix(rp, pixs, pixt);
    if (!cmap) {
        pixXor(pixt, pixt, pixs);
        pixZero(pixt, &zero);
        if (zero)
            fprintf(stderr, "OK.  Two TB flips gives I\n");
        else {
            pixCountPixels(pixt, &count, NULL);
            fprintf(stderr, "Failure for two TB flips; count = %d\n", count);
        }
    }
    pixDestroy(&pixt);
    return;
}
예제 #6
0
int main(int    argc,
         char **argv)
{
char        *filein, *fname, *argp, *argn;
char         buffer[512];
l_int32      i, w, h, ignore;
l_float32    scale;
FILE        *fp;
PIX         *pixs, *pixt;
static char  mainName[] = "printimage";

    if (argc < 2 || argc > 4)
        return ERROR_INT(
            " Syntax:  printimage filein [-P<printer>] [-#<number>]",
            mainName, 1);

        /* parse args */
    filein = argv[1];
    argp = argn = NULL;
    if (argc > 2) {
        for (i = 2; i < argc; i++) {
            if (argv[i][1] == 'P')
                argp = argv[i];
            else if (argv[i][1] == '#')
                argn = argv[i];
        }
    }

    lept_rm(NULL, "print_image.ps");

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

    pixGetDimensions(pixs, &w, &h, NULL);
    if (w > h) {
        pixt = pixRotate90(pixs, 1);
        pixGetDimensions(pixt, &w, &h, NULL);
    }
    else {
        pixt = pixClone(pixs);
    }
    scale = L_MIN(FILL_FACTOR * 2550 / w, FILL_FACTOR * 3300 / h);
    fname = genPathname("/tmp", "print_image.ps");
    fp = lept_fopen(fname, "wb+");
    pixWriteStreamPS(fp, pixt, NULL, 300, scale);
    lept_fclose(fp);

        /* print it out */
    if (argp && !argn) {
        sprintf(buffer, "lpr %s %s &", argp, fname);
        ignore = system(buffer);
    } else if (!argp && argn) {
        sprintf(buffer, "lpr %s %s &", argn, fname);
        ignore = system(buffer);
    } else if (argp && argn) {
        sprintf(buffer, "lpr %s %s %s &", argp, argn, fname);
        ignore = system(buffer);
    }

    lept_free(fname);
    pixDestroy(&pixs);
    pixDestroy(&pixt);
    return 0;
}
예제 #7
0
main(int    argc,
     char **argv)
{
l_int32      i, w, h, dir;
PIX         *pixs, *pixd, *pixt;
l_float32    pops;
char        *filein, *fileout;
static char  mainName[] = "rotateorthtest1";

    if (argc != 3 && argc != 4)
	exit(ERROR_INT(" Syntax:  rotateorthtest1 filein fileout [direction]",
	       mainName, 1));

    filein = argv[1];
    fileout = argv[2];
    if (argc == 4)
	dir = atoi(argv[3]);
    else
	dir = 1;

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

        /* Do a single operation */
#if 1
    pixd = pixRotate90(pixs, dir);
#elif 0
    pixd = pixRotate180(NULL, pixs);
#elif 0
    pixd = pixRotateLR(NULL, pixs);
#elif 0
    pixd = pixRotateTB(NULL, pixs);
#endif

	/* Time rotate 90, allocating & destroying each time */
#if 0
    startTimer();
    w = pixGetWidth(pixs);
    h = pixGetHeight(pixs);
    for (i = 0; i < NTIMES; i++) {
	pixd = pixRotate90(pixs, dir);
	pixDestroy(&pixd);
    }
    pops = (l_float32)(w * h * NTIMES) / stopTimer();
    fprintf(stderr, "MPops for 90 rotation: %7.3f\n", pops / 1000000.);
    pixd = pixRotate90(pixs, dir);
#endif

	/* Time rotate 180, with no alloc/destroy */
#if 0
    startTimer();
    w = pixGetWidth(pixs);
    h = pixGetHeight(pixs);
    pixd = pixCreateTemplate(pixs);
    for (i = 0; i < NTIMES; i++)
	pixRotate180(pixd, pixs);
    pops = (l_float32)(w * h * NTIMES) / stopTimer();
    fprintf(stderr, "MPops for 180 rotation: %7.3f\n", pops / 1000000.);
#endif


	/* Test rotate 180 not in-place */
#if 0
    pixt = pixRotate180(NULL, pixs);
    pixd = pixRotate180(NULL, pixt);
    pixEqual(pixs, pixd, &eq);
    if (eq) fprintf(stderr, "2 rots gives I\n");
    else fprintf(stderr, "2 rots fail to give I\n");
    pixDestroy(&pixt);
#endif

       /* Test rotate 180 in-place */
#if 0
    pixd = pixCopy(NULL, pixs);
    pixRotate180(pixd, pixd);
    pixRotate180(pixd, pixd);
    pixEqual(pixs, pixd, &eq);
    if (eq) fprintf(stderr, "2 rots gives I\n");
    else fprintf(stderr, "2 rots fail to give I\n");
#endif

	/* Mix rotate 180 with LR/TB */
#if 0
    pixd = pixRotate180(NULL, pixs);
    pixRotateLR(pixd, pixd);
    pixRotateTB(pixd, pixd);
    pixEqual(pixs, pixd, &eq);
    if (eq) fprintf(stderr, "180 rot OK\n");
    else fprintf(stderr, "180 rot error\n");
#endif

    if (pixGetDepth(pixd) < 8)
	pixWrite(fileout, pixd, IFF_PNG);
    else
	pixWrite(fileout, pixd, IFF_JFIF_JPEG);

    pixDestroy(&pixs);
    pixDestroy(&pixd);
    return 0;
}
예제 #8
0
int main(int argc,
         char **argv) {
#if 1
    l_int32 i, pageno, w, h, left, right;
    NUMA *nar, *naro, *narl, *nart, *nai, *naio, *nait;
    PIX *pixs, *pixr, *pixg, *pixgi, *pixd, *pix1, *pix2;
    PIXA *pixa1, *pixa2;
    static char mainName[] = "croptest";

    if (argc != 1)
        return ERROR_INT("syntax: croptest", mainName, 1);

    pixa1 = pixaCreate(2);
    for (i = 0; i < 2; i++) {
        pageno = extractNumberFromFilename(fnames[i], 5, 0);
        fprintf(stderr, "Page %d\n", pageno);
        pixs = pixRead(fnames[i]);
        pixr = pixRotate90(pixs, (pageno % 2) ? 1 : -1);
        pixg = pixConvertTo8(pixr, 0);
        pixGetDimensions(pixg, &w, &h, NULL);

        /* Get info on vertical reversal profile */
        nar = pixReversalProfile(pixg, 0.8, L_VERTICAL_LINE,
                                 0, h - 1, mindif, 1, 1);
        naro = numaOpen(nar, 11);
        gplotSimple1(naro, GPLOT_PNG, "/tmp/root1", "Reversals Opened");
        narl = numaLowPassIntervals(naro, 0.1, 0.0);
        fprintf(stderr, "narl:");
        numaWriteStream(stderr, narl);
        nart = numaThresholdEdges(naro, 0.1, 0.5, 0.0);
        fprintf(stderr, "nart:");
        numaWriteStream(stderr, nart);
        numaDestroy(&nar);
        numaDestroy(&naro);

        /* Get info on vertical intensity profile */
        pixgi = pixInvert(NULL, pixg);
        nai = pixAverageIntensityProfile(pixgi, 0.8, L_VERTICAL_LINE,
                                         0, h - 1, 1, 1);
        naio = numaOpen(nai, 11);
        gplotSimple1(naio, GPLOT_PNG, "/tmp/root2", "Intensities Opened");
        nait = numaThresholdEdges(naio, 0.4, 0.6, 0.0);
        fprintf(stderr, "nait:");
        numaWriteStream(stderr, nait);
        numaDestroy(&nai);
        numaDestroy(&naio);

        /* Analyze profiles for left/right edges  */
        GetLeftCut(narl, nart, nait, w, &left);
        GetRightCut(narl, nart, nait, w, &right);
        fprintf(stderr, "left = %d, right = %d\n", left, right);

        /* Output visuals */
#ifndef  _WIN32
        sleep(1);
#else
        Sleep(1000);
#endif  /* _WIN32 */
        pixa2 = pixaCreate(3);
        pixSaveTiled(pixr, pixa2, 1.0, 1, 25, 32);
        pix1 = pixRead("/tmp/root1.png");
        pix2 = pixRead("/tmp/root2.png");
        pixSaveTiled(pix1, pixa2, 1.0, 1, 25, 32);
        pixSaveTiled(pix2, pixa2, 1.0, 0, 25, 32);
        pixd = pixaDisplay(pixa2, 0, 0);
        pixaDestroy(&pixa2);
        pixaAddPix(pixa1, pixd, L_INSERT);
        pixDisplay(pixd, 100, 100);
        pixDestroy(&pixs);
        pixDestroy(&pixr);
        pixDestroy(&pixg);
        pixDestroy(&pixgi);
        pixDestroy(&pix1);
        pixDestroy(&pix2);
        numaDestroy(&narl);
        numaDestroy(&nart);
        numaDestroy(&nait);
    }

    pixaConvertToPdf(pixa1, 75, 1.0, L_JPEG_ENCODE, 0, "Profiles",
                     "/tmp/croptest.pdf");
    pixaDestroy(&pixa1);
    return 0;
}
예제 #9
0
파일: croptest.c 프로젝트: chewi/leptonica
int main(int    argc,
         char **argv)
{
l_int32      i, pageno, w, h, left, right;
NUMA        *na1, *nar, *naro, *narl, *nart, *nai, *naio, *nait;
PIX         *pixs, *pixr, *pixg, *pixgi, *pixd, *pix1, *pix2;
PIXA        *pixa1, *pixa2;
static char  mainName[] = "croptest";

    if (argc != 1)
        return ERROR_INT("syntax: croptest", mainName, 1);

    setLeptDebugOK(1);
    lept_mkdir("lept/crop");

    pixa1 = pixaCreate(2);
    for (i = 0; i < 2; i++) {
        pageno = extractNumberFromFilename(fnames[i], 5, 0);
        fprintf(stderr, "Page %d\n", pageno);
        pixs = pixRead(fnames[i]);
        pixr = pixRotate90(pixs, (pageno % 2) ? 1 : -1);
        pixg = pixConvertTo8(pixr, 0);
        pixGetDimensions(pixg, &w, &h, NULL);

            /* Get info on vertical reversal profile */
        nar = pixReversalProfile(pixg, 0.8, L_VERTICAL_LINE,
                                 0, h - 1, mindif, 1, 1);
        naro = numaOpen(nar, 11);
        gplotSimple1(naro, GPLOT_PNG, "/tmp/lept/crop/reversals",
                     "Reversals Opened");
        narl = numaLowPassIntervals(naro, 0.1, 0.0);
        fprintf(stderr, "narl:");
        numaWriteStream(stderr, narl);
        nart = numaThresholdEdges(naro, 0.1, 0.5, 0.0);
        fprintf(stderr, "nart:");
        numaWriteStream(stderr, nart);
        numaDestroy(&nar);
        numaDestroy(&naro);

            /* Get info on vertical intensity profile */
        pixgi = pixInvert(NULL, pixg);
        nai = pixAverageIntensityProfile(pixgi, 0.8, L_VERTICAL_LINE,
                                         0, h - 1, 1, 1);
        naio = numaOpen(nai, 11);
        gplotSimple1(naio, GPLOT_PNG, "/tmp/lept/crop/intensities",
                     "Intensities Opened");
        nait = numaThresholdEdges(naio, 0.4, 0.6, 0.0);
        fprintf(stderr, "nait:");
        numaWriteStream(stderr, nait);
        numaDestroy(&nai);
        numaDestroy(&naio);

            /* Analyze profiles for left/right edges  */
        GetLeftCut(narl, nart, nait, w, &left);
        GetRightCut(narl, nart, nait, w, &right);
        fprintf(stderr, "left = %d, right = %d\n", left, right);

            /* Output visuals */
        pixa2 = pixaCreate(3);
        pixSaveTiled(pixr, pixa2, 1.0, 1, 25, 32);
        pix1 = pixRead("/tmp/lept/crop/reversals.png");
        pix2 = pixRead("/tmp/lept/crop/intensities.png");
        pixSaveTiled(pix1, pixa2, 1.0, 1, 25, 32);
        pixSaveTiled(pix2, pixa2, 1.0, 0, 25, 32);
        pixd = pixaDisplay(pixa2, 0, 0);
        pixaDestroy(&pixa2);
        pixaAddPix(pixa1, pixd, L_INSERT);
        pixDisplay(pixd, 100, 100);
        pixDestroy(&pixs);
        pixDestroy(&pixr);
        pixDestroy(&pixg);
        pixDestroy(&pixgi);
        pixDestroy(&pix1);
        pixDestroy(&pix2);
        numaDestroy(&narl);
        numaDestroy(&nart);
        numaDestroy(&nait);
    }

    fprintf(stderr, "Writing profiles to /tmp/lept/crop/croptest.pdf\n");
    pixaConvertToPdf(pixa1, 75, 1.0, L_JPEG_ENCODE, 0, "Profiles",
                     "/tmp/lept/crop/croptest.pdf");
    pixaDestroy(&pixa1);

        /* Now plot the profiles from text lines */
    pixs = pixRead("1555.007.jpg");
    pixGetDimensions(pixs, &w, &h, NULL);
    na1 = pixReversalProfile(pixs, 0.98, L_HORIZONTAL_LINE,
                                  0, h - 1, 40, 3, 3);
    gplotSimple1(na1, GPLOT_PNG, "/tmp/lept/crop/rev", "Reversals");
    numaDestroy(&na1);

    na1 = pixAverageIntensityProfile(pixs, 0.98, L_HORIZONTAL_LINE,
                                    0, h - 1, 1, 1);
    gplotSimple1(na1, GPLOT_PNG, "/tmp/lept/crop/inten", "Intensities");
    numaDestroy(&na1);
    pixa1 = pixaCreate(3);
    pixaAddPix(pixa1, pixScale(pixs, 0.5, 0.5), L_INSERT);
    pix1 = pixRead("/tmp/lept/crop/rev.png");
    pixaAddPix(pixa1, pix1, L_INSERT);
    pix1 = pixRead("/tmp/lept/crop/inten.png");
    pixaAddPix(pixa1, pix1, L_INSERT);
    pixd = pixaDisplayTiledInRows(pixa1, 32, 1000, 1.0, 0, 30, 2);
    pixWrite("/tmp/lept/crop/profiles.png", pixd, IFF_PNG);
    pixDisplay(pixd, 100, 100);
    pixDestroy(&pixs);
    pixDestroy(&pixd);
    pixaDestroy(&pixa1);
    return 0;
}
int main(int    argc,
         char **argv)
{
    char        *filein, *fname, *printer;
    char         buf[512];
    l_int32      nx, ny, i, w, h, ws, hs, n, ignore;
    l_float32    scale;
    FILE        *fp;
    PIX         *pixs, *pixt, *pixr;
    PIXA        *pixa;
    SARRAY      *sa;
    static char  mainName[] = "printsplitimage";

    if (argc != 4 && argc != 5)
        return ERROR_INT(" Syntax:  printsplitimage filein nx ny [printer]",
                         mainName, 1);

    filein = argv[1];
    nx = atoi(argv[2]);
    ny = atoi(argv[3]);
    if (argc == 5)
        printer = argv[4];

    lept_rmdir("split");
    lept_mkdir("split");

    if ((pixs = pixRead(filein)) == NULL)
        return ERROR_INT("pixs not made", mainName, 1);
    pixGetDimensions(pixs, &ws, &hs, NULL);
    if (ny * ws > nx * hs) {
        pixr = pixRotate90(pixs, 1);
        pixa = pixaSplitPix(pixr, ny, nx, 0, 0);
    } else {
        pixr = pixClone(pixs);
        pixa = pixaSplitPix(pixr, nx, ny, 0, 0);
    }
    pixDestroy(&pixr);

    n = pixaGetCount(pixa);
    sa = sarrayCreate(n);
    for (i = 0; i < n; i++) {
        pixt = pixaGetPix(pixa, i, L_CLONE);
        pixGetDimensions(pixt, &w, &h, NULL);
        scale = L_MIN(FILL_FACTOR * 2550 / w, FILL_FACTOR * 3300 / h);
        sprintf(buf, "image%d.ps", i);
        fname = genPathname("/tmp/split", buf);
        fprintf(stderr, "fname: %s\n", fname);
        sarrayAddString(sa, fname, L_INSERT);
        fp = lept_fopen(fname, "wb+");
        pixWriteStreamPS(fp, pixt, NULL, 300, scale);
        lept_fclose(fp);
        pixDestroy(&pixt);
    }

    if (argc == 5) {
        for (i = 0; i < n; i++) {
            fname = sarrayGetString(sa, i, L_NOCOPY);
            sprintf(buf, "lpr -P%s %s &", printer, fname);
            ignore = system(buf);
        }
    }

    sarrayDestroy(&sa);
    pixaDestroy(&pixa);
    pixDestroy(&pixs);
    return 0;
}
예제 #11
0
/*!
 * \brief   pixOrientCorrect()
 *
 * \param[in]    pixs 1 bpp, deskewed, English text, 150 - 300 ppi
 * \param[in]    minupconf minimum value for which a decision can be made
 * \param[in]    minratio minimum conf ratio required for a decision
 * \param[out]   pupconf [optional] ; use NULL to skip
 * \param[out]   pleftconf [optional] ; use NULL to skip
 * \param[out]   protation [optional] ; use NULL to skip
 * \param[in]    debug 1 for debug output; 0 otherwise
 * \return  pixd  may be rotated by 90, 180 or 270; null on error
 *
 * <pre>
 * Notes:
 *      (1) Simple top-level function to detect if Roman text is in
 *          reading orientation, and to rotate the image accordingly if not.
 *      (2) Returns a copy if no rotation is needed.
 *      (3) See notes for pixOrientDetect() and pixOrientDecision().
 *          Use 0.0 for default values for %minupconf and %minratio
 *      (4) Optional output of intermediate confidence results and
 *          the rotation performed on pixs.
 * </pre>
 */
PIX *
pixOrientCorrect(PIX        *pixs,
                 l_float32   minupconf,
                 l_float32   minratio,
                 l_float32  *pupconf,
                 l_float32  *pleftconf,
                 l_int32    *protation,
                 l_int32     debug)
{
l_int32    orient;
l_float32  upconf, leftconf;
PIX       *pix1;

    PROCNAME("pixOrientCorrect");

    if (!pixs || pixGetDepth(pixs) != 1)
        return (PIX *)ERROR_PTR("pixs undefined or not 1 bpp", procName, NULL);

    lept_mkdir("lept/orient");

        /* Get confidences for orientation */
    pixUpDownDetectDwa(pixs, &upconf, 0, debug);
    pix1 = pixRotate90(pixs, 1);
    pixUpDownDetectDwa(pix1, &leftconf, 0, debug);
    pixDestroy(&pix1);
    if (pupconf) *pupconf = upconf;
    if (pleftconf) *pleftconf = leftconf;

        /* Decide what to do */
    makeOrientDecision(upconf,leftconf, minupconf, minratio, &orient, debug);

        /* Do it */
    switch (orient)
    {
    case L_TEXT_ORIENT_UNKNOWN:
        L_INFO("text orientation not determined; no rotation\n", procName);
        if (protation) *protation = 0;
        return pixCopy(NULL, pixs);
        break;
    case L_TEXT_ORIENT_UP:
        L_INFO("text is oriented up; no rotation\n", procName);
        if (protation) *protation = 0;
        return pixCopy(NULL, pixs);
        break;
    case L_TEXT_ORIENT_LEFT:
        L_INFO("landscape; text oriented left; 90 cw rotation\n", procName);
        if (protation) *protation = 90;
        return pixRotateOrth(pixs, 1);
        break;
    case L_TEXT_ORIENT_DOWN:
        L_INFO("text oriented down; 180 cw rotation\n", procName);
        if (protation) *protation = 180;
        return pixRotateOrth(pixs, 2);
        break;
    case L_TEXT_ORIENT_RIGHT:
        L_INFO("landscape; text oriented right; 270 cw rotation\n", procName);
        if (protation) *protation = 270;
        return pixRotateOrth(pixs, 3);
        break;
    default:
        L_ERROR("invalid orient flag!\n", procName);
        return pixCopy(NULL, pixs);
    }
}