我在 Linux Mint 19.1 Tessa 上。
我按照此处描述的说明安装 OpenCV。现在我将它安装在目录“/home/dell/opencv”中。
我尝试通过运行命令“cmake”来运行位于“/home/dell/opencv/samples/cpp/example_cmake/”的示例项目。在终端上,我收到以下错误:
CMake Error at CMakeLists.txt:14 (find_package):
By not providing "FindOpenCV.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "OpenCV", but
CMake did not find one.
Could not find a package configuration file provided by "OpenCV" with any
of the following names:
OpenCVConfig.cmake
opencv-config.cmake
Add the installation prefix of "OpenCV" to CMAKE_PREFIX_PATH or set
"OpenCV_DIR" to a directory containing one of the above files. If "OpenCV"
provides a separate development package or SDK, be sure it has been
installed.
-- Configuring incomplete, errors occurred!
See also "/home/dell/opencv/samples/cpp/example_cmake/CMakeFiles/CMakeOutput.log".
“CMakeLists.txt”文件包含以下内容:
# cmake needs this line
cmake_minimum_required(VERSION 3.1)
# Enable C++11
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
# Define project name
project(opencv_example_project)
# Find OpenCV, you may need to set OpenCV_DIR variable
# to the absolute path to the directory containing OpenCVConfig.cmake file
# via the command line or GUI
find_package(OpenCV REQUIRED)
# If the package has been found, several variables will
# be set, you can find the full list with descriptions
# in the OpenCVConfig.cmake file.
# Print some message showing some of them
message(STATUS "OpenCV library status:")
message(STATUS " config: ${OpenCV_DIR}")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
# Declare the executable target built from your sources
add_executable(opencv_example example.cpp)
# Link your application with OpenCV libraries
target_link_libraries(opencv_example LINK_PRIVATE ${OpenCV_LIBS})
我通过互联网搜索了很多,这似乎是一个常见问题。但是,我仍然没有按照我找到的说明来解决它。
我在浏览 OpenCV 文件夹时注意到的一件事是,我拥有的版本(我认为它是最新的)确实不包含任何“OpenCVConfig.cmake”文件,正如您在此处看到的那样。但是,我在 github 上找到的最旧版本的 OpenCV 有这个文件,你可以在这里看到。
那么,也许某些配置设置为这个最旧的版本并导致冲突?如何更改它并使其适用于最新版本?我认为这一定很容易解决,但我是新手。
提前致谢。