l_int32 main(int argc, char **argv) { l_int32 i; L_STRCODE *strc; /* Method 1: generate autogen.137.c and autogen.137.h */ strc = strcodeCreate(137); for (i = 0; i < 2; i++) strcodeGenerate(strc, files[i], "PIXA"); strcodeFinalize(&strc, NULL); /* Method 2: generate autogen.138.c and autogen.138.c */ l_binaryWrite("/tmp/fontnames.txt", "w", (char *) filetext, strlen(filetext)); strcodeCreateFromFile("/tmp/fontnames.txt", 138, NULL); return 0; }
/*! * \brief strcodeCreateFromFile() * * \param[in] filein containing filenames of serialized data * \param[in] fileno integer that labels the two output files * \param[in] outdir [optional] if null, files are made in /tmp/lept/auto * \return 0 if OK, 1 on error * * <pre> * Notes: * (1) The %filein has one filename on each line. * Comment lines begin with "#". * (2) The output is 2 files: * autogen.\<fileno\>.c * autogen.\<fileno\>.h * </pre> */ l_int32 strcodeCreateFromFile(const char *filein, l_int32 fileno, const char *outdir) { char *fname; const char *type; l_uint8 *data; size_t nbytes; l_int32 i, n, index; SARRAY *sa; L_STRCODE *strcode; PROCNAME("strcodeCreateFromFile"); if (!filein) return ERROR_INT("filein not defined", procName, 1); if ((data = l_binaryRead(filein, &nbytes)) == NULL) return ERROR_INT("data not read from file", procName, 1); sa = sarrayCreateLinesFromString((char *)data, 0); LEPT_FREE(data); if (!sa) return ERROR_INT("sa not made", procName, 1); if ((n = sarrayGetCount(sa)) == 0) { sarrayDestroy(&sa); return ERROR_INT("no filenames in the file", procName, 1); } strcode = strcodeCreate(fileno); for (i = 0; i < n; i++) { fname = sarrayGetString(sa, i, L_NOCOPY); if (fname[0] == '#') continue; if (l_getIndexFromFile(fname, &index)) { L_ERROR("File %s has no recognizable type\n", procName, fname); } else { type = l_assoc[index].type; L_INFO("File %s is type %s\n", procName, fname, type); strcodeGenerate(strcode, fname, type); } } strcodeFinalize(&strcode, outdir); return 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; }