gpt4 book ai didi

opencv - CMake搜索OpenCV库

转载 作者:行者123 更新时间:2023-12-02 17:41:22 25 4
gpt4 key购买 nike

我已经安装了Opencv-3.2,可以看到bin和lib文件

$ ls /share/apps/computer/opencv-3.2.0/built/bin/opencv_
opencv_annotation opencv_createsamples opencv_traincascade opencv_version opencv_visualisation
$ ls /share/apps/computer/opencv-3.2.0/built/lib/
libopencv_calib3d.so libopencv_imgcodecs.so.3.2.0 libopencv_stitching.so.3.2
libopencv_calib3d.so.3.2 libopencv_imgproc.so libopencv_stitching.so.3.2.0
libopencv_calib3d.so.3.2.0 libopencv_imgproc.so.3.2 libopencv_superres.so
libopencv_core.so libopencv_imgproc.so.3.2.0 libopencv_superres.so.3.2
libopencv_core.so.3.2 libopencv_ml.so libopencv_superres.so.3.2.0
libopencv_core.so.3.2.0 libopencv_ml.so.3.2 libopencv_videoio.so
libopencv_features2d.so libopencv_ml.so.3.2.0 libopencv_videoio.so.3.2
libopencv_features2d.so.3.2 libopencv_objdetect.so libopencv_videoio.so.3.2.0
libopencv_features2d.so.3.2.0 libopencv_objdetect.so.3.2 libopencv_video.so
libopencv_flann.so libopencv_objdetect.so.3.2.0 libopencv_video.so.3.2
libopencv_flann.so.3.2 libopencv_photo.so libopencv_video.so.3.2.0
libopencv_flann.so.3.2.0 libopencv_photo.so.3.2 libopencv_videostab.so
libopencv_highgui.so libopencv_photo.so.3.2.0 libopencv_videostab.so.3.2
libopencv_highgui.so.3.2 libopencv_shape.so libopencv_videostab.so.3.2.0
libopencv_highgui.so.3.2.0 libopencv_shape.so.3.2 pkgconfig/
libopencv_imgcodecs.so libopencv_shape.so.3.2.0
libopencv_imgcodecs.so.3.2 libopencv_stitching.so

现在,根据 tutorial,我编写了一个简单的程序。问题是, cmake出现一些错误,似乎无法找到该库。
CMake Error at CMakeLists.txt:3 (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.

我不知道如何设置 CMAKE_PREFIX_PATHOpenCV_DIR。我该如何解决?

CMakeLists.txt的内容是
cmake_minimum_required(VERSION 2.8)
project( DisplayImage )
find_package( OpenCV REQUIRED )
add_executable( DisplayImage DisplayImage.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )

最佳答案

这取决于您是否具有OpenCVConfig.cmake脚本,该脚本随OpenCV的安装一起提供(即,在安装目录/share/apps/computer/opencv-3.2.0/built/下)。

如果您安装的OpenCV 缺少OpenCVConfig.cmake脚本的,则需要使用脚本FindOpenCV.cmake运送您的项目(查找并从网上复制它,几乎任何一种都适用),并将带有此脚本的目录添加到CMAKE_MODULE_PATH变量中:

list(APPEND CMAKE_MODULE_PATH <directory-with-find-script>)

提示CMake有关您的OpenCV安装的可能方法:
  • 如果您具有OpenCVConfig.cmake脚本,请将OpenCV_DIR变量设置为包含此脚本的目录:
    cmake -DOpenCV_DIR=/share/apps/computer/opencv-3.2.0/built/<...>
  • CMAKE_PREFIX_PATH变量设置为OpenCV的安装前缀:
    cmake -DCMAKE_PREFIX_PATH=/share/apps/computer/opencv-3.2.0/built

    这适用于OpenCVConfig.cmakeFindOpenCV.cmake脚本。另请参见该问题:Hinting Find<name>.cmake Files with a custom directory
  • 关于opencv - CMake搜索OpenCV库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44355096/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com