美文网首页
c++调用tesseract api识别汉字

c++调用tesseract api识别汉字

作者: 一路向后 | 来源:发表于2022-10-01 19:53 被阅读0次

    1.源码实现

    #include <iostream>
    #include <leptonica/allheaders.h>
    #include <tesseract/baseapi.h>
    
    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识别汉字

          本文链接:https://www.haomeiwen.com/subject/wjbdartx.html