1

我在 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 有这个文件,你可以在这里看到。

那么,也许某些配置设置为这个最旧的版本并导致冲突?如何更改它并使其适用于最新版本?我认为这一定很容易解决,但我是新手。

提前致谢。

4

2 回答 2

0

CMake 会告诉你该怎么做:

将“OpenCV”的安装前缀添加到 CMAKE_PREFIX_PATH 或将“OpenCV_DIR”设置为包含上述文件之一的目录。

另一种选择 - 请再次阅读CMakeLists.txt您粘贴的文件中的评论。

他们说:

您可能需要将 OpenCV_DIR 变量设置为包含 OpenCVConfig.cmake 的目录的绝对路径

另一个问题 - 源内构建,通过将点传递给 cmake 来执行。最好为构建文件创建单独的目录。

以这种方式构建可以让您轻松地将构建目录添加到.gitignore并且不会用编译的二进制文件污染源代码存储库。此外,如果出现问题,您可以删除该构建目录并从头开始。这比一个一个地处理文件要容易得多。

所以,你需要像下面这样调用 CMake

mkdir build
cd build 
OpenCV_DIR=/home/dell/opencv cmake ..

或者

mkdir build
cd build
cmake .. -DCMAKE_PREFIX_PATH=/home/dell/opencv

或以下也应该做的伎俩

mkdir build
cd build
cmake .. -DOpenCV_DIR=/home/dell/opencv
于 2019-09-20T07:11:31.533 回答
0

如下更新您的 OpenCV 搜索目录路径,

find_package(OpenCV 3.4 REQUIRED PATHS "/usr/local/opencv/" NO_DEFAULT_PATH)
于 2019-09-20T11:10:55.713 回答