tesseract api使用

tangshi.jpg
#include 
#include 

int main()
{
   char *outText;
 
    tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();
    
    // Initialize tesseract-ocr with English, without specifying tessdata path
    if (api->Init(NULL, "chi_sim")) 
    {
        fprintf(stderr, "Could not initialize tesseract.\n");
        exit(1);
    }
 
    // Open input image with leptonica library
    Pix *image = pixRead("tangshi.jpg");
    api->SetImage(image);
    
    // Get 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;
}
g++ -o myprogram myprogram.cpp -llept -ltesseract -std=c++11 

你可能感兴趣的:(tesseract api使用)