Qt5 and Tesseract 3.04.01in Ubuntu



  • Hallo, I am integrating Tesseract OCR in Qt. While in the Debug mode (no optimization used ..!), everything works perfect. The OCR result ist quite good in debug mode. But when I just run without debugging, it just outputs totally wrong ( but everytime same result ) result. I dont know where to start. Because when I compile the same code (without Qt Framework code ) in linux GCC, it works great. Please give me any hint, where to start digging..

    Will be very thankful for any hint.. !!


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    That's pretty strange. Are you sure you are linking against the correct libraries ? i.e. release version of Tesseract when build against release version of your application ?



  • Actually I compiled tesseract myself from source. I have also tried to link against library downloaded via "apt-get install tesseract-ocr". But same result.. I am really stuck now.. Thinking of IPC between two binaries (Qt for frontend and Mingw compiled binary for backend...!), but it's not effective way though..!

    Regards...!!


  • Lifetime Qt Champion

    Can you provide a minimal sample that shows that strange behavior ?



  • Hallo,
    Here the result in Debug version : Link
    And here the result in Run Version : Link

    With Regards


  • Lifetime Qt Champion

    Silly question, is it only the visualization that's messed or is it the result returned by tesseract that is different ? e.g. does printing the string on the console show the same difference ?



  • Hi,
    It has nothing to do with output.. I met some interesting scenario. When I create the Qt project in commandline without QAppliction framework

    int main(int argc, char *argv[])
    {
    //QApplication a(argc, argv);
     CODE
    //return a.exec();.
    }
    

    it just works fine. As soon as I uncomment QApplication a(argc, argv); and return a.exec(); it just gives wrong result.. I dont know now, what effect has QApplication Framework on Tesseract Code..??


  • Lifetime Qt Champion

    How are you initializing the tesseract API ?



  • #include <QApplication>
    #include <tesseract/baseapi.h>
    #include <leptonica/allheaders.h>
    
    int main()
    {
        //QApplication a(argc, argv);
        char *outText;
    
        tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();
       
        if (api->Init(NULL, "eng")) {
            fprintf(stderr, "Could not initialize tesseract.\n");
            exit(1);
        }
    
       
        Pix *image = pixRead("/home/ubuntu/Desktop/image.png");
    	
    	api->SetPageSegMode(tesseract::PSM_AUTO_OSD);
        api->SetImage(image);
       
        // OCR result
        outText = api->GetUTF8Text();
        printf("OCR output:\n%s", outText);
    
        // Destroy used object and release memory
        api->End();
        delete [] outText;
        pixDestroy(&image);
    
        return 0;
       //return a.exec();
    }
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.