zl程序教程

您现在的位置是:首页 >  后端

当前栏目

Could not find a package configuration file provided by “OpenCV“ with any of the following names: Op

Opencv The not of with File by Find
2023-09-11 14:19:19 时间

使用Cmake报错

CMake Error at CMakeLists.txt:12 (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.

方法已经给出

1.Add the installation prefix of “OpenCV” to CMAKE_PREFIX_PATH
or
2.set “OpenCV_DIR” to a directory containing one of the above files
翻译:

1.将opencv安装目录添加到CMAKE_PREFIX_PATH

例如,按照错误信息指示,在CMakeLists.txt中加入一行list,路径要改成自己的opencv安装路径。

list(APPEND CMAKE_PREFIX_PATH "/home/xiaoming/opencv4.5.5/")
find_package(OpenCV REQUIRED)

或者
2.设置OpenCV_DIR为一个包含OpenCVConfig.cmake或者opencv-config.cmake的目录

按照错误信息指示,在CMakeLists.txt中加入一行set OpenCV_DIR,以opencv4为例,后面的路径要改成你的路径,注意不是安装根目录,是安装目录中包含OpenCVConfig.cmake的文件夹路径

set(OpenCV_DIR /opt/opencv4.5.5/lib/cmake/opencv4)
find_package(OpenCV REQUIRED)