Advertisement
zdenop

tesseract-ocr API example in C++

Jun 13th, 2013
699
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. /*
  2.   Basic tesseract-ocr API example in C++
  3. */
  4.  
  5. #include <tesseract/baseapi.h>
  6. #include <leptonica/allheaders.h>
  7.  
  8. int main()
  9. {
  10.     char *outText;
  11.  
  12.     tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();
  13.     // Initialize tesseract-ocr with English, without specifying tessdata path
  14.     if (api->Init(NULL, "eng")) {
  15.         fprintf(stderr, "Could not initialize tesseract.\n");
  16.         exit(1);
  17.     }
  18.  
  19.     // Open input image with leptonica library
  20.     Pix *pix = pixRead("/usr/src/tesseract-3.02/phototest.tif");
  21.     api->SetImage(image);
  22.     // Get OCR result
  23.     outText = api->GetUTF8Text();
  24.     printf("OCR output:\n%s", outText);
  25.  
  26.     // Destroy used object and release memory
  27.     api->End();
  28.     delete [] outText;
  29.     pixDestroy(&pix);
  30.  
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement