How to use Tesseract OCR with Cmake on Windows?

Viewed 1287

I'm tryint to use tesseract in my cmake project on Windows. I installed tesseract 5.0 and tesseract 4.0. They both come with no cmake folder so the line

find_package(Tesseract REQUIRED)

produces

CMake Error at CMakeLists.txt:14 (find_package):
  By not providing "FindTesseract.cmake" in CMAKE_MODULE_PATH this project
  has asked CMake to find a package configuration file provided by
  "Tesseract", but CMake did not find one.

  Could not find a package configuration file provided by "Tesseract"
  (requested version 4.0) with any of the following names:

    TesseractConfig.cmake
    tesseract-config.cmake

  Add the installation prefix of "Tesseract" to CMAKE_PREFIX_PATH or set
  "Tesseract_DIR" to a directory containing one of the above files.  If
  "Tesseract" provides a separate development package or SDK, be sure it has
  been installed.

However, in the installation folder for tesseract 5.0, there's libtesseract-5.dll and many others. Can I link those in my cmake project? If so, how? And why there are no include files in the installation folder? How am I suppose to include the .h files in my project?

2 Answers

UB-Mannheim installer is autotools build and it has only runtime part of tesseract (e.g. executables and linked libraries). You can not use it for any development because it does not provide needed files (libraries and header files), so missing cmake files are reasonable consequences of this installation. You can check this information in detail where installer finished.

Have you tried using the MSYS/Mingw build of tesseract: pacman -S mingw-w64-x86_64-tesseract-ocr? Since there is no cmake config file you will have to use pkg_check_modules instead (see also cMakefile for using tesseract and opencv without the opencv bit)

Related