コード例 #1
0
ファイル: croptest.c プロジェクト: mehulsbhatt/MyOCRTEST
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;
}
コード例 #2
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;
}