Tesseract provide c++ library. Version 3.02 (at the moment it is in the svn) will bring also MSVC library on Windows (minwg library is possible to create too).
So it is a time for simple example that shows how to call tesseract-ocr from your c++ program. It could be compiled by gcc.
Let’s create file ‘simple-ocr.cpp’ with most simple code:
notextile..
#include <baseapi.h> #include <allheaders.h> #include <sys/time.h>
int main() { // [1] tesseract::TessBaseAPI *myOCR = new tesseract::TessBaseAPI(); // [2] printf(“Tesseract-ocr version: %s\n”, myOCR->Version()); printf(“Leptonica version: %s\n”, getLeptonicaVersion()); // [3] if (myOCR->Init(NULL, “eng”)) { fprintf(stderr, “Could not initialize tesseract.\n”); exit(1); } // [4] Pix *pix = pixRead(“phototest.tif”); myOCR->SetImage(pix); // [5] char* outText = myOCR->GetUTF8Text(); printf(“OCR output:\n\n”); printf(outText); // [6] myOCR->Clear(); myOCR->End(); delete [] outText; pixDestroy(&pix); return 0; }
You can compile with this command (maybe you need to adjust your path to tesseract and leptonica header files):
$ g++ test_simple.cpp -o test_simple \ -I/usr/include/leptonica \ -I/usr/local/include/tesseract \ -llept -ltesseract
It will create executable ‘test_simple’, that you can run.