How Can We Help?
OCR on a Multipage TIFF Image File (C++)
This function process several images stored in a TIFF file. The OCR results are stored in a text file.
void myOutputHandler(int infotype,int param);
FILE *file; // file handler for result file
int ProcessFile(const char *tifffile, const char *resultfile)
{
SETOFIMG *set;
IMG *img;
int i;
// load TIFF file
set=LoadMultipleImg(tifffile);
// check for error
if (!set)
return -1;
// Open result file
file=fopen(resultfile,"w");
// Initialize OCR engine
SetLanguage(ENGLISH,".");
SetOutputMode(OM_TEXT);
OCRSetOutputHandler(myOutputHandler);
for(i=0;i<GetNbImages(set);i++)
{
// get an image
img=GetImage(set,i);
// process it
CR(img,0);
}
// free the set
FreeMultipleImg(set);
// close result file
fclose(file);
}
This function uses a OCR output handler that is defined now:
void myOutputHandler(int infotype,int param)
{
int i;
switch(infotype)
{
case OT_TEXT:
fprintf(file,"%c",(char) param);
break;
case OT_ENDL:
fprintf(file,"\\n");
break;
case OT_ENDZ:
fprintf(file,"\\n\\n");
}
}