Hello,

I attached a cpp file which i tried something with it. It is not a tidy
code but i think you can find some clues on how to use api directory of
tesseract.
Below is the console command on linux that i use to compile this cpp file

g++ deneme234.cpp -I /usr/include/opencv -L/usr/lib
-L/usr/lib/pyshared/python2.7/opencv -lcxcore -lcv -lhighgui -lcvaux -I
/usr/include -I /usr/local/include/leptonica -I /usr/include/leptonica -I
/usr/local/include -I /usr/local/include/tesseract -L/usr/local/lib -I ./
-ltesseract_api -ltesseract_textord -ltesseract_main -ltesseract_wordrec
-ltesseract_classify -ltesseract_dict -ltesseract_viewer -ltesseract_ccutil
-ltesseract_ccstruct -ltesseract_cutil -ltesseract_image -ltiff -lpthread
-L ./ -g -O0 -o deneme2346


2011/11/13 zdenko podobny <[email protected]>

>
>
> On Sun, Nov 13, 2011 at 5:32 AM, cyrt <[email protected]> wrote:
>
>> Could someone please explain how I can use tesseract in c++?
>
>
> use  api/tesseractmain.cpp api/tesseractmain.h as example
>
>> I
>> downloaded the source files via svn and compiled the solution. Which
>> libraries do I now have to link and where do I find an include
>> directory containing all necessary header files?
>>
> officially there is no windows library solution yet.
>
> But have a look at developer forum - there are information with proposed
> solution for library on windows.
>
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "tesseract-ocr" group.
>> To post to this group, send email to [email protected]
>> To unsubscribe from this group, send email to
>> [email protected]
>> For more options, visit this group at
>> http://groups.google.com/group/tesseract-ocr?hl=en
>>
>
>  --
> You received this message because you are subscribed to the Google
> Groups "tesseract-ocr" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/tesseract-ocr?hl=en
>

-- 
You received this message because you are subscribed to the Google
Groups "tesseract-ocr" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/tesseract-ocr?hl=en
#include "deneme234.h"
#include "cvdeneme2.h"

int mainOfTesseract(const char* langString, const char*imageString, const char* outputString, const char* datapathString) {
#ifdef USE_NLS
  setlocale (LC_ALL, "");
  bindtextdomain (PACKAGE, LOCALEDIR);
  textdomain (PACKAGE);
#endif
 
char **argv={};
  // Make the order of args a bit more forgiving than it used to be.
  const char* lang = "eng";
  const char* image = NULL;
  const char* output = NULL;
const char* datapath=NULL;
  tesseract::PageSegMode pagesegmode = tesseract::PSM_SINGLE_CHAR;
  
      lang = langString;
     image = imageString;
      output = outputString;
datapath=datapathString;
   

  tesseract::TessBaseAPI  api;

  api.SetOutputName(output);
  api.Init(datapath, lang, tesseract::OEM_DEFAULT,
           &(argv[0]), 0, NULL, NULL, false);
  // We have 2 possible sources of pagesegmode: a config file and
  // the command line. For backwards compatability reasons, the
  // default in tesseract is tesseract::PSM_SINGLE_BLOCK, but the
  // default for this program is tesseract::PSM_AUTO. We will let
  // the config file take priority, so the command-line default
  // can take priority over the tesseract default, so we use the
  // value from the command line only if the retrieved mode
  // is still tesseract::PSM_SINGLE_BLOCK, indicating no change
  // in any config file. Therefore the only way to force
  // tesseract::PSM_SINGLE_BLOCK is from the command line.
  // It would be simpler if we could set the value before Init,
  // but that doesn't work.
  //if (api.GetPageSegMode() == tesseract::PSM_SINGLE_BLOCK)
    api.SetPageSegMode(pagesegmode);


  FILE* fin = fopen(image, "rb");
  if (fin == NULL) {
    printf("Cannot open input file: %s\n", image);
    exit(2);
  }
  fclose(fin);

  PIX   *pixs;
  if ((pixs = pixRead(image)) == NULL) {
    printf("Unsupported image type.\n");
    exit(3);
  }
  pixDestroy(&pixs);

  STRING text_out;
/*bool TessBaseAPI::ProcessPage(Pix* pix, int page_index, const char* filename,
                              const char* retry_config, int timeout_millisec,
                              STRING* text_out) {

bool TessBaseAPI::ProcessPages(const char* filename,
                               const char* retry_config, int timeout_millisec,
                               STRING* text_out) {

*/
  if (!api.ProcessPages(image, NULL, 0, &text_out)) {
    printf("Error during processing.\n");
  }

tesseract::ResultIterator* ri=api.GetIterator();
Pix* pixa=(*ri).GetBinaryImage(tesseract::RIL_SYMBOL);
printf("%d",(pixa[1]).data);
(*ri).Begin();
printf("-----%s",(*ri).GetUTF8Text(tesseract::RIL_SYMBOL));

tesseract::ChoiceIterator* ci=new tesseract::ChoiceIterator(*ri);
(*ci).Next();
const char *txt=(ci)->GetUTF8Text();
printf("-----%s",(txt));
  STRING outfile = output;
  outfile += ".txt";
  FILE* fout = fopen(outfile.string(), "wb");
  if (fout == NULL) {
    printf("Cannot create output file %s\n", outfile.string());
    exit(1);
  }
  fwrite(text_out.string(), 1, text_out.length(), fout);
  fclose(fout);

  return 0;                      // Normal exit
};


int pixsOfOneWord(const char* langString, const char*imageString, Pix *outputData, const char* datapathString) {
#ifdef USE_NLS
  setlocale (LC_ALL, "");
  bindtextdomain (PACKAGE, LOCALEDIR);
  textdomain (PACKAGE);
#endif
 
char **argv={};
  
  const char* lang = "eng";
  const char* image = NULL;
const char* datapath=NULL;
  tesseract::PageSegMode pagesegmode = tesseract::PSM_SINGLE_CHAR;
  
      lang = langString;
     image = imageString;
datapath=datapathString;
   

  tesseract::TessBaseAPI  api;

  api.Init(datapath, lang, tesseract::OEM_DEFAULT,&(argv[0]), 0, NULL, NULL, false);
    api.SetPageSegMode(pagesegmode);

/*

  FILE* fin = fopen(image, "rb");
  if (fin == NULL) {
    printf("Cannot open input file: %s\n", image);
    exit(2);
  }
  fclose(fin);

  PIX   *pixs;
  if ((pixs = pixRead(image)) == NULL) {
    printf("Unsupported image type.\n");
    exit(3);
  }
  pixDestroy(&pixs);

  STRING text_out;

  if (!api.ProcessPages(image, NULL, 0, &text_out)) {
    printf("Error during processing.\n");
  }
*/
IplImage* img=0;

img=cvLoadImage("paket2copy.png");
printf("width:%d",img->width);
printf("byte depth:%d",img->depth/8);
printf("widthStep:%d",img->widthStep);

api.SetImage((uchar*)img->imageData,img->width,img->height,img->depth/8,img->widthStep);

api.SetRectangle(0,0,img->width, img->height);
int left,top,right,bottom;
left=0;top=0;right=0;bottom=0;
api.Recognize(NULL);
tesseract::ResultIterator *ri=api.GetIterator();
tesseract::ChoiceIterator *choiceItr;
const tesseract::ResultIterator itr = *ri;
choiceItr = new tesseract::ChoiceIterator(itr);
const char * out=choiceItr->GetUTF8Text();
char * out2=(*ri).GetUTF8Text(tesseract::RIL_SYMBOL);
if((*ri).BoundingBox(tesseract::RIL_SYMBOL,&left,&top,&right,&bottom))
{printf("bb dogru\n");printf("%d,%d,%d,%d",left,top,right,bottom);}
printf("out:%s,out2:%s",out,out2);
//pixDestroy(&pixa);

printf("buraya da geldi...\n");
  cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE); 
  cvMoveWindow("mainWin", img->width,img->height);

 printf("buraya da geldi........\n");
  // show the image
  cvShowImage("mainWin", img );

  // wait for a key
  cvWaitKey(0);

  // release the image
  cvReleaseImage(&img );



  return 0;                      // Normal exit
};


/*int main(){

mainOfTesseract("klm","adsizue.tif","outputcikti",".");

return 0;

};*/



int main()
{
  IplImage* img = 0; 
  int height,width,step,channels;
  uchar *data;
  int i,j,k;
Pix* pixa;
pixsOfOneWord("klm", "paket2.tif", pixa, ".");

//img=cvCreateImage(cvSize((int)pixa[0].w,(int)pixa[0].h),IPL_DEPTH_8U,1);

  // get the image data
  /*height    = img->height;
  width     = img->width;
  step      = img->widthStep;
  channels  = img->nChannels;
  data      = (uchar *)img->imageData;
  printf("Processing a %dx%d image with %d channels\n",height,width,channels); 
*/
  // create a window
  //cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE); 
  //cvMoveWindow("mainWin", (int)pixa[0].w,(int)pixa[0].h);
/*
  // invert the image
  for(i=0;i<height;i++) for(j=0;j<width;j++) for(k=0;k<channels;k++)
    data[i*step+j*channels+k]=255-data[i*step+j*channels+k];
*/
  // show the image
  //cvShowImage("mainWin", img );

  // wait for a key
  //cvWaitKey(0);

  // release the image
  //cvReleaseImage(&img );
  return 0;
};

Reply via email to