c++调用tesseract api识别汉字

1.源码实现

#include 
#include 
#include 

using namespace std;

int main()
{
    tesseract::TessBaseAPI *api = NULL;
    Pix *image = NULL;
    char *outText;

    api = new tesseract::TessBaseAPI();

    if(api->Init(NULL, "chi_sim"))
    {
        fprintf(stderr, "Could not initialize tesseract.\n");

        delete api;

        exit(1);
    }

    image = pixRead("1.png");

    api->SetImage(image);

    outText = api->GetUTF8Text();

    cout << outText << endl;

    api->End();

    pixDestroy(&image);

    delete api;

    delete outText;

    return 0;
}

2.测试图片

1.png

3.编译源码

$ g++ -o test test.cpp -std=c++11 -I/usr/local/tesseract/include -L/usr/local/tesseract/lib -ltesseract -llept -Wl,-rpath=/usr/local/tesseract/lib

4.运行及其结果

$ ./test
你 好

你可能感兴趣的:(c++调用tesseract api识别汉字)