我正在尝试从 tesseract 4.1.1 源代码生成一个 Visual Studio 2019 C++ 项目。最终,我想在我的自定义解决方案中包含一个使用 OCR 结果的 tesseract C++ 项目。
当我按照以下步骤操作时:
C:\Windows\System32>cd "C:\tesseract"
C:\tesseract>mkdir 构建
C:\tesseract>cd build
C:\tesseract\build>cmake ..
我收到此错误:
Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)
CMake Error at CMakeLists.txt:224 (find_package):
Could not find a package configuration file provided by "Leptonica"
(requested version 1.74) with any of the following names:
LeptonicaConfig.cmake
leptonica-config.cmake
Add the installation prefix of "Leptonica" to CMAKE_PREFIX_PATH or set
"Leptonica_DIR" to a directory containing one of the above files. If
"Leptonica" provides a separate development package or SDK, be sure it has
been installed.
-- Configuring incomplete, errors occurred!
See also "C:/tesseract/build/CMakeFiles/CMakeOutput.log".
这是 CMakeLists.txt 文件的相关部分:
find_package(PkgConfig)
if(PKG_CONFIG_EXECUTABLE AND NOT Leptonica_DIR)
pkg_check_modules(Leptonica REQUIRED lept>=${MINIMUM_LEPTONICA_VERSION})
link_directories(${Leptonica_LIBRARY_DIRS})
else()
find_package(Leptonica ${MINIMUM_LEPTONICA_VERSION} REQUIRED CONFIG)
endif()
if (NOT Leptonica_FOUND)
message(FATAL_ERROR "Cannot find required library Leptonica. Quitting!")
endif(NOT Leptonica_FOUND)
find_package(LibArchive)
if(LibArchive_FOUND)
set(HAVE_LIBARCHIVE ON)
endif()
解决方案:
在学习了 user898678 提供的教程和实验之后,这是我学到的东西。
教程中列出的命令(以及下面提供的列表中)可以在正常的命令提示符下执行。它们不需要在 Visual Studio 的开发人员命令提示中执行。
教程(一般来说)使它非常混乱,因为它们试图包含所有内容和每个场景的步骤。就我而言,我只是在为 Tesseract 寻找一个有效的 VS 项目。 user898678 提供的这个 blogpost 是最有用的。我将运行所需的命令提炼为以下内容:
set INSTALL_DIR="C:\Temp\Tesseract"
set PATH=%PATH%;%INSTALL_DIR%\bin
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\Build\vcvars64.bat" x64
set INCLUDE=%INCLUDE%;%INSTALL_DIR%\include
set LIBPATH=%LIBPATH%;%INSTALL_DIR%\lib
git clone --depth 1 https://github.com/DanBloomberg/leptonica.git
cd leptonica
cmake -Bbuild -DCMAKE_BUILD_TYPE=Release ^
-DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% -DCMAKE_PREFIX_PATH=%INSTALL_DIR% ^
-DBUILD_PROG=OFF -DSW_BUILD=OFF -DBUILD_SHARED_LIBS=ON
cmake --build build --config Release --target install
cd ..
git clone -b 4.1.1 --depth 1 https://github.com/tesseract-ocr/tesseract.git
cd tesseract
cmake -Bbuild -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% ^
-DCMAKE_PREFIX_PATH=%INSTALL_DIR% ^
-DLeptonica_DIR=%INSTALL_DIR%\lib\cmake ^
-DBUILD_TRAINING_TOOLS=OFF -DSW_BUILD=OFF ^
-DOPENMP_BUILD=OFF -DBUILD_SHARED_LIBS=ON
cmake --build build --config Release --target install
对我来说,在剔除分散在命令语法中的所有讨论和说明后,命令变得更容易理解。
答案 0 :(得分:0)
有几个教程如何使用 cmake 和 VS 在 Windows 上构建 tesseract,例如https://bucket401.blogspot.com/2021/03/building-tesserocr-on-ms-windows-64bit.html(您可以忽略教程结束 - python 模块)、minimalist tesseract 或 with clang