2

So I've linked OpenCV already and that was pretty straightforward and there are many guides online how to do it.

But I don't know how to go about downloading Tesseract for usage in one's own applications. I want to get the API and use it in my code in conjunction with OpenCV. Can anyone guide me through what I need to download and what settings I'd need to tinker with to achieve this?

Eshmam
  • 53
  • 1
  • 7

2 Answers2

1

Install vcpkg ( MS packager to install windows based open source projects) and use powershell command like so .\vcpkg install tesseract:x64-windows-static. Dependency libraries like Leptonica will be auto installed for you. The tesseract can be auto integrated to your VS project using .\vcpkg integrate install.

seccpur
  • 4,996
  • 2
  • 13
  • 21
  • Okay where should I do this bit: .\vcpkg integrate install. Also, would I need to mess around with the solution settings such as specifying include libs or additional dependencies? – Eshmam Oct 20 '19 at 18:07
  • Once you installed vcpkg, you can open Powershell to enter these command lines. You can also mannually specify the location of the .h and .lib – seccpur Oct 20 '19 at 23:51
0

I had a similar problem and in this thread I shared my experience on how I solved it. May be helpful for someone. I'll cope the text here:

I've been trying to link tesseract library to my c++ project in Visual Studio 2019 for a couple of days and I finally managed to do it. Any thread that I found or even official tesseract documentation do not have full list of instructions on what to do.

I'll list what I have done, hopefully it will help someone. I don't pretend its the optimal way to do so.

  1. There are basic tips in official tesseract documentation. Go to "Windows" section. I did install sw and cppan but I guess it wasn't necessary. The main thing here is installing vcpkg. It requiers Git so I installed it. then:

    > cd c:tools (I installed it in c:\tools, you may choose any dir)

    > git clone https://github.com/microsoft/vcpkg

    > .\vcpkg\bootstrap-vcpkg.bat

    > .\vcpkg\vcpkg install tesseract:x64-windows-static (I used x64 version)

    > .\vcpkg\vcpkg integrate install

At this point everything should work, they said. Headers should be included, libs should be linked. But none was working for me.

  1. Change project configuration to Release x64 (or Release x86 if you installed x86 tesseract).

  2. To include headers: Go to project properties -> C/C++ -> General. Set Additional Include Directories to C:\tools\vcpkg\installed\x64-windows-static\include (or whereever you installed vcpkg)

  3. To link libraries : project properties -> Linker -> General. Set Additional Library Directories to C:\tools\vcpkg\installed\x64-windows-static\lib

  4. Project properties -> C/C++ -> Code Generation. Set Runtime Library to Multi-threaded(/MT). Otherwise I got errors like "runtime mismatch static vs DLL"

  5. Tesseract lib couldn't link to its dependcies, so I added all libs that I had installed to C:\tools\vcpkg\installed\x64-windows-static\lib. Project properties -> Linker -> Input. I set Additional Dependencies to archive.lib;bz2.lib;charset.lib;gif.lib;iconv.lib;jpeg.lib;leptonica-1.80.0.lib;libcrypto.lib;libpng16.lib;libssl.lib;libwebpmux.lib;libxml2.lib;lz4.lib;lzma.lib;lzo2.lib;openjp2.lib;tesseract41.lib;tiff.lib;tiffxx.lib;turbojpeg.lib;webp.lib;webpdecoder.lib;webpdemux.lib;xxhash.lib;zlib.lib;zstd_static.lib;%(AdditionalDependencies)

And after that it finally compiled and launched.

But... api->Init returned -1. To work with tesseract you should have tessdata directory with .traineddata files for the languages you need.

  1. Download tessdata. I got it from official docs. BTW, tessdata_fast worked better than tessdata_best for my purposes :) So I downloaded single "eng" file and saved it like C:\tools\TesseractData\tessdata\eng.traineddata.

  2. Then I added environment variable TESSDATA_PREFIX with value C:\tools\TesseractData\tessdata. I also added C:\tools\TesseractData to Path variables (just in case)

And after all this it is finally working for me.

Nick
  • 71
  • 1
  • 2