Advertisement
zdenop

tesseract-ocr: output word font attributes example

Jan 15th, 2013
935
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.61 KB | None | 0 0
  1. /*
  2.   g++ -o test_font_features test_font_features-2.cpp -ltesseract
  3. */
  4.  
  5. #include <tesseract/baseapi.h>
  6. #include <leptonica/allheaders.h>
  7.  
  8. int main() {
  9.     tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();
  10.  
  11.     if (api->Init(NULL, "eng")) {
  12.         fprintf(stderr, "Could not initialize tesseract.\n");
  13.         exit(1);
  14.     }
  15.  
  16.     Pix *pix = pixRead("/usr/src/tesseract-3.02/phototest.tif");
  17.     api->SetImage(pix);
  18.  
  19.     int lcount = 1;
  20.     api->Recognize(0);
  21.     tesseract::ResultIterator* ri = api->GetIterator();
  22.     if (ri != 0) {
  23.         do {
  24.             const char* word = ri->GetUTF8Text(tesseract::RIL_WORD);
  25.             if (word != 0) {
  26.                 const char *font_name;
  27.                 bool bold, italic, underlined, monospace, serif, smallcaps;
  28.                 int pointsize, font_id;
  29.                 font_name = ri->WordFontAttributes(&bold, &italic, &underlined,
  30.                                                    &monospace, &serif,
  31.                                                    &smallcaps, &pointsize,
  32.                                                    &font_id);
  33.                 printf("%s \t=> fontname: %s, size: %d, font_id: %d, bold: %d,"\
  34.                        " italic: %d, underlined: %d, monospace: %d, serif: %d,"\
  35.                        " smallcap: %d\n", word, font_name, pointsize, font_id,
  36.                        bold, italic, underlined, monospace, serif, smallcaps);
  37.             }
  38.             delete[] word;
  39.             lcount++;
  40.         } while (ri->Next(tesseract::RIL_WORD));
  41.     }
  42.  
  43.     delete ri;
  44.     api->End();
  45.     pixDestroy(&pix);
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement