#include <iostream>
#include <string>
#include <tesseract/baseapi.h>
#include <leptonica/allheaders.h>
#include <opencv2/opencv.hpp>

using namespace std;
using namespace cv;

int main()
{
    string outText = "", imPath = "image.jpeg";
    Mat im = cv::imread(imPath, cv::IMREAD_GRAYSCALE);
    cv::bitwise_not(im, im);
    cv::imwrite("image_inverted.jpeg", im);

    tesseract::TessBaseAPI* ocr = new tesseract::TessBaseAPI();

    if (ocr->Init(NULL, "Impact"))
    {
        cout << "Failed to initialize." << endl;
    }
    else
    {
        //ocr->SetVariable("tessedit_char_whitelist", "ABCDEFGHIJKLMNOP");
        ocr->SetVariable("user_defined_dpi", "96");
        //ocr->SetVariable("unlv_tilde_crunching", "false");
        //ocr->SetImage(im.data, im.cols, im.rows, 1, im.cols);
        Pix* image = pixRead("image_inverted.jpeg");
        ocr->SetImage(image);

        cout << "test1" << endl;
        char* str = ocr->GetUTF8Text();
        outText = string(str);
        cout << outText << endl;
        cout << "test2" << endl;

        ocr->Clear();
        //ocr->End();

        delete ocr;
        if (str)
            delete[] str;
        pixDestroy(&image);
    }

    system("pause");
}

VS2019 - v142
Windows 10
vcpkg build of Tesseract (static libs) - 4.1.1#5

-- 
You received this message because you are subscribed to the Google Groups 
"tesseract-ocr" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to tesseract-ocr+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tesseract-ocr/774d1a41-1e6e-4bcd-951f-290e3b65e723n%40googlegroups.com.

Reply via email to