Search code examples
c++packageinstallationtesseractvcpkg

Tesseract install using vcpkg in Windows 10


My setup: Currently I'm working with c++ in visual studio 2017 on Windows 10.

The objective: To start using tesseract ocr in my basic c++ application. First, to make sure I'm able to #include the tesseract library and compile and execute a very simple program, I'm trying to run the simple test program below, provided on the official tesseract project's "APIExample" page.

What I've done so far: Following the advice of this stack overflow answer, I've ran the vcpkg install tesseract:x64-windows command in the command prompt along with the command .\vcpkg integrate install. When I run the command vcpkg list I see all of the packages that I installed(shown below in screenshot), but despite this intellisense in visual studio gives me errors saying it can't find the includes to run the aforementioned test project whose code I've posted below. What gives? I've provided a screenshot below of my visual studio setup with the errors and error codes produced for reference.

#include <tesseract/baseapi.h>
#include <leptonica/allheaders.h>

int main()
{
    char *outText;

    tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();
    // Initialize tesseract-ocr with English, without specifying tessdata path
    if (api->Init(NULL, "eng")) {
        fprintf(stderr, "Could not initialize tesseract.\n");
        exit(1);
    }

    // Open input image with leptonica library
    Pix *image = pixRead("/usr/src/tesseract/testing/phototest.tif");
    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;
}

enter image description here

enter image description here


Solution

  • Looks like your tesseract package has been installed for x64 platform, but your project settings seems to be in x86. Correct that and ensure you choose "multi-threaded dynamically linked" in the library settings. If all goes well, MSCV IDE will automatically copy those dependency DLLs to your application directory at runtime.