示例#1
0
/*!
 *  pixRead()
 *
 *      Input:  filename (with full pathname or in local directory)
 *      Return: pix if OK; null on error
 *
 *  Notes:
 *      (1) See at top of file for supported formats.
 */
PIX *
pixRead(const char  *filename)
{
FILE  *fp;
PIX   *pix;

    PROCNAME("pixRead");

    if (!filename)
        return (PIX *)ERROR_PTR("filename not defined", procName, NULL);

    if ((fp = fopenReadStream(filename)) == NULL) {
        L_ERROR("image file not found: %s\n", procName, filename);
        return NULL;
    }
    if ((pix = pixReadStream(fp, 0)) == NULL) {
        fclose(fp);
        return (PIX *)ERROR_PTR("pix not read", procName, NULL);
    }

        /* Close the stream except if GIF under windows, because
         * DGifCloseFile() closes the windows file stream! */
    if (pixGetInputFormat(pix) != IFF_GIF)
        fclose(fp);
#ifndef _WIN32
    else  /* gif file */
        fclose(fp);
#endif  /* ! _WIN32 */

    return pix;
}
char* ProcessPagesFileStream(const char* image,tesseract::TessBaseAPI* api) {
	
	Pix *pix;
	STRING mstr;
	int page=0;
	FILE *fp=fopen(image,"rb");
	pix=pixReadStream(fp,0);
	api->ProcessPage(pix, page, NULL, NULL, 0, &mstr);
	const char *tmpStr=mstr.string();
	char *retStr = new char[strlen(tmpStr) + 1];
	strcpy (retStr,tmpStr);
	//printf("ok->%s",retStr);
	fclose(fp);
	return retStr;
 }
示例#3
0
/*!
 *  pixReadWithHint()
 *
 *      Input:  filename (with full pathname or in local directory)
 *              hint (bitwise OR of L_HINT_* values for jpeg; use 0 for no hint)
 *      Return: pix if OK; null on error
 *
 *  Notes:
 *      (1) The hint is not binding, but may be used to optimize jpeg decoding.
 *          Use 0 for no hinting.
 */
PIX *
pixReadWithHint(const char  *filename,
                l_int32      hint)
{
FILE  *fp;
PIX   *pix;

    PROCNAME("pixReadWithHint");

    if (!filename)
        return (PIX *)ERROR_PTR("filename not defined", procName, NULL);

    if ((fp = fopenReadStream(filename)) == NULL)
        return (PIX *)ERROR_PTR("image file not found", procName, NULL);
    pix = pixReadStream(fp, hint);
    fclose(fp);

    if (!pix)
        return (PIX *)ERROR_PTR("image not returned", procName, NULL);
    return pix;
}
示例#4
0
/*!
 *  pixRead()
 *
 *      Input:  filename (with full pathname or in local directory)
 *      Return: pix if OK; null on error
 *
 *  Notes:
 *      (1) See at top of file for supported formats.
 */
PIX *
pixRead(const char  *filename)
{
    FILE  *fp;
    PIX   *pix;

    PROCNAME("pixRead");

    if (!filename)
        return (PIX *)ERROR_PTR("filename not defined", procName, NULL);

    if ((fp = fopenReadStream(filename)) == NULL) {
        L_ERROR("image file not found: %s\n", procName, filename);
        return NULL;
    }
    if ((pix = pixReadStream(fp, 0)) == NULL) {
        fclose(fp);
        return (PIX *)ERROR_PTR("pix not read", procName, NULL);
    }
    fclose(fp);

    return pix;
}
char* ProcessPagesBuffer(char* buffer, int fileLen, tesseract::TessBaseAPI* api) {
	
	FILE *stream;
	//int ch;
	stream=fmemopen((void*)buffer,fileLen,"rb");
	//int count;
	//while ((ch = fgetc (stream)) != EOF)
	//	printf ("Got %d:%c\n", count++,ch);
	//fclose (stream);
	//puts("''''''''''''''''''");
	
	Pix *pix;
	int page=0;
	STRING mstr;
	
	pix=pixReadStream(stream,0);
	api->ProcessPage(pix, page, NULL, NULL, 0, &mstr);
	const char *tmpStr=mstr.string();
	char *retStr = new char[strlen(tmpStr) + 1];
	strcpy (retStr,tmpStr);
	//printf("ok->%s",retStr);

	return retStr;
 }